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

Username:   Password: 
 RegisterRegister   
 Moving the way a object is facing
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Hack.saw




PostPosted: Mon Jun 26, 2006 8:35 pm   Post subject: Moving the way a object is facing

This is my code:
code:
var chars : array char of boolean
var walking, walkingright, walkingleft : boolean := false
var x, y, x2, y2 : int
x := 300
y := 240
x2 := 340
y2 := 260
%setscreen ("offscreenonly")

proc backset
    drawfillbox (0, 0, 640, 480, green)
end backset

 proc charmove

drawfillbox (x, y, x2, y2, red)
drawfilloval (x, y + 10, 10, 10, red)
drawfilloval (x + 40, y + 10, 10, 10, red)
drawfillbox (x, y, x2, y2 - 25, blue)
drawfilloval (x + 20, y + 14, 11, 11, grey)
%View.Update
loop

    Input.KeyDown (chars)

    if chars (KEY_UP_ARROW) then
        walking := true
        y := y + 5
        y2 := y2 + 5
        delay (10)

    elsif chars (KEY_RIGHT_ARROW) then
        walkingright := true
        x := x + 5
        x2 := x2 + 5
        delay (10)

    elsif chars (KEY_DOWN_ARROW) then
        y := y - 5
        y2 := y2 - 5
        delay (10)

    elsif chars (KEY_LEFT_ARROW) then
        walkingleft := true
        x := x - 5
        x2 := x2 - 5
        delay (10)

    else
        walking := false
        walkingright := false
        walkingleft := false
    end if

    if walking = true then
        drawfillbox (x, y, x2, y2 - 35, blue)
    end if

    if walkingleft = true then
        drawfillbox (x, y, x2 + 10, y2 - 25, blue)
    end if

    if walkingright = true then
        drawfillbox (x - 10, y, x2, y2 - 25, blue)
    end if

    drawfillbox (x, y, x2, y2, red)
    drawfilloval (x, y + 10, 10, 10, red)
    drawfilloval (x + 40, y + 10, 10, 10, red)
    drawfillbox (x, y, x2, y2 - 25, blue)
    drawfilloval (x + 20, y + 14, 11, 11, grey)
    backset
    %View.Update
end loop

end charmove



charmove


this is a rough birds eye view of a character. When he moves to the right or left or forward the cloak moves with him. (You may have to un% the view.updates i leave them out casue it slows down my comp too much)
I want to be able to still have this effect, but no one strafes like that... htye actually turn and face the way they walk. I know you can do pic.rotate or sumthin like that but a) that would mean i have ot make it into a pic and b) wouldn't he rotate every second i hold the key down for?

(Sorry for my terrible typing skillz Mad )
Sponsor
Sponsor
Sponsor
sponsor
upthescale




PostPosted: Mon Jun 26, 2006 9:47 pm   Post subject: (No subject)

i dont understand the question...wanna say it again with grammer?
Clayton




PostPosted: Mon Jun 26, 2006 10:09 pm   Post subject: (No subject)

y not just Pic.Save your guy then Pic.Rotate him, it shouldnt slow down the program that much... just save him in the positions you want when he goes there and then draw him to your hearts content Very Happy
Cervantes




PostPosted: Tue Jun 27, 2006 9:02 am   Post subject: (No subject)

If you're going to use Pic.Rotate, do that before you enter your main loop. Make 36 (or so) images of him, each rotated 10 degrees beyond the last. Store these in an array. Pic.Rotate is a slow function and will make your program run way too slow if you put it inside the loop (if you try to Pic.Rotate in real-time).

Do you actually want to strafe like that, or do you want to be able to turn him with the right and left arrow keys, and the forward and backward arrow keys move in forward or backwards in the direction that he is facing. If so, that's entirely possible, but you'll need to know basic trigonometry.

A few coding suggestions:
- You shouldn't put the delay inside those if statements. Have one delay, and put it after the View.Update or somewhere around there.
- Your backset procedure call is in the wrong spot. It should go before all those drawfill's.
- You don't need to say, `if walking = true'. Because walking is true (it is a boolean, let's assume it's true), you don't need to compare true = true. `if walking then' evaluates to `if true then', and so the if statement is entered.
-If you want to be able to move in a diagonal, change that input if structure with all the elsif's to be several individual if statements. No elsif's, because that prevents the right arrow key from being registered if the up arrow key is.
-You could safely get rid of the drawfill's and View.Update at the beginning of your charmove procedure. They don't serve any purpose, since almost instantaneously after they are drawn, they will be overdrawn by the drawing in the loop.
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  [ 4 Posts ]
Jump to:   


Style:  
Search: