Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Apr 18th, 2005, 9:56 PM   #1
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,799
Rep Power: 5 Sane will become famous soon enough
*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
Old Apr 18th, 2005, 9:59 PM   #2
thechristelegacy
Expert Programmer
 
thechristelegacy's Avatar
 
Join Date: Jul 2004
Location: Somerset, Pa
Posts: 707
Rep Power: 4 thechristelegacy is on a distinguished road
Send a message via AIM to thechristelegacy Send a message via MSN to thechristelegacy
Looks awesome sane. I would be interested in seeing all the code with the images. Post the zip.
thechristelegacy is offline   Reply With Quote
Old Apr 18th, 2005, 10:05 PM   #3
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,799
Rep Power: 5 Sane will become famous soon enough
I think it's attatched to this message. You can run it from character_auto.py. Just take out the arguments for the main character, because the sprite collection was incomplete.

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" ,
             )

(Remove the bold, which includes the comma)

P.S. The images right now don't have transparent pixels like they should. So if you tried to use these images on top of a non-white background, it won't work until you add the transparent pixels in PNG format.
Attached Files
File Type: zip sub.zip (16.4 KB, 19 views)

Last edited by Sane; Apr 18th, 2005 at 10:13 PM.
Sane is offline   Reply With Quote
Old Apr 19th, 2005, 6:30 PM   #4
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,799
Rep Power: 5 Sane will become famous soon enough
Updated. Run from temp_call.py

See auto_character.py - def figure_path > for different path options, and the randomize option. (rand 20)

I think I fixed all the bugs too.

Edit:

I've been writing path functions to make it easier to mass program.

Update for def path_figure
def path_figure(event):
    path=[]
    if event[0:4]=="cust":
        if event[5:]=="1":path=D,D,L,L,D,D,L,L,L,U,U,U,U
    elif event[0:4]=="patt":
        patha=event+" "
        for a in range(4,len(event)+2):
            if patha[a]==" ":
                if patha[a+3]==" ":patha=patha[:a+2]+"0"+patha[a+2:]
        b=(len(patha)-4)/4
        for l in range(b):
            r1=int(patha[6+l*4]);r2=int(patha[7+l*4]);r=10*(r1)+1*(r2)
            for z in range(r+1):
                a=patha[5+l*4]
                if a=="D":path.append(D)
                elif a=="U":path.append(U)
                elif a=="L":path.append(L)
                elif a=="R":path.append(R)
    elif event[0:4]=="rand":
        for z in range(int(event[5:])):
            a=random.randrange(1,5)
            if a==1:path.append(D)
            elif a==2:path.append(U)
            elif a==3:path.append(L)
            elif a==4:path.append(R)
    return path

Update for temp_call.py
from character_auto import*


#########################################################################
##############################PATH_FIGURE################################
#########################################################################
#                                                                       #
#To randomize movement -------------------------------- ("rand xx")     #
#---- x = Any Number of Random Steps                                    #
#                                                                       #
#To make large sequences easily ----------------------- ("patt Dx Dxx") #
#---- D = Direction [U/D/L/R]                                           #
#---- x = 1 or 2 digit number: steps for that direction                 #
#                                                                       #
#To call a custom made path --------------------------- ("cust x")      #
#---- x = Call number for that custom path                              #
#                                                                       #
#########################################################################


path=path_figure("patt L5 D5 U12 R14 D6")

demo_movement((
    ("Goblin",(200,200),(path)),
    ("Goblin",(400,200),(path)),
    ),2,10,("front","nostep"),)

I think I've finally got the whole Python thing down, I feel like a pro. :p

I even made it so if you could input one digit, instead of 0 then the digit (8 vs 08). It then adds a 0 into the string to keep it synchronized with itself. If you look at the arguments you use for patt in path_figure, you'll see what I mean. It was tricky, but good practice.
Attached Files
File Type: zip sub.zip (16.6 KB, 17 views)

Last edited by Sane; Apr 19th, 2005 at 9:15 PM.
Sane is offline   Reply With Quote
Reply

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 1:25 AM.

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