Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pygame.snake-0.0.1a0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

pygame.snake-0.0.1a0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file pygame.snake-0.0.1a0.tar.gz.

File metadata

  • Download URL: pygame.snake-0.0.1a0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

File hashes

Hashes for pygame.snake-0.0.1a0.tar.gz
Algorithm Hash digest
SHA256 d588b33a5ada783c8483f57f30ab16fc1486c71e3e0ad4f6cf88e8c7e848d0ea
MD5 139d87aba579e092f0530d72517c9b31
BLAKE2b-256 27c34b48fa89f614b1a3f736a3835d1c5ecfc0c20e79285b394bdbf6e2281660

See more details on using hashes here.

File details

Details for the file pygame.snake-0.0.1a0-py3-none-any.whl.

File metadata

  • Download URL: pygame.snake-0.0.1a0-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

File hashes

Hashes for pygame.snake-0.0.1a0-py3-none-any.whl
Algorithm Hash digest
SHA256 85c22e36d20a30497e4ee5e75aca1402fa854469614dfaed4095a914701b0633
MD5 1c72d9ecf651884817d80e2356d93530
BLAKE2b-256 9d66193465970f30130c80749e7f8f9f30156f9062a638bbd095f0931df9017e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page