czas, waga i kolor

This commit is contained in:
s464859 2022-05-05 18:35:07 +02:00
parent 2aa596db5f
commit 414211131b
5 changed files with 36 additions and 3 deletions

BIN
assets/sprites/mine2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
assets/sprites/mine3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
assets/sprites/mine4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -10,20 +10,45 @@ class Mine:
position_y:int
size:int
image:pygame.surface.Surface
image_text:pygame.surface.Surface
timer_text:pygame.surface.Surface
timer_event:pygame.USEREVENT
font:pygame.font.Font
difficulty:int = 1
weight:float = 1.0
explosion_timer:int = 100
def __init__(self,position_x, position_y, size):
def __init__(self,position_x, position_y, size, difficulty=1, weight=1.0, timer=100):
self.position_x=position_x
self.position_y=position_y
self.size=size
self.image = pygame.image.load("assets/sprites/mine_fun_sized.png")
self.weight = weight
self.explosion_timer = timer
self.difficulty = difficulty
if self.difficulty == 2:
self.image = pygame.image.load("assets/sprites/mine2.png")
elif self.difficulty == 3:
self.image = pygame.image.load("assets/sprites/mine3.png")
elif self.difficulty == 4:
self.image = pygame.image.load("assets/sprites/mine4.png")
else:
self.image = pygame.image.load("assets/sprites/mine_fun_sized.png")
self.image = pygame.transform.scale(self.image, (self.size, self.size))
self.font = pygame.font.SysFont('Comic Sans MS', int(self.size*0.4))
self.image_text = self.font.render(str(self.weight), False, (0, 0, 0))
self.timer_text = self.font.render(str(self.explosion_timer), False, (255, 0, 0))
timer_interval = 1000
self.timer_event = pygame.USEREVENT + 1
pygame.time.set_timer(self.timer_event , timer_interval)
def draw(self, window):
self.timer_text = self.font.render(str(self.explosion_timer), False, (255, 0, 0))
position_on_screen = (self.size*self.position_x, self.size*self.position_y)
window.blit(self.image, position_on_screen)
window.blit(self.image_text, (position_on_screen[0]+self.size/4, position_on_screen[1]+self.size/2))
window.blit(self.timer_text, (position_on_screen[0]+self.size/4, position_on_screen[1]-self.size/8))
class Cliff:
position_x:int
@ -137,7 +162,10 @@ class Map:
ok = False
break
if ok and randrange(10)==0 and not (i<2 and j<3):
mine = Mine(j, i, self.tile_size)
difficulty = randrange(0,4)+1
weight = randrange(10, 31)/10
timer = randrange(100, 200)
mine = Mine(j, i, self.tile_size, difficulty, weight, timer)
self.mines.append(mine)
def draw_tiles(self):

View File

@ -16,6 +16,8 @@ MUSIC = False
# ustalenie FPS
FPS = 60
#włączenie tekstu
pygame.font.init()
def main():
if MUSIC:
@ -70,6 +72,9 @@ def main():
if event.type == pygame.QUIT:
game_loop = False
pygame.quit()
elif event.type in [i.timer_event for i in map.mines]:
for i in map.mines:
i.explosion_timer-=1
if __name__ == "__main__":