Can Someone Turn This Script Into a ‘Node’ Tutorial, Please?
Hey there everyone. I’m new to the fourms; it’s nice to meet you all. So, I’m just a humble taxi driver trying to become a programmer with the help of Ole’s amazing contribution to the Python community (Thank you very kindly for all your hard work and dedication. The Pythonista app is absolutely astounding!) By the way, I’d just like to add: I’d gladly pay you another $10 for a “Code-folding” feature (haha).
As of right now, I've got under a years worth of experience with the study of Python. Notably, I’ve been focusing on 2D game development by studying rcruz63's "Cards.py" script, amongst other open-source contributions, to learn the fundamentals and basics of game development and programming in general.
I've amounted a decent grasp of how the Layer objects operate within Pythonista, but am truly looking to have a better understanding of the scene.Node(s). If someone wouldn't mind (and I understand a lot of you are professional programmers and probably tied up with life to the fullest extent) converting rcruz63's 'Cards.py' script into a Scene.Node tutorial, that's Python 3.6 compatible, I'd be tremendously grateful and thankful for your time and energy!
Here's a link to rcruz's 'Cards.py' script:
Thanks in advance, guys and gals!
Oh, and please script it to be OOP, having classes and such! Thank you!
Here’s my current rendition of rcruz63’s Cards.py. I’ve turned the game board into a 5x5 layout with 12 pairs of face emojis and a ‘Wild’ imp face emoji, and adding a bit more functionality to the user interface and experience. I don’t understand enough about classes and the scene.Node format to be able to convert the entirerty of the game, so I still had to use the scene_drawing.Layer format.
I welcome constructive critisim and pointers, so please fire away!
ccc last edited by
I provided a pull request that does not yet move to Nodes but removes xrange(). This allows the cards to be displayed (in the wrong places) in Python 3.
enceladus last edited by enceladus
Not tested well. Seems to work fine. Hopefully gives an idea on how to implement with nodes.
@ccc I’ve, too, dabbled with swapping xrange(len(images)) for range(0, len(images)) in an attempt to produce an equivalent outcome, However, the output always seems to positions the cards in somewhat of an “ascending staircase” pattern... I have no idea as to why. Hah
@enceladus Now that is a great starting point! Thank you for your timly response and contribution! I’ve definitely enjoyed looking through your scripting style and techniques. Do you know why the cards refuse to be in the center of the screen? I attempted making the cards once myself, out of Nodes, and I was unable to get them center as well. I roughly used the same exact logic that rcruz used with his Layers format of the cards, and they always seem to favor a more low-left output... No idea why...
Try looking at the anchor_point -- I forget the default, but you can make the X,y refer to a corner, or center.
@ccc I reviewed your PR and approved it; thank you for the pro tips and etiquette!
@JonB The default is definitely the center of the sprite, that’s why it doesn’t make sense that the same logic to center the layer objects wouldn’t work for the node objects.
The andhor point just says what part of the node your are placung with
position. But the coordinate system of the parent which you place into is always based in the corner. so, if you are trying to create a grid, using corner coordinates probably makes more sense, or else, you need to reference everything to the center, and use vector addition.
center=parent.bbox.size/2.0 #(w/2, h/2) somenode.position = center + Vector2( j*colwidth, i*rowheight)
where i,j are row/col, as measured from the center.
ccc last edited by ccc
The puzzle is that in Python 2 the cards are all properly aligned but in Python 3 they are staggered.
Phuket2 last edited by
@ccc , its the / operator , need the // version in py3.x
for i, front_image in enumerate(self.front_images): x, y = i%5, i//5
fwiw, i always forget this, but
divmodlets you do both in one operation:
y,x = divmod(i, 5)
@Phuket2 Wow, that definitely solved the alignment issue! But OP is still hoping someone can convert this memory card game into a “Tutorial.” Maybe in the same format as the Alien Game that Ole provided within the examples of Pythonista.