From b4d835fe701f74db56d9cb0f8c23128784712141 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Fri, 8 May 2015 11:24:33 +0100 Subject: [PATCH] Runtime Debugging --- Play The Game.py | 2 +- bullet.py | 10 ++++------ game.py | 22 ++++++++-------------- player.py | 11 ++++++++--- target.py | 4 ++-- 5 files changed, 23 insertions(+), 26 deletions(-) diff --git a/Play The Game.py b/Play The Game.py index 82b61f6..eb24864 100644 --- a/Play The Game.py +++ b/Play The Game.py @@ -1,3 +1,3 @@ print("Game Loading...") import GUI -GUI.display() \ No newline at end of file +GUI.display() diff --git a/bullet.py b/bullet.py index 6983626..ab4ebe2 100644 --- a/bullet.py +++ b/bullet.py @@ -10,15 +10,13 @@ class Bullet(pygame.sprite.Sprite): self.image.fill((255,255,255)) self.rect = self.image.get_rect() self.rect.x = parent.rect.x + parent.width/2 - self.rect.y = parent.rect.y + self.rect.y = parent.rect.y + parent.width/2 self.speed = 5 - self.type = "TARGET" + self.type = "PLAYER" + self.parent = parent def set_position(self,x,y): self.rect.x, self.rect.y = x,y def update(self): - self.rect.y -= self.speed #direction may need editing? - - def at_top(self): - return (self.rect.y == 0) \ No newline at end of file + self.rect.y -= self.speed #direction may need editing? \ No newline at end of file diff --git a/game.py b/game.py index 42cdb6f..90a5433 100644 --- a/game.py +++ b/game.py @@ -1,7 +1,6 @@ import pygame, logging from time import time from random import randint -import bullet, player, textures from bullet import Bullet from player import Shooter from assets import Textures, Levels, generate_random_level @@ -56,10 +55,8 @@ def generate_targets(player): changed = False while not changed: index = randint(0, len(group)-1) - if group[index].type != "SHOOTER" + if group[index].type != "SHOOTER": group[index].type == "SHOOTER" - group[index].image.fill((150,0,30)) - group[index].rect = group[image].image.get_rect() changed = True else: group[randint(0, len(group)-1)].type == "NORMAL" @@ -84,9 +81,8 @@ def play(window): target_movement_timeout = target_movement_timeout_default while PLAYING_GAME: - window.fill((0,0,0)) - player_group.update() - + window.fill((13,123,123)) + for event in pygame.event.get(): if event.type == pygame.QUIT: logging.critical("Exiting Game...") @@ -114,9 +110,8 @@ def play(window): bullet_group.add(temp) for sprite in bullet_group: - if not sprite.at_bound(): - sprite.update() - if sprite.rect.y < 0 or sprite.rect.y > player.rect.y: + sprite.update() + if sprite.rect.y < 0 or (sprite.rect.y > player.rect.y and sprite.type == "TARGET"): bullet_group.remove(sprite) for bullet in bullet_group: @@ -130,7 +125,7 @@ def play(window): hit_list = pygame.sprite.spritecollide(bullet, player_group, True) for player in hit_list: - if bullet.type != "TARGET" continue + if bullet.type != "TARGET": continue bullet_group.remove(bullet) logging.info("") player.lives -= 1 @@ -141,7 +136,7 @@ def play(window): drop_targets = False for target in target_group: target.move() - if target.rect.x <= 20 or target.rect.x >=WINDOW_SIZE[0] - 20 + target.width: + if target.rect.x <= 30 or target.rect.x >=WINDOW_SIZE[0] - 30: drop_targets = True if target.rect.y >= player.rect.y + 10: @@ -168,10 +163,9 @@ def play(window): update_level(window, player.level) update_lives(window, player.lives) - player_group.update() + player_group.draw(window) bullet_group.draw(window) target_group.draw(window) - player_group.draw(window) pygame.display.update() target_movement_timeout -= 1 diff --git a/player.py b/player.py index 87f2f8e..fcedb9f 100644 --- a/player.py +++ b/player.py @@ -2,12 +2,13 @@ import pygame class Shooter(pygame.sprite.Sprite): - def __init__(self, window, color=(30,0,150), width=50, height=25): + def __init__(self, window, color=(255,255,255), width=50, height=25): super().__init__() self.width = width self.height = height + self.colour = color self.image = pygame.Surface((width, height)) - self.image.fill(color) + self.image.fill(self.colour) self.rect = self.image.get_rect() self.speed = 3 self.window_rect = window.get_rect() @@ -22,4 +23,8 @@ class Shooter(pygame.sprite.Sprite): def move(self, value): self.rect.x += value - self.rect.clamp_ip(self.window_rect) \ No newline at end of file + self.rect.clamp_ip(self.window_rect) + + def update(self): + self.image.fill(self.colour) + self.rect = self.image.get_rect() \ No newline at end of file diff --git a/target.py b/target.py index ad6da93..f69ab8d 100644 --- a/target.py +++ b/target.py @@ -9,7 +9,7 @@ class Target(pygame.sprite.Sprite): self.image = pygame.Surface((self.width, self.height)) self.image.fill(color) self.rect = self.image.get_rect() - self.speed = 10 + self.speed = 7 self.rect.x, self.rect.y = (x+(self.width/2)),(y+(self.width/2)) # centres co-ordinates self.type = "NORMAL" @@ -17,7 +17,7 @@ class Target(pygame.sprite.Sprite): self.rect.x += self.speed def drop(self): - self.rect.y += 20 + self.rect.y += 17 self.speed *= -1