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
    28617
    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

      def touch_began(self, touch):
          self.player.run_action(
              a.sequence(
                  a.move_by(128, 64, 0.5, TIMING_LINEAR),
                  a.wait(0.1),
                  a.move_by(128, 128, 2, TIMING_LINEAR)), 'tag:player-jump')
      

      But it means he moves on 128 forward, cause move_by(dx, dy, duration, timing_mode). And after wait he should move Dow, so dy with minus? And what is 'tag:player-jump'?

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

        my game example will show u MANY things throught and is currently at 1400 lines

        @stephen this is *10 more than anything I have ever read๐Ÿ˜ณ Don't worry, you can't show too little things in it๐Ÿ˜…
        I should be an easy game, I thought I the beginning

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

          @Karina ill be posting the example shortly

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

            @Karina said:

            def touch_began(self, touch):
                self.player.run_action(
                    a.sequence(
                        a.move_by(128, 64, 0.5, TIMING_LINEAR),
                        a.wait(0.1),
                        a.move_by(128, 128, 2, TIMING_LINEAR)), 'tag:player-jump')
            

            But it means he moves on 128 forward, cause move_by(dx, dy, duration, timing_mode). And after wait he should move Dow, so dy with minus? And what is 'tag:player-jump'?

            yes your correct i made a boo boo lol i didnt test i just wrote

            def touch_began(self, touch):
                self.player.run_action(
                    a.sequence(
                        a.move_by(128, 64, 0.5, TIMING_LINEAR),
                        a.wait(0.1),
                        a.move_by(-128, -128, 2, TIMING_LINEAR)), 'tag:player-jump')
            
            
            1 Reply Last reply Reply Quote 0
            • Karina
              Karina last edited by

              @stephen still nothing. I just did copy paste for not to do mistakes. Maybe it's somewhere else in the code

              from scene import *
              import sound
              import random
              import time
              
              
              def sw(): return get_screen_size()[0]
              def sh(): return get_screen_size()[1]
              def bw(): return 64
              def bh(): return 96
              def so(): return 1 if sw() > sh() else 2
              def lw(): return 1024.0 if so() == 1 else 768.0
              def lh(): return 1024.0 if so() == 2 else 768.0 
              
              
              A = Action()
              player_textures = [Texture('plf:AlienBeige_walk1'),
              Texture('plf:AlienBeige_walk2'), Texture('plf:AlienBeige_hit'), Texture('plf:AlienBeige_jump'), Texture('plf:AlienBeige_stand')]
              
              
              def GroundBlock(parent):
              	return SpriteNode('plf:Ground_Grass', parent=parent)
              	
              
              def ColumnBlock(parent, x, y):
              	return SpriteNode('plc:Brown_Block', parent=parent, anchor_point = (0.5, 0), position = Point(x, y))
              
              
              class BottomBrush(Node):
              	def __init__(self):
              		self.ground = GroundBlock(self)
              		self.position = (self.size.w)
              		
              	
              class Game(Scene):
              	def setup(self):
              		self.background_color = '#99d7ff'
              		#to track when 5 seconds passed and need to add a new column
              		self.time_passed = 0
              		#add the first column so you don't have to wait for it 5 seconds
              		self.columns = []
              		self.moveTo = (220, 120)
              		self.add_column()
              		x = 0
              		ground = Node(parent=self)
              		ground.z_position = -1
              		#building the upper and lower ground
              		while x < self.size.w:
              			lower_tile = SpriteNode('plf:Ground_Grass', position = Point(x, 30))
              			higher_tile = SpriteNode('plf:Ground_GrassCenter', position = Point(x, 738))
              			x += bw() - 2
              			ground.add_child(lower_tile)
              			ground.add_child(higher_tile)
              			
              		self.player = SpriteNode('plf:AlienBeige_front', parent=self)
              		self.player.position = (40, 120)
              		self.play_effect = 0
              		self.game_over = False
              		
              	
              	def update(self):
              		if self.t > 1:
              			self.player_runs()
              		self.time_passed += self.dt
              		if self.time_passed >= 1.5:
              			self.add_column()
              			self.time_passed = 0
              		self.column_moves()
              		self.player_hit()
              		if self.game_over == True and self.player.position.y < 30:
              			self.player.remove_from_parent()
              		
              	def touch_began(self, touch):
              		#self.player_jumps()
              		self.player.run_action(
                      A.sequence(
                          A.move_by(128, 64, 0.5, TIMING_LINEAR),
                          A.wait(0.1),
                          A.move_by(-128, -128, 2, TIMING_LINEAR)), 'tag:player-jump')
              		
              			
              	def new_game(self):
              		A.wait(2)
              		for i in self.columns:
              			i.remove_from_parent()
              		self.player.texture = player_textures[4]
              		self.player.position = (40, 120)
              		
              		
              	def add_column(self):
              		lower = random.randint(0, 360) // bw()
              		#building the lower part
              		for i in range(lower):
              			self.columns.append(ColumnBlock(self, self.size.w + bw(), i*64 + 55))
              		#building the higher part
              		for i in range(9 - lower):
              			self.columns.append(ColumnBlock(self, self.size.w + bw(), (self.size.h - 100) - i*64))
              			
              			
              	def column_moves(self):
              		action = A.move_by(-self.size.w - bw(), 0, 0.7, TIMING_SINODIAL)
              		for i in self.columns:
              			i.run_action(action)
              				
              				
              	def player_runs(self):
              		self.player.x_scale = 1
              		walking_sounds = ['rpg:Footstep04', 'rpg:Footstep05']
              		if self.player.position.x <= 200:
              			step = int(self.player.position.x/5) % 2
              			self.player.texture = player_textures[step]
              			action = A.move_by(20, 0, 1.5)
              			self.player.run_action(action)
              			self.play_effect += 1
              			if self.play_effect % 30 == 0:
              				sound.play_effect(walking_sounds[step])
              				
              				
              	def player_hit(self):
              		player_hitbox = Rect(self.player.position.x - 10, self.player.position.y + 10, 10, 10)
              		for c in self.columns:
              			if c.frame.intersects(player_hitbox):
              				self.player.texture = player_textures[2]
              				self.player.run_action(A.move_by(0, -200, 0.2))
              				sound.play_effect('arcade:Hit_2')
              				self.game_over = True
              				
              				
              	def player_jumps(self):
              		 self.player.run_action(
                      A.sequence(
                          A.move_by(128, 64, 0.5, TIMING_LINEAR),
                          A.wait(0.1),
                          A.move_by(-128, -128, 2, TIMING_LINEAR)), 'tag:player-jump')
              		
              			
              			
              run(Game())
              
              stephen 1 Reply Last reply Reply Quote 0
              • stephen
                stephen @Karina last edited by

                @Karina i added isGrounded and adjusted the Actions. it needs some fine tuning but he jumps. im finalizing my game now so after a few touchups ill postit here

                
                from scene import *
                import sound
                import random
                import time
                
                
                def sw(): return get_screen_size()[0]
                def sh(): return get_screen_size()[1]
                def bw(): return 64
                def bh(): return 96
                def so(): return 1 if sw() > sh() else 2
                def lw(): return 1024.0 if so() == 1 else 768.0
                def lh(): return 1024.0 if so() == 2 else 768.0
                
                
                A = Action()
                player_textures = [Texture('plf:AlienBeige_walk1'),
                Texture('plf:AlienBeige_walk2'), Texture('plf:AlienBeige_hit'), Texture('plf:AlienBeige_jump'), Texture('plf:AlienBeige_stand')]
                
                
                def GroundBlock(parent):
                	return SpriteNode('plf:Ground_Grass', parent=parent)
                	
                	
                def ColumnBlock(parent, x, y):
                	return SpriteNode('plc:Brown_Block', parent=parent, anchor_point = (0.5, 0), position = Point(x, y))
                	
                	
                class BottomBrush(Node):
                	def __init__(self):
                		self.ground = GroundBlock(self)
                		self.position = (self.size.w)
                		
                		
                class Game(Scene):
                	def setup(self):
                		self.background_color = '#99d7ff'
                		#to track when 5 seconds passed and need to add a new column
                		self.time_passed = 0
                		#add the first column so you don't have to wait for it 5 seconds
                		self.columns = []
                		self.moveTo = (220, 120)
                		self.add_column()
                		x = 0
                		ground = Node(parent=self)
                		ground.z_position = -1
                		#building the upper and lower ground
                		while x < self.size.w:
                			lower_tile = SpriteNode('plf:Ground_Grass', position = Point(x, 30))
                			higher_tile = SpriteNode('plf:Ground_GrassCenter', position = Point(x, 738))
                			x += bw() - 2
                			ground.add_child(lower_tile)
                			ground.add_child(higher_tile)
                			
                		self.player = SpriteNode('plf:AlienBeige_front', parent=self)
                		self.player.position = (40, 120)
                		self.play_effect = 0
                		self.game_over = False
                		self.isGrounded=True
                		
                		
                		
                	def update(self):
                	
                		if self.t > 1:
                			self.player_runs()
                		self.time_passed += self.dt
                		if self.time_passed >= 1.5:
                			self.add_column()
                			self.time_passed = 0
                		self.column_moves()
                		self.player_hit()
                		if self.game_over == True and self.player.position.y < 30:
                			self.player.remove_from_parent()
                			
                	def touch_began(self, touch):
                		self.player_jumps()
                		
                		
                		
                	def toggle_Grounded(self):
                		self.isGrounded = not self.isGrounded
                		
                		
                	def new_game(self):
                		A.wait(2)
                		for i in self.columns:
                			i.remove_from_parent()
                		self.player.texture = player_textures[4]
                		self.player.position = (40, 120)
                		
                		
                	def add_column(self):
                		lower = random.randint(0, 360) // bw()
                		#building the lower part
                		for i in range(lower):
                			self.columns.append(ColumnBlock(self, self.size.w + bw(), i*64 + 55))
                		#building the higher part
                		for i in range(9 - lower):
                			self.columns.append(ColumnBlock(self, self.size.w + bw(), (self.size.h - 100) - i*64))
                			
                			
                	def column_moves(self):
                		action = A.move_by(-self.size.w - bw(), 0, 0.9, TIMING_SINODIAL)
                		for i in self.columns:
                			i.run_action(action)
                			
                			
                	def player_runs(self):
                		self.player.x_scale = 1
                		walking_sounds = ['rpg:Footstep04', 'rpg:Footstep05']
                		if self.player.position.x <= 200 and self.isGrounded:
                			step = int(self.player.position.x/5) % 2
                			self.player.texture = player_textures[step]
                			action = A.move_by(20, 0, 0.5)
                			#self.player.run_action(action)
                			self.play_effect += 1
                			if self.play_effect % 30 == 0:
                				sound.play_effect(walking_sounds[step])
                				
                				
                	def player_hit(self):
                		player_hitbox = Rect(self.player.position.x - 10, self.player.position.y + 10, 10, 10)
                		for c in self.columns:
                			if c.frame.intersects(player_hitbox):
                				self.player.texture = player_textures[2]
                				self.player.run_action(A.move_by(0, -200, 0.2))
                				sound.play_effect('arcade:Hit_2')
                				self.game_over = True
                				
                				
                	def player_jumps(self):
                		self.player.run_action(
                			A.sequence(
                				A.move_by(32, 128, 0.5, TIMING_LINEAR),
                				A.move_to(self.player.position[0]+128, 120, 0.5, TIMING_LINEAR)))
                		
                run(Game())
                
                
                
                1 Reply Last reply Reply Quote 0
                • stephen
                  stephen last edited by

                  here is the game lol made new thread fo it

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

                    @stephen thank you, I've began to read it

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

                      @Karina Awesome if you have any questions please post on the new thread ๐Ÿ˜‰

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

                        @Karina also "brushes" are properly used in the example so hopfully you see the diference

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