RPG Character Control
Author |
Message |
good_fella
|
Posted: Sun Oct 19, 2003 6:20 pm Post subject: RPG Character Control |
|
|
I'm making an RPG and i need help with the character control.
Okay, here's the problem:
I need the user to be able to press the keys. When a key is pressed, the little dude on the screen needs to move. But the picture needs to change for whatever direction he's facing.
Also, the picture needs to alternate. (ie. One with his right leg forward, one with his left leg forward, to create the impression of walking.)
The background image that the character is walking on top of also needs to stay the same.
And the Screen can't flash.
I've managed to get some of these things to work, but still having a hard time. Any help would be appreciated!
[I have Turing 4.0 so all the Input.KeyDown and other commands will work.]
Thanx! |
|
|
|
|
|
Sponsor Sponsor
|
|
|
AsianSensation
|
Posted: Sun Oct 19, 2003 7:21 pm Post subject: (No subject) |
|
|
ok, to answer these questions:
1. You want the user to input, and have the guy walk. Also, he needs to face some direction.
Suggestion: have a integer variable called direction, and everytime you press one of the arrow keys, then you assign a value to direction. Example:
code: | var direction : int
var chars : array char of boolean
loop
Input.KeyDown (chars)
if chars (KEY_UP_ARROW) then
direction := 1
end if
if direction = 1 then
Pic.Draw (picup, x, y, picMerge)
end if
end loop |
this checks to see what direction the guy is facing, and then draws the corresponding picture.
2. To have the guy's legs alternate.
Suggestion: when you draw the guy moving, draw the left-legged pic, then delay for a small amount of time, and then draw the right legged pic, except that the right legged pic would have to have move a bit from the left legged one, depending on which direction he is facing, creating the "walking" effect.
3. To have the background stay the same.
Suggestion: don't change the background coordinates
4. Flicker-free animation
Suggestion: use View.Update, I beleive there is a very good tutorial in the tutorial section, there is no need for me to explain it. |
|
|
|
|
|
good_fella
|
Posted: Sun Oct 19, 2003 8:15 pm Post subject: (No subject) |
|
|
Okay. I got the guy to move by pressing the arrow keys. However there's still some major problems.
One, when you let go of the arrow keys, the pic of the guy dissapears!
Two, I still can't get the guys legs to alternate using 2 different pics!
Here's the code i have for the movement, can someone tell me whats wrong with it:
code: |
loop
View.Update
delay (100)
cls
Pic.Draw (town1, 0,0,0)
Input.KeyDown (chars)
if chars (KEY_DOWN_ARROW) then
count1 := count1 - 2
direction := 1
Pic.Draw (steppingforward1, count2, count1, picMerge)
end if
if chars (KEY_UP_ARROW) then
count1 := count1 + 2
Pic.Draw (steppingbackward1, count2, count1, picMerge)
end if
if chars (KEY_RIGHT_ARROW) then
count2 := count2 + 2
Pic.Draw (steppingright1, count2, count1, picMerge)
end if
if chars (KEY_LEFT_ARROW) then
count2 := count2 - 2
Pic.Draw (steppingleft1, count2, count1, picMerge)
end if
end loop
|
In the code above, town1 is the background picture i need to use. steppingforward1, steppingright1, etc. are all the pics of the character stepping in whatever direction. I need to somehow use the pics steppingleft2, steppingright2, to make his legs alternate.
I hope that somebody understands what im talking about. |
|
|
|
|
|
poly
|
Posted: Sun Oct 19, 2003 8:33 pm Post subject: (No subject) |
|
|
well first off, all those IF statements can be made into 1 If statement with Elsif's
To answer your question:
Well basically your code just shows the guy when a key is pressed. roughly you want something like this
code: |
loop
if
%Inside here is your If statements
end if
% In here add draw regular characters stance
View.Update
end loop
|
|
|
|
|
|
|
good_fella
|
Posted: Sun Oct 19, 2003 9:40 pm Post subject: (No subject) |
|
|
I'm still not getting it. Nothing seems to work |
|
|
|
|
|
AsianSensation
|
Posted: Sun Oct 19, 2003 10:30 pm Post subject: (No subject) |
|
|
Because Input.KeyDown check to see if a key is held down, therefore, when you draw the pictures for your guy, you need delays. When you don't have delays, you will see the guy go into one direction really really fast.
to make the guy step:
code: | Pic.Draw (steppingforward1, x, y, picMerge)
delay (10)
Pic.Draw (steppingforward2, x + a, y + b, picMerge)
delay (100 |
where x and y are the coordinates, and a and b are some constants, depending on what direction you are facing, a and b take on different values. |
|
|
|
|
|
good_fella
|
Posted: Mon Oct 20, 2003 12:04 am Post subject: (No subject) |
|
|
alrite i got it to work!
thanx alot! |
|
|
|
|
|
good_fella
|
Posted: Mon Oct 20, 2003 1:27 pm Post subject: (No subject) |
|
|
wait! i cant get the pics to alternate!
can someone tell me how to fix this code to display two different pics (one of each leg forward) everytime you hit a key!
code: | loop
View.Update
delay (30)
Input.KeyDown (chars)
if chars (KEY_DOWN_ARROW) then
count1 := count1 - 2
position := "steppingforward1"
elsif chars (KEY_UP_ARROW) then
count1 := count1 + 2
position := "steppingbackward1"
elsif chars (KEY_RIGHT_ARROW) then
count2 := count2 + 2
position := "steppingright1"
elsif chars (KEY_LEFT_ARROW) then
count2 := count2 - 2
position := "steppingleft1"
end if
if position = "steppingforward1" then
cls
Pic.Draw (town1, 0, 0, 0)
Pic.Draw (steppingforward1, count2, count1, picMerge)
elsif position = "steppingbackward1" then
cls
Pic.Draw (town1, 0, 0, 0)
Pic.Draw (steppingbackward1, count2, count1, picMerge)
elsif position = "steppingright1" then
cls
Pic.Draw (town1, 0, 0, 0)
Pic.Draw (steppingright1, count2, count1, picMerge)
elsif position = "steppingleft1" then
cls
Pic.Draw (town1, 0, 0, 0)
Pic.Draw (steppingleft1, count2, count1, picMerge)
end if
end loop
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Mazer
|
Posted: Mon Oct 20, 2003 4:55 pm Post subject: (No subject) |
|
|
instead of instantly setting the position to "steppingforward1", you could first check what it was.
ie
code: |
if position = "steppingforward1" then
position := "steppingforward2"
else
position := "steppingforward1"
end if
|
that's assuming you'll have only two pictures for the walking animation. if that's true, then you'll probably want a longer delay so the player can actually see the pictures. |
|
|
|
|
|
nis
|
Posted: Thu Nov 06, 2003 6:35 pm Post subject: (No subject) |
|
|
Create an array for each picture
code: |
var steppingforward, steppingbackwards: array 1 .. 2 of int
steppingforward(1) := Pic.FileNew("whatever your firstpicture is.bmp")
steppingforward(2) := Pic.FileNew("whatever your firstpicture is.bmp")
steppingbackwards(1):= Pic.FileNew("whatever your firstpicture is.bmp")
steppingbackwards(2):= Pic.FileNew("whatever your firstpicture is.bmp")
etc....
loop
for i : 1 .. 2
View.Update
Pic.Draw (town1, 0,0,0)
Input.KeyDown (chars)
if chars (KEY_UP_ARROW) then
Pic.Draw (steppingforward(i), x, y, picMerge)
end if
if chars (KEY_DOWN_ARROW) then
Pic.Draw (steppingbackwards(i), x, y, picMerge)
end if
delay(100)
end for
end loop
|
Of course thats just up and down but you get the idea, good luck |
|
|
|
|
|
good_fella
|
Posted: Wed Nov 12, 2003 4:45 pm Post subject: (No subject) |
|
|
alrite i got it to work great. thanks ppl. |
|
|
|
|
|
|
|