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

Re: [pygame] Yeah looks like i'm doing quite well so far, completed my goal for today.



Lamonte Harris wrote:
> Can you give me a very basic example, I've been trying to look at code
> examples and the docs and I'm still not catching on.

Attached is a very basic example. Note that I use the Rect move_ip
function; if you aren't familiar with pygame.rect.Rect, this might be
new to you.

Ethan
import pygame
import sys

pygame.init()

class sprite(object):
    def __init__(self):
        pass


s = sprite()

img = pygame.Surface((100, 100))
img.fill((255, 255, 255))
s.image = img
s.rect = pygame.Rect(10, 10, 100, 100)

pygame.display.set_mode((800, 600))
d = pygame.display.get_surface()

v = [1, 1]

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT: sys.exit()

    d.fill((0, 0, 0))

    d.blit(s.image, s.rect)

    s.rect.move_ip(v)

    if s.rect.left < 0 or s.rect.right > d.get_width():
        v[0] = -v[0]
    
    if s.rect.bottom > d.get_height() or s.rect.top < 0:
        v[1] = -v[1]

    pygame.display.flip()

Attachment: signature.asc
Description: OpenPGP digital signature