Added HP Bars
@ -4,7 +4,7 @@ from pygame.locals import *
|
||||
|
||||
# Runtime settings
|
||||
WINDOW_WIDTH = 720
|
||||
WINDOW_HEIGHT = 720
|
||||
WINDOW_HEIGHT = 1000
|
||||
FPS = 30
|
||||
WIN_NAME = "Kostschevsky's shooter"
|
||||
|
||||
|
Before Width: | Height: | Size: 556 B |
Before Width: | Height: | Size: 83 KiB After Width: | Height: | Size: 92 KiB |
Before Width: | Height: | Size: 162 B After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 228 B After Width: | Height: | Size: 211 B |
Before Width: | Height: | Size: 227 B After Width: | Height: | Size: 239 B |
BIN
data/graphics/splash.png
Normal file
After Width: | Height: | Size: 26 KiB |
@ -24,6 +24,11 @@ clock2=pygame.time.Clock()
|
||||
clock2.tick()
|
||||
timer2=1000
|
||||
|
||||
bars=[]
|
||||
|
||||
bars.append(HPBar(200,886))
|
||||
bars.append(HPBar(570,886))
|
||||
|
||||
def events():
|
||||
global running
|
||||
for event in pygame.event.get():
|
||||
@ -57,8 +62,10 @@ def bullethits():
|
||||
hits2=pygame.sprite.groupcollide(p1_group, p2_bullet_group, False, True)
|
||||
if hits1:
|
||||
players[1].gothit()
|
||||
bars[1].gothit()
|
||||
if hits2:
|
||||
players[0].gothit()
|
||||
bars[0].gothit()
|
||||
|
||||
def player1_input(keys):
|
||||
if keys[P1_SHOOT]:
|
||||
|
23
mygame.py
@ -1,6 +1,6 @@
|
||||
# import all files
|
||||
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 *
|
||||
import maps
|
||||
import events
|
||||
@ -25,7 +25,7 @@ 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,14 +40,25 @@ def draw_debug_text():
|
||||
screen.blit(text, (0,count*12))
|
||||
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():
|
||||
screen.fill(BGCOLOR)
|
||||
screen.blit(splash,(0,0))
|
||||
pygame.display.flip()
|
||||
waitforkey()
|
||||
|
||||
# game loop
|
||||
while events.mainloop:
|
||||
print('asd')
|
||||
#startscreen()
|
||||
while events.running:
|
||||
clock.tick(FPS)
|
||||
# events
|
||||
@ -60,7 +71,7 @@ while events.mainloop:
|
||||
break
|
||||
# draw
|
||||
screen.blit(bg,(0,0))
|
||||
draw_debug_text()
|
||||
#draw_debug_text()
|
||||
all_sprites.draw(screen)
|
||||
pygame.display.flip()
|
||||
print('asd')
|
||||
|
23
sprites.py
@ -17,6 +17,12 @@ def load_img(name):
|
||||
image.set_colorkey(colorkey, RLEACCEL)
|
||||
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):
|
||||
sound_path=os.path.join('data/sounds')
|
||||
sound=pygame.mixer.Sound(sound_path)
|
||||
@ -25,7 +31,6 @@ def load_sound(name):
|
||||
# sprite groups
|
||||
|
||||
all_sprites=pygame.sprite.Group()
|
||||
|
||||
# sprites classes
|
||||
|
||||
vec=pygame.math.Vector2
|
||||
@ -130,3 +135,19 @@ class Bullet(pygame.sprite.Sprite):
|
||||
self.shoot()
|
||||
if not pygame.sprite.spritecollideany(self, maps.bwalls, collided = None)==None:
|
||||
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
|