wiecej klas

This commit is contained in:
s464859 2022-03-24 11:28:11 +01:00
parent c4a623ae6d
commit 531fa42e75
7 changed files with 145 additions and 45 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

View File

@ -4,20 +4,20 @@ from random import randrange
class AI:
window:system.Window
map:minesweeper.Map
current_map:minesweeper.Map
saper:minesweeper.Minesweeper
#jak True to można się poruszać strzałkami, jak False sam się porusza
user_controlled=False
def __init__(self, window, map, saper):
def __init__(self, window, current_map, saper):
self.window = window
self.map = map
self.current_map = current_map
self.saper = saper
#co ma zrobić tylko na początku
def ready(self):
pass
self.saper.set_map(self.current_map)
#co ma robić przy każdym FPS'ie
def update(self):
@ -31,21 +31,21 @@ class AI:
def minesweeper_controls(self):
keys = pygame.key.get_pressed()
if keys[pygame.K_DOWN]:
self.saper.move(self.map, 0)
self.saper.move(0)
elif keys[pygame.K_UP]:
self.saper.move(self.map, 180)
self.saper.move(180)
elif keys[pygame.K_LEFT]:
self.saper.move(self.map, 270)
self.saper.move(270)
elif keys[pygame.K_RIGHT]:
self.saper.move(self.map, 90)
self.saper.move(90)
def chaos_controls(self):
dir = randrange(4)
if dir==0:
self.saper.move(self.map, 0)
self.saper.move(0)
elif dir==1:
self.saper.move(self.map, 180)
self.saper.move(180)
elif dir==2:
self.saper.move(self.map, 270)
self.saper.move(270)
elif dir==3:
self.saper.move(self.map, 90)
self.saper.move(90)

View File

@ -9,10 +9,11 @@ class Mine:
position_x:int
position_y:int
size:int
difficulty:int = 1
weight:float = 1.0
image:pygame.surface.Surface
difficulty:int = 1
weight:float = 1.0
def __init__(self,position_x, position_y, size):
self.position_x=position_x
self.position_y=position_y
@ -30,22 +31,29 @@ class Cliff:
size:int
image:pygame.surface.Surface
type: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_y=position_y
self.size=size
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.rotate(self.image, self.rotation)
def draw(self, window):
position_on_screen = (self.size*self.position_x, self.size*self.position_y)
window.blit(self.image, position_on_screen)
#mapa
@ -76,7 +84,6 @@ class Map:
image = pygame.image.load("assets/sprites/stone.png")
image = pygame.transform.scale(image, (tile_size,tile_size))
self.tile_palette[10]=image
def generate(self):
#generowanie terenu
@ -84,14 +91,33 @@ class Map:
for i in range(self.tiles_y):
matrix.append([])
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
rng = randrange(10)
if rng==0:
if ok and rng==0 and not (i<2 and j<3):
matrix[i].append(10)
elif rng<2:
elif ok and rng<2 and not (i<2 and j<3):
matrix[i].append(0)
cliff = Cliff(j,i,self.tile_size, randrange(4)*90)
#self.cliffs.append(cliff)
rand_rotate = 0#randrange(4)*90
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:
matrix[i].append(0)
self.terrain_matrix = matrix
@ -99,7 +125,12 @@ class Map:
for i in range(self.tiles_y):
for j in range(self.tiles_x):
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)
self.mines.append(mine)
@ -115,6 +146,57 @@ class Map:
for cliff in self.cliffs:
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
class Minesweeper:
@ -125,6 +207,7 @@ class Minesweeper:
rotated_image:pygame.surface.Surface
offset_x:int=0
offset_y:int=0
current_map:Map
carried_objects=[]
@ -141,15 +224,10 @@ class Minesweeper:
self.image = pygame.transform.scale(self.image, (self.size, self.size))
self.rotated_image = self.image
def check_position(self, map:Map):
for mine in map.mines:
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 set_map(self, map:Map):
self.current_map = map
def update_offset(self, delta:float, map):
def update_offset(self, delta:float):
dist=round(self.speed*delta/8)
finished=False
if self.offset_x>0:
@ -173,15 +251,14 @@ class Minesweeper:
pygame.mixer.Channel(1).stop()
self.offset_y=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)
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
#wschód - 90
#północ - 180
@ -192,28 +269,31 @@ class Minesweeper:
self.rotated_image = pygame.transform.rotate(self.image, dir)
move_legal=True
cliff_jump=False
if dir==0:
if self.position_y+1 == map.tiles_y:
if self.position_y+1 == self.current_map.tiles_y:
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
elif dir==180:
if self.position_y-1 == -1:
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
elif dir==270:
if self.position_x-1 == -1:
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
elif dir==90:
if self.position_x+1 == map.tiles_x:
if self.position_x+1 == self.current_map.tiles_x:
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
if move_legal:
if cliff_jump:
pass
pygame.mixer.Channel(1).set_volume(0.3)
pygame.mixer.Channel(1).play(pygame.mixer.Sound("assets/sounds/moving.wav"))
if dir==0:
@ -230,4 +310,24 @@ class Minesweeper:
self.offset_x=-self.size
else:
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

View File

@ -11,7 +11,7 @@ TILES_X = 16
TILES_Y = 10
#wł/wył muzyki
MUSIC=True
MUSIC=False
#ustalenie FPS
FPS = 60
@ -51,7 +51,7 @@ def main():
#narysowanie terenu i obiektów
map.draw_tiles()
map.draw_objects()
saper.draw(window.window, delta, map)
saper.draw(window.window, delta)
#odświeżenie ekranu
pygame.display.update()