Return to repo list

gatemender

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

commit 0f15c9705deeca47b0fc0ce70094f02f61caa050
parent 30906dd81e251ad0173314afffb7b1d666013fe6
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Sun,  6 Dec 2020 23:07:10 -0600

added camera and start of ui

Diffstat:
Mdata/space_background.png | 0
Msrc/constants.py | 3++-
Msrc/game.py | 23++++++++++++++++-------
Msrc/sprites.py | 4++--
4 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/data/space_background.png b/data/space_background.png Binary files differ. diff --git a/src/constants.py b/src/constants.py @@ -28,7 +28,8 @@ IMAGE_FILES = { "White_Halo_Angle" : os.path.join("data", "white_halo_angle.png"), "Alpha_Icon" : os.path.join("data", "alpha_material.png"), "Beta_Icon" : os.path.join("data", "beta_material.png"), - "Gamma_Icon" : os.path.join("data", "gamma_material.png") + "Gamma_Icon" : os.path.join("data", "gamma_material.png"), + "UI_Tray" : os.path.join("data", "hud_tray.png") } TURN_LEFT_KEY = pygame.K_a TURN_RIGHT_KEY = pygame.K_d diff --git a/src/game.py b/src/game.py @@ -8,6 +8,9 @@ class Game(object): self.on = True self.screen = pygame.display.set_mode(SCREEN_DIM) self.screen_rect = self.screen.get_rect() + self.camera_surface = pygame.Surface((SCREEN_DIM[0], SCREEN_DIM[1] - 96)) + self.camera_surface_rect = self.camera_surface.get_rect() + self.camera_surface_rect.topleft = (0, 0) self.frameclock = pygame.time.Clock() # Loading @@ -15,11 +18,14 @@ class Game(object): self.keys = [ False for k in range(0, 256) ] # Game objects - self.drawables = pygame.sprite.Group() + self.screen_draw_group = pygame.sprite.Group() + 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.drawables.add(self.ship) + 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 @@ -70,7 +76,7 @@ class Game(object): else: im = self.images["Gate_Straight_" + bstr] or_name = "Straight" - self.drawables.add(sprites.GatePiece(self, im, n[3], n[2], or_name, n[0], rqstr)) + self.camera_draw_group.add(sprites.GatePiece(self, im, n[3], n[2], or_name, n[0], rqstr)) x += 1 def shift_frames(self): @@ -97,9 +103,12 @@ class Game(object): self.keys[event.key] = False def update_screen(self): - self.screen.fill((0, 0, 0)) - self.screen.blit(self.images["Space_Background"], (0, 0)) - self.drawables.update(self.screen) + self.screen.fill((44, 44, 44)) + self.camera_surface.fill((0, 0, 0)) + self.camera_surface.blit(self.images["Space_Background"], (0, 0)) + self.camera_draw_group.update(self.camera_surface) + self.screen.blit(self.camera_surface, self.camera_surface_rect) + self.screen_draw_group.update(self.screen) pygame.display.update() def spawn_asteroids(self): @@ -113,7 +122,7 @@ class Game(object): im = self.images["Big_Asteroid"] spawnpos = (random.randint(0, SCREEN_DIM[1]), -65) a = sprites.Asteroid(self, im, spawnpos, 270, size) - self.drawables.add(a) + self.camera_draw_group.add(a) self.asteroids.add(a) self.asteroid_spawn_timer = 10 * (10 / self.level_factor) else: diff --git a/src/sprites.py b/src/sprites.py @@ -71,7 +71,7 @@ class Ship(CustomSprite): def shoot(self): b = Bullet(self.manager, self.manager.images["Bullet"], self.rect.center, self.angle) - self.manager.drawables.add(b) + self.manager.camera_draw_group.add(b) self.manager.bullets.add(b) def act(self): @@ -157,7 +157,7 @@ class Asteroid(CustomSprite): x = -1 y = -1 for p in range(0, 4): - self.manager.drawables.add(AsteroidParticle(self.manager, self.manager.images["Asteroid_Particle"], self.rect.center, 0, (x, y))) + self.manager.camera_draw_group.add(AsteroidParticle(self.manager, self.manager.images["Asteroid_Particle"], self.rect.center, 0, (x, y))) y += 1 if y % 2 != 0: x += 2