Computer Science Canada

Movin animations quickly

Author:  Blade [ Thu Mar 06, 2003 9:31 pm ]
Post subject:  Movin animations quickly

I'm currently making a pacman game... and i cant get him to open/close his mouth, and be able to make him move quickly at the same time... here's the animation code i'm currently using
code:

loop
    drawfillarc (x, y, 30, 30, 50, 330, yellow)
    delay (100)
    cls
    drawfillarc (x, y, 30, 30, 30, 370, yellow)
    delay(100)
    cls
end loop

with the delays being 100 in there i cant get him to move quickly around the screen, is there any other way to animate pacman??

Author:  Dan [ Thu Mar 06, 2003 10:09 pm ]
Post subject:  mr. pac man

i whode use pics to do this but they can be hard to figer out so i will tell you how to do it your way. basilky you animate it by having it when the key is hit the face swichs to the next frame and the picher moves in the diserid direction.

here is an example.

code:

var key:string(1)
var x:int := maxx div 2
var y:int := maxy div 2
var frame:int := 1


loop
    getch(key)   
   
    cls
   
    if ord(key) = 205 and frame = 1 then
        x += 5
        drawfillarc (x, y, 30, 30, 50, 330, yellow)
        frame := 0
    elsif ord(key) = 205 and frame = 0 then
        x += 5
        drawfillarc (x, y, 30, 30, 30, 370, yellow)
        frame := 1
    elsif ord(key) = 203 and frame = 1 then
        x -= 5
        drawfillarc (x, y, 30, 30, 50, 330, yellow)
        frame := 0
    elsif ord(key) = 203 and frame = 0 then
        x -= 5
        drawfillarc (x, y, 30, 30, 30, 370, yellow)
        frame := 1
    end if
   
    delay (100)
   
end loop


this code only use left and right keys and pac man looks same way going in both dircetions but you get the idea.

Author:  Tony [ Thu Mar 06, 2003 10:33 pm ]
Post subject: 

also the use for delay is general a bad idea in the games... I mean why wait Wink

but if you need to keep pacman from running around like a road-runner, you can just decrease the movement distance per loop. Such as instead of x:=x+1 you can slow it down 2 times by using x:=x+0.5 Its more accurate too

Another good way to consider is the use of an actual timer that calls procedures when the time is right. This way the program will run at the same speed on any machine (since 3GHz P4 is about 6 times faster then my Celeron 550 Crying or Very sad )

Author:  Blade [ Thu Mar 06, 2003 10:44 pm ]
Post subject: 

tony wrote:
also the use for delay is general a bad idea in the games... I mean why wait Wink ...


the reason i had to use the delays was because he would be animating waaay to fast.. then it slowed down the movement of pacman... you see what i mean?

Author:  Asok [ Thu Mar 06, 2003 10:48 pm ]
Post subject: 

Highest delay in a moving game should be 50.

if he is moving too fast change the movement modifier (the number x/y is increasing/decreasing by)

Author:  Tony [ Thu Mar 06, 2003 10:51 pm ]
Post subject: 

ya, thats what I explained after... delay(100) might be too much...

delay(1000) is 1 second. So 100 is 0.1 of a second. Your eyes keep an image for 0.06 of a second so thats not good enough. Movie's framerate is 32 per second Wink

It might be a nice feature to add in a game to make delay duration a variable, so that the user can set the gamespeed. Also you can't go into negatives and I was playing in my own snakegame on 0 delay Confused

Author:  Blade [ Thu Mar 06, 2003 11:05 pm ]
Post subject: 

that's not really the problem... dan knew what i was talking about... the problem was, with the image... he was chomping way too quickly, and i couldnt make him move as fast as i wanted him to... but if i lowered the delay, it looked really crappy cuz he was chomping too quickly, but he was able to move a little better, but not what i wanted... with dans code, its good though, because he moves as he chomps, i'd never thought of that

Author:  Tony [ Thu Mar 06, 2003 11:08 pm ]
Post subject: 

ahh... so thats the problem Wink

should have played original pacman 8)

but hey, still some good things to keep in mind while setting up the speed of your game

Author:  Dan [ Thu Mar 06, 2003 11:09 pm ]
Post subject: 

also i think that in the real pac man game he only chops when he moves. but i could be wrong i have not played it in like 3 years, lol.

Author:  Asok [ Thu Mar 06, 2003 11:11 pm ]
Post subject: 

No you're right dan, that's how Pacman AND Ms.Pacman work.

Ms.Pacman is cute Embarassed

Author:  Blade [ Thu Mar 06, 2003 11:26 pm ]
Post subject: 

haha, yeah it is right... my mom's still obsessed with that game.. Rolling Eyes

but yeah, i want to thank you all for your help, i will keep that other stuff in mind Very Happy


: