Added splash & end screens beta

This commit is contained in:
Marcin Kostrzewski 2019-01-31 19:23:25 +01:00
parent 2973df597e
commit aedbd71588
13 changed files with 72 additions and 22 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
data/graphics/end0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

BIN
data/graphics/endp1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

BIN
data/graphics/endp2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 158 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 580 B

View File

@ -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

View File

@ -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)
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
@ -74,6 +117,8 @@ while events.mainloop:
#draw_debug_text()
all_sprites.draw(screen)
pygame.display.flip()
print('asd')
endscreen()
clear_round()
firstrun=False
pygame.quit()
sys.exit()

View File

@ -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')
@ -112,6 +111,9 @@ 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)
@ -136,6 +138,9 @@ class Bullet(pygame.sprite.Sprite):
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):
pygame.sprite.Sprite.__init__(self)
@ -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):