[sbfury] push by hugoruscitti - creando un sistema de controles basico. on 2010-01-02 03:17 GMT

1 view
Skip to first unread message

codesite...@google.com

unread,
Jan 1, 2010, 10:17:45 PM1/1/10
to losersjue...@googlegroups.com
Revision: a881c771b0
Author: hugoruscitti
Date: Fri Jan 1 19:17:17 2010
Log: creando un sistema de controles basico.
http://code.google.com/p/sbfury/source/detail?r=a881c771b0

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

=======================================
--- /dev/null
+++ /sbfury/control.py Fri Jan 1 19:17:17 2010
@@ -0,0 +1,19 @@
+from PySFML import sf
+
+class Control:
+
+ def __init__(self, input):
+ self.input = input
+ self.update(0)
+
+ def update(self, dt):
+
+ if self.input.IsKeyDown(sf.Key.Left):
+ self.left = True
+ else:
+ self.left = False
+
+ if self.input.IsKeyDown(sf.Key.Right):
+ self.right = True
+ else:
+ self.right = False
=======================================
--- /sbfury/sbfury.py Fri Jan 1 13:40:35 2010
+++ /sbfury/sbfury.py Fri Jan 1 19:17:17 2010
@@ -1,6 +1,7 @@
from PySFML import sf
import sys
import common
+import control

import shaolin

@@ -18,14 +19,16 @@

app.UseVerticalSync(True)

-
-player = shaolin.Shaolin()
+control = control.Control(input)
+
+player = shaolin.Shaolin(control)

while True:
dt = app.GetFrameTime()
app.Clear(color)
app.Draw(player)

+ control.update(dt)
player.update(dt)

while app.GetEvent(event):
=======================================
--- /sbfury/shaolin.py Fri Jan 1 14:00:53 2010
+++ /sbfury/shaolin.py Fri Jan 1 19:17:17 2010
@@ -4,7 +4,7 @@

class Shaolin(sf.Sprite):

- def __init__(self):
+ def __init__(self, control):
image = common.load_sheet("../data/shaolin/stand.png", 4, 1)
sf.Sprite.__init__(self, image.image)
image.Assign(self)
@@ -12,6 +12,7 @@
self.SetPosition(200, 200)
self._load_animations()
self.set_animation('stand')
+ self.control = control

def _load_animations(self):

@@ -27,6 +28,13 @@
def update(self, dt):
self.update_animation(dt)

+ if self.control.left:
+ self.Move(-dt * 200, 0)
+ elif self.control.right:
+ self.Move(dt * 200, 0)
+
+
def update_animation(self, dt):
- self.animation.update(dt)
+ was_restarted = self.animation.update(dt)
self.animation.Assign(self)
+ return was_restarted

Reply all
Reply to author
Forward
0 new messages