r/Python • • Jan 20 '19

Asteroids pyxel game! timbledum/asteroids on github

481 Upvotes

30 comments sorted by

View all comments

Show parent comments

6

u/TheIncorrigible1 `__import__('rich').get_console().log(':100:')` Jan 20 '19

It's mostly collision detection and rendering that are the hard bits

4

u/Please_Not__Again Jan 20 '19

If you don't mind answering would you do an if else statement for it? Like if it comes too close then game over?

3

u/TheIncorrigible1 `__import__('rich').get_console().log(':100:')` Jan 20 '19

I'm not sure if there's an event loop or something like that with the pyxel library they're using, but the approach I would take: check the bounding boxes between the game area, asteroids, and the player with each frame; you'd be checking for overlapping coordinates.

1

u/timbledum Jan 20 '19

Oh and pyxel totally has an event loop with two end points accessible to the user: an update function for game state and a display function for rendering - this allows it to skip frames if necessary.