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
-
@Karina now im off to write the game in the way i would. so you can compare. in no way is MY way the best or even the most correct. but it is the way i learned to implement different objects and functionality over the years.
-
@Karina just an update ive been a bit busy but i might have my project ready in the next 20 hours or so. it wont have a lot of comments but ill put a few. but im trying to use only descriptive naming so it should not beva problem.hope to see what you learned from this project π€π€π€
-
@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?
-
@karina said:
@stephen said:
self.point=Point(w() + self.position.w, h() - self.size.h)
Ah, I forgot that we're inside Node, not Scenei 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 positionif 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 thefor
and thewhie
loops are "blocking" and both can be used to achive hat you want.. The only prolem i can see making thefor
loop better choice here is that awhile
loop has the possibility of being infinit if somthing doesnt go right where thefor
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. π
-
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 -
@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?
-
@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
-
@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.
- w()
-
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
-
@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?
-
@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 levelrun()
function fromscene
or class methodView.Present()
fromui
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.. lolscene
usesui
quite heavely. and you dont need to importui
separatly. by usingfrom scene import *
ui
is also included. from your game just callui.
and then whatever you want from there. when you run yourscene
game it actually prepares theui
stuff for you and then presents aSceneView
if you setup a customView
class in your game script you can create ascene.SceneView
and set itsSceneView.scene
property to your Game Object. then instead of usingrun(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. -
@Karina and im almost finished with the Animation/Actions demo. should be posted later this evening.
currently 5pm my time
-
@Karina and im almost finished with the Animation/Actions demo. should be posted later this evening.
currently 5pm my timeπ
-
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
-
@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)
-
@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 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?
-
@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)
-
@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.
-
@stephen looking good! I always was a little too lazy to try them all out... and Iβm not using scene much nowadays.