|
From: João <lv...@us...> - 2009-12-05 18:43:52
|
This is an automated email from the git, the tree hashes are:
via e34e5b37510b74bd665338bc43a14f434ec1ef4d (commit)
via 978658525405dc2f1bdf72b0ee63cf8107950487 (commit)
from 9bf3725e8aab7ebc9785d91f94b750d733a98a4e (commit)
- Log -----------------------------------------------------------------
commit e34e5b37510b74bd665338bc43a14f434ec1ef4d
Merge: 9786585 9bf3725
Author: João <jcorrea@marvim.(none)>
Date: Sat Dec 5 16:43:30 2009 -0200
Merge branch 'master' of ssh://lvwr@deadchannel.git.sourceforge.net/gitroot/deadchannel/deadchannel
commit 978658525405dc2f1bdf72b0ee63cf8107950487
Author: João <jcorrea@marvim.(none)>
Date: Sat Dec 5 16:42:52 2009 -0200
Added support to different enemy behaviours
diff --git a/code/bullet.py b/code/bullet.py
index a5962b6..de1a054 100644
--- a/code/bullet.py
+++ b/code/bullet.py
@@ -27,7 +27,7 @@ class Bullet(GameObject):
if list != None:
self.add(list)
- def update(self, dt, ms):
+ def update(self, dt, ms, *args):
GameObject.update(self, dt, ms)
if self.max_distance == -1:
return
@@ -69,7 +69,7 @@ class GuidedBullet(Bullet):
self.enemy_list = enemy_list
self.target = self.lock_target()
- def update(self, dt, ms):
+ def update(self, dt, ms, *args):
"""
Set speed before calling Bullet update method.
Speed will be set to keep the bullet following the target.
diff --git a/code/enemy.py b/code/enemy.py
index 35fb369..1a1d622 100644
--- a/code/enemy.py
+++ b/code/enemy.py
@@ -29,16 +29,48 @@ class Enemy(Actor):
Creates an enemy character that could has one of the following
behaves: normal, fast, or diagonal.
"""
+
+ self.counter = 1
+ self.orientation = True
+ self.behaviour = behaviour
if behaviour == "normal":
speed = [-4, 0]
elif behaviour == "fast":
speed = [-7, 0]
elif behaviour == "diagonal":
speed = [-3, 1]
+ elif behaviour == "seeker":
+ speed = [-3, 1]
+ elif behaviour == "zigzag":
+ speed = [-3, 1]
Actor.__init__(self, position, rotation, life, speed,
rotation_speed, image)
+ def update(self, dt, ms, counter, x, y):
+ if self.behaviour == "zigzag":
+ if self.counter % 15 == 0:
+ if self.orientation == False:
+ self.speed = [-3, -8]
+ self.orientation = True
+ else:
+ self.speed = [-3, 8]
+ self.orientation = False
+ elif self.behaviour == "seeker":
+ if self.counter %2 == 0:
+ if self.orientation == True:
+ e_x, e_y = self.get_pos()
+ if e_y > y:
+ self.speed = [-3, -1]
+ elif e_y < y:
+ self.speed = [-3, 1]
+ else:
+ self.speed = [-3, 0]
+ else:
+ self.speed = [-3, 0]
+ self.counter = self.counter + 1
+ Actor.update(self, dt, ms)
+
def get_behaviours():
"""
Returns a list with all the possible behaviours
diff --git a/code/game.py b/code/game.py
index 742900d..d90cb68 100644
--- a/code/game.py
+++ b/code/game.py
@@ -313,8 +313,10 @@ class Game:
"""
self.background.update(dt)
+ x, y = self.player.get_pos()
+
for actor in self.actors_list.values():
- actor.update(dt, ms)
+ actor.update(dt, ms, self.counter, x, y)
self.hud.update(self.screen, ms)
@@ -386,7 +388,7 @@ class Game:
# increase xp based on hits
self.player.set_xp(self.player.get_xp() + len(hitted))
- def manage_elements(self, stage, counter):
+ def manage_elements(self, stage):
"""
Creates enemies and itens based on the xml parsed file
"""
@@ -400,7 +402,7 @@ class Game:
self.ticks = 0
# creates enemies based on xml file
- L = stage.pop(counter)
+ L = stage.pop(self.counter)
for element in L:
if element.type == "enemy":
# FIX: Create enemies and itens similarly (create a generic class)
@@ -437,7 +439,7 @@ class Game:
# loads stage configuration
stage = Stage("stage1.xml")
stage.buildStage()
- counter = 0
+ self.counter = 0
# creates the background
self.background = Background("tile.png")
@@ -480,10 +482,10 @@ class Game:
self.actors_act()
# create enemies based on xml file
- self.manage_elements(stage, counter)
+ self.manage_elements(stage)
# draw the elements to the back buffer
self.actors_draw()
# flip the front and back buffer
pygame.display.flip()
- counter += 1
+ self.counter += 1
diff --git a/code/game_object.py b/code/game_object.py
index c4bcbde..b58f169 100644
--- a/code/game_object.py
+++ b/code/game_object.py
@@ -40,7 +40,7 @@ class GameObject(pygame.sprite.Sprite):
self.set_speed(speed or (0,0))
self.set_rotation_speed(rotation_speed)
- def update(self, dt, ms):
+ def update(self, dt, ms, *args):
"""
Updates the position and rotation angle and destroy the object
if it's out of the screen
diff --git a/code/player.py b/code/player.py
index fd2303b..6665908 100644
--- a/code/player.py
+++ b/code/player.py
@@ -31,7 +31,7 @@ class Player(Actor):
Actor.__init__(self, position, rotation, life, [0, 0], 0, image)
self.set_xp(0)
- def update(self, dt, ms):
+ def update(self, dt, ms, *args):
"""
Override GameObjecte update()
Keep the player inside the screen instead of killing it
diff --git a/code/power_up.py b/code/power_up.py
index 82aaf59..aff7ffc 100644
--- a/code/power_up.py
+++ b/code/power_up.py
@@ -26,7 +26,7 @@ class PowerUp(GameObject):
self.special = special
self.set_life_time(life_time)
- def update(self, dt, ms):
+ def update(self, dt, ms, *args):
"""
Overrides GameObject update
"""
diff --git a/code/stage.py b/code/stage.py
index b21f907..a8be1a1 100644
--- a/code/stage.py
+++ b/code/stage.py
@@ -106,10 +106,6 @@ class Stage:
while nextx == position:
subList.append(self.L.pop())
nextx = self.getNextX()
- print(len(subList))
- print(len(self.L))
- print(position)
- print(nextx)
return subList
def buildStage(self):
diff --git a/data/stage1.xml b/data/stage1.xml
index 4f3363c..54dd5b7 100644
--- a/data/stage1.xml
+++ b/data/stage1.xml
@@ -14,18 +14,18 @@
<speed>0</speed>
<life>1</life>
<image>none</image>
- <behaviour>normal</behaviour>
+ <behaviour>zigzag</behaviour>
<special>0</special>
</item>
<item>
<type>enemy</type>
- <cc>120</cc>
+ <cc>200</cc>
<pos_x>0</pos_x>
<pos_y>30</pos_y>
<speed>0</speed>
<life>1</life>
<image>none</image>
- <behaviour>normal</behaviour>
+ <behaviour>seeker</behaviour>
<special>0</special>
</item>
<item>
-----------------------------------------------------------------------
Summary of changes:
code/bullet.py | 4 ++--
code/enemy.py | 32 ++++++++++++++++++++++++++++++++
code/game.py | 14 ++++++++------
code/game_object.py | 2 +-
code/player.py | 2 +-
code/power_up.py | 2 +-
code/stage.py | 4 ----
data/stage1.xml | 6 +++---
8 files changed, 48 insertions(+), 18 deletions(-)
--
Dead Channel is a sci-fi shoot 'em up game developed using pygame.
|