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

Username:   Password: 
 RegisterRegister   
 How To Constantly Check Values?! Help=20 Bits
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Rasta Fella




PostPosted: Thu Jan 19, 2006 7:09 pm   Post subject: How To Constantly Check Values?! Help=20 Bits

AHHH...Due Tommorow and I was Procrastinating the whole time.
Ok, I made a dot so that when you press any arrow key and let go it will go in that direction forever untill another direction is pressed. Now the problem is I want to now constantly check the x,y cordinates while it moving across the page. Right now the problem is that it only checks the x,y values when you press that key...but I want it to check even if you are not pressing that key. The reason I need this is because I need whatdotcolour to "read" these values. Please help below is my source. I can't change much because we had to hand in psedocode to my teacher already.

Below is Code:
code:
proc movedot                                                                                       
    Input.KeyDown (chars)
        if chars (KEY_UP_ARROW) then
            if y <= 337 then
                loop
                    y := y + 1
                    drawfilloval (x, y, 1, 1, white)
                    delay (5)
                    drawfilloval (x, y, 1, 1, black)
                    Input.KeyDown (chars)
                    exit when chars (KEY_DOWN_ARROW) or chars (KEY_RIGHT_ARROW) or chars (KEY_LEFT_ARROW)
                    if y>= 337 then
                        boom_death_reset
                        movedot
                    elsif whatdotcolour(x,y)=red then
                        boom_death_reset
                    elsif whatdotcolour(x,y)=yellow then
                        exit
                    end if
                end loop
            end if
        end if
        if chars (KEY_RIGHT_ARROW) then
            if x <= 547 then
                loop
                    x := x + 1
                    drawfilloval (x, y, 1, 1, white)
                    delay (5)
                    drawfilloval (x, y, 1, 1, black)
                    Input.KeyDown (chars)
                    exit when chars (KEY_DOWN_ARROW) or chars (KEY_UP_ARROW) or chars (KEY_LEFT_ARROW)
                    if x >= 547 then
                        boom_death_reset
                    end if
                end loop
            end if
        end if
        if chars (KEY_LEFT_ARROW) then
            if x >= 13 then
                loop
                    x := x - 1
                    drawfilloval (x, y, 1, 1, white)
                    delay (5)
                    drawfilloval (x, y, 1, 1, black)
                    Input.KeyDown (chars)
                    exit when chars (KEY_DOWN_ARROW) or chars (KEY_UP_ARROW) or chars (KEY_RIGHT_ARROW)
                    if x <= 13 then
                        boom_death_reset
                    end if
                end loop       
            end if
        end if
        if chars (KEY_DOWN_ARROW) then
            if y >= 53 then
                loop
                    y := y - 1
                    drawfilloval (x, y, 1, 1, white)
                    delay (5)
                    drawfilloval (x, y, 1, 1, black)
                    Input.KeyDown (chars)
                    exit when chars (KEY_LEFT_ARROW) or chars (KEY_UP_ARROW) or chars (KEY_RIGHT_ARROW)
                    if y<= 53 then
                        boom_death_reset
                    end if
                end loop
            end if
        end if
        if chars (KEY_ENTER) then
            x:=20
            y:=60
                delay(100)
    end if
        drawfilloval (x, y, 1, 1, white)
    delay (5)
        drawfilloval (x, y, 1, 1, black)
    locatexy(90,14)
        colourback(red)
            colour(white) 
                put tdeaths..
    locatexy(163,14)
        colourback(red)
            colour(white) 
                put score..
end movedot


Thanks In Advance...
Sponsor
Sponsor
Sponsor
sponsor
Drakain Zeil




PostPosted: Thu Jan 19, 2006 8:38 pm   Post subject: (No subject)

Why not just have it move once, check to see if it needs to stop, a new direction has happened, and then move it again in that direction?
example:

loop

if (check if x+1 works) it does, then
x+=1
end if
if (new direction) then
do the thinggs to change direction
end if

end loop
Tony




PostPosted: Thu Jan 19, 2006 9:10 pm   Post subject: (No subject)

to clarify what Drakain Zeil is saying, you should move your whatdotcolour outside of if chars() statements.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Rasta Fella




PostPosted: Thu Jan 19, 2006 9:28 pm   Post subject: (No subject)

Thanks Tony...my levels are procedures so can i put the whatdotcolour there? And if I understood properly your suggestions would still not fix my code. My problem for example that when you push the right key the dot moves and goes towards right but the x,y cordinates that were last registered by the computer were when you pushed the right arrow not while it is moving across the screen. I need help..this is due tommorow.
Clayton




PostPosted: Tue Jan 24, 2006 2:25 am   Post subject: (No subject)

i know its a bit late but hopefully this would work
code:

View.Set("graphics:max;max")
var x,y:int:=0
var chars:array char of boolean
Input.KeyDown (chars)
if chars(KEY_RIGHT_ARROW) then
       loop
              x+=1
              if x=maxx then
                     x:=maxx
              end if
        exit when hash
        end loop
%and so on for each key
end if

this will let you press the key once and it will continuously move until its reached as far as it can go and then it stops until you press another key
sorry about it being late but now you know
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  [ 5 Posts ]
Jump to:   


Style:  
Search: