Return to repo list

gatemender

Arcade game about fixing warp gates. LibreJam Dec 2020 Entry.
Return to HMagellan.com

commit 50166ac5cec6253079fe79f5222e1691df0e4b78
parent 985cbc702fa9a8770eef5b512c74b756a83df300
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Mon,  7 Dec 2020 07:36:51 -0600

update bullet appearance and add screen wrap

Diffstat:
Mdata/bullet1.png | 0
Msrc/game.py | 25+++++++++++++------------
Msrc/sprites.py | 15+++++++++++++++
3 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/data/bullet1.png b/data/bullet1.png Binary files differ. diff --git a/src/game.py b/src/game.py @@ -22,23 +22,19 @@ class Game(object): self.camera_draw_group = pygame.sprite.Group() self.asteroids = pygame.sprite.Group() self.bullets = pygame.sprite.Group() - self.ship = sprites.Ship(self, self.images["Ship"], self.screen.get_rect().center) - self.camera_draw_group.add(self.ship) - self.tray = sprites.CustomSprite(self, self.images["UI_Tray"], (self.screen_rect.centerx, 700)) - self.screen_draw_group.add(self.tray) # Others self.level_factor = 1 self.asteroid_spawn_timer = 100 self.gate_defs = [ - [ bool(random.getrandbits(1)), random.randint(0, 2), 0, (416, 100) ], - [ bool(random.getrandbits(1)), random.randint(0, 2), 0, (480, 100) ], - [ bool(random.getrandbits(1)), random.randint(0, 2), 270, (544, 100) ], - [ bool(random.getrandbits(1)), random.randint(0, 2), 270, (544, 164) ], - [ bool(random.getrandbits(1)), random.randint(0, 2), 180, (544, 228) ], - [ bool(random.getrandbits(1)), random.randint(0, 2), 180, (480, 228) ], - [ bool(random.getrandbits(1)), random.randint(0, 2), 90, (416, 228) ], - [ bool(random.getrandbits(1)), random.randint(0, 2), 90, (416, 164) ], + [ bool(random.getrandbits(1)), random.randint(0, 2), 0, (416, 200) ], + [ bool(random.getrandbits(1)), random.randint(0, 2), 0, (480, 200) ], + [ bool(random.getrandbits(1)), random.randint(0, 2), 270, (544, 200) ], + [ bool(random.getrandbits(1)), random.randint(0, 2), 270, (544, 264) ], + [ bool(random.getrandbits(1)), random.randint(0, 2), 180, (544, 328) ], + [ bool(random.getrandbits(1)), random.randint(0, 2), 180, (480, 328) ], + [ bool(random.getrandbits(1)), random.randint(0, 2), 90, (416, 328) ], + [ bool(random.getrandbits(1)), random.randint(0, 2), 90, (416, 264) ], ] self.load_level() @@ -79,6 +75,11 @@ class Game(object): self.camera_draw_group.add(sprites.GatePiece(self, im, n[3], n[2], or_name, n[0], rqstr)) x += 1 + self.ship = sprites.Ship(self, self.images["Ship"], self.screen.get_rect().center) + self.camera_draw_group.add(self.ship) + self.tray = sprites.CustomSprite(self, self.images["UI_Tray"], (self.screen_rect.centerx, 700)) + self.screen_draw_group.add(self.tray) + def shift_frames(self): self.frameclock.tick(FRAMERATE) diff --git a/src/sprites.py b/src/sprites.py @@ -99,6 +99,21 @@ class Ship(CustomSprite): else: self.shoot_cooldown -= 1 + # Check for wrapping + if not self.rect.colliderect(self.manager.camera_surface_rect): + x = self.rect.centerx + y = self.rect.centery + if self.rect.centerx > self.manager.camera_surface_rect.width: + x = 0 - (self.rect.width / 2) + elif self.rect.centerx < 0: + x = self.manager.camera_surface_rect.width + (self.rect.width / 2) + if self.rect.centery > self.manager.camera_surface_rect.height: + y = 0 - (self.rect.height / 2) + elif self.rect.centery < 0: + y = self.manager.camera_surface_rect.height + (self.rect.height / 2) + self.rect.center = (x, y) + self.position = pygame.Vector2(self.rect.center) + # Bullet class class Bullet(CustomSprite):