Added killing
This commit is contained in:
parent
80aee6c546
commit
86cd71cc50
Binary file not shown.
Binary file not shown.
@ -7,6 +7,8 @@ from config import *
|
|||||||
running=True
|
running=True
|
||||||
players=[]
|
players=[]
|
||||||
|
|
||||||
|
p1_group=pygame.sprite.Group()
|
||||||
|
p2_group=pygame.sprite.Group()
|
||||||
p1_bullet=[]
|
p1_bullet=[]
|
||||||
p2_bullet=[]
|
p2_bullet=[]
|
||||||
|
|
||||||
@ -40,6 +42,8 @@ def collision_check(p):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
def bullethits():
|
||||||
|
hits=pygame.sprite.groupcollide(p2_group, p1_bullet_group, True, True)
|
||||||
|
|
||||||
def player1_input(keys):
|
def player1_input(keys):
|
||||||
if keys[P1_SHOOT]:
|
if keys[P1_SHOOT]:
|
||||||
@ -83,6 +87,7 @@ def event_handler():
|
|||||||
events()
|
events()
|
||||||
keys=pygame.key.get_pressed()
|
keys=pygame.key.get_pressed()
|
||||||
collision_check(-1)
|
collision_check(-1)
|
||||||
|
bullethits()
|
||||||
player1_input(keys)
|
player1_input(keys)
|
||||||
player2_input(keys)
|
player2_input(keys)
|
||||||
|
|
||||||
|
@ -22,6 +22,8 @@ clock=pygame.time.Clock()
|
|||||||
|
|
||||||
events.players.append(Player('asd', 400, 100, 10))
|
events.players.append(Player('asd', 400, 100, 10))
|
||||||
events.players.append(Player('qwe', 400, 500, 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)
|
all_sprites.add(events.players)
|
||||||
|
|
||||||
events.running=True
|
events.running=True
|
||||||
@ -31,7 +33,6 @@ events.running=True
|
|||||||
font=pygame.font.SysFont("Arial", 12)
|
font=pygame.font.SysFont("Arial", 12)
|
||||||
|
|
||||||
def draw_debug_text():
|
def draw_debug_text():
|
||||||
text_sprites=pygame.sprite.Group()
|
|
||||||
texts=[
|
texts=[
|
||||||
font.render("P1 facing: " + str(events.players[0].facing), True, (100,100,100)),
|
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)),
|
font.render("P2 facing: " + str(events.players[1].facing), True, (100,100,100)),
|
||||||
@ -44,6 +45,9 @@ def draw_debug_text():
|
|||||||
count+=1
|
count+=1
|
||||||
|
|
||||||
# set hitbox objects as screen boundaries ### DEBUG ###
|
# set hitbox objects as screen boundaries ### DEBUG ###
|
||||||
|
boundary=pygame.sprite.Group()
|
||||||
|
boundary.add=Hitbox(int(WINDOW_WIDTH/2), 0, WINDOW_WIDTH, 10)
|
||||||
|
|
||||||
# game loop
|
# game loop
|
||||||
|
|
||||||
while events.running:
|
while events.running:
|
||||||
|
@ -114,9 +114,12 @@ class Bullet(pygame.sprite.Sprite):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.shoot()
|
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):
|
class Hitbox(pygame.sprite.Sprite):
|
||||||
def __init__(self, x, y, w, h):
|
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=self.size.get_rect()
|
||||||
self.rect.center=vec(x,y)
|
self.rect.center=vec(x,y)
|
||||||
|
print(self.rect.center)
|
Loading…
Reference in New Issue
Block a user