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
    25337
    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.
    • Karina
      Karina last edited by

      @stephen said:

      self.point=Point(w() + self.position.w, h() - self.size.h) <

      Ah, I forgot that we're inside Node, not Scene

      i understand what lw() does, but what is lower port width? And lw() is the returns the width, if add bw(), we should get beyond the screen?

      self.size.w is somthing crazy like 2389488754589433357

      I went to check the self.size.w, and it is 1024. What do you it is smth like thatπŸ‘†? And why in that case for is better than while?

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

        @karina said:

        @stephen said:

        self.point=Point(w() + self.position.w, h() - self.size.h)
        Ah, I forgot that we're inside Node, not Scene

        i understand what lw() does, but what is lower port width? And lw() is the returns the width, if add bw(), we should get beyond the screen?

        Response:

            sw β‡’ screen width
            bw β‡’ block width
            lw β‡’ level view port width
        

        top part and lower part , at least in this case, are the same size width. so both top and bottom parts get their size width from our bw() Block Width.
        Yes we do want to add AT LEAST block width past screen width.
        Video Games are Feuled by immersion. You wand the End User to feel that our Level already exists.. so they must not see the objects pop into our level. so we do this just outside the view port. same for removinghe objects. we wait till they are at least Block Width negative position if block.w < -block.w: del block.
        Also in our position checks we want to compare < for removing blocks and > for adding blocks and not <= and >=. by doing this we get a 1 point buffer insuring our create and delete actions are not visible bo End User.


        @karina said:

        @stephen said:

        self.size.w is somthing crazy like 2389488754589433357

        I went to check the self.size.w, and it is 1024. What do you it is smth like thatπŸ‘†? And why in that case for is better than while?

        Response:

        β€œ πŸ€“πŸ˜… unlikely i know but just for fun... ”

        the value 2389488754589433357 this game is simple so this shouldnt happen. you coud see similar if you had bad execution order while using large open world type game environment...

        since python has a GIL Global Interpreter Lock both the for and the whie loops are "blocking" and both can be used to achive hat you want.. The only prolem i can see making the for loop better choice here is that a while loop has the possibility of being infinit if somthing doesnt go right where the for loop has a predefined end point. insuring the game will not freeze forever do to your code withen.



        did i cover what you were confused for these? im not sure i completey understook your questions. πŸ™ƒ

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

          I thought of grouping the blocks but don't know how to do it.

          It's quite difficult to me to formulate them now cause I don't have anything to write on and can't buy it😿 But:

          I don't know what the timing_sinodial, timing_ease in and others mean. I tried to play with them in examples but didn't see the difference, also anti-alias and its 4x multisampling
          And the Brushes, so didn't implement it and MaxSizeBrush, but maybe I will when do the jumps

          1 Reply Last reply Reply Quote 0
          • 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
                                            • First post
                                              Last post
                                            Powered by NodeBB Forums | Contributors