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

@ -1,3 +1,3 @@
print("Game Loading...")
import GUI
GUI.display()
GUI.display()

View file

@ -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)
self.rect.y -= self.speed #direction may need editing?

22
game.py
View file

@ -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

View file

@ -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)
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.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