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

Username:   Password: 
 RegisterRegister   
 I NEED HELP WITH GAME
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Guy




PostPosted: Thu May 12, 2005 11:19 am   Post subject: 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
Sponsor
Sponsor
Sponsor
sponsor
mat




PostPosted: Thu May 12, 2005 12:31 pm   Post subject: (No subject)

this might help you.

code:
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




PostPosted: Thu May 12, 2005 3:13 pm   Post subject: (No subject)

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 [ code][ /code] tags. Smile Just nicer to look at.

Lastly, the easiest (and best) way to do this is to use Input.KeyDown. Check the help file or the Turing Tutorials section to learn how to use it. Smile
Guy




PostPosted: Thu May 12, 2005 3:41 pm   Post subject: Thanks for da help

i did not check if it works yet becasue i don have my game with me...but thnxs anyways
Guy




PostPosted: Thu May 12, 2005 3:45 pm   Post subject: 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




PostPosted: Thu May 12, 2005 4:07 pm   Post subject: (No subject)

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:
code:

    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... Rolling Eyes)
Guy wrote:
Show me how to...
Guy




PostPosted: Thu May 12, 2005 4:54 pm   Post subject: 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




PostPosted: Thu May 12, 2005 5:28 pm   Post subject: (No subject)

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...
Rolling Eyes
Sponsor
Sponsor
Sponsor
sponsor
Guy




PostPosted: Thu May 12, 2005 8:13 pm   Post subject: lol..not understanding

can u please do it for me becasue i dont understand what you're saying[/b]
Delos




PostPosted: Thu May 12, 2005 8:21 pm   Post subject: Re: LOL..Still Problems

Guy wrote:
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 [code] tags. Please. See, I'm even being nice to you!

After that, there is a chance you might get help. Note, help, not I'll do your work for you. There is a difference.
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  [ 10 Posts ]
Jump to:   


Style:  
Search: