
-----------------------------------
Mystify
Thu Dec 01, 2005 9:34 pm

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??

-----------------------------------
iker
Thu Dec 01, 2005 9:59 pm


-----------------------------------
I have the program, but I'm in the process of making a game, so I will just give you a small tutorial


%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 :D

-----------------------------------
iker
Thu Dec 01, 2005 10:04 pm


-----------------------------------
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 :P also, instead of adding to  the step int in every loop, only add to it if movement is true. Sry about missing that...

-----------------------------------
Mystify
Thu Dec 01, 2005 10:13 pm


-----------------------------------
Uhh i changed it around but it doesnt work at all :S


%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 


-----------------------------------
iker
Sat Dec 03, 2005 7:55 pm


-----------------------------------
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
