[sbfury] 2 new revisions pushed by hugoruscitti on 2010-01-01 22:04 GMT

1 view
Skip to first unread message

codesite...@google.com

unread,
Jan 1, 2010, 5:05:17 PM1/1/10
to losersjue...@googlegroups.com
2 new revisions:

Revision: d5f8f7404c
Author: hugoruscitti
Date: Fri Jan 1 13:40:35 2010
Log: creating sprite object for shaolin.
http://code.google.com/p/sbfury/source/detail?r=d5f8f7404c

Revision: 3d2f1d2796
Author: hugoruscitti
Date: Fri Jan 1 14:00:53 2010
Log: agregando animaciones al protagonista.
http://code.google.com/p/sbfury/source/detail?r=3d2f1d2796

==============================================================================
Revision: d5f8f7404c
Author: hugoruscitti
Date: Fri Jan 1 13:40:35 2010
Log: creating sprite object for shaolin.
http://code.google.com/p/sbfury/source/detail?r=d5f8f7404c

Added:
/sbfury/shaolin.py
Modified:
/sbfury/sbfury.py

=======================================
--- /dev/null
+++ /sbfury/shaolin.py Fri Jan 1 13:40:35 2010
@@ -0,0 +1,14 @@
+from PySFML import sf
+import common
+
+class Shaolin(sf.Sprite):
+
+ def __init__(self):
+ image = common.load_sheet("../data/shaolin/stand.png", 4, 1)
+ sf.Sprite.__init__(self, image.image)
+ image.Assign(self)
+ self.image = image
+ self.SetPosition(200, 200)
+
+ def update(self, dt):
+ pass
=======================================
--- /sbfury/sbfury.py Fri Jan 1 13:33:31 2010
+++ /sbfury/sbfury.py Fri Jan 1 13:40:35 2010
@@ -2,6 +2,9 @@
import sys
import common

+import shaolin
+
+
app = sf.RenderWindow()
app.Create(sf.VideoMode(720, 480), "sbfury")
app.SetPosition(300, 200)
@@ -16,14 +19,14 @@
app.UseVerticalSync(True)


-image = common.load_sheet("../data/shaolin/stand.png", 4, 1)
-sprite = sf.Sprite(image.image)
-image.Assign(sprite)
+player = shaolin.Shaolin()

while True:
dt = app.GetFrameTime()
app.Clear(color)
- app.Draw(sprite)
+ app.Draw(player)
+
+ player.update(dt)

while app.GetEvent(event):


==============================================================================
Revision: 3d2f1d2796
Author: hugoruscitti
Date: Fri Jan 1 14:00:53 2010
Log: agregando animaciones al protagonista.
http://code.google.com/p/sbfury/source/detail?r=3d2f1d2796

Added:
/sbfury/animation.py
Modified:
/sbfury/shaolin.py

=======================================
--- /dev/null
+++ /sbfury/animation.py Fri Jan 1 14:00:53 2010
@@ -0,0 +1,44 @@
+# License: Public Domain
+# Author: Hugo Ruscitti (http://www.losersjuegos.com.ar)
+import sheet
+
+class Animation:
+
+ def __init__(self, sheet, delay, sequence, stop_when_finish=False):
+ self.step_in_sequence = 0
+ self.sheet = sheet
+ self.delay = delay
+ self.reset()
+ self.sequence = sequence
+ self.stop_when_finish = stop_when_finish
+
+ def reset(self):
+ self.delay_counter = 0
+
+ def update(self, dt):
+ "Avanza en la animacion y retorna True si ha reiniciado."
+ self.delay_counter += dt
+
+ if self.delay_counter >= self.delay:
+ self.reset()
+ return self.next_frame()
+
+ def Assign(self, sprite):
+ self.sheet.Assign(sprite)
+
+ def next_frame(self):
+ "Avanza en la secuencia y retorna True si la animacion termina."
+ was_restarted = False
+ self.step_in_sequence += 1
+
+ if self.step_in_sequence >= len(self.sequence):
+ if self.stop_when_finish:
+ self.step_in_sequence -= 1
+ else:
+ self.step_in_sequence = 0
+ was_restarted = True
+
+ frame_to_show = self.sequence[self.step_in_sequence]
+ self.sheet.SetFrameIndex(frame_to_show)
+
+ return was_restarted
=======================================
--- /sbfury/shaolin.py Fri Jan 1 13:40:35 2010
+++ /sbfury/shaolin.py Fri Jan 1 14:00:53 2010
@@ -1,5 +1,6 @@
from PySFML import sf
import common
+import animation

class Shaolin(sf.Sprite):

@@ -9,6 +10,23 @@
image.Assign(self)
self.image = image
self.SetPosition(200, 200)
+ self._load_animations()
+ self.set_animation('stand')
+
+ def _load_animations(self):
+
+ image = common.load_sheet("../data/shaolin/stand.png", 4, 1)
+
+ self.animations = {
+ 'stand': animation.Animation(image, 0.20, [0, 1, 2, 3]),
+ }
+
+ def set_animation(self, animation_name):
+ self.animation = self.animations[animation_name]

def update(self, dt):
- pass
+ self.update_animation(dt)
+
+ def update_animation(self, dt):
+ self.animation.update(dt)
+ self.animation.Assign(self)

Reply all
Reply to author
Forward
0 new messages