Added HP Bars

This commit is contained in:
Marcin 2019-01-31 09:17:12 +01:00
parent c45ead5bb8
commit 2973df597e
15 changed files with 48 additions and 9 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -4,7 +4,7 @@ from pygame.locals import *
# Runtime settings # Runtime settings
WINDOW_WIDTH = 720 WINDOW_WIDTH = 720
WINDOW_HEIGHT = 720 WINDOW_HEIGHT = 1000
FPS = 30 FPS = 30
WIN_NAME = "Kostschevsky's shooter" WIN_NAME = "Kostschevsky's shooter"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 556 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 83 KiB

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 162 B

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 228 B

After

Width:  |  Height:  |  Size: 211 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 227 B

After

Width:  |  Height:  |  Size: 239 B

BIN
data/graphics/splash.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View File

@ -24,6 +24,11 @@ clock2=pygame.time.Clock()
clock2.tick() clock2.tick()
timer2=1000 timer2=1000
bars=[]
bars.append(HPBar(200,886))
bars.append(HPBar(570,886))
def events(): def events():
global running global running
for event in pygame.event.get(): for event in pygame.event.get():
@ -57,8 +62,10 @@ def bullethits():
hits2=pygame.sprite.groupcollide(p1_group, p2_bullet_group, False, True) hits2=pygame.sprite.groupcollide(p1_group, p2_bullet_group, False, True)
if hits1: if hits1:
players[1].gothit() players[1].gothit()
bars[1].gothit()
if hits2: if hits2:
players[0].gothit() players[0].gothit()
bars[0].gothit()
def player1_input(keys): def player1_input(keys):
if keys[P1_SHOOT]: if keys[P1_SHOOT]:

View File

@ -1,6 +1,6 @@
# import all files # import all files
from config import * from config import *
from sprites import Player, all_sprites, load_img, screen from sprites import Player, all_sprites, load_img, screen, HPBar, load_img_noalpha
from colours import * from colours import *
import maps import maps
import events import events
@ -25,7 +25,7 @@ events.p1_group.add(events.players[0])
events.p2_group.add(events.players[1]) events.p2_group.add(events.players[1])
all_sprites.add(events.players) all_sprites.add(events.players)
events.running=True events.running=True
all_sprites.add(events.bars)
# debug text # debug text
font=pygame.font.SysFont("Arial", 12) font=pygame.font.SysFont("Arial", 12)
@ -40,14 +40,25 @@ def draw_debug_text():
screen.blit(text, (0,count*12)) screen.blit(text, (0,count*12))
count+=1 count+=1
bg, bg_rect=load_img("bg.png") bg, bg_rect=load_img_noalpha("bg.png")
splash, splash_rect=load_img_noalpha("splash.png")
def waitforkey():
waiting=True
while waiting:
clock.tick(FPS)
keys=pygame.key.get_pressed()
if keys[pygame.K_SPACE]:
waiting=False
def startscreen(): def startscreen():
screen.fill(BGCOLOR) screen.blit(splash,(0,0))
pygame.display.flip()
waitforkey()
# game loop # game loop
while events.mainloop: while events.mainloop:
print('asd') #startscreen()
while events.running: while events.running:
clock.tick(FPS) clock.tick(FPS)
# events # events
@ -60,7 +71,7 @@ while events.mainloop:
break break
# draw # draw
screen.blit(bg,(0,0)) screen.blit(bg,(0,0))
draw_debug_text() #draw_debug_text()
all_sprites.draw(screen) all_sprites.draw(screen)
pygame.display.flip() pygame.display.flip()
print('asd') print('asd')

View File

@ -17,6 +17,12 @@ def load_img(name):
image.set_colorkey(colorkey, RLEACCEL) image.set_colorkey(colorkey, RLEACCEL)
return image, image.get_rect() return image, image.get_rect()
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()
def load_sound(name): def load_sound(name):
sound_path=os.path.join('data/sounds') sound_path=os.path.join('data/sounds')
sound=pygame.mixer.Sound(sound_path) sound=pygame.mixer.Sound(sound_path)
@ -25,7 +31,6 @@ def load_sound(name):
# sprite groups # sprite groups
all_sprites=pygame.sprite.Group() all_sprites=pygame.sprite.Group()
# sprites classes # sprites classes
vec=pygame.math.Vector2 vec=pygame.math.Vector2
@ -130,3 +135,19 @@ class Bullet(pygame.sprite.Sprite):
self.shoot() self.shoot()
if not pygame.sprite.spritecollideany(self, maps.bwalls, collided = None)==None: if not pygame.sprite.spritecollideany(self, maps.bwalls, collided = None)==None:
self.kill() self.kill()
class HPBar(pygame.sprite.Sprite):
def __init__(self, x, y):
pygame.sprite.Sprite.__init__(self)
self.image=pygame.Surface((150, 30))
self.image.fill((87,156,135))
self.rect=self.image.get_rect()
self.rect.center=((x, y))
self.width=150
def gothit(self):
self.width-=int(150*(BULLET_DMG/100))
self.image=pygame.transform.scale(self.image, (self.width, 30))
def update(self):
self.gothit