Sprite Walking
Author |
Message |
Mystify
![](http://www50.brinkster.com/kcharle/Misc/babymilosmall.jpg)
|
Posted: Thu Dec 01, 2005 9:34 pm Post subject: Sprite Walking |
|
|
Anyone have an example of a simple little program that draws a sprite say like mega man or sumthing walking in the direction of the arrow you push and stopping at the spot when you let go?? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
iker
![](http://compsci.ca/v3/uploads/user_avatars/6313105374b04e31c7b33a.png)
|
Posted: Thu Dec 01, 2005 9:59 pm Post subject: (No subject) |
|
|
I have the program, but I'm in the process of making a game, so I will just give you a small tutorial
code: |
%always:
stescreen ("graphics, offscreenonly")
%declare all of you variables such as:
var chars : array char of boolean
var x, y, : int := (n)
%use a boolean for each direction and for a movement
var up, down, left, right, movement : boolean := false
%use a step counter, necessary for multiple pictures
var step : int
%declare 3 or more pictures for every direction, 1 being still, the other 2 + being actual movement
ui := Pic.FileNew ("ui.bmp")% ui being idle facing up
u1 := Pic.FileNew ("u1.bmp")%1st step up
u2 := Pic.FileNew ("u2.bmp")%2nd step up
di := Pic.FileNew ("di.bmp")% idle facing down
%...
%do a procedure with all the pictures being drawn, for example:
procedure direction
if movement = true then
if step > 40 then %you can change the number, depending on how fast you want the steps
if up = true then
Draw.Pic (u1, x, y, pic.Merge)
elsif down = true then
%...
if step > 80 then
if up = true then
Draw.Pic (u2, x, y, picMerge)
elsif down = true then
%...
elsif movement = false then
if up = true then
Draw.Pic (ui, x, y, picMerge)%since there is no movement, you use the idle pose
elsif down = true then
%...
step += 1 %this is where the step counter comes into play
if step > 120 then
step := 0
end if
end direction
%now have a loop with your background first, then draw characters, refresh the screen, and repeat
loop
%draw background with ether a procedure or a picture
Input.KeyDown (chars)
if chars (KEY_UP_ARROW) then
up := true %if the up arrow is pressed, up is true, everything else is false
down := false
left := false
right := false
elsif chars (KEY_DOWN_ARROW) then
up := false
down := true
%...
View.Update
delay (n)
end loop
|
Now, this code is for a 4 way movement, you can change it to 8 easily by having two if chars (KEY... statements, one with up and down, the other with left and right. If you can't figure this out, ask again, and I'll expand a bit, but it is pretty basic.
Anyways, happy coding ![Very Happy Very Happy](http://compsci.ca/v3/images/smiles/icon_biggrin.gif) |
|
|
|
|
![](images/spacer.gif) |
iker
![](http://compsci.ca/v3/uploads/user_avatars/6313105374b04e31c7b33a.png)
|
Posted: Thu Dec 01, 2005 10:04 pm Post subject: (No subject) |
|
|
oops, just remembered, right after I posted. Since it is important, right after you draw the background, before the Input.KeyDown, make sure to change movement to false, and if a key is pressed, make it true also, instead of adding to the step int in every loop, only add to it if movement is true. Sry about missing that... |
|
|
|
|
![](images/spacer.gif) |
Mystify
![](http://www50.brinkster.com/kcharle/Misc/babymilosmall.jpg)
|
Posted: Thu Dec 01, 2005 10:13 pm Post subject: (No subject) |
|
|
Uhh i changed it around but it doesnt work at all :S
code: |
%always:stescreen ("graphics, offscreenonly")
%declare all of you variables such as:
var chars : array char of boolean
var x, y : int
%use a boolean for each direction and for a movement
var up, down, left, right, movement : boolean := false
%use a step counter, necessary for multiple pictures
var step : int
%declare 3 or more pictures for every direction, 1 being still, the other 2 + being actual movement
var ui : int := Pic.FileNew ("mm1.bmp")% ui being idle facing up
var u1 : int := Pic.FileNew ("mm2.bmp")%1st step up
var u2 : int := Pic.FileNew ("mm3.bmp")%2nd step up
var di : int := Pic.FileNew ("mm4.bmp")% idle facing down
%...
%do a procedure with all the pictures being drawn, for example:
procedure direction
if movement = true then
if step > 40 then %you can change the number, depending on how fast you want the steps
if up = true then
Pic.Draw (u1, x, y, picMerge)
elsif down = true then
%...
if step > 80 then
if up = true then
Pic.Draw (u2, x, y, picMerge)
elsif down = true then
%...
elsif movement = false then
if up = true then
Pic.Draw (ui, x, y, picMerge)%since there is no movement, you use the idle pose
elsif down = true then
%...
step += 1 %this is where the step counter comes into play
if step > 120 then
step := 0
end if
end if
end if
end if
end if
end if
end if
end direction
%now have a loop with your background first, then draw characters, refresh the screen, and repeat
loop
%draw background with ether a procedure or a picture
Input.KeyDown (chars)
if chars (KEY_UP_ARROW) then
up := true %if the up arrow is pressed, up is true, everything else is false
down := false
left := false
right := false
elsif chars (KEY_DOWN_ARROW) then
up := false
down := true
%...
View.Update
end if
end loop
|
|
|
|
|
|
![](images/spacer.gif) |
iker
![](http://compsci.ca/v3/uploads/user_avatars/6313105374b04e31c7b33a.png)
|
Posted: Sat Dec 03, 2005 7:55 pm Post subject: (No subject) |
|
|
yah, sorry, the code that i wrote wasn't an actual code, its an example for you to finish off, because its not complete... I'll post it in a bit |
|
|
|
|
![](images/spacer.gif) |
|
|