I Haz Codes

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Menu
Basic drawing
Basic animation
Edge detection
Rectangles and obstacles
Key events
Playing music
Learning the basics of pygame

In order to learn pygame you need to go through the following key lessons. These will introduce you to some of the key ideas before you can start a more complex project.

Make sure you go through them in the order listed below!

Basic drawing

Syntax This page will show you how to basic drawing in pygame. There is a lot of initial code you need to get used to before really embarking on pygame, the most important of which is the game loop. Syntax screen = display. set_mode ((640,480)) draw. rect( screen, (255,0,0), (10, 10, 100, 100), 4) Drawing […]

Basic animation

  Animation in pygame is all about using variables when drawing shapes or images. The code below and video above explain how you can introduce basic variables in order to do simple animation.

Edge detection

Edge detection When dealing with edge detection you must manually add it to your programs. Pygame does offer collision detection, which will be covered later, but simple screen boundary checks can be done using 2 if statements. By adding the x and y speeds (shown as dx and dy), you can easily manipulate them by […]

Rectangles and obstacles

In this tutorial you will see how to do collision detection using rectangles. When testing if two things have collided you need to consider how accurate you want to be. In this set of examples we are doing collision detection with rectangles which means, as we have a ball, it may not always look smooth. […]

Key events

Syntax for e in event. get() if e.type == KEYDOWN : if e.key == K_a : The event loop in pygame is a common feature of 99% of all pygame projects and as such, is one which you must master. It will always be found in the game loop and takes the form of a […]

Playing music

Syntax mixer. init() mixer. music. load(" filename ") mixer. music. play() Pygame uses a mixer class to allow both sound and music to be played at the same time. As a computer only has one set of speakers, sounds must be mixed together before they are sent to the speaker. Pygame mixer handles the complexity […]

Comments are closed.

Information