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
-
def player_flies(self): g = gravity() speed = 1000 if abs(g.x) > 0.05: y = self.player.position.y self.player.position.y = min(sh(), max(41, y + speed*g.y)) print(self.player.position.y)
I tried to move him with gravity but also doesn't work, like player.position.y is unchangeable or = doesn't work
Don't know what to doπ -
@Karina said:
def player_flies(self): g = gravity() speed = 1000 if abs(g.x) > 0.05: y = self.player.position.y self.player.position.y = min(sh(), max(41, y + speed*g.y)) print(self.player.position.y)
I tried to move him with gravity but also doesn't work, like player.position.y is unchangeable or = doesn't work
Don't know what to doπtry changing
min(sh(), max(41, y + speed*g.y))
to
min(sh(), max(41, self.player.position.y + speed*g.y))
that shouldnt change anything but just a debugging step..then try using:
def player_flies(self, speed=100,): if gravity()[1] > 0.5: x, y = self.player.position self.player.position = Point(x, (y + speed) * gravity()[1]) print(self.player.position[1])
from my knowledge you cannot set position.y you have to set the whole point.
also if you want the player to move upwards by tilting the top of device down. you must multiply by -1gravity()[1] * -1
that way your output is positive. also thex, y, z
properties of gravity are real numbers0.0-1.0
just incase you didnt know. πAlso my example game is just about ready. just doing some gui stuff and Annotations.
-
@stephen actually I want it to jump when I touch, but I couldn't do this. Now I get what was the problem but didn't fix it
I always forget to use the Point for position, can you show why it's better?
-
@stephen i've read your code with brushes, got it but have some little questions
1
class TopBrush(Node): def __init__(self, brushSize, *args, **kwargs): self.base=BaseBlock(self) self.size=Size(64, 64) self.position=Point(w()+(self.size.w), h()-self.size.h) self.brushSize=brushSize self.blocks=list([self.base, ]) #what means the , in the end of the list? And how we add base blocks of next brushes to the list?
2, 3
class MyScene (Scene): def setup(self): self.background=SpriteNode(Texture('plf:BG_Colored_grass'), size=Size(w(), h()), position=self.size/2, parent=self) self.preset=[(1, 7),(2, 6),(3, 5),(4, 4),(5, 3),(6, 2),(7, 1)] self.i=0.0 self.brushSpawnTimer=3.0 self.brushes=list([]) #But the [] is already list self.scrollSpeed=40 for x in range(int((w()*128)/64)): #so it's w()*2? Why 2? self.brushes.append(Stone(self, x))
-
@stephen said:
Vibrate(self, repeat, speed, t=TIMING_LINEAR):
self.node.run_action(
a.repeat(
a.group(
a.sequence(
a.move_by( 5, 5, speed, t),
a.move_by(-5,-5, speed, t),
a.move_by(-5, 5, speed, t),
a.move_by( 5,-5, speed, t)),
a.sequence(
a.scale_y_by( 0.1, speed, t),
a.scale_y_by(-0.1, speed, t),
a.scale_y_by( 0.1, speed, t),
a.scale_y_by(-0.1, speed, t))
),repeat))I think I have a problem in my action that after moving up there's down, so it does nothing. But here you do itπ³
-
@Karina said:
@stephen i've read your code with brushes, got it but have some little questions
1
class TopBrush(Node): def __init__(self, brushSize, *args, **kwargs): self.base=BaseBlock(self) self.size=Size(64, 64) self.position=Point(w()+(self.size.w), h()-self.size.h) self.brushSize=brushSize self.blocks=list([self.base, ]) #what means the , in the end of the list? And how we add base blocks of next brushes to the list?
2, 3
class MyScene (Scene): def setup(self): self.background=SpriteNode(Texture('plf:BG_Colored_grass'), size=Size(w(), h()), position=self.size/2, parent=self) self.preset=[(1, 7),(2, 6),(3, 5),(4, 4),(5, 3),(6, 2),(7, 1)] self.i=0.0 self.brushSpawnTimer=3.0 self.brushes=list([]) #But the [] is already list self.scrollSpeed=40 for x in range(int((w()*128)/64)): #so it's w()*2? Why 2? self.brushes.append(Stone(self, x))
that comma is optional but it just indicates that you intend on adding more to the list. just a habbit.
that brush example is not good. my game example will show u MANY things throught and is currently at 1400 lines without comments. i should have it posted in the next 8 hours. this script im making will show u actual brushes.. i would ignore the old one.
and to add bade block to that list just do
self.blocks.append(block)
-
@Karina said:
@stephen actually I want it to jump when I touch, but I couldn't do this. Now I get what was the problem but didn't fix it
I always forget to use the Point for position, can you show why it's better?
jump on tap is prety easy. in your touch_began trigger somthing like the following for a very simple way.
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')
this should give an abrupt leap then more of a glide back down. the wait is just a buffer for junt in case and use whatever timing that looks best for ur needs. this is not desinged for uneven ground. u need collision checks for uneven and i show that in my new exmple
-
@Karina said:
def player_flies(self): g = gravity() speed = 1000 if abs(g.x) > 0.05: y = self.player.position.y self.player.position.y = min(sh(), max(41, y + speed*g.y)) print(self.player.position.y)
I tried to move him with gravity but also doesn't work, like player.position.y is unchangeable or = doesn't work
Don't know what to doπin my earlierpost i show that you must set the hole position you cannot set just x or y
-
@Karina said:
@stephen said:
Vibrate(self, repeat, speed, t=TIMING_LINEAR):
self.node.run_action(
a.repeat(
a.group(
a.sequence(
a.move_by( 5, 5, speed, t),
a.move_by(-5,-5, speed, t),
a.move_by(-5, 5, speed, t),
a.move_by( 5,-5, speed, t)),
a.sequence(
a.scale_y_by( 0.1, speed, t),
a.scale_y_by(-0.1, speed, t),
a.scale_y_by( 0.1, speed, t),
a.scale_y_by(-0.1, speed, t))
),repeat))I think I have a problem in my action that after moving up there's down, so it does nothing. But here you do itπ³
this was an example of doing a vibration effect. so it needs to move even amounts in directions because its doesnt move anywhere. just "shakes"
was mainly meant to show you a repeated group with sequence sections for action structures
-
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'?
-
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 -
@Karina ill be posting the example shortly
-
@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')
-
@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())
-
@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())
-
here is the game lol made new thread fo it
-
@stephen thank you, I've began to read it
-
@Karina Awesome if you have any questions please post on the new thread π
-
@Karina also "brushes" are properly used in the example so hopfully you see the diference