Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Apr 18th, 2005, 10:56 PM   #1
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,076
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
*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
Sane is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:03 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC