Browse files

fixed enemy lasers dissapearing when enemy dies bug/misconception

  • Loading branch information...
1 parent 432bba8 commit 5e2af64093f2cffe13b22aae6e1602d6f7015242 michael committed Aug 5, 2012
Showing with 86 additions and 30 deletions.
  1. +1 −0 sources/common_pygame.py
  2. +25 −21 sources/enemy.py
  3. +21 −9 sources/game.py
  4. +39 −0 sources/lasers.py
View
1 sources/common_pygame.py
@@ -12,3 +12,4 @@
screenwidth=screen.get_width()
screenheight=screen.get_height()
+
View
46 sources/enemy.py
@@ -10,7 +10,9 @@ class Enemy():
whentoshoot = 0
nbAsteroids = 0
- def __init__(self, single_sprites, sprite_sequences,sounds, x, y, movementdirection, typeofship, menu):
+ def __init__(self, single_sprites, sprite_sequences,sounds, x, y, \
+ movementdirection, typeofship, menu):
+
self.menu=menu
self.x = x
@@ -223,7 +225,7 @@ def processHit(self,laserlist, ship):
return oldlasers
#blit the correct frame connected with the status
- def update(self, ship):
+ def update(self, ship, lasers):
#if dying, blit the explosion frame
if self.dying:
if self.dying_index/2<len(self.sprite_explosion_list):
@@ -347,7 +349,9 @@ def update(self, ship):
if not self.bonus and not self.dying and ( self.typeofship==0 or self.typeofship==2):
#shooting out a laser
if self.lasercompteur==0:
- self.laserlist.append((self.x+self.w/2, self.y+self.h))
+
+ lasers.addLaser(self.x+self.w/2, self.y+self.h)
+ #self.laserlist.append((self.x+self.w/2, self.y+self.h))
#if we are the boss, shoot out the lasers faster
if self.typeofship==2:
@@ -359,26 +363,26 @@ def update(self, ship):
#print(self.lasercompteur)
self.lasercompteur=self.lasercompteur-1
- #updating shot lasers
- tmplist = list()
- for index in range(len(self.laserlist)):
- (x, y) = self.laserlist[index]
- self.laserlist[index]=(x, y+10)
- self.screen.blit(self.single_sprites['sprite_laser_blue_light.png'],(x-29-32,y-10-22-32))
- self.screen.blit(self.single_sprites['sprite_laser_blue.png'],(x,y-10))
- #is the ship getting hit by one of our lasers ?
+ ##updating shot lasers
+ #tmplist = list()
+ #for index in range(len(self.laserlist)):
+ #(x, y) = self.laserlist[index]
+ #self.laserlist[index]=(x, y+10)
+ #self.screen.blit(self.single_sprites['sprite_laser_blue_light.png'],(x-29-32,y-10-22-32))
+ #self.screen.blit(self.single_sprites['sprite_laser_blue.png'],(x,y-10))
+ ##is the ship getting hit by one of our lasers ?
- if collisions.iscollision(x, y,
- self.single_sprites['sprite_laser_blue.png'].get_width(),
- self.single_sprites['sprite_laser_blue.png'].get_height(),
- ship.position_ship_x, ship.position_ship_y, ship.width,
- ship.height ):
- ship.damage(10, x-40)
- tmplist.append(self.laserlist[index])
+ #if collisions.iscollision(x, y,
+ #self.single_sprites['sprite_laser_blue.png'].get_width(),
+ #self.single_sprites['sprite_laser_blue.png'].get_height(),
+ #ship.position_ship_x, ship.position_ship_y, ship.width,
+ #ship.height ):
+ #ship.damage(10, x-40)
+ #tmplist.append(self.laserlist[index])
- #and we delete the old lasers
- for index in range(len(tmplist)):
- self.laserlist.remove(tmplist[index])
+ ##and we delete the old lasers
+ #for index in range(len(tmplist)):
+ #self.laserlist.remove(tmplist[index])
#if we are the boss : shooting out lasers
#if self.typeofship==2:
View
30 sources/game.py
@@ -14,6 +14,7 @@ def game():
import effects
import particles
import smoke
+ import lasers
pygame = common_pygame.pygame
screen= common_pygame.screen
@@ -40,6 +41,8 @@ def game():
#lasershoot_height = single_sprites['sprite_lasershoot.png'].get_height()
+
+ #the ship's laser list
laserlist = list()
lasershoot = 7
@@ -52,10 +55,6 @@ def game():
-
-
-
-
hud= hud.Hud(single_sprites, menu, sounds)
#start the menu
menu.init2(single_sprites, sounds, background, hud)
@@ -70,7 +69,10 @@ def game():
decal_laser_ship_x = (ship.width /2)
coord_laser_ship_y = -40
-
+
+
+ #the enemy laser system
+ lasers = lasers.Lasers(single_sprites, ship)
enemy_list = list()
@@ -104,19 +106,22 @@ def game():
boolrand = bool(random.getrandbits(1))
for i in range(1):
enemy_list.append(enemy.Enemy( single_sprites, sprite_sequences , sounds,
- i*80+250+60*int(boolrand), -single_sprites['sprite_enemy.png'].get_height(),boolrand , 0, menu))
+ i*80+250+60*int(boolrand), -single_sprites['sprite_enemy.png'].get_height(),boolrand \
+ , 0, menu))
#print (enemy_list[0].nbAsteroids)
if level==2:
if compteur%(2*60)==0:
boolrand = bool(random.getrandbits(1))
for i in range(6):
enemy_list.append(enemy.Enemy( single_sprites, sprite_sequences , sounds,
- i*80+190+60*int(boolrand), -single_sprites['sprite_enemy.png'].get_height(),boolrand , 0, menu))
+ i*80+190+60*int(boolrand), -single_sprites['sprite_enemy.png'].get_height(),boolrand \
+ , 0, menu))
#print (enemy_list[0].nbAsteroids)
if level==3 and not spawnedBoss:
enemy_list.append(enemy.Enemy( single_sprites, sprite_sequences , sounds,
- 400-single_sprites['boss1.png'].get_width()/2, -single_sprites['boss1.png'].get_height(),1 , 2, menu))
+ 400-single_sprites['boss1.png'].get_width()/2, -single_sprites['boss1.png'].get_height(),1 ,\
+ 2, menu))
spawnedBoss=True
#if compteur%(1*60)==0:
@@ -235,7 +240,7 @@ def game():
#blit and process the enemies
for index in range(len(enemy_list)):
oldLasers=enemy_list[index].processHit(laserlist, ship)
- enemy_list[index].update(ship)
+ enemy_list[index].update(ship, lasers)
if enemy_list[index].alive==False:
deadEnemies.append(enemy_list[index])
#purge old lasers
@@ -245,6 +250,13 @@ def game():
#purge dead enemies
for index in range(len(deadEnemies)):
enemy_list.remove(deadEnemies[index])
+
+
+ #blit and process the enemy's lasers
+ lasers.update()
+
+
+
#blit the hud
level = hud.blit(ship, level)
View
39 sources/lasers.py
@@ -0,0 +1,39 @@
+import common_pygame
+import collisions
+import random
+pygame = common_pygame.pygame
+screen= common_pygame.screen
+
+class Lasers():
+ #init the laser object
+ def __init__(self, single_sprites, ship):
+ self.laserlist = list()
+ self.single_sprites= single_sprites
+ self.ship = ship
+ #adding a laser to the list
+ def addLaser(self, x, y ):
+ self.laserlist.append((x, y))
+
+
+
+ def update(self):
+ #updating shot lasers
+ tmplist = list()
+ for index in range(len(self.laserlist)):
+ (x, y) = self.laserlist[index]
+ self.laserlist[index]=(x, y+10)
+ screen.blit(self.single_sprites['sprite_laser_blue_light.png'],(x-29-32,y-10-22-32))
+ screen.blit(self.single_sprites['sprite_laser_blue.png'],(x,y-10))
+ #is the ship getting hit by one of our lasers ?
+
+ if collisions.iscollision(x, y,
+ self.single_sprites['sprite_laser_blue.png'].get_width(),
+ self.single_sprites['sprite_laser_blue.png'].get_height(),
+ self.ship.position_ship_x, self.ship.position_ship_y, self.ship.width,
+ self.ship.height ):
+ self.ship.damage(10, x-40)
+ tmplist.append(self.laserlist[index])
+
+ #and we delete the old lasers
+ for index in range(len(tmplist)):
+ self.laserlist.remove(tmplist[index])

0 comments on commit 5e2af64

Please sign in to comment.