Code: Select all
input()
Code: Select all
import pygame, sys
from pygame.locals import *
pygame.init()
# set up the tick timer
FPS = 30 # frames per second
fpsClock = pygame.time.Clock()
# set up the window - drawing area = (0..399, 0..299)
DISPLAYSURF = pygame.display.set_mode((400,300),0,32)
pygame.display.set_caption('Cat Amimation')
# set up the display
WHITE = (255, 255, 255)
catImg = pygame.image.load('makinggames/cat.png')
catx = 10
caty = 10
direction = 'right'
# run the game loop
running = True
while running:
# draw on the surface object
DISPLAYSURF.fill(WHITE)
if direction == 'right':
catx += 5
if catx == 280:
direction = 'down'
elif direction == 'down':
caty +=5
if caty == 220:
direction = 'left'
elif direction == 'left':
catx -=5
if catx == 10:
direction = 'up'
elif direction == 'up':
caty -= 5
if caty == 10:
direction = 'right'
DISPLAYSURF.blit(catImg, (catx, caty))
for event in pygame.event.get():
if event.type == QUIT:
running = False
pygame.display.update()
fpsClock.tick(FPS)
pygame.quit()
Thanks. RPi's connections are being used by work laptop, so cannot fire it up at present. However sounds like it will work if in the same directory or maybe also if I give it a full path? /home/pi/Python/makinggames/cat.png (which is where the cat image is - program is in Python). I will give it a whirl later tonight. Peterantiloquax wrote:vinntec wrote:It seems to be connected with those which use an external file, such as image, for which I am using relative addresses? This is the simplest example - remember this works fine in IDLE3:
I've just tried this and when I changed the image file-name bit to "cat.png", (ie deleted "makinggames/" it worked.
mark
Code: Select all
import os
# ...
DATA_PATH = os.path.join(os.path.dirname(__file__), 'makinggames')
# ...
catImg = pygame.image.load(os.path.join(DATA_PATH, 'cat.png'))
Code: Select all
while not self.asleep():
sheep += 1