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

Username:   Password: 
 RegisterRegister   
 Diagonal Movement
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
bluedevils_77




PostPosted: Fri Apr 21, 2006 5:01 pm   Post subject: Diagonal Movement

My code:

var chars :array char of boolean
var x,y,x1,y1: int
x1 := 100%variables duh
y1:= 190
x:= 100
y:= 100

loop
Input.KeyDown(chars)
%drawing it
Draw.Line (x,y,x1,y1,7)
delay(10)
cls
%it going up
if chars (KEY_UP_ARROW) then
y:=y +2
y1:= y1 +2
%it gonig down
elsif chars (KEY_DOWN_ARROW) then
y:=y-2
y1:= y1 - 2
%left
elsif chars (KEY_LEFT_ARROW) then
x:=x - 2
x1:= x1 - 2
%right
elsif chars (KEY_RIGHT_ARROW) then
x:= x + 2
x1:= x1 + 2
%TEYING TO GET TO GO DIAGONAL UP AND TO THE LEFT.. IUNNO HOW, AND THIS ISNT WORKING
elsif chars (KEY_UP_ARROW) and chars (KEY_LEFT_ARROW) then
x:=x-2
y:=y +2
end if
end loop




im tryin to get this simple line to get ^ and to the <-- at the same time, but when i press both the up and left button it either goes up or left??
Sponsor
Sponsor
Sponsor
sponsor
TokenHerbz




PostPosted: Fri Apr 21, 2006 5:22 pm   Post subject: (No subject)

its because in your IF statement, if you press one key it will only acknowledge the true statemnet one at a time.

What you need to do is make it inyo 2 if statments like so...

code:

var chars : array char of boolean
var x, y, x1, y1 : int
x1 := 100 %variables duh
y1 := 190
x := 100
y := 100

loop
    Input.KeyDown (chars)
    %drawing it
    Draw.Line (x, y, x1, y1, 7)
    delay (10)
    cls
    %it going up
    if chars (KEY_UP_ARROW) then
        y := y + 2
        y1 := y1 + 2
        %it gonig down
    elsif chars (KEY_DOWN_ARROW) then
        y := y - 2
        y1 := y1 - 2
        %left
    end if
    if chars (KEY_LEFT_ARROW) then
        x := x - 2
        x1 := x1 - 2
        %right
    elsif chars (KEY_RIGHT_ARROW) then
        x := x + 2
        x1 := x1 + 2
        %TEYING TO GET TO GO DIAGONAL UP AND TO THE LEFT.. IUNNO HOW, AND THIS ISNT WORKING
    elsif chars (KEY_UP_ARROW) and chars (KEY_LEFT_ARROW) then
        x := x - 2
        y := y + 2
    end if
end 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  [ 2 Posts ]
Jump to:   


Style:  
Search: