Original Post
Well I'm working on my second game and I have decided that it would be like a Zelda. I have successfully gotten the map to scroll, zelda image to move, and turn. But the image has an animation, though I can't see it. My guess is that I'm reloading the image to fast to. Is there a way I can make the animation show? The animation is simply the user walking. here is the code here is the picture
Thanks, Joe [Edited by - avgprogramingjoe on August 9, 2007 7:57:07 PM]
#Import
import pygame
from pygame.locals import *
#defing globals
global zelda_image
global image
image = "zelda_walk_right.gif"
zelda_image = pygame.image.load(image)
zelda_image = zelda_image.convert()
#initiate screen
pygame.init()
screen = pygame.display.set_mode((800, 600))
pygame.display.set_caption("Zelda Suck Ass ed.")
background = pygame.image.load("map.PNG")
background = background.convert()
#define
class map_update:
def __init__(self, bg, zelda_pos):
self.bg = bg
self.zelda = [zelda_pos[0], zelda_pos[1]]
def scroll(self):
self.bg = [self.bg[0], self.bg[1]]
self.keystate = pygame.key.get_pressed()
if self.zelda[1] <= 70 and self.bg[1] not in range(-10, 100):
if self.keystate[pygame.locals.K_UP]:
self.bg[1] += 5
if self.zelda[1] >= 505:
if self.keystate[pygame.locals.K_DOWN]:
self.bg[1] -= 5
if self.zelda[0] >= 705:
if self.keystate[pygame.locals.K_RIGHT]:
self.bg[0] -= 5
if self.zelda[0] <= 70 and self.bg[0] not in range(-10, 100):
if self.keystate[pygame.locals.K_LEFT]:
self.bg[0] += 5
return self.bg
class zelda_update:
def __init__(self, zelda, bg_p):
self.zelda = [zelda[0], zelda[1]]
self.bgp = [bg_p[0], bg_p[1]]
def move(self):
global zelda_image, image
self.keystate = pygame.key.get_pressed()
if self.keystate[pygame.locals.K_DOWN]:
if image != "zelda_walk_down.gif":
image = "zelda_walk_down.gif"
zelda_image = pygame.image.load(image)
zelda_image = zelda_image.convert()
if self.zelda[1] <= 505:
self.zelda[1] += 3
elif self.keystate[pygame.locals.K_RIGHT]:
if image != "zelda_walk_right.gif":
image = "zelda_walk_right.gif"
zelda_image = pygame.image.load(image)
zelda_image = zelda_image.convert()
if self.zelda[0] <= 705:
self.zelda[0] += 3
elif self.keystate[pygame.locals.K_UP]:
if image != "zelda_walk_up.gif":
image = "zelda_walk_up.gif"
zelda_image = pygame.image.load(image)
zelda_image = zelda_image.convert()
if self.zelda[1] >= 70:
self.zelda[1] -= 3
elif self.keystate[pygame.locals.K_LEFT]:
if image != "zelda_walk_left.gif":
image = "zelda_walk_left.gif"
zelda_image = pygame.image.load(image)
zelda_image = zelda_image.convert()
if self.zelda[0] >= 70:
self.zelda[0] -= 3
self.zelda =(self.zelda[0], self.zelda[1])
return self.zelda
#set vars out of loop
bg_p = (-10, -10)
zelda_pos = (100, 100)
keepgoing = True
clock = pygame.time.Clock()
# Set up main loop
while keepgoing:
#time
clock.tick(30)
#initiate classes
zelda = zelda_update(zelda_pos, bg_p)
map = map_update(bg_p, zelda_pos)
#Start event loop
for event in pygame.event.get():
if event.type == pygame.QUIT:
keepgoing = False
#movement
bg_p = map.scroll()
zelda_pos = zelda.move()
#blit images to screen
screen.blit(background, bg_p)
screen.blit(zelda_image, zelda_pos)
pygame.display.flip()
#end of loop