Skip to content

Commit

Permalink
Lasers with random speeds, life powerup
Browse files Browse the repository at this point in the history
  • Loading branch information
ktzar committed Nov 5, 2011
1 parent 503fc08 commit 0351660
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions game/enemies.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def update(self):
self.dead_time = self.age
if self.age - self.dead_time > self.explosions:
self.status = 2
self.image.set_alpha(max(0,255-(self.age - self.dead_time)*10))
#don't shoot
return

Expand Down
6 changes: 4 additions & 2 deletions game/laser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pygame
import random
import math
import utils

Expand Down Expand Up @@ -49,8 +50,9 @@ def __init__(self, source, target):
self.target = target.copy()
self.rect.top = source.top
self.rect.left = source.left
self.a_y = (self.rect.top - self.target.top ) / 40
self.a_x = (self.rect.left - self.target.left ) / 40
#30 and 40 are the min/max boundaries for the random speed
self.a_y = (self.rect.top - self.target.top ) / random.randint(30,40)
self.a_x = (self.rect.left - self.target.left ) / random.randint(30,40)
if self.a_y == 0:
angle = 0
else:
Expand Down
1 change: 1 addition & 0 deletions game/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __init__(self):
pygame.init()
self.screen = pygame.display.set_mode((640, 480), pygame.DOUBLEBUF)
pygame.display.set_caption('VacuumFire')
#pygame.display.toggle_fullscreen()
pygame.mouse.set_visible(0)
#icon
icon, foo = utils.load_image('icon.png')
Expand Down
5 changes: 5 additions & 0 deletions game/ship.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Ship(pygame.sprite.Sprite):
max_x_momentum = 10
#Initial life counter
life = 10
max_life = 10
#'up' or 'down' (for the animation)
status = ''
#Ship.LEFT or Ship.RIGHT (for the animation)
Expand Down Expand Up @@ -71,6 +72,10 @@ def update(self):
def damage(self):
self.life-=1

def life_up(self):
if self.life < self.max_life:
self.life += 1

def stop_move_left(self):
self.x_status = ''

Expand Down
2 changes: 1 addition & 1 deletion game/sprites.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from math import *


class Flying_Score(pygame.sprite.Sprite):
class Flying_Label(pygame.sprite.Sprite):

def __init__(self, position, score):
self.age = 0
Expand Down
11 changes: 10 additions & 1 deletion game/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,26 @@ def process_powerups(self):
self.sounds['powerup'].play()
self.score.add_score(powerup_obtained.value)
#TODO powerup should be processed in ship
if powerup_obtained.type == 0:
self.ship.life_up()
self.hud.add(Flying_Label( self.ship.rect, 'Energy!'))
self.lifemeter.life = self.ship.life

if powerup_obtained.type == 1 and self.ship.powerup['speedup'] < 5:
self.ship.powerup['speedup'] += 1
self.powerup_speed.set_status(self.ship.powerup['speedup'])
self.hud.add(Flying_Label( self.ship.rect, 'Speed up!'))
#print "Increase speed to {0}".format(self.ship.powerup['speedup'])
elif powerup_obtained.type == 2 and Laser.max_lasers < 5:
Laser.max_lasers += 1
Laser.move += 2
self.powerup_weapon.set_status(Laser.max_lasers)
print "Increase lasers to {0}".format(Laser.max_lasers)
self.hud.add(Flying_Label( self.ship.rect, 'More lasers!'))

elif powerup_obtained.type == 3 and self.ship.powerup['penetrate'] == False:
print "Activate penetration"
self.hud.add(Flying_Label( self.ship.rect, 'Penetration!'))
self.ship.powerup['penetrate'] = True
else:
print "No more powerups available"
Expand Down Expand Up @@ -183,7 +192,7 @@ def process_killedaliens(self):
self.add_explosion(fireball.rect)
scored = (1+dead.value)*1000
self.score.add_score(scored)
self.hud.add(Flying_Score( dead.rect, scored))
self.hud.add(Flying_Label( dead.rect, scored))
if penetration == False:
fireball.kill()

Expand Down

0 comments on commit 0351660

Please sign in to comment.