wiecej klas
This commit is contained in:
parent
c4a623ae6d
commit
531fa42e75
Binary file not shown.
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 6.4 KiB |
BIN
assets/sprites/cliff_corner.png
Normal file
BIN
assets/sprites/cliff_corner.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.4 KiB |
BIN
assets/sprites/cliff_end1.png
Normal file
BIN
assets/sprites/cliff_end1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.4 KiB |
BIN
assets/sprites/cliff_end2.png
Normal file
BIN
assets/sprites/cliff_end2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.5 KiB |
@ -4,20 +4,20 @@ from random import randrange
|
|||||||
|
|
||||||
class AI:
|
class AI:
|
||||||
window:system.Window
|
window:system.Window
|
||||||
map:minesweeper.Map
|
current_map:minesweeper.Map
|
||||||
saper:minesweeper.Minesweeper
|
saper:minesweeper.Minesweeper
|
||||||
|
|
||||||
#jak True to można się poruszać strzałkami, jak False sam się porusza
|
#jak True to można się poruszać strzałkami, jak False sam się porusza
|
||||||
user_controlled=False
|
user_controlled=False
|
||||||
|
|
||||||
def __init__(self, window, map, saper):
|
def __init__(self, window, current_map, saper):
|
||||||
self.window = window
|
self.window = window
|
||||||
self.map = map
|
self.current_map = current_map
|
||||||
self.saper = saper
|
self.saper = saper
|
||||||
|
|
||||||
#co ma zrobić tylko na początku
|
#co ma zrobić tylko na początku
|
||||||
def ready(self):
|
def ready(self):
|
||||||
pass
|
self.saper.set_map(self.current_map)
|
||||||
|
|
||||||
#co ma robić przy każdym FPS'ie
|
#co ma robić przy każdym FPS'ie
|
||||||
def update(self):
|
def update(self):
|
||||||
@ -31,21 +31,21 @@ class AI:
|
|||||||
def minesweeper_controls(self):
|
def minesweeper_controls(self):
|
||||||
keys = pygame.key.get_pressed()
|
keys = pygame.key.get_pressed()
|
||||||
if keys[pygame.K_DOWN]:
|
if keys[pygame.K_DOWN]:
|
||||||
self.saper.move(self.map, 0)
|
self.saper.move(0)
|
||||||
elif keys[pygame.K_UP]:
|
elif keys[pygame.K_UP]:
|
||||||
self.saper.move(self.map, 180)
|
self.saper.move(180)
|
||||||
elif keys[pygame.K_LEFT]:
|
elif keys[pygame.K_LEFT]:
|
||||||
self.saper.move(self.map, 270)
|
self.saper.move(270)
|
||||||
elif keys[pygame.K_RIGHT]:
|
elif keys[pygame.K_RIGHT]:
|
||||||
self.saper.move(self.map, 90)
|
self.saper.move(90)
|
||||||
|
|
||||||
def chaos_controls(self):
|
def chaos_controls(self):
|
||||||
dir = randrange(4)
|
dir = randrange(4)
|
||||||
if dir==0:
|
if dir==0:
|
||||||
self.saper.move(self.map, 0)
|
self.saper.move(0)
|
||||||
elif dir==1:
|
elif dir==1:
|
||||||
self.saper.move(self.map, 180)
|
self.saper.move(180)
|
||||||
elif dir==2:
|
elif dir==2:
|
||||||
self.saper.move(self.map, 270)
|
self.saper.move(270)
|
||||||
elif dir==3:
|
elif dir==3:
|
||||||
self.saper.move(self.map, 90)
|
self.saper.move(90)
|
@ -9,9 +9,10 @@ class Mine:
|
|||||||
position_x:int
|
position_x:int
|
||||||
position_y:int
|
position_y:int
|
||||||
size:int
|
size:int
|
||||||
|
image:pygame.surface.Surface
|
||||||
|
|
||||||
difficulty:int = 1
|
difficulty:int = 1
|
||||||
weight:float = 1.0
|
weight:float = 1.0
|
||||||
image:pygame.surface.Surface
|
|
||||||
|
|
||||||
def __init__(self,position_x, position_y, size):
|
def __init__(self,position_x, position_y, size):
|
||||||
self.position_x=position_x
|
self.position_x=position_x
|
||||||
@ -30,14 +31,23 @@ class Cliff:
|
|||||||
size:int
|
size:int
|
||||||
image:pygame.surface.Surface
|
image:pygame.surface.Surface
|
||||||
|
|
||||||
|
type:int
|
||||||
rotation:int
|
rotation:int
|
||||||
|
|
||||||
def __init__(self,position_x, position_y, size, rotation):
|
def __init__(self,position_x, position_y, size, rotation, type=0):
|
||||||
self.position_x=position_x
|
self.position_x=position_x
|
||||||
self.position_y=position_y
|
self.position_y=position_y
|
||||||
self.size=size
|
self.size=size
|
||||||
self.rotation = rotation
|
self.rotation = rotation
|
||||||
self.image = pygame.image.load("assets/sprites/cliff.png")
|
self.type = type
|
||||||
|
if self.type==0:
|
||||||
|
self.image = pygame.image.load("assets/sprites/cliff.png")
|
||||||
|
elif self.type==1:
|
||||||
|
self.image = pygame.image.load("assets/sprites/cliff_corner.png")
|
||||||
|
elif self.type==2:
|
||||||
|
self.image = pygame.image.load("assets/sprites/cliff_end1.png")
|
||||||
|
elif self.type==3:
|
||||||
|
self.image = pygame.image.load("assets/sprites/cliff_end2.png")
|
||||||
self.image = pygame.transform.scale(self.image, (self.size, self.size))
|
self.image = pygame.transform.scale(self.image, (self.size, self.size))
|
||||||
self.image = pygame.transform.rotate(self.image, self.rotation)
|
self.image = pygame.transform.rotate(self.image, self.rotation)
|
||||||
|
|
||||||
@ -46,8 +56,6 @@ class Cliff:
|
|||||||
window.blit(self.image, position_on_screen)
|
window.blit(self.image, position_on_screen)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#mapa
|
#mapa
|
||||||
class Map:
|
class Map:
|
||||||
window:system.Window
|
window:system.Window
|
||||||
@ -77,21 +85,39 @@ class Map:
|
|||||||
image = pygame.transform.scale(image, (tile_size,tile_size))
|
image = pygame.transform.scale(image, (tile_size,tile_size))
|
||||||
self.tile_palette[10]=image
|
self.tile_palette[10]=image
|
||||||
|
|
||||||
|
|
||||||
def generate(self):
|
def generate(self):
|
||||||
#generowanie terenu
|
#generowanie terenu
|
||||||
matrix = []
|
matrix = []
|
||||||
for i in range(self.tiles_y):
|
for i in range(self.tiles_y):
|
||||||
matrix.append([])
|
matrix.append([])
|
||||||
for j in range(self.tiles_x):
|
for j in range(self.tiles_x):
|
||||||
|
#sprawdza czy są tu jakieś klify
|
||||||
|
ok = True
|
||||||
|
for cliff in self.cliffs:
|
||||||
|
for i2 in range(i-1,i+2):
|
||||||
|
if (j, i2) == (cliff.position_x, cliff.position_y):
|
||||||
|
ok = False
|
||||||
|
break
|
||||||
|
elif (j-1, i2) == (cliff.position_x, cliff.position_y):
|
||||||
|
ok = False
|
||||||
|
break
|
||||||
|
elif (j+1, i2) == (cliff.position_x, cliff.position_y):
|
||||||
|
ok = False
|
||||||
|
break
|
||||||
#od liczby zależy jaki teren, np. 0 - piasek
|
#od liczby zależy jaki teren, np. 0 - piasek
|
||||||
rng = randrange(10)
|
rng = randrange(10)
|
||||||
if rng==0:
|
if ok and rng==0 and not (i<2 and j<3):
|
||||||
matrix[i].append(10)
|
matrix[i].append(10)
|
||||||
elif rng<2:
|
elif ok and rng<2 and not (i<2 and j<3):
|
||||||
matrix[i].append(0)
|
matrix[i].append(0)
|
||||||
cliff = Cliff(j,i,self.tile_size, randrange(4)*90)
|
rand_rotate = 0#randrange(4)*90
|
||||||
#self.cliffs.append(cliff)
|
if rand_rotate==0 and j+3<self.tiles_x and not (i==0 or i==self.tiles_y-1 or j==0 or j==self.tiles_x-1):
|
||||||
|
cliff = Cliff(j,i,self.tile_size, rand_rotate, type=2)
|
||||||
|
self.cliffs.append(cliff)
|
||||||
|
cliff = Cliff(j+1,i,self.tile_size, rand_rotate, type=0)
|
||||||
|
self.cliffs.append(cliff)
|
||||||
|
cliff = Cliff(j+2,i,self.tile_size, rand_rotate, type=3)
|
||||||
|
self.cliffs.append(cliff)
|
||||||
else:
|
else:
|
||||||
matrix[i].append(0)
|
matrix[i].append(0)
|
||||||
self.terrain_matrix = matrix
|
self.terrain_matrix = matrix
|
||||||
@ -99,7 +125,12 @@ class Map:
|
|||||||
for i in range(self.tiles_y):
|
for i in range(self.tiles_y):
|
||||||
for j in range(self.tiles_x):
|
for j in range(self.tiles_x):
|
||||||
if matrix[i][j]<10:
|
if matrix[i][j]<10:
|
||||||
if randrange(10)==0:
|
ok = True
|
||||||
|
for cliff in self.cliffs:
|
||||||
|
if (j, i) == (cliff.position_x, cliff.position_y):
|
||||||
|
ok = False
|
||||||
|
break
|
||||||
|
if ok and randrange(10)==0 and not (i<2 and j<3):
|
||||||
mine = Mine(j, i, self.tile_size)
|
mine = Mine(j, i, self.tile_size)
|
||||||
self.mines.append(mine)
|
self.mines.append(mine)
|
||||||
|
|
||||||
@ -115,6 +146,57 @@ class Map:
|
|||||||
for cliff in self.cliffs:
|
for cliff in self.cliffs:
|
||||||
cliff.draw(self.window.window)
|
cliff.draw(self.window.window)
|
||||||
|
|
||||||
|
#broń
|
||||||
|
class Weapon:
|
||||||
|
size:int
|
||||||
|
image:pygame.surface.Surface
|
||||||
|
rotated_image:pygame.surface.Surface
|
||||||
|
|
||||||
|
owner:str
|
||||||
|
weight:float
|
||||||
|
weapon_type:int
|
||||||
|
|
||||||
|
#baza operacji
|
||||||
|
class Base:
|
||||||
|
position_x:int
|
||||||
|
position_y:int
|
||||||
|
size:int
|
||||||
|
image:pygame.surface.Surface
|
||||||
|
|
||||||
|
weapon_level:int
|
||||||
|
weapons=[]
|
||||||
|
|
||||||
|
#schron
|
||||||
|
class Shelter:
|
||||||
|
position_x:int
|
||||||
|
position_y:int
|
||||||
|
size:int
|
||||||
|
image:pygame.surface.Surface
|
||||||
|
|
||||||
|
#składowisko
|
||||||
|
class Dumpster:
|
||||||
|
position_x:int
|
||||||
|
position_y:int
|
||||||
|
size:int
|
||||||
|
image:pygame.surface.Surface
|
||||||
|
|
||||||
|
|
||||||
|
#cywile
|
||||||
|
class NPC:
|
||||||
|
position_x:int
|
||||||
|
position_y:int
|
||||||
|
size:int
|
||||||
|
image:pygame.surface.Surface
|
||||||
|
rotated_image:pygame.surface.Surface
|
||||||
|
offset_x:int=0
|
||||||
|
offset_y:int=0
|
||||||
|
current_map:Map
|
||||||
|
|
||||||
|
type:int
|
||||||
|
value:int
|
||||||
|
weight:float
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#saper
|
#saper
|
||||||
class Minesweeper:
|
class Minesweeper:
|
||||||
@ -125,6 +207,7 @@ class Minesweeper:
|
|||||||
rotated_image:pygame.surface.Surface
|
rotated_image:pygame.surface.Surface
|
||||||
offset_x:int=0
|
offset_x:int=0
|
||||||
offset_y:int=0
|
offset_y:int=0
|
||||||
|
current_map:Map
|
||||||
|
|
||||||
carried_objects=[]
|
carried_objects=[]
|
||||||
|
|
||||||
@ -141,15 +224,10 @@ class Minesweeper:
|
|||||||
self.image = pygame.transform.scale(self.image, (self.size, self.size))
|
self.image = pygame.transform.scale(self.image, (self.size, self.size))
|
||||||
self.rotated_image = self.image
|
self.rotated_image = self.image
|
||||||
|
|
||||||
def check_position(self, map:Map):
|
def set_map(self, map:Map):
|
||||||
for mine in map.mines:
|
self.current_map = map
|
||||||
if (self.position_x, self.position_y) == (mine.position_x, mine.position_y):
|
|
||||||
map.mines.remove(mine)
|
|
||||||
pygame.mixer.Channel(3).set_volume(0.7)
|
|
||||||
pygame.mixer.Channel(3).play(pygame.mixer.Sound("assets/sounds/pickup.wav"))
|
|
||||||
break
|
|
||||||
|
|
||||||
def update_offset(self, delta:float, map):
|
def update_offset(self, delta:float):
|
||||||
dist=round(self.speed*delta/8)
|
dist=round(self.speed*delta/8)
|
||||||
finished=False
|
finished=False
|
||||||
if self.offset_x>0:
|
if self.offset_x>0:
|
||||||
@ -173,15 +251,14 @@ class Minesweeper:
|
|||||||
pygame.mixer.Channel(1).stop()
|
pygame.mixer.Channel(1).stop()
|
||||||
self.offset_y=0
|
self.offset_y=0
|
||||||
self.offset_x=0
|
self.offset_x=0
|
||||||
self.check_position(map)
|
|
||||||
|
|
||||||
|
|
||||||
def draw(self, window, delta:float, map):
|
def draw(self, window, delta:float):
|
||||||
position_on_screen = (self.size*self.position_x + self.offset_x, self.size*self.position_y + self.offset_y)
|
position_on_screen = (self.size*self.position_x + self.offset_x, self.size*self.position_y + self.offset_y)
|
||||||
window.blit(self.rotated_image, position_on_screen)
|
window.blit(self.rotated_image, position_on_screen)
|
||||||
self.update_offset(delta, map)
|
self.update_offset(delta)
|
||||||
|
|
||||||
def move(self, map:Map, dir:int):
|
def move(self, dir:int):
|
||||||
#południe - 0
|
#południe - 0
|
||||||
#wschód - 90
|
#wschód - 90
|
||||||
#północ - 180
|
#północ - 180
|
||||||
@ -192,28 +269,31 @@ class Minesweeper:
|
|||||||
self.rotated_image = pygame.transform.rotate(self.image, dir)
|
self.rotated_image = pygame.transform.rotate(self.image, dir)
|
||||||
|
|
||||||
move_legal=True
|
move_legal=True
|
||||||
|
cliff_jump=False
|
||||||
if dir==0:
|
if dir==0:
|
||||||
if self.position_y+1 == map.tiles_y:
|
if self.position_y+1 == self.current_map.tiles_y:
|
||||||
move_legal=False
|
move_legal=False
|
||||||
elif map.terrain_matrix[self.position_y+1][self.position_x]>9:
|
elif self.current_map.terrain_matrix[self.position_y+1][self.position_x]>9:
|
||||||
move_legal=False
|
move_legal=False
|
||||||
elif dir==180:
|
elif dir==180:
|
||||||
if self.position_y-1 == -1:
|
if self.position_y-1 == -1:
|
||||||
move_legal=False
|
move_legal=False
|
||||||
elif map.terrain_matrix[self.position_y-1][self.position_x]>9:
|
elif self.current_map.terrain_matrix[self.position_y-1][self.position_x]>9:
|
||||||
move_legal=False
|
move_legal=False
|
||||||
elif dir==270:
|
elif dir==270:
|
||||||
if self.position_x-1 == -1:
|
if self.position_x-1 == -1:
|
||||||
move_legal=False
|
move_legal=False
|
||||||
elif map.terrain_matrix[self.position_y][self.position_x-1]>9:
|
elif self.current_map.terrain_matrix[self.position_y][self.position_x-1]>9:
|
||||||
move_legal=False
|
move_legal=False
|
||||||
elif dir==90:
|
elif dir==90:
|
||||||
if self.position_x+1 == map.tiles_x:
|
if self.position_x+1 == self.current_map.tiles_x:
|
||||||
move_legal=False
|
move_legal=False
|
||||||
elif map.terrain_matrix[self.position_y][self.position_x+1]>9:
|
elif self.current_map.terrain_matrix[self.position_y][self.position_x+1]>9:
|
||||||
move_legal=False
|
move_legal=False
|
||||||
|
|
||||||
if move_legal:
|
if move_legal:
|
||||||
|
if cliff_jump:
|
||||||
|
pass
|
||||||
pygame.mixer.Channel(1).set_volume(0.3)
|
pygame.mixer.Channel(1).set_volume(0.3)
|
||||||
pygame.mixer.Channel(1).play(pygame.mixer.Sound("assets/sounds/moving.wav"))
|
pygame.mixer.Channel(1).play(pygame.mixer.Sound("assets/sounds/moving.wav"))
|
||||||
if dir==0:
|
if dir==0:
|
||||||
@ -231,3 +311,23 @@ class Minesweeper:
|
|||||||
else:
|
else:
|
||||||
pygame.mixer.Channel(2).set_volume(0.5)
|
pygame.mixer.Channel(2).set_volume(0.5)
|
||||||
pygame.mixer.Channel(2).play(pygame.mixer.Sound("assets/sounds/collision.wav"))
|
pygame.mixer.Channel(2).play(pygame.mixer.Sound("assets/sounds/collision.wav"))
|
||||||
|
|
||||||
|
def pick_up(self):
|
||||||
|
if self.offset_x!=0 or self.offset_y!=0:
|
||||||
|
return
|
||||||
|
for mine in self.current_map.mines:
|
||||||
|
if (self.position_x, self.position_y) == (mine.position_x, mine.position_y):
|
||||||
|
self.current_map.mines.remove(mine)
|
||||||
|
pygame.mixer.Channel(3).set_volume(0.7)
|
||||||
|
pygame.mixer.Channel(3).play(pygame.mixer.Sound("assets/sounds/pickup.wav"))
|
||||||
|
break
|
||||||
|
|
||||||
|
def drop_bombs(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def drop_civilians(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def sensor(self):
|
||||||
|
sensor_list = [[],[],[]]
|
||||||
|
return sensor_list
|
4
main.py
4
main.py
@ -11,7 +11,7 @@ TILES_X = 16
|
|||||||
TILES_Y = 10
|
TILES_Y = 10
|
||||||
|
|
||||||
#wł/wył muzyki
|
#wł/wył muzyki
|
||||||
MUSIC=True
|
MUSIC=False
|
||||||
|
|
||||||
#ustalenie FPS
|
#ustalenie FPS
|
||||||
FPS = 60
|
FPS = 60
|
||||||
@ -51,7 +51,7 @@ def main():
|
|||||||
#narysowanie terenu i obiektów
|
#narysowanie terenu i obiektów
|
||||||
map.draw_tiles()
|
map.draw_tiles()
|
||||||
map.draw_objects()
|
map.draw_objects()
|
||||||
saper.draw(window.window, delta, map)
|
saper.draw(window.window, delta)
|
||||||
|
|
||||||
#odświeżenie ekranu
|
#odświeżenie ekranu
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
Loading…
Reference in New Issue
Block a user