diff --git a/__pycache__/events.cpython-37.pyc b/__pycache__/events.cpython-37.pyc index f7649ad..29bdf93 100644 Binary files a/__pycache__/events.cpython-37.pyc and b/__pycache__/events.cpython-37.pyc differ diff --git a/__pycache__/sprites.cpython-37.pyc b/__pycache__/sprites.cpython-37.pyc index 8307f7b..fcc26b0 100644 Binary files a/__pycache__/sprites.cpython-37.pyc and b/__pycache__/sprites.cpython-37.pyc differ diff --git a/events.py b/events.py index 433a224..1b8184b 100644 --- a/events.py +++ b/events.py @@ -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) diff --git a/mygame.py b/mygame.py index 6e58113..bbc8d2c 100644 --- a/mygame.py +++ b/mygame.py @@ -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: diff --git a/sprites.py b/sprites.py index 3480b0f..d7fd6c7 100644 --- a/sprites.py +++ b/sprites.py @@ -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) \ No newline at end of file + self.rect.center=vec(x,y) + print(self.rect.center) \ No newline at end of file