
-----------------------------------
Guy
Thu May 12, 2005 11:19 am

I NEED HELP WITH GAME
-----------------------------------
I NEED HELP MOVING ONE OF MY GUYS ON MY GAME... I NEED TO KNOW HOW TO USE MY ARROW KEYS TO MOVE HIM.  SHOW ME AN EXAMPLE OF HOW TO DO THIS

-----------------------------------
mat
Thu May 12, 2005 12:31 pm


-----------------------------------
this might help you.

var x, y : int := 200

loop
    var input : char := getchar

    drawfilloval (x, y, 5, 5, 0)
    if input = KEY_UP_ARROW then
        y := y + 5
    elsif input = KEY_DOWN_ARROW then
        y := y - 5
    elsif input = KEY_LEFT_ARROW then
        x := x - 5
    elsif input = KEY_RIGHT_ARROW then
        x := x + 5
    end if
    drawfilloval (x, y, 5, 5, red)
end loop
Im not sure if the KEY_ thing works on all versions of turing. It does not work for my verion at home.
hope this helps.

-----------------------------------
Cervantes
Thu May 12, 2005 3:13 pm


-----------------------------------
Please try to avoid the whole ALL CAPITAL LETTERS thing.  It gets annoying.
mat: if you figured out how to use colours, surely you can use te Input.KeyDown.  Check the help file or the Turing Tutorials section to learn how to use it. :)

-----------------------------------
Guy
Thu May 12, 2005 3:41 pm

Thanks for da help
-----------------------------------
i did not check if it works yet becasue i don have my game with me...but thnxs anyways

-----------------------------------
Guy
Thu May 12, 2005 3:45 pm

At last it moves...but.........
-----------------------------------
if you will run this, the red dot will not appear at the beginning only wehn i start moving and can i move it faster? Show me how to move it faster and  fort he dot to appear before i sue any of the arrow keys...


colorback (black)
cls
setscreen ("graphics: vga")
drawfilloval (10, 190, 5, 5, red)
drawfilloval (620,190, 5, 5, blue)
var x, y : int := 200

loop
var input : char := getchar

drawfilloval (x, y, 5, 5, black)
if input = KEY_UP_ARROW then
y := y + 5
elsif input = KEY_DOWN_ARROW then
y := y - 5
elsif input = KEY_LEFT_ARROW then
x := x - 5
elsif input = KEY_RIGHT_ARROW then
x := x + 5
end if
drawfilloval (x, y, 5, 5, red)
end loop

-----------------------------------
Cervantes
Thu May 12, 2005 4:07 pm


-----------------------------------
The red dot does not appear because your program waits until a key is pressed.  Therefore, because the code to draw the circle occurs after the getchar, the dot will not appear until you press a key to move it.  To fix this, simply move the draw code before the getchar.  But, that's not really fixing anything.  What we want is for the program be executing the lines of code at all times, not pausing for input.  Have you ever played a good game (apart from the old RPGs) in which everything waits for you to hit a key?  Doubtful.  So, there are two ways to fix this.  One would be to wrap that getch in a if hasch then statement, like this:

    if hasch then
        input := getchar
    end if

(Also, I changed that line around so that we're not declaring the variable over and over again inside the loop.  Though Turing will let you do this, it's bad.)
Try that.  You'll notice that when you hit a key, the dot moves really, really fast.  Well, maybe if we decrease the incriment (from 5 to, say, 1) and add a delay things will be better.  Try that.  Now you'll notice that if you hold a key for  awhile and then release it, that key will still appear pressed, based on the output of your program.  To fix this, let's go to Input.KeyDown, shall we?

Also, two nitpicking this:  1, use code tags, please.  2, giving people orders is not the best way to get help (as I just explained to something else... :roll:)
Show me how to...

-----------------------------------
Guy
Thu May 12, 2005 4:54 pm

LOL..Still Problems
-----------------------------------
it says i need to declare "input" but i already did..look: (if it wrong may you fix it for me?)

colorback (black)
cls
setscreen ("graphics: vga")
drawfilloval (620,190, 5, 5, blue)
var x, y : int := 200
loop
var input2 : char := getchar
drawfilloval (x, y, 5, 5, black)
if input2 = KEY_UP_ARROW then
y := y + 5
elsif input2 = KEY_DOWN_ARROW then
y := y - 5
elsif input2 = KEY_LEFT_ARROW then
x := x - 5
elsif input2 = KEY_RIGHT_ARROW then
x := x + 5
end if
drawfilloval (x, y, 5, 5, red)
end loop
if hasch then
        input2 := getchar
    end if

-----------------------------------
Cervantes
Thu May 12, 2005 5:28 pm


-----------------------------------
What did I say about a) code tags and b) declaring variables inside loops? Also, I said wrap the input := getchar in an if statement, not add the code I posted at the end of your program...
:roll:

-----------------------------------
Guy
Thu May 12, 2005 8:13 pm

lol..not understanding
-----------------------------------
can u please do it for me becasue i dont understand what you're saying[/b]

-----------------------------------
Delos
Thu May 12, 2005 8:21 pm

Re: LOL..Still Problems
-----------------------------------
it says i need to declare "input" but i already did..look: (if it wrong may you fix it for me?)

colorback (black)
cls
setscreen ("graphics: vga")
drawfilloval (620,190, 5, 5, blue)
var x, y : int := 200
loop
var input2 : char := getchar
drawfilloval (x, y, 5, 5, black)
if input2 = KEY_UP_ARROW then
y := y + 5
elsif input2 = KEY_DOWN_ARROW then
y := y - 5
elsif input2 = KEY_LEFT_ARROW then
x := x - 5
elsif input2 = KEY_RIGHT_ARROW then
x := x + 5
end if
drawfilloval (x, y, 5, 5, red)
end loop
if hasch then
        input2 := getchar
    end if

Your problem is that you've declared "input2" inside a loop.  This makes it local, ergo it cannot be fathomed from outside of the loop.

Now, listen to Cervantes, he is quite powerful.  Use help, not I'll do your work for you.  There is a difference.
