Computer Science Canada Changing object's movement speed |
Author: | Aange10 [ Sun Sep 04, 2011 12:52 pm ] | ||
Post subject: | Changing object's movement speed | ||
What is it you are trying to achieve? I'm trying to set a speed for my oval. (I'm making frogger! ![]() What is the problem you are having? I can't put a real number in the integer syntax (?) Describe what you have tried to solve this problem I've gone around and tried to read about movement, and I've tried altering my coding. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Please specify what version of Turing you are using 4.1 ------ALSO------- As I develop the game I know i'll have a few more questions that either A: Weren't on the tutorials or B: I couldn't find them there.. So how would I: 1) Make the computer generate the cars (Rectangles!)? 2) Make the cars disappear once they cross to border? (Necessary?) 3) Make the generated rectangles colide with my frog. (I think this would have to do with an array generating the x1,y1,x2,y2 for the rectangles, and then using the Rectangle on Rectangle collision code except instead of the cars having varriables, i use the generated arrays.. Or something along those lines... ![]() 4) [Optional] Drawling a road/ adding collision sounds? -------------------- Thanks so much for you guys' help! In three days I've almost programmed my two favorite games!! |
Author: | Insectoid [ Sun Sep 04, 2011 1:09 pm ] | ||
Post subject: | RE:Changing object\'s movement speed | ||
This help? |
Author: | Aange10 [ Sun Sep 04, 2011 3:43 pm ] |
Post subject: | RE:Changing object\'s movement speed |
The syntax for that is Draw.Dot (x,y,color) ... It would only be a pixel in radius... That's too small for my frogger D: |
Author: | Insectoid [ Sun Sep 04, 2011 3:55 pm ] |
Post subject: | RE:Changing object\'s movement speed |
That's just an example. You need to adapt it to your own program. The round() part is what's important. |
Author: | Aange10 [ Sun Sep 04, 2011 4:49 pm ] | ||
Post subject: | RE:Changing object\'s movement speed | ||
Ahh, you sir, are awesome. Thankyou! Incase your curious, or would like to criticze, here is the "Testing Code" I used to know that your suggestion is awesome.
See the decimals at the top left!! xD!! |
Author: | Raknarg [ Mon Sep 05, 2011 10:37 am ] |
Post subject: | RE:Changing object\'s movement speed |
For your car generation and collision, you definitlely need to look into arrays first. Otherwise you're going to end up with way more code than you need. |
Author: | Aange10 [ Mon Sep 05, 2011 11:04 am ] | ||
Post subject: | RE:Changing object\'s movement speed | ||
I keep reading the tutorial over and over, but from what I understand an array is just a varriable of varriables...
Is all it is used for is having a bunch of varriables (my_array(1..10)) in one line? ^ I'm sure thats not, but I'm having trouble putting it into practice. |
Author: | DemonWasp [ Mon Sep 05, 2011 11:13 am ] | ||||
Post subject: | RE:Changing object\'s movement speed | ||||
The more important change is that you can refer to those elements by their index, or number. That lets you use for loops with more than one variable:
versus
That's with 5 elements, because I hate typing. Imagine the difference with 100 elements, or 1000 -- the first example doesn't get any longer, but the second sure does. Imagine if you didn't know the number of things beforehand -- the first example still works, but it's nearly impossible to write the second correctly. In your case, you probably want an array of all the cars, or else an array of all the car X coordinates, all the car Y coordinates, etc. Then you can determine whether car-i and car-j collide by looking at car_x (i), car_x (j), car_y (i), car_y (j) (or whatever name you choose). You can write your collision code once, not for every pair of cars in the game. |