Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 making a sprite run using multiple pictures-heres my code-
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
DanceMacabre




PostPosted: Sat Apr 22, 2006 9:39 am   Post subject: making a sprite run using multiple pictures-heres my code-

I just need a good example of what I can do to make variables Rup1 through 8 draw/cycle through their pictures when the user presses and holds the up key. Know what I mean? btw there is alot of code here I havent delt with yet, so bear with me.

code:

var x, y : int := 100
var sorax, soray : int :=200
var rikux, rikuy : int :=500
var charpress: array char of boolean

View.Set ("offscreenonly")

var Rup1 : int := Pic.FileNew ("R-up1.jpg")
var Rup2 : int := Pic.FileNew ("R-up2.jpg")
var Rup3 : int := Pic.FileNew ("R-up3.jpg")
var Rup4 : int := Pic.FileNew ("R-up4.jpg")
var Rup5 : int := Pic.FileNew ("R-up5.jpg")
var Rup6 : int := Pic.FileNew ("R-up6.jpg")
var Rup7 : int := Pic.FileNew ("R-up7.jpg")
var Rup8 : int := Pic.FileNew ("R-up8.jpg")


procedure movesora (var sorax : int, var soray : int)
    Input.KeyDown (charpress)
    if charpress (KEY_UP_ARROW) then
        soray := soray + 2
    end if
    if charpress (KEY_RIGHT_ARROW) then
        sorax := sorax + 2
    end if
    if charpress (KEY_LEFT_ARROW) then
        sorax := sorax - 2
    end if
    if charpress (KEY_DOWN_ARROW) then
        soray := soray - 2
        end if
        if charpress ('l') then
        sorax:=500
        soray:=300
        end if
    end movesora
   
procedure moveriku (var rikux :int, var rikuy :int)   
if charpress ('w') then
rikuy:=rikuy+2
end if
if charpress ('s') then
rikuy:=rikuy-2
end if
if charpress ('a') then
rikux:=rikux-2
end if
if charpress ('d') then
rikux:=rikux+2
end if
if charpress ('e') then
rikux:=200
rikuy:=200
end if
end moveriku

View.Set ("offscreenonly")
loop
    cls
    Draw.FillBox (0,0, maxx, 10, green)
    Draw.FillBox (0,10, 10,maxy, green)
    Draw.FillBox (0,10,0,maxy,green)
    movesora (sorax, soray)
    moveriku(rikux, rikuy)
    Pic.Draw (Rup1,sorax, soray, picMerge)
    Pic.Draw (Rup2, rikux, rikuy, picMerge)
    View.Update
end loop
code:
Sponsor
Sponsor
Sponsor
sponsor
HellblazerX




PostPosted: Sat Apr 22, 2006 10:10 am   Post subject: (No subject)

why not have those 8 pictures place into an array, like this:

code:
var Rup : array 1 .. 8 of int
for i : 1 .. 8
    Rup (i) := Pic.FileNew ("R-up" + intstr (i) + ".jpg")
end for


now, for changing the pictures, use a counter that increases every time the user presses the up key, and just draw what image in the array that the counter is pointing to:

code:
var count : int := 1
if charpress (KEY_UP_ARROW) then
    count += 1
    if count > 8 then
        count -= 8
    end if
end if
Pic.Draw (Rup(count), sorax, soray, picMerge)
Albrecd




PostPosted: Sat Apr 22, 2006 10:10 am   Post subject: (No subject)

You should use a counter to determine which picture to draw.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: