Added killing

This commit is contained in:
Marcin Kostrzewski 2019-01-21 23:43:13 +01:00
parent 80aee6c546
commit 86cd71cc50
5 changed files with 15 additions and 3 deletions

Binary file not shown.

Binary file not shown.

View File

@ -7,6 +7,8 @@ from config import *
running=True
players=[]
p1_group=pygame.sprite.Group()
p2_group=pygame.sprite.Group()
p1_bullet=[]
p2_bullet=[]
@ -40,6 +42,8 @@ def collision_check(p):
else:
return False
def bullethits():
hits=pygame.sprite.groupcollide(p2_group, p1_bullet_group, True, True)
def player1_input(keys):
if keys[P1_SHOOT]:
@ -83,6 +87,7 @@ def event_handler():
events()
keys=pygame.key.get_pressed()
collision_check(-1)
bullethits()
player1_input(keys)
player2_input(keys)

View File

@ -22,6 +22,8 @@ clock=pygame.time.Clock()
events.players.append(Player('asd', 400, 100, 10))
events.players.append(Player('qwe', 400, 500, 10))
events.p1_group.add(events.players[0])
events.p2_group.add(events.players[1])
all_sprites.add(events.players)
events.running=True
@ -31,7 +33,6 @@ events.running=True
font=pygame.font.SysFont("Arial", 12)
def draw_debug_text():
text_sprites=pygame.sprite.Group()
texts=[
font.render("P1 facing: " + str(events.players[0].facing), True, (100,100,100)),
font.render("P2 facing: " + str(events.players[1].facing), True, (100,100,100)),
@ -44,6 +45,9 @@ def draw_debug_text():
count+=1
# set hitbox objects as screen boundaries ### DEBUG ###
boundary=pygame.sprite.Group()
boundary.add=Hitbox(int(WINDOW_WIDTH/2), 0, WINDOW_WIDTH, 10)
# game loop
while events.running:

View File

@ -114,9 +114,12 @@ class Bullet(pygame.sprite.Sprite):
def update(self):
self.shoot()
if self.rect.bottom<0 or self.rect.right<0 or self.rect.left>WINDOW_WIDTH or self.rect.top>WINDOW_HEIGHT:
self.kill()
class Hitbox(pygame.sprite.Sprite):
def __init__(self, x, y, w, h):
self.size=vec(w, h)
self.size=pygame.Surface((x,y))
self.rect=self.size.get_rect()
self.rect.center=vec(x,y)
print(self.rect.center)