|
Programming Guru
Join Date: Apr 2005
Posts: 1,827
Rep Power: 5 
|
*is proud of himself*
I managed to make, in about 90 minutes, a program that will take a simple function call and output any amount of characters walking around on a set path by you.
from game_settings import *
from character_move import *
import pygame;screen=video_settings();pygame.draw.rect(screen,(255,255,255),((0,0),(800,700)),0)
def demo_movement(input,speed,inc,pos,step):
frames=len(input[0][2]);xChange=[];yChange=[]
for rep in range(len(input)):xChange.append(0);yChange.append(0)
for a in range(frames):
for rep in range(len(input)):
if len(step)==7:pic=pygame.image.load(input[rep][0]+"_"+pos+"_"+step[0:6]+".png")
else:pic=pygame.image.load(input[rep][0]+"_"+pos+"_"+step+".png")
screen.blit(pic,(input[rep][1][0]+xChange[rep],input[rep][1][1]+yChange[rep]))
time.sleep(speed);pygame.display.flip()
for a in range(frames):
step,pos=character_change(step,pos,input[rep][2][a])
pygame.draw.rect(screen,(255,255,255),((0,0),(800,700)),0)
for rep in range(len(input)):
if input[rep][2][a]=="RIGHT":xChange[rep]+=inc
elif input[rep][2][a]=="LEFT":xChange[rep]-=inc
elif input[rep][2][a]=="UP":yChange[rep]-=inc
elif input[rep][2][a]=="DOWN":yChange[rep]+=inc
if len(step)==7:pic=pygame.image.load(input[rep][0]+"_"+pos+"_"+step[0:6]+".png")
else:pic=pygame.image.load(input[rep][0]+"_"+pos+"_"+step+".png")
screen.blit(pic,(input[rep][1][0]+xChange[rep],input[rep][1][1]+yChange[rep]))
time.sleep(speed);pygame.display.flip()
R="RIGHT";L="LEFT";U="UP";D="DOWN"
So for example, I could make some characters walk around like so:
demo_movement(
(
( "Goblin", (200, 200), (R, D, L, U, L, L, D) ) ,
( "main_character", (400, 400), (R, D, L, U, L, L, D) )
) , 0.5 , 10 , "front" , "nostep" ,
)
The arguments stand for:
#demo_movement(
#(
#( "Domain of Sprite", (StartX, StartY), (Path to follow) ) ,
#( Repeat For More Characters )
#) , DelayBetweenSteps , DistanceOfSteps , "StartingPosition" , "ValueOfStep" ,
#)
If anyone is interested in seeing the entire code and all the image requirements and the other modules that I made that are involved in it, gimme a hollar.
The reason I'm so proud, is because I'm like a total n00b at this. :p
|