Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Scene and turn-based game
-
I am making a turn-based game in which I have units (armies). How to set the sequential movement of armies in the Scene? Everything works in parallel in the Scene. And my armies are all moving together. I want them to move one by one. For example: unit1 and unit2 is moving together, not one by one. :((((
actions = [] actions.append(A.move_by(50, 0, d)) actions.append(A.wait(p)) self.unit1.run_action(A.sequence(actions)) actions = [] actions.append(A.move_by(0, 50, d)) actions.append(A.wait(p)) self.unit2.run_action(A.sequence(actions))
-
@vs212, here is one example:
from functools import partial from scene import * from scene import Action as A class MyScene (Scene): def setup(self): self.background_color = 'midnightblue' self.unit1 = SpriteNode('spc:PlayerShip1Orange') self.unit1.position = self.size / 2 self.add_child(self.unit1) self.unit2 = SpriteNode('spc:PlayerShip1Orange') self.unit2.position = self.size / 4 self.add_child(self.unit2) def touch_began(self, touch): unit1_actions = A.sequence( A.move_by(0, 50), A.wait(1), ) unit2_actions = A.sequence( A.move_by(0, 50), A.wait(1), ) self.unit1.run_action( A.sequence( unit1_actions, A.call(partial( self.unit2.run_action, unit2_actions)) ) ) run(MyScene())
-
@vs212, but for this, I would suggest you
pip install pythonista-scripter
, which lets you do the following:from scene import * from scripter import * class MyScene (Scene): def setup(self): self.background_color = 'midnightblue' self.unit1 = SpriteNode('spc:PlayerShip1Orange') self.unit1.position = self.size / 2 self.add_child(self.unit1) self.unit2 = SpriteNode('spc:PlayerShip1Orange') self.unit2.position = self.size / 4 self.add_child(self.unit2) start_scripter(self.view) def touch_began(self, touch): self.move_units() @script def move_units(self): move_by(self.unit1, 0, 50) yield move_by(self.unit2, 0, 50) run(MyScene())
-
(See docs at https://github.com/mikaelho/scripter.)
-
This post is deleted! -
This post is deleted! -
@mikael Thank you very much. A very powerful package!
-
This post is deleted! -
@vs212, always nice to hear when people find a use for it.
I think you found the
duration
parameter. See below an example for changing the global default as well.from scene import * import scripter as s s.default_duration = 0.2 class MyScene (Scene): def setup(self): self.background_color = 'midnightblue' self.unit1 = SpriteNode('spc:PlayerShip1Orange') self.unit1.position = self.size / 2 self.add_child(self.unit1) self.unit2 = SpriteNode('spc:PlayerShip1Orange') self.unit2.position = self.size / 4 self.add_child(self.unit2) s.start_scripter(self.view) def touch_began(self, touch): self.move_units() @s.script def move_units(self): s.move_by(self.unit1, 0, 50, duration=1.0) yield s.move_by(self.unit2, 0, 50) run(MyScene())
-
@mikael My mistake was - I didn't use ‘ duration=’ ))
Thank you!
-
@mikael It's not just nice. You saved me. I've already climbed into such abysses. And here everything is so elegant and simple. You are an excellent programmer.