|
From: João <lv...@us...> - 2009-12-05 04:58:28
|
This is an automated email from the git, the tree hashes are:
via 71889b94137ca9a043dc8b14ac85cb7176ac5170 (commit)
via 091eca2725410724ca024a1a8134a126379d0410 (commit)
from 6d919fc872b07572540022ecfbdc34fbe97c502e (commit)
- Log -----------------------------------------------------------------
commit 71889b94137ca9a043dc8b14ac85cb7176ac5170
Merge: 091eca2 6d919fc
Author: João <jcorrea@marvim.(none)>
Date: Sat Dec 5 02:58:12 2009 -0200
Merge branch 'master' of ssh://lvwr@deadchannel.git.sourceforge.net/gitroot/deadchannel/deadchannel
commit 091eca2725410724ca024a1a8134a126379d0410
Author: João <jcorrea@marvim.(none)>
Date: Sat Dec 5 02:57:14 2009 -0200
More descriptive xml objects and better parser
diff --git a/code/game.py b/code/game.py
index 069eb42..67ee162 100644
--- a/code/game.py
+++ b/code/game.py
@@ -402,14 +402,15 @@ class Game:
for element in L:
if element.type == "enemy":
# FIX: Create enemies and itens similarly (create a generic class)
- enemy = Enemy([0, 0], element.rot, element.life, element.behaviour,
- element.rotspeed, self.image_enemy)
+ enemy = Enemy([0, 0], 0, element.life, element.behaviour,
+ 0, self.image_enemy)
size = enemy.get_size()
y = Random.randint(size[1] / 2, self.screen_size[1] - size[1] / 2)
pos = [self.screen_size[0] + size[0] / 2, y]
enemy.set_pos(pos)
# add sprite to group
self.actors_list["enemies"].add(enemy)
+ print("enemy")
elif element.type in ["first_aid_kit", "sw_mult", "sw_frag",
"sw_guided"]:
powerup = PowerUp([0,0], element.life,
@@ -421,6 +422,7 @@ class Game:
pos = [self.screen_size[0] + size[0] / 2, y]
powerup.set_pos(pos)
self.actors_list["powerups"].add(powerup)
+ print(element.type)
elif element.type == "background":
self.background.nextTile(element.image)
print "backgs"
diff --git a/code/stage.py b/code/stage.py
index 622c34b..b21f907 100644
--- a/code/stage.py
+++ b/code/stage.py
@@ -15,39 +15,85 @@ import xml.dom
import xml.dom.minidom
class Callable:
-
def __init__(self, anycallable):
self.__call__ = anycallable
class Item:
- def __init__(self, x, y, speed_x, speed_y, rot, rotspeed, life, image,
- type, behaviour, special):
- self.x = x
- self.y = y
- self.speed_x = speed_x
- self.speed_y = speed_y
- self.rot = rot
- self.rotspeed = rotspeed
- self.life = life
- self.image = image
- self.type = type
- self.behaviour = behaviour
- self.special = special
+ def __init__(self, node):
+ self.type = node.getElementsByTagName("type")[0].childNodes[0].nodeValue
+ self.cc = int(node.getElementsByTagName("cc")[0].childNodes[0].nodeValue)
+
+class Backg(Item):
+ def __init__(self, node):
+ Item.__init__(self, node)
+ self.image = node.getElementsByTagName("image")[0].childNodes[0].nodeValue
+ self.layer = node.getElementsByTagName("layer")[0].childNodes[0].nodeValue
+
+class Enemy(Item):
+ def __init__(self, node):
+ Item.__init__(self, node)
+ self.pos_x = node.getElementsByTagName("pos_x")[0].childNodes[0].nodeValue
+ self.pos_y = node.getElementsByTagName("pos_y")[0].childNodes[0].nodeValue
+ self.behaviour = node.getElementsByTagName("behaviour")[0].childNodes[0].nodeValue
+ self.life = node.getElementsByTagName("life")[0].childNodes[0].nodeValue
+ self.image = node.getElementsByTagName("image")[0].childNodes[0].nodeValue
+ self.speed = node.getElementsByTagName("speed")[0].childNodes[0].nodeValue
+
+class Sw(Item):
+ def __init__(self, node):
+ Item.__init__(self, node)
+ self.pos_x = node.getElementsByTagName("pos_x")[0].childNodes[0].nodeValue
+ self.pos_y = node.getElementsByTagName("pos_y")[0].childNodes[0].nodeValue
+ self.speed_x = node.getElementsByTagName("speed_y")[0].childNodes[0].nodeValue
+ self.speed_y = node.getElementsByTagName("speed_x")[0].childNodes[0].nodeValue
+ self.name = node.getElementsByTagName("name")[0].childNodes[0].nodeValue
+ self.ammo = node.getElementsByTagName("ammo")[0].childNodes[0].nodeValue
+ self.max_ammo = node.getElementsByTagName("max_ammo")[0].childNodes[0].nodeValue
+ self.cooldown = node.getElementsByTagName("cooldown")[0].childNodes[0].nodeValue
+ self.heating = node.getElementsByTagName("heating")[0].childNodes[0].nodeValue
+ self.time = node.getElementsByTagName("time")[0].childNodes[0].nodeValue
+
+class Mult(Sw):
+ def __init__(self, node):
+ Sw.__init__(self, node)
+ self.special1 = node.getElementsByTagName("special1")[0].childNodes[0].nodeValue
+ self.special2 = node.getElementsByTagName("special2")[0].childNodes[0].nodeValue
+
+class Frag(Sw):
+ def __init__(self, node):
+ Sw.__init__(self, node)
+ self.special1 = node.getElementsByTagName("special1")[0].childNodes[0].nodeValue
+ self.max_charge = node.getElementsByTagName("max_charge")[0].childNodes[0].nodeValue
+
+class Guided(Sw):
+ def __init__(self, node):
+ Sw.__init__(self, node)
+ self.special1 = node.getElementsByTagName("special1")[0].childNodes[0].nodeValue
+ self.special2 = node.getElementsByTagName("special2")[0].childNodes[0].nodeValue
+
+class FirstAidKit(Item):
+ def __init__(self, node):
+ Item.__init__(self, node)
+ self.pos_x = node.getElementsByTagName("pos_x")[0].childNodes[0].nodeValue
+ self.pos_y = node.getElementsByTagName("pos_y")[0].childNodes[0].nodeValue
+ self.speed_x = node.getElementsByTagName("speed_x")[0].childNodes[0].nodeValue
+ self.speed_y = node.getElementsByTagName("speed_y")[0].childNodes[0].nodeValue
+ self.life = node.getElementsByTagName("life")[0].childNodes[0].nodeValue
+ self.time = node.getElementsByTagName("time")[0].childNodes[0].nodeValue
class Stage:
-
L = list()
def __init__(self, file):
self.data = xml.dom.minidom.parse(file)
def __cmp__(self, other):
- return cmp(self.x, other.x)
+ return cmp(self.cc, other.cc)
def getNextX(self):
if len(self.L) > 0:
item = self.L[len(self.L) - 1]
- return item.x
+ return item.cc
else:
return -1
@@ -56,39 +102,36 @@ class Stage:
def pop(self, position):
subList = list()
- nextx = self.getNextX()
+ nextx = int(self.getNextX())
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 get_special(self, nodes):
- node = nodes.getElementsByTagName("special")[0].childNodes[0].nodeValue
- return node.split(',')
-
def buildStage(self):
- for nodes in self.data.getElementsByTagName("item"):
- itemType = nodes.getElementsByTagName("type")[0].childNodes[0].nodeValue
- x = int(nodes.getElementsByTagName("x")[0].childNodes[0].nodeValue)
- image = nodes.getElementsByTagName("image")[0].childNodes[0].nodeValue
-
- if itemType == "background":
- item = Item(x, "", "", "", "", "", "", image, itemType, "", "")
-
- else:
-
- life = int(nodes.getElementsByTagName("life")[0].childNodes[0].nodeValue)
- y = int(nodes.getElementsByTagName("y")[0].childNodes[0].nodeValue)
- speed_x = int(nodes.getElementsByTagName("speed_x")[0].childNodes[0].nodeValue)
- speed_y = int(nodes.getElementsByTagName("speed_y")[0].childNodes[0].nodeValue)
- rot = int(nodes.getElementsByTagName("rot")[0].childNodes[0].nodeValue)
- rotspeed = int(nodes.getElementsByTagName("rotspeed")[0].childNodes[0].nodeValue)
- life = int(nodes.getElementsByTagName("life")[0].childNodes[0].nodeValue)
- behaviour = nodes.getElementsByTagName("behaviour")[0].childNodes[0].nodeValue
- special = self.get_special(nodes)
- item = Item(x, y, speed_x, speed_y, rot, rotspeed, life, image,
- itemType, behaviour, special)
+ for node in self.data.getElementsByTagName("item"):
+ type = node.getElementsByTagName("type")[0].childNodes[0].nodeValue
+ if type == "background":
+ item = Backg(node)
+ elif type == "enemy":
+ item = Enemy(node)
+ elif type == "sw_mult":
+ item = Mult(node)
+ elif type == "sw_frag":
+ item = Frag(node)
+ elif type == "sw_guided":
+ item = Guided(node)
+ elif type == "first_aid_kit":
+ item = FirstAidKit(node)
+ elif type == "sw_mult":
+ item = Mult(node)
+
+ print(item.cc)
self.include(item)
#below is some black magic I'm not sure how to deal with... but works
#taken from stackoverflow.org
- self.L.sort(key=lambda item: item.x, reverse=True)
+ self.L.sort(key=lambda item: item.cc, reverse=True)
diff --git a/data/stage1.xml b/data/stage1.xml
index 5b1800f..4f3363c 100644
--- a/data/stage1.xml
+++ b/data/stage1.xml
@@ -2,243 +2,233 @@
<fase>
<item>
<type>background</type>
- <x>1</x>
+ <cc>1</cc>
<image>tiles/stars1.jpg</image>
+ <layer>1</layer>
</item>
<item>
- <type>enemy</type>
- <x>100</x>
- <y>40</y>
- <speed_x>0</speed_x>
- <speed_y>0</speed_y>
- <rot>7</rot>
- <rotspeed>2</rotspeed>
- <life>1</life>
- <image>none</image>
- <behaviour>normal</behaviour>
- <special>0</special>
-</item>
-<item>
- <type>enemy</type>
- <x>200</x>
- <y>388</y>
- <speed_x>0</speed_x>
- <speed_y>0</speed_y>
- <rot>20</rot>
- <rotspeed>20</rotspeed>
- <life>1</life>
- <image>none</image>
- <behaviour>fast</behaviour>
- <special>0</special>
+ <type>enemy</type>
+ <cc>100</cc>
+ <pos_x>0</pos_x>
+ <pos_y>40</pos_y>
+ <speed>0</speed>
+ <life>1</life>
+ <image>none</image>
+ <behaviour>normal</behaviour>
+ <special>0</special>
</item>
<item>
- <type>background</type>
- <x>200</x>
- <image>tiles/stars3.jpg</image>
+ <type>enemy</type>
+ <cc>120</cc>
+ <pos_x>0</pos_x>
+ <pos_y>30</pos_y>
+ <speed>0</speed>
+ <life>1</life>
+ <image>none</image>
+ <behaviour>normal</behaviour>
+ <special>0</special>
</item>
<item>
- <type>enemy</type>
- <x>200</x>
- <y>200</y>
- <speed_x>0</speed_x>
- <speed_y>0</speed_y>
- <rot>40</rot>
- <rotspeed>0</rotspeed>
- <life>1</life>
- <image>none</image>
- <behaviour>normal</behaviour>
- <special>0</special>
-</item>
-<item>
- <type>sw_mult</type>
- <x>300</x>
- <y>10</y>
- <speed_x>-3</speed_x>
- <speed_y>0</speed_y>
- <rot>0</rot>
- <rotspeed>0</rotspeed>
- <life>3000</life>
- <image>none</image>
- <behaviour>none</behaviour>
- <special>Stuck Duck, 20, 100, 400, 300, 300, 0, 60, 3</special>
-</item>
-<item>
- <type>first_aid_kit</type>
- <x>350</x>
- <y>10</y>
- <speed_x>-2</speed_x>
- <speed_y>1</speed_y>
- <rot>0</rot>
- <rotspeed>0</rotspeed>
- <life>5000</life>
- <image>none</image>
- <behaviour>none</behaviour>
- <special>3</special>
-</item>
-<item>
- <type>sw_frag</type>
- <x>400</x>
- <y>10</y>
- <speed_x>-4</speed_x>
- <speed_y>0</speed_y>
- <rot>0</rot>
- <rotspeed>0</rotspeed>
- <life>2000</life>
- <image>none</image>
- <behaviour>none</behaviour>
- <special>Last Kiss, 10, 10, 450, 600, 600, 1000, 4</special>
-</item>
-<item>
- <type>sw_mult</type>
- <x>500</x>
- <y>10</y>
- <speed_x>-3</speed_x>
- <speed_y>0</speed_y>
- <rot>0</rot>
- <rotspeed>0</rotspeed>
- <life>4000</life>
- <image>none</image>
- <behaviour>none</behaviour>
- <special>Psycho Killer, 100, 100, 400, 300, 300, 0, 360, 10</special>
-</item>
-<item>
- <type>sw_mult</type>
- <x>580</x>
- <y>10</y>
- <speed_x>-3</speed_x>
- <speed_y>0</speed_y>
- <rot>0</rot>
- <rotspeed>0</rotspeed>
- <life>4000</life>
- <image>none</image>
- <behaviour>none</behaviour>
- <special>Psycho Killer, 20, 100, 400, 300, 300, 0, 360, 10</special>
-</item>
-<item>
- <type>sw_guided</type>
- <x>700</x>
- <y>10</y>
- <speed_x>-4</speed_x>
- <speed_y>0</speed_y>
- <rot>0</rot>
- <rotspeed>0</rotspeed>
- <life>2000</life>
- <image>none</image>
- <behaviour>none</behaviour>
- <special>Seek and Destroy, 45, 50, 150, 900, 300, 0</special>
-</item>
-<item>
- <type>enemy</type>
- <x>800</x>
- <y>388</y>
- <speed_x>0</speed_x>
- <speed_y>0</speed_y>
- <rot>20</rot>
- <rotspeed>20</rotspeed>
- <life>1</life>
- <image>none</image>
- <behaviour>diagonal</behaviour>
- <special>0</special>
-</item>
-<item>
- <type>enemy</type>
- <x>900</x>
- <y>200</y>
- <speed_x>0</speed_x>
- <speed_y>0</speed_y>
- <rot>40</rot>
- <rotspeed>0</rotspeed>
- <life>1</life>
- <image>none</image>
- <behaviour>normal</behaviour>
- <special>0</special>
+ <type>background</type>
+ <cc>200</cc>
+ <image>tiles/stars3.jpg</image>
+ <layer>1</layer>
+</item>
+<item>
+ <type>sw_mult</type>
+ <cc>300</cc>
+ <pos_x>0</pos_x>
+ <pos_y>10</pos_y>
+ <speed_x>-3</speed_x>
+ <speed_y>0</speed_y>
+ <name>Stuck Duck</name>
+ <ammo>20</ammo>
+ <max_ammo>100</max_ammo>
+ <cooldown>400</cooldown>
+ <heating>300</heating>
+ <max_charge>300</max_charge>
+ <time>60</time>
+ <special1>30</special1>
+ <special2>30</special2>
+ <special>Stuck Duck, 20, 100, 400, 300, 300, 0, 60, 3</special>
+</item>
+<item>
+ <type>first_aid_kit</type>
+ <cc>350</cc>
+ <pos_x>0</pos_x>
+ <pos_y>10</pos_y>
+ <speed_x>-2</speed_x>
+ <speed_y>1</speed_y>
+ <life>5</life>
+ <time>5000</time>
+</item>
+<item>
+ <type>sw_frag</type>
+ <cc>400</cc>
+ <pos_x>0</pos_x>
+ <pos_y>10</pos_y>
+ <speed_x>-4</speed_x>
+ <speed_y>0</speed_y>
+ <name>Last Kiss</name>
+ <ammo>10</ammo>
+ <max_ammo>10</max_ammo>
+ <cooldown>450</cooldown>
+ <heating>600</heating>
+ <max_charge>1000</max_charge>
+ <time>60</time>
+ <special1>1000</special1>
+ <special2>40</special2>
+ <special>Last Kiss, 10, 10, 450, 600, 600, 1000, 4</special>
+</item>
+<item>
+ <type>sw_mult</type>
+ <cc>500</cc>
+ <pos_x>0</pos_x>
+ <pos_y>10</pos_y>
+ <speed_x>-3</speed_x>
+ <speed_y>0</speed_y>
+ <name>Psycho Killah!</name>
+ <ammo>100</ammo>
+ <max_ammo>100</max_ammo>
+ <cooldown>400</cooldown>
+ <heating>300</heating>
+ <max_charge>300</max_charge>
+ <time>60</time>
+ <special1>360</special1>
+ <special2>10</special2>
+</item>
+<item>
+ <type>sw_mult</type>
+ <cc>580</cc>
+ <pos_x>0</pos_x>
+ <pos_y>10</pos_y>
+ <speed_x>-3</speed_x>
+ <speed_y>0</speed_y>
+ <name>Pala Infinita!</name>
+ <ammo>20</ammo>
+ <max_ammo>100</max_ammo>
+ <cooldown>400</cooldown>
+ <heating>300</heating>
+ <max_charge>300</max_charge>
+ <time>60</time>
+ <special1>360</special1>
+ <special2>10</special2>
+</item>
+<item>
+ <type>sw_guided</type>
+ <cc>700</cc>
+ <pos_x>0</pos_x>
+ <pos_y>10</pos_y>
+ <speed_x>-4</speed_x>
+ <speed_y>0</speed_y>
+ <name>Seeeeeeek... Seek and Destroy!</name>
+ <ammo>40</ammo>
+ <max_ammo>50</max_ammo>
+ <cooldown>150</cooldown>
+ <heating>900</heating>
+ <max_charge>300</max_charge>
+ <time>60</time>
+ <special1>30</special1>
+ <special2>30</special2>
+</item>
+<item>
+ <type>enemy</type>
+ <cc>800</cc>
+ <pos_x>0</pos_x>
+ <pos_y>70</pos_y>
+ <speed>0</speed>
+ <life>1</life>
+ <image>none</image>
+ <behaviour>normal</behaviour>
+ <special>0</special>
+</item>
+<item>
+ <type>enemy</type>
+ <cc>900</cc>
+ <pos_x>0</pos_x>
+ <pos_y>30</pos_y>
+ <speed>0</speed>
+ <life>1</life>
+ <image>none</image>
+ <behaviour>normal</behaviour>
+ <special>0</special>
</item>
<item>
<type>background</type>
- <x>1000</x>
+ <cc>1000</cc>
<image>tiles/stars1.jpg</image>
+ <layer>1</layer>
</item>
<item>
<type>background</type>
- <x>1010</x>
+ <cc>1010</cc>
<image>tiles/stars3.jpg</image>
-</item>
-<item>
- <type>enemy</type>
- <x>1200</x>
- <y>200</y>
- <speed_x>0</speed_x>
- <speed_y>0</speed_y>
- <rot>40</rot>
- <rotspeed>0</rotspeed>
- <life>2</life>
- <image>none</image>
- <behaviour>normal</behaviour>
- <special>0</special>
-</item>
-<item>
- <type>enemy</type>
- <x>1300</x>
- <y>200</y>
- <speed_x>0</speed_x>
- <speed_y>0</speed_y>
- <rot>40</rot>
- <rotspeed>0</rotspeed>
- <life>2</life>
- <image>none</image>
- <behaviour>fast</behaviour>
- <special>0</special>
-</item>
-<item>
- <type>enemy</type>
- <x>1400</x>
- <y>200</y>
- <speed_x>0</speed_x>
- <speed_y>0</speed_y>
- <rot>40</rot>
- <rotspeed>0</rotspeed>
- <life>3</life>
- <image>none</image>
- <behaviour>normal</behaviour>
- <special>0</special>
-</item>
-<item>
- <type>enemy</type>
- <x>1500</x>
- <y>200</y>
- <speed_x>0</speed_x>
- <speed_y>0</speed_y>
- <rot>40</rot>
- <rotspeed>0</rotspeed>
- <life>3</life>
- <image>none</image>
- <behaviour>diagonal</behaviour>
- <special>0</special>
-</item>
-<item>
- <type>enemy</type>
- <x>1800</x>
- <y>200</y>
- <speed_x>0</speed_x>
- <speed_y>0</speed_y>
- <rot>40</rot>
- <rotspeed>0</rotspeed>
- <life>3</life>
- <image>none</image>
- <behaviour>normal</behaviour>
- <special>0</special>
-</item>
-<item>
- <type>enemy</type>
- <x>2000</x>
- <y>200</y>
- <speed_x>0</speed_x>
- <speed_y>0</speed_y>
- <rot>40</rot>
- <rotspeed>0</rotspeed>
- <life>3</life>
- <image>none</image>
- <behaviour>diagonal</behaviour>
- <special>0</special>
+ <layer>1</layer>
+</item>
+<item>
+ <type>enemy</type>
+ <cc>1200</cc>
+ <pos_x>0</pos_x>
+ <pos_y>30</pos_y>
+ <speed>0</speed>
+ <life>2</life>
+ <image>none</image>
+ <behaviour>normal</behaviour>
+ <special>0</special>
+</item>
+<item>
+ <type>enemy</type>
+ <cc>1300</cc>
+ <pos_x>0</pos_x>
+ <pos_y>30</pos_y>
+ <speed>0</speed>
+ <life>2</life>
+ <image>none</image>
+ <behaviour>normal</behaviour>
+ <special>0</special>
+</item>
+<item>
+ <type>enemy</type>
+ <cc>1400</cc>
+ <pos_x>0</pos_x>
+ <pos_y>30</pos_y>
+ <speed>0</speed>
+ <life>2</life>
+ <image>none</image>
+ <behaviour>normal</behaviour>
+ <special>0</special>
+</item>
+<item>
+ <type>enemy</type>
+ <cc>1500</cc>
+ <pos_x>0</pos_x>
+ <pos_y>30</pos_y>
+ <speed>0</speed>
+ <life>1</life>
+ <image>none</image>
+ <behaviour>normal</behaviour>
+ <special>0</special>
+</item>
+<item>
+ <type>enemy</type>
+ <cc>1800</cc>
+ <pos_x>0</pos_x>
+ <pos_y>30</pos_y>
+ <speed>0</speed>
+ <life>1</life>
+ <image>none</image>
+ <behaviour>normal</behaviour>
+ <special>0</special>
+</item>
+<item>
+ <type>enemy</type>
+ <cc>2000</cc>
+ <pos_x>0</pos_x>
+ <pos_y>30</pos_y>
+ <speed>0</speed>
+ <life>1</life>
+ <image>none</image>
+ <behaviour>normal</behaviour>
+ <special>0</special>
</item>
</fase>
-----------------------------------------------------------------------
Summary of changes:
code/game.py | 6 +-
code/stage.py | 131 +++++++++++------
data/stage1.xml | 436 +++++++++++++++++++++++++++----------------------------
3 files changed, 304 insertions(+), 269 deletions(-)
--
Dead Channel is a sci-fi shoot 'em up game developed using pygame.
|