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.


    Flappy bird

    Pythonista
    4
    81
    25223
    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.
    • stephen
      stephen last edited by stephen

      @Karina ill whip up a quick example that will show the diferences and ill Annotate as much as i can 🙃 hang tight

      what do you mean you have nothing to write on?

      1 Reply Last reply Reply Quote 0
      • Karina
        Karina last edited by

        @stephen a notebook or smth and I wouldn't have to look what was in the beginning and had important things in front of me

        stephen 1 Reply Last reply Reply Quote 0
        • stephen
          stephen @Karina last edited by

          @Karina said:

          @stephen a notebook or smth and I wouldn't have to look what was in the beginning and had important things in front of me

          what are you using currently? and im sorry im taking so long to get back but i read overball the comments and im not sure i covered all the questions before. do you still not understand how the following works?

          • w()
            -update(self)
            -self.dt
            -self
            -self.size.w
            -lw()

          my final example full game will include all these and more but i dont want you to throw a full script at you unless you can comprehend a good amount. most of what has been covered has been mostly linear and the full script ill feel like a spider web lol but ill annotate as much as i can.

          1 Reply Last reply Reply Quote 0
          • Karina
            Karina last edited by

            w()
            -update(self)
            -self.dt
            -self
            -self.size.w
            -lw()

            This yes, here it looks quite easy.
            I'm trying to write for now like I can, though it's not the best way and I get annoying bugs sometimes
            What it means that it all was linear?

            the full script ill feel like a spider web lol but ill annotate as much as i can.

            Wow I'm scared

            1 Reply Last reply Reply Quote 0
            • Karina
              Karina last edited by Karina

              @stephen You said @in_background makes smth run on a dif thread. I'm not into the ui for now, but what is the dif thread?

              stephen 2 Replies Last reply Reply Quote 0
              • stephen
                stephen @Karina last edited by

                @Karina what i mean by linear is the scripts are writen in a step by step manner. and then the rest is all focused inside the loop body. just a way i refer to simple writing techniques. where alternatively i tend write in a manner that jumps around. multiple inheritence, conroller types, delegates.. and so on.

                @karina said:

                @stephen You said @in_background makes smth run on a dif thread. I'm not into the ui for now, but what is the dif thread?

                ui.in_background() decorator executes the following process in the main thread instead of on your current event loop's. whenever you call module level run() function from scene or class method View.Present()from ui you create a new event loop separate from Interpreters main thread. Python uses GIL (Global Interpreter Lock) that only alows one thread. you can still use multiprocessing though. for info on that check out Asynchronous programming. the reason for GIL is objC memory managment is not considered "Thread Safe".

                Docs said:

                ui.in_background(fn):

                Call a function on the main interpreter thread. This is useful to perform long-running tasks from an action or delegate callback without blocking the UI. It can also be used for functions that don’t support being called from the main UI thread (e.g. console.alert()).

                as far as you not using the ui module... you have been this whole time.. lol scene uses ui quite heavely. and you dont need to import ui separatly. by using from scene import * ui is also included. from your game just call ui. and then whatever you want from there. when you run your scene game it actually prepares the ui stuff for you and then presents a SceneView if you setup a custom View class in your game script you can create a scene.SceneView and set its SceneView.scene property to your Game Object. then instead of using run(MyScene()) you present the View which places your game in its own frame on your screen making it easy to add ui objects as your gui for ur game.

                1 Reply Last reply Reply Quote 0
                • stephen
                  stephen @Karina last edited by

                  @Karina and im almost finished with the Animation/Actions demo. should be posted later this evening.

                  currently 5pm my time

                  1 Reply Last reply Reply Quote 0
                  • Karina
                    Karina last edited by

                    @Karina and im almost finished with the Animation/Actions demo. should be posted later this evening.
                    currently 5pm my time

                    👍

                    1 Reply Last reply Reply Quote 0
                    • Karina
                      Karina last edited by ccc

                      def touch_began(self, touch):
                      		sound.play_effect('arcade:Jump_4')
                      		self.player.texture = player_textures[3]
                      		jumping = [A.move_by(0, 100, 0.2), A.wait(1), A.move_by(0, -100, 0.1)]
                      		self.player.run_action(A.sequence(jumping)
                      

                      I tried to make him jump but it doesn't work. I know there should be a more clever way to do that but I have no idea

                      1 Reply Last reply Reply Quote 0
                      • Drizzel
                        Drizzel last edited by

                        @Karina I haven’t used Actions much, I prefer animating nodes myself. But theoretically, from reading the docs, your code should work (assuming your indentation is correct and your actual code doesn’t miss the closed bracket at the end)

                        1 Reply Last reply Reply Quote 0
                        • Karina
                          Karina last edited by

                          @stephen you mean fixing the Node pos by yourself? Action should work smoother and easier to write. If it also worked here)
                          And why in your program you called this blocks brushes?🖌

                          stephen 1 Reply Last reply Reply Quote 0
                          • Karina
                            Karina last edited by

                            I began to read about threads and sometimes don't understand what about this all, but in general understand. And for what here to use them? It encreases the speed of smth?

                            Drizzel 1 Reply Last reply Reply Quote 0
                            • stephen
                              stephen last edited by

                              @Karina @Drizzel here is a demo for action timing. i intended to have much more informative and visually attractive version and ill improve it in time but for noe you can see a visual difference between each interpolation.

                              note: this is formated for ipad only. future versions will have formatting for other devices. i appoligise.

                              from scene import *
                              
                              class BaseSign(SpriteNode):
                              	def __init__(self, texture=None, tag='Sign', *args, **kwargs):
                              		super().__init__(texture=texture, *args, **kwargs)
                              		self.anchor_point=(0.0, 1.0)
                              		self.position = Point(10, get_screen_size()[1]-10)
                              		self.z_position=1
                              		self.color='#000000'
                              		self.size=Size(get_screen_size()[0]-20, get_screen_size()[1]-20)
                              		self.bg=SpriteNode(
                              			texture=None, 
                              			color='#80cdff', 
                              			position=Point(3, -3),
                              			anchor_point=(0.0, 1.0),
                              			size=Size(get_screen_size()[0]-26, get_screen_size()[1]-26),
                              			parent=self)
                              		self.sign=LabelNode(
                              			'',
                              			position=Point(1, 15),
                              			z_position=3,
                              			font=('Ubuntu Mono', 18), 
                              			parent=self.bg, 
                              			color='#000000',
                              			anchor_point=(0.0, 1.0))	
                              
                              
                              class MyScene (Scene):
                              	def setup(self):
                              		self.dur=5
                              		self.moveToPos=(73, 245)
                              		
                              		self.sign=BaseSign(parent=self, position=self.size/2)
                              		
                              		self.sign.sign.text=self.Text()
                              		for x in range(16):
                              			b=SpriteNode(Texture('pzl:BallGray'),
                              			size=Size(16, 16),
                              			color='#00f90b',
                              			position=Point(73, (get_screen_size()[1]-132) - 36.15*x),
                              			z_position=9,
                              			parent=self)
                              			b.run_action(
                              				Action.repeat(
                              					Action.sequence(
                              						Action.call(self.UpdateTime, 0.1),
                              						Action.wait(0.5),
                              						Action.move_to(self.moveToPos[1], b.position[1], 2, x),
                              						Action.move_to(self.moveToPos[0], b.position[1], 2, x)),-1))
                              						
                              					
                              		
                              	def UpdateTime(self, node, progress):
                              		if self.speed is 1:
                              			self.speed=0.5
                              		else:
                              			self.speed=1
                              		self.sign.sign.text=self.Text()
                              	
                              	def Text(self):
                              		return f'''
                              	╔════════════════════════╗
                              	║    BUILT_IN_CONSTANT   ║
                              	╠════╦════════╦══════════╣
                              	║ 2s ║ 2 part ║ 1x speed ║
                              	╠════╩════════╩══════════╣
                              	║TIMING_LINEAR           ║
                              	╟═╡                    ╞═╢
                              	║TIMING_EASE_IN_2        ║
                              	╟═╡                    ╞═╢
                              	║TIMING_EASE_IN_2        ║
                              	╟═╡                    ╞═╢
                              	║TIMING_EASE_OUT         ║
                              	╟═╡                    ╞═╢
                              	║TIMING_EASE_OUT_2       ║
                              	╟═╡                    ╞═╢
                              	║TIMING_EASE_IN_OUT      ║
                              	╟═╡                    ╞═╢
                              	║TIMING_SINODIAL         ║
                              	╟═╡                    ╞═╢
                              	║TIMING_ELASTIC_OUT      ║
                              	╟═╡                    ╞═╢
                              	║TIMING_ELASTIC_IN       ║
                              	╟═╡                    ╞═╢
                              	║TIMING_ELASTIC_IN_OUT   ║
                              	╟═╡                    ╞═╢
                              	║TIMING_BOUNCE_OUT       ║
                              	╟═╡                    ╞═╢
                              	║TIMING_BOUNCE_IN        ║
                              	╟═╡                    ╞═╢
                              	║TIMING_BOUNCE_IN_OUT    ║
                              	╟═╡                    ╞═╢
                              	║TIMING_EASE_BACK_IN     ║
                              	╟═╡                    ╞═╢
                              	║TIMING_EASE_BACK_OUT    ║
                              	╟═╡                    ╞═╢
                              	║TIMING_EASE_BACK_IN_OUT ║
                              	╟═╡                    ╞═╢
                              	╚════════════════════════╝'''
                              	
                              
                              
                              if __name__ == '__main__':
                              	
                              	run(MyScene(), show_fps=True)
                              	
                              
                              
                              Drizzel 1 Reply Last reply Reply Quote 2
                              • Drizzel
                                Drizzel last edited by

                                @Karina I think you got me mixed up with @stephen :) And yes, I do prefer to fix the node‘s position manually.

                                My version of flappy bird I posted here some days ago is a good example. I used basic physics formulas to give the bird an acceleration, and then use that to calculate the bird‘s speed and thus position at a given time. Then adjusting the gravity and weight parameters made the motion feel “just right” (in my opinion).

                                Technical stuff aside, I just do it for greater control, so I can get the feeling of motions right.

                                1 Reply Last reply Reply Quote 0
                                • Drizzel
                                  Drizzel @stephen last edited by

                                  @stephen looking good! I always was a little too lazy to try them all out... and I’m not using scene much nowadays.

                                  1 Reply Last reply Reply Quote 1
                                  • stephen
                                    stephen @Karina last edited by

                                    @Karina said:

                                    @stephen you mean fixing the Node pos by yourself? Action should work smoother and easier to write. If it also worked here)
                                    And why in your program you called this blocks brushes?🖌

                                    i did mean changing the nodes pos manually and its prety smooth esspecially when you implement your own interpolation (the TIMING constants used with Actions).

                                    what my main concern was that you were creating an Action Proccess for every block instead of having one Action Process for a group of blocks. this group would be the brushes i keep talking about.

                                    in my older exampe i did refer to blocks as brushes and then later i corrected myself. in my final example (the game not the action demo and i havnt finished my version of the game yet) will have "brushes" and everything will be anotated so you its easy to understand each part.

                                    Brush: predefined graphical structure to be instantiated multiple times. often cached for fast referencing." Example: Trees and Vilages in MineCraft..

                                    1 Reply Last reply Reply Quote 1
                                    • Drizzel
                                      Drizzel @Karina last edited by Drizzel

                                      @Karina said:

                                      I began to read about threads and sometimes don't understand what about this all, but in general understand. And for what here to use them? It encreases the speed of smth?

                                      I certainly don’t know everything about threads either, but here’s my understanding of them.

                                      The basics:

                                      • I think of threads like... well threads, as in strings or a thin rope. And when you open a thread, the code in this thread is run separated to other threads.

                                      • Thus Threads allow for separate codes to run “at the same time” (this technically isn’t possible, and is done through some tricks so that it appears so. Thus the quotation mark. But I’m not here to confuse you, so let’s go on)

                                      • Therefore you can have one section of code that (for example) has a time.sleep(100000) in it, and a thread that prints stuff in an infinite loop. Since they run in different threads, your code will still print stuff, even though there’s a stupidly long sleep statement in it

                                      Edit If you want some coding examples, I can write you some with comments

                                      stephen 1 Reply Last reply Reply Quote 0
                                      • stephen
                                        stephen @Drizzel last edited by

                                        @Drizzel @Karina

                                        ###Quick Update..

                                        Nearly finished with the example game. I usually dont take this long but lifes been crazy lol

                                        Done:

                                        • EventManager
                                        • block type classes
                                        • GameObject class for creating individual objects
                                        • Brush class for creating brush objects (template groups of GameObjects)
                                        • land and sky generation
                                        • Obsticle Gap Generation (better flow of gap hieght generation)
                                        • Animation Class (added to GameObjects and Brushes as Instance Properties)
                                        • Standard Obsticle Brush (objects with gap to flap/fly through)
                                        • Connection of GameObjects, Brush Objects, Animations, EventManager and Scene Class. (pretymuch everyone can talk to everyone and all get Tick/Update calls to stay current)

                                        TODO:

                                        • Player class
                                        • points score and rewards system
                                        • Main Menu
                                        • Settings Menu (maybe.. depends on time)
                                        • PowerUps/Buffs/Boosters
                                        • Game State Handle

                                        NOTE:

                                        @Karina did the Action timing demo help you understand the differences between each? it wasnt as informative as i like but figured it was ok givin the visual aspect

                                        1 Reply Last reply Reply Quote 0
                                        • Karina
                                          Karina last edited by Karina

                                          @Drizzel But in pythonista threads can't run in parallel, so it shouldn't increase the speed. So what benefits we have?
                                          And when I put sleep, I don't want things to print

                                          ###Quick Update..

                                          Already some familiar things in it)

                                          Drizzel 1 Reply Last reply Reply Quote 0
                                          • Karina
                                            Karina last edited by Karina

                                            @Karina did the Action timing demo help you understand the differences between each? it wasnt as informative as i like but figured it was ok givin the visual aspect

                                            @stephen Yes but it seems that all they are alike, some are nearly the same. But what the columns 2s, 2 part, 1x speed?
                                            And how did you built this table?)

                                            And I'm learning, most of time with my ipad, the most important that it's suitable for it

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