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

Username:   Password: 
 RegisterRegister   
 need help on decreasin speed
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
markEGz




PostPosted: Sun Mar 12, 2006 1:38 am   Post subject: need help on decreasin speed

Hi i got a real quick question - my class started turing about 3 weeks ago, their only on loopin n all but im jumpin kinda ahead and making progress on my own...

My project is to make a racing game -

Ive made the tracks aleady beeing looped so the car looks like its moving

Basicly the border or the "sdie where the car cant go out of" looks like ..
"*****-~-~-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****"

Ive made it look like its moving by simply removing one * from the left and a symbol from the right side etc..

Ive also used arrow keys for movement

My Question was if any of you guys had an idea how i could make when i release my forward arrow key the borders dont just suddently stop moving but slowly make it look like the car is decreasing speed
((( Maybe the key is to tell the comp when the key is NOT beeing pressed ... but got confused on how to exactly specify that cmd)))
thanks alot, and if you need more info on how ive put it together please ask Smile thx again
Sponsor
Sponsor
Sponsor
sponsor
cool dude




PostPosted: Sun Mar 12, 2006 10:22 am   Post subject: (No subject)

Quote:

Ive made it look like its moving by simply removing one * from the left and a symbol from the right side etc..


i hadn't seen your code, and it would help if u post it but from wat i can see u have the * getting removed so why don't u say in your code if the up arrow has no value then put a delay on the astricks(*) disapearing. please post your code though so i can be more of help Smile
Delos




PostPosted: Sun Mar 12, 2006 10:27 am   Post subject: (No subject)

Hello and welcome.

Glad to hear that you're stepping forward and doing some independant learning. We'll come back to that soon.

A couple of quick netiquette rules: generally, when you post up a question it's a good idea to either include the code in [ code] tags, or attach it as a file. Try to make sure that (if you post a snippet) that the code still runs and we don't have to spend a dozen minutes just redeclaring all those variables. (In your own case, you described the problem well enough for me to understand it, but I might just be a special case. It's always a good idea to include the code for those who prefer debugging through algorithm analysis instead.)
Also, make sure you know how to use the Search button up top there, since many questions have already been answered many, many times. (Yours, well in other forms but you may have been hard-pressed to find it.)
The [Turing Walkthrough] is one of the best resources on the site, linking you to all of our awsome tutorials. Check it out.

On to your question. This is entirely possible, and requires a little variable manipulation. Right now when an arrow key is pressed, you move the stars a little in that direction (or opposite was it? Makes no difference). Since I don't have the code (!), I'm going to guess that this a text-based graphical game? Again, this is not that important - what is important is the underlying concept.
The idea of 'slowing down' is a relative one meaning 'it is now moving less quickly than it was before', or if we throw in a little basic physics: 'the rate of change of position per unit time is lower now than before'. Translate that a little into coding-speak and we get: 'when the object is moving "fast", its position-variable changes by a large unit each iteration, while when it is moving "slowly", its position-variable changes by a small unit'.

Got that?

To simulate increasing speed, simply increase the number of units by which your object moves each loop. And vice versa.
When it comes to 'slowing down', you can base this on a counter-variable: each iteration of the loop it will decrease. Additionally, this value is used in determining how 'fast' the object will move.

This would all make much more sense with a little code, don't you think? That's what I thought.
code:

% This is just pseudo-code!
if left-arrow is pressed and counter is less than max-value then
  increase value of counter
if left-arrow is not pressed and counter is greater than zero then
  decrease value of counter

change coordinate values of object
draw object


Back to the independant learning: check out the tuts I mentioned. To get through a lot of these concepts you'll need a fairly good knowledge of how loops and if-structures work. From there, I would suggest you moving on to records and types, but first get this down.
Post up some code when it's done so we can see how you've progressed.
markEGz




PostPosted: Sun Mar 12, 2006 1:46 pm   Post subject: (No subject)

oh very sorry ^_^

well here is my code --> i've changed the border count for each just to simply show how it working and no confusion this time Smile

code:

                               
            if BorderCount = 0 then
              BorderHigher := "*****-~-~-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****"
            elsif BorderCount = 1 then
              BorderHigher := "****-~-~-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****-"
            elsif BorderCount = 2 then
              BorderHigher := "***-~-~-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****-~"
            elsif BorderCount = 3 then
              BorderHigher := "**-~-~-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****-~-"
            elsif BorderCount = 4 then
              BorderHigher := "*-~-~-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****-~-~"
            elsif BorderCount = 5 then         
              BorderHigher := "-~-~-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****-~-~-"
            elsif BorderCount = 6 then         
              BorderHigher := "~-~-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****-~-~-~"
            elsif BorderCount = 7 then
              BorderHigher := "-~-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****-~-~-~-"
            elsif BorderCount = 8 then
              BorderHigher := "~-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****-~-~-~-~"
            elsif BorderCount = 9 then
              BorderHigher := "-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****-~-~-~-~-"
            elsif BorderCount = 10 then
              BorderHigher := "~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****-~-~-~-~-~"
            elsif BorderCount = 11 then
              BorderHigher := "-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****-~-~-~-~-~*"
            elsif BorderCount = 12 then
              BorderHigher := "~-~*****~-~-~-~-~-*****-~-~-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****-~-~-~-~-~**"
            elsif BorderCount = 13 then
              BorderHigher := "-~*****~-~-~-~-~-*****-~-~-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****-~-~-~-~-~***"
            elsif BorderCount = 14 then
              BorderHigher := "~*****~-~-~-~-~-*****-~-~-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****-~-~-~-~-~****"
            elsif BorderCount = 15 then
              BorderHigher := "*****~-~-~-~-~-*****-~-~-~-~-~*****~-~-~-~-~-*****-~-~-~-~-~*****-~-~-~-~-~*****"
           end if
         

       if BorderCount >= 0 then
       put x
       put BorderCount
       put Plus15numberCount
       put DelaySpeed
       put BRIGHTIDEAMAN
       put ""
       put ""
       put BorderHigher
       put ""
       put ""
       put ""
       put ""
       put ""                                         % Sets the screen for Borders
       put ""
       put ""
       put ""
       put ""
       put ""
       put ""
       put ""
       put ""
       put ""
       put ""
       put BorderHigher
       end if
     


Having said that, heres the code for my forward (which is actualy the right key because the game is left - right view not up - down)

code:

if MoveAcrossBlockOneRIGHTs1 = true and chars (KEY_RIGHT_ARROW) then
                x:=x+5
                CheckSpeed := false           
             else
                x:=100
                Plus15numberCount:=0
                DelaySpeed:=DelaySpeed+10
                SpeedUpNumberCount:=0
            end if
           
                if DelaySpeed >= 200 then
                DelaySpeed := 200
                end if
( there might be shorter ways to do it but im still learning so as long as i get the concept il change to make it mroe efficient after). So as you see, the x value keeps increasing. It is the only value which doesnt change the cordinates for the car but it only moves the borders on the screen, otherwise the car will always be going out of the picture)

Now, my DelaySpeed max is 200. Whenever the right key is not beeing pressed i reset everything to what the car started off before ( exept delay time doesnt go to 200 right away, instead decrease by 10 so if u tap your right key it looks as if your lossing, picking up speed)

Knowing how my delaytime works, my borders basicaly loop through and 1 bordercount = 15 cordercount.

Now, what i wanted to do is somehow, when i release my forwardkey ( right key ) my delayspeed starts increasing ( as i already did ) and i wanted the borders depending on which delayspeed is start going on oppositve direction. Example - If i am going non stop and my delay speed is at minimum already(means car is going at fastest speed which is 8) and i let go of my right key - the bordercount stops but instead i want to make it decrease. - the exit of that loop to be made will basicly be when delaytime = 200 then stop the bordercount count down. The problems ive had were that if when the car stops border coutn is 1 then it gotta decrease 1 - 0 - 15 - 14 and so on. So i hope ive been a little more clear this time and i really appriciate if you guys help me out Smile
MysticVegeta




PostPosted: Sun Mar 12, 2006 3:53 pm   Post subject: (No subject)

wow have you ever heard of loops? Thats just crazy pseudo code in the beginning there, why dont you firsyt simplify it, then repost the code?
cool dude




PostPosted: Sun Mar 12, 2006 5:13 pm   Post subject: (No subject)

MysticVegeta wrote:
wow have you ever heard of loops? Thats just crazy pseudo code in the beginning there, why dont you firsyt simplify it, then repost the code?


not only that. if u read wat Delos wrote u would have see make sure the code runs!!! u have to declare your variables and i'm not goin to sit there and declare all of them on my own so do that and repost. as well u could really really use loops as mysticVegeta said. its a waste of time to write all that code out when it could be condensed to 5 times smaller
Delos




PostPosted: Mon Mar 13, 2006 8:55 am   Post subject: (No subject)

Hmm...three weeks of Turing and no loops?! Either your teacher is very slow or your class is...Laughing. Either way, the others are quite right. You really should have adherred to the guidlines I mentioned, and if you don't know loops yet - go learn them from the Tuts.
cool dude




PostPosted: Mon Mar 13, 2006 11:38 am   Post subject: (No subject)

this is the deal. i'll help u on two conditions

1)make better variable names and INITIALIZE them because the program crashes (READ Delos post about your program running and not crashing)

2)Declare all your variables so the program will run!!!
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Wed Mar 15, 2006 5:19 pm   Post subject: (No subject)

wow, um when ur righting code make sure to comment some of the parts for example, when ur declaring ur variables make sure to, either in the names of the variable itself or with a comment, what that variable does, for example, wut does BorderHigher do and wut is it for?? also look into loops in the Turing Walkthrough, they will help u GREATLY!!!! that code u posted could have been shortened by about a bajillion lines if u loop a couple parts in it. also make sure that if the code will run without at least major changes in it, or if it doesnt run it better be easy to read and should be able to be understood easily so that the debugger looking at it can actually visualize wut is going or supposed to happen on the screen and wut it should look like graphically (if req'd) this is all mentioned in Delos' post above so please read this and think about it and you will make everyones life easier
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  [ 9 Posts ]
Jump to:   


Style:  
Search: