diff --git a/__pycache__/colours.cpython-37.pyc b/__pycache__/colours.cpython-37.pyc index bcc151a..e756ecd 100644 Binary files a/__pycache__/colours.cpython-37.pyc and b/__pycache__/colours.cpython-37.pyc differ diff --git a/__pycache__/config.cpython-37.pyc b/__pycache__/config.cpython-37.pyc index be4139e..dec1aeb 100644 Binary files a/__pycache__/config.cpython-37.pyc and b/__pycache__/config.cpython-37.pyc differ diff --git a/__pycache__/events.cpython-37.pyc b/__pycache__/events.cpython-37.pyc index cf24544..90e9840 100644 Binary files a/__pycache__/events.cpython-37.pyc and b/__pycache__/events.cpython-37.pyc differ diff --git a/__pycache__/maps.cpython-37.pyc b/__pycache__/maps.cpython-37.pyc index 07b85ce..243fdd1 100644 Binary files a/__pycache__/maps.cpython-37.pyc and b/__pycache__/maps.cpython-37.pyc differ diff --git a/__pycache__/sprites.cpython-37.pyc b/__pycache__/sprites.cpython-37.pyc index c289118..43edba8 100644 Binary files a/__pycache__/sprites.cpython-37.pyc and b/__pycache__/sprites.cpython-37.pyc differ diff --git a/data/graphics/end0.png b/data/graphics/end0.png new file mode 100644 index 0000000..fe335d6 Binary files /dev/null and b/data/graphics/end0.png differ diff --git a/data/graphics/endp1.png b/data/graphics/endp1.png new file mode 100644 index 0000000..7244fa1 Binary files /dev/null and b/data/graphics/endp1.png differ diff --git a/data/graphics/endp2.png b/data/graphics/endp2.png new file mode 100644 index 0000000..cacd1f0 Binary files /dev/null and b/data/graphics/endp2.png differ diff --git a/data/graphics/hp.png b/data/graphics/hp.png deleted file mode 100644 index e655c46..0000000 Binary files a/data/graphics/hp.png and /dev/null differ diff --git a/data/graphics/qwe.png b/data/graphics/qwe.png deleted file mode 100644 index daf57cd..0000000 Binary files a/data/graphics/qwe.png and /dev/null differ diff --git a/events.py b/events.py index 60fed3a..bec50ba 100644 --- a/events.py +++ b/events.py @@ -26,14 +26,13 @@ timer2=1000 bars=[] -bars.append(HPBar(200,886)) -bars.append(HPBar(570,886)) - def events(): global running for event in pygame.event.get(): if event.type == pygame.QUIT: - running=False + pygame.quit() + sys.exit() + #running=False def collision_check(p): # collision between players diff --git a/mygame.py b/mygame.py index 95cea72..47bd168 100644 --- a/mygame.py +++ b/mygame.py @@ -17,15 +17,14 @@ pygame.init() pygame.display.set_caption(WIN_NAME) clock=pygame.time.Clock() -# initialize two players +# init resources + +bg=load_img_noalpha("bg.png") +splash=load_img_noalpha("splash.png") +end=load_img_noalpha("end0.png") +p2end=load_img_noalpha("endp1.png") +p1end=load_img_noalpha("endp2.png") -events.players.append(Player('p1', 400, 100, 10)) -events.players.append(Player('p2', 430, 300, 10)) -events.p1_group.add(events.players[0]) -events.p2_group.add(events.players[1]) -all_sprites.add(events.players) -events.running=True -all_sprites.add(events.bars) # debug text font=pygame.font.SysFont("Arial", 12) @@ -40,25 +39,69 @@ def draw_debug_text(): screen.blit(text, (0,count*12)) count+=1 -bg, bg_rect=load_img_noalpha("bg.png") -splash, splash_rect=load_img_noalpha("splash.png") +def init_round(): + events.players.append(Player('p1', 400, 100, 10)) + events.players.append(Player('p2', 430, 300, 10)) + events.p1_group.add(events.players[0]) + events.p2_group.add(events.players[1]) + all_sprites.add(events.players) + events.running=True + events.bars.append(HPBar(200,886)) + events.bars.append(HPBar(570,886)) + all_sprites.add(events.bars) + +def clear_round(): + events.players[0].delete() + events.players[1].delete() + for i in events.p1_bullet: + i.delete() + for i in events.p2_bullet: + i.delete() + events.p1_group.remove() + events.p2_group.remove() + events.players.clear() + events.bars.clear() + events.p1_bullet.clear() + events.p2_bullet.clear() + events.p1_bullet_group.remove() + events.p2_bullet_group.remove() + all_sprites.remove() def waitforkey(): waiting=True while waiting: - clock.tick(FPS) + clock.tick(FPS) + pygame.event.pump() + events.event_handler() keys=pygame.key.get_pressed() if keys[pygame.K_SPACE]: waiting=False + if keys[pygame.K_ESCAPE]: + pygame.quit() + sys.exit() def startscreen(): screen.blit(splash,(0,0)) pygame.display.flip() waitforkey() - + +def endscreen(): + if events.players[0].hp<=0 and events.players[1].hp<=0: #both players dead + screen.blit(end,(0,0)) + elif events.players[0].hp<=0: + screen.blit(p1end,(0,0)) + elif events.players[1].hp<=0: + screen.blit(p2end,(0,0)) + pygame.display.flip() + waitforkey() + # game loop +firstrun=True while events.mainloop: - #startscreen() + init_round() + if firstrun: + startscreen() + pygame.event.clear() while events.running: clock.tick(FPS) # events @@ -73,7 +116,9 @@ while events.mainloop: screen.blit(bg,(0,0)) #draw_debug_text() all_sprites.draw(screen) - pygame.display.flip() - print('asd') + pygame.display.flip() + endscreen() + clear_round() + firstrun=False pygame.quit() sys.exit() \ No newline at end of file diff --git a/sprites.py b/sprites.py index 122a297..b514000 100644 --- a/sprites.py +++ b/sprites.py @@ -20,8 +20,7 @@ def load_img(name): def load_img_noalpha(name): img_path=os.path.join('data/graphics', name) image=pygame.image.load(img_path).convert() - colorkey=image.get_at((0,0)) - return image, image.get_rect() + return image def load_sound(name): sound_path=os.path.join('data/sounds') @@ -111,7 +110,10 @@ class Player(pygame.sprite.Sprite): def update(self): self.move() - + + def delete(self): + self.kill() + class Bullet(pygame.sprite.Sprite): def __init__(self, fname, x, y, direction): pygame.sprite.Sprite.__init__(self) @@ -135,6 +137,9 @@ class Bullet(pygame.sprite.Sprite): self.shoot() if not pygame.sprite.spritecollideany(self, maps.bwalls, collided = None)==None: self.kill() + + def delete(self): + self.kill() class HPBar(pygame.sprite.Sprite): def __init__(self, x, y): @@ -147,6 +152,7 @@ class HPBar(pygame.sprite.Sprite): def gothit(self): self.width-=int(150*(BULLET_DMG/100)) + self.width=max([self.width, 0]) self.image=pygame.transform.scale(self.image, (self.width, 30)) def update(self):