1
Fork 0

Runtime Debugging

This commit is contained in:
Jake Howard 2015-05-08 11:24:33 +01:00
parent 654498fcbb
commit b4d835fe70
5 changed files with 23 additions and 26 deletions

View file

@ -10,15 +10,13 @@ class Bullet(pygame.sprite.Sprite):
self.image.fill((255,255,255)) self.image.fill((255,255,255))
self.rect = self.image.get_rect() self.rect = self.image.get_rect()
self.rect.x = parent.rect.x + parent.width/2 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.speed = 5
self.type = "TARGET" self.type = "PLAYER"
self.parent = parent
def set_position(self,x,y): def set_position(self,x,y):
self.rect.x, self.rect.y = x,y self.rect.x, self.rect.y = x,y
def update(self): def update(self):
self.rect.y -= self.speed #direction may need editing? self.rect.y -= self.speed #direction may need editing?
def at_top(self):
return (self.rect.y == 0)

18
game.py
View file

@ -1,7 +1,6 @@
import pygame, logging import pygame, logging
from time import time from time import time
from random import randint from random import randint
import bullet, player, textures
from bullet import Bullet from bullet import Bullet
from player import Shooter from player import Shooter
from assets import Textures, Levels, generate_random_level from assets import Textures, Levels, generate_random_level
@ -56,10 +55,8 @@ def generate_targets(player):
changed = False changed = False
while not changed: while not changed:
index = randint(0, len(group)-1) index = randint(0, len(group)-1)
if group[index].type != "SHOOTER" if group[index].type != "SHOOTER":
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 changed = True
else: else:
group[randint(0, len(group)-1)].type == "NORMAL" group[randint(0, len(group)-1)].type == "NORMAL"
@ -84,8 +81,7 @@ def play(window):
target_movement_timeout = target_movement_timeout_default target_movement_timeout = target_movement_timeout_default
while PLAYING_GAME: while PLAYING_GAME:
window.fill((0,0,0)) window.fill((13,123,123))
player_group.update()
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == pygame.QUIT: if event.type == pygame.QUIT:
@ -114,9 +110,8 @@ def play(window):
bullet_group.add(temp) bullet_group.add(temp)
for sprite in bullet_group: for sprite in bullet_group:
if not sprite.at_bound():
sprite.update() sprite.update()
if sprite.rect.y < 0 or sprite.rect.y > player.rect.y: if sprite.rect.y < 0 or (sprite.rect.y > player.rect.y and sprite.type == "TARGET"):
bullet_group.remove(sprite) bullet_group.remove(sprite)
for bullet in bullet_group: for bullet in bullet_group:
@ -130,7 +125,7 @@ def play(window):
hit_list = pygame.sprite.spritecollide(bullet, player_group, True) hit_list = pygame.sprite.spritecollide(bullet, player_group, True)
for player in hit_list: for player in hit_list:
if bullet.type != "TARGET" continue if bullet.type != "TARGET": continue
bullet_group.remove(bullet) bullet_group.remove(bullet)
logging.info("") logging.info("")
player.lives -= 1 player.lives -= 1
@ -141,7 +136,7 @@ def play(window):
drop_targets = False drop_targets = False
for target in target_group: for target in target_group:
target.move() 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 drop_targets = True
if target.rect.y >= player.rect.y + 10: if target.rect.y >= player.rect.y + 10:
@ -168,10 +163,9 @@ def play(window):
update_level(window, player.level) update_level(window, player.level)
update_lives(window, player.lives) update_lives(window, player.lives)
player_group.update() player_group.draw(window)
bullet_group.draw(window) bullet_group.draw(window)
target_group.draw(window) target_group.draw(window)
player_group.draw(window)
pygame.display.update() pygame.display.update()
target_movement_timeout -= 1 target_movement_timeout -= 1

View file

@ -2,12 +2,13 @@ import pygame
class Shooter(pygame.sprite.Sprite): 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__() super().__init__()
self.width = width self.width = width
self.height = height self.height = height
self.colour = color
self.image = pygame.Surface((width, height)) self.image = pygame.Surface((width, height))
self.image.fill(color) self.image.fill(self.colour)
self.rect = self.image.get_rect() self.rect = self.image.get_rect()
self.speed = 3 self.speed = 3
self.window_rect = window.get_rect() self.window_rect = window.get_rect()
@ -23,3 +24,7 @@ class Shooter(pygame.sprite.Sprite):
def move(self, value): def move(self, value):
self.rect.x += value self.rect.x += value
self.rect.clamp_ip(self.window_rect) self.rect.clamp_ip(self.window_rect)
def update(self):
self.image.fill(self.colour)
self.rect = self.image.get_rect()

View file

@ -9,7 +9,7 @@ class Target(pygame.sprite.Sprite):
self.image = pygame.Surface((self.width, self.height)) self.image = pygame.Surface((self.width, self.height))
self.image.fill(color) self.image.fill(color)
self.rect = self.image.get_rect() 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.rect.x, self.rect.y = (x+(self.width/2)),(y+(self.width/2)) # centres co-ordinates
self.type = "NORMAL" self.type = "NORMAL"
@ -17,7 +17,7 @@ class Target(pygame.sprite.Sprite):
self.rect.x += self.speed self.rect.x += self.speed
def drop(self): def drop(self):
self.rect.y += 20 self.rect.y += 17
self.speed *= -1 self.speed *= -1