[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] looking for pygame minimal examples



On Wed, 8 Oct 2008 10:45:52 +0100, "Paulo Silva" <nitrofurano@xxxxxxxxx>
wrote:
> Hi!
> 
> I'm looking for webpages could have minimal examples, just like from:
> . http://nitrofurano.linuxkafe.com/sdlbasic/MinimalExamples_050624.zip
> . http://nitrofurano.linuxkafe.com/python/PythonStuff_060822.zip
> 
> i'm needing them, since i'm still having really huge difficulties on
> starting coding on Pygame... and i think i know a bit about Python and
> SDL, but they seems to be not that enough...
> 
> if you all know urls having very simple and encouraging pygame
> examples, please share with us newbies...
> thanks and regards,


Have you looked through the material on pygame.org? Also, are there
specific things you'd like to know? Doing a minimal Pygame demonstration is
as simple as:

<code>
## Create an SDL window for graphics, and draw a blue square.
import pygame
screen = pygame.display.set_mode((800,600))
pygame.draw.rect((42,42,200,200),(0,0,255),0)) ## Parameter order might be
wrong
pygame.display.update()
</code>

Or to demonstrate the input loop:

<code>
## Until user hits a key, print a rising counter's value over and over.
import pygame
from pygame.locals import * ## For the KEYDOWN constant
spam = 0
done = False
while not done:

    ## Handle events such as keypresses.
    for event in pygame.event.get():
        if event.type == KEYDOWN:
            done = True ## Some would suggest "break" instead, which
ignores other events this cycle.

    ## Do actual processing stuff like gameplay here, or before the event
handling.
    print spam
    spam += 1

</code>