The super-simple pygame framework.
Project description
pygame.snake
Snake supports scenes through the @game.scene
decorator. This
README doesn't cover them though. Despite that, snake's scenes are
awesome, look out for the documentation for them when I make it!
Snake has been designed with the absolute beginner in mind.
None of that fussing around with pygame.event.get()
,
pygame.display.set_mode()
, pygame.image.load()
, etc.
In fact, you can make a game in snake without import pygame
anywhere! A lot of the following code snippets are actually entire
snake projects. It's that simple to use.
import snake
game = snake.Game()
while True:
game.next_frame()
game.assets.player.stamp((0, 0))
game.assets
? That's the assets/
folder automatically loaded
with file types detected and filtered into the right things for you.
game.assets.player
could have been assets/player.png
. It might
also have been assets/player.jpg
or any other image format. Snake
doesn't care.
That's boring. Let's get some user input going on:
import snake
game = snake.Game()
while True:
events = game.next_frame()
if events.keys.space:
print("Space is pressed!")
else:
print("Space isn't pressed")
That was easy. Notice how the keyboard was dropped into events.keys
?
Let's have a look at mouse input:
print("Mouse is at " + str(events.mouse.pos))
Nice. I wonder if we can scroll?
if events.scroll.up:
print("Scroll up")
Oh. Nice. My game's a little more advanced though. I'm going to need some sprites. No worries.
player = game.sprite(game.assets.player)
while True:
game.next_frame()
player.x += 1
Too easy. Onto fonts:
label = game.sprite(game.assets.my_font)
while True:
events = game.next_frame()
if events.keys.space:
label.text = "Space is pressed"
else:
label.text = "Space is not pressed"
Remember that game.assets.my_font
is going to be
assets/my_font.ttf
, so make sure you have a font file there.
Quitting isn't even something that needs to be covered. It's handled implicitly for you. No problems there.
Now at the moment everything has been working with the origin, but that's boring. Let's add an FPS counter in the top right corner.
counter = game.sprite(game.assets.my_font)
counter.stick = game.NE
while True:
game.next_frame()
counter.text = str(round(game.fps, 2))
We've got a few new things here. The important part is
counter.stick
which tells snake where to place the sprite.
North-east is the top right which is what we want. The default is
game.CENTRE
. The other new thing is game.fps
. No surprises there;
it's the FPS.
I don't like the fact the text is mushed right against the side of the window though. Let's fix that:
counter = game.sprite(game.assets.my_font, x=32, y=32)
Now we're offsetting it by 32 pixels in both directions. Easy as anything.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pygame.snake-0.0.1a0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85c22e36d20a30497e4ee5e75aca1402fa854469614dfaed4095a914701b0633 |
|
MD5 | 1c72d9ecf651884817d80e2356d93530 |
|
BLAKE2b-256 | 9d66193465970f30130c80749e7f8f9f30156f9062a638bbd095f0931df9017e |