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 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..
-
@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
-
-
###Quick Update..
Nearly finished with the example game. I usually dont take this long but lifes been crazy lol
Done:
- EventManager
- block type classes
- GameObject class for creating individual objects
- Brush class for creating brush objects (template groups of GameObjects)
- land and sky generation
- Obsticle Gap Generation (better flow of gap hieght generation)
- Animation Class (added to GameObjects and Brushes as Instance Properties)
- Standard Obsticle Brush (objects with gap to flap/fly through)
- Connection of GameObjects, Brush Objects, Animations, EventManager and Scene Class. (pretymuch everyone can talk to everyone and all get Tick/Update calls to stay current)
TODO:
- Player class
- points score and rewards system
- Main Menu
- Settings Menu (maybe.. depends on time)
- PowerUps/Buffs/Boosters
- Game State Handle
NOTE:
@Karina did the Action timing demo help you understand the differences between each? it wasnt as informative as i like but figured it was ok givin the visual aspect
-
@Drizzel But in pythonista threads can't run in parallel, so it shouldn't increase the speed. So what benefits we have?
And when I put sleep, I don't want things to print###Quick Update..
Already some familiar things in it)
-
@Karina did the Action timing demo help you understand the differences between each? it wasnt as informative as i like but figured it was ok givin the visual aspect
@stephen Yes but it seems that all they are alike, some are nearly the same. But what the columns 2s, 2 part, 1x speed?
And how did you built this table?)And I'm learning, most of time with my ipad, the most important that it's suitable for it
-
@Karina Now yes, threads may not always speed up your program. But they can keep your program responsive even though there’s some time consuming task being done. I also sometimes use them to constantly check if a variable changed, and then trigger a function. (There’s better ways to do that. But hey, I’m learning too.)
Even though this is in no way specific to Pythonista, let’s take a slight detour. Some time ago, I built a door manager for the chicken pen of my family (yeah, it’s a bit unusual). It opens and closes the door at given times, but also constantly checks a button and email for a manual overrides. Since the button needs to be checked every 0.1 seconds, but checking the email takes about 4 seconds (establishing a connection to the google servers takes some time), the button wouldn’t be checked while the code is trying to get the new email. This is solved with threads, so they get checked in parallel, not after each
Therefore the button stays responsive, even though checking mails uses up a lot of time -
@Drizzel Sorry, i've not so understood what have you done. What means door manager for chicken pen? Your family has a chicken that has a pen and needs door manager??) what
But what here does the thread I got -
@Karina Yeah, we have a little “chicken house” and I wrote a script that opens and closes the door by turning on and off a motor. But that’s not the point :) I just needed an example to better illustrate the uses of threads
-
First A Litle On The Thread Conversation
this comes from years experience ith event driving C# programing, but doesnt mean its correct 😉
Stop thinking so much about threads ☺️. multiprocessing is what we do.
StackOverflow said:
What is meant by synchronous and asynchronous?
Synchronous basically means that you can only execute one thing at a time. Asynchronous means that you can execute multiple things at a time and you don't have to finish executing the current thing in order to move on to next one.
https://www.techwalla.com › articles said:
Which is faster synchronous or asynchronous?
Asynchronous transfers are generally faster than synchronous transfers. This is because they do not take up time prior to the transfer to coordinate their efforts. However, because of this, more errors tend to occur in asynchronous transfers as opposed to synchronous transfers.
I know its not a great source but its not always the worst 😉🙃
https://en.m.wikipedia.org/wiki/Asynchronous_I/O said:In computer science, asynchronous I/O (also non-sequential I/O) is a form of input/output processing that permits ...
@Karina said:
@stephen Yes but it seems that all they are alike, some are nearly the same. But what the columns 2s, 2 part, 1x speed?
And how did you built this table?)They are very similar yes but when you combine them in different ways with multiple objects you can see the way they are differnent.
this is already shown in my game example that is nearly finished. i think you will benifit alot from it. im trying to write it as clearly as i can which is why its taking so long..
the
2s 2 part 1x speed
is just data not colums but i can see how i made it sem that way but its just info about the example.2s ↠ 2 seconds animation duration per part.
2 part ↠ loop is 2 parts part one is
●⇒
and part two is⇐●
1x speed ↠ the Scene's
Scene.speed
is set to1
i put them in just to clearify settings. ☺️
the lines/borders i used are Unicode from the Drawing chart. i have already included these in the Example script i modified here for
Special Characters.py
the comments instruct how to se it 🙃🤓well back to the game lol
-
@stephen it's ok that it takes time, I'm trying to read your and Drizzel's programs and adding things to mine
-
@Drizzel can you show a short example how you do animation? I have experience only with Action
-
heres an example of a animation layer. i use group of sequences then stack oher groups in objects to create my deired effect. and the gam ont be production worthy just simple with my touch 😎 but im using many different techniques for see. nearly done just couple more classes nd thn annotations and its all ya'lls
def 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))
-
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