omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    2
    11
    2641
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • vs212
      vs212 last edited by ccc

      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))
      mikael 2 Replies Last reply Reply Quote 0
      • mikael
        mikael @vs212 last edited by

        @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 1 Reply Last reply Reply Quote 1
        • mikael
          mikael @vs212 last edited by

          @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())
          
          
          mikael vs212 3 Replies Last reply Reply Quote 1
          • mikael
            mikael @mikael last edited by

            (See docs at https://github.com/mikaelho/scripter.)

            vs212 1 Reply Last reply Reply Quote 1
            • vs212
              vs212 @mikael last edited by

              This post is deleted!
              1 Reply Last reply Reply Quote 0
              • vs212
                vs212 @mikael last edited by

                This post is deleted!
                1 Reply Last reply Reply Quote 0
                • vs212
                  vs212 @mikael last edited by

                  @mikael Thank you very much. A very powerful package!

                  mikael 1 Reply Last reply Reply Quote 1
                  • vs212
                    vs212 @mikael last edited by vs212

                    This post is deleted!
                    1 Reply Last reply Reply Quote 0
                    • mikael
                      mikael @vs212 last edited by

                      @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())
                      
                      
                      vs212 2 Replies Last reply Reply Quote 1
                      • vs212
                        vs212 @mikael last edited by

                        @mikael My mistake was - I didn't use ‘ duration=’ ))

                        Thank you!

                        1 Reply Last reply Reply Quote 0
                        • vs212
                          vs212 @mikael last edited by

                          @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.

                          1 Reply Last reply Reply Quote 1
                          • First post
                            Last post
                          Powered by NodeBB Forums | Contributors