Flappy bird browsing

• posted
1

Hello everyone! I'm writing the game and at the beginning now

• posted
0

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

• posted
0

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

• posted
0

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

• posted
0

@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

• posted
1

@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

• posted
0

@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

• posted
0

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'?

• posted
0

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

• posted
0

@Karina ill be posting the example shortly

• posted
0

@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')

• posted
0

@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()
def sh(): return get_screen_size()
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)
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

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.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
self.player.position = (40, 120)

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
self.player.run_action(A.move_by(0, -200, 0.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())

• posted
0

@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()
def sh(): return get_screen_size()
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)
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

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.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
self.player.position = (40, 120)

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
self.player.run_action(A.move_by(0, -200, 0.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+128, 120, 0.5, TIMING_LINEAR)))

run(Game())

• posted
0

• posted
0

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

• posted
0

@Karina Awesome if you have any questions please post on the new thread 😉

• posted
0

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

Internal error.

Oops! Looks like something went wrong!