Computer Science Canada I cant figure out how to make it so that you don't teleport if you jump when your under a platform |
Author: | ThePyroManiac [ Tue Mar 08, 2016 1:22 pm ] | ||
Post subject: | I cant figure out how to make it so that you don't teleport if you jump when your under a platform | ||
I cant figure out how to make it so that you don't teleport if you jump when your under a platform
Please specify what version of Turing you are using 4.1.1 |
Author: | Insectoid [ Tue Mar 08, 2016 2:43 pm ] |
Post subject: | RE:I cant figure out how to make it so that you don\'t teleport if you jump when your under a platform |
First of all, you can put all of your platform coordinates into an array and loop over it to check for collisions/whatever. That should clean up your code quite a bit and make it easier to debug. If you treat the ground as one big platform, then you can eliminate all code that deals with the ground, which will simplify it even more. |
Author: | ThePyroManiac [ Tue Mar 08, 2016 7:51 pm ] |
Post subject: | Re: I cant figure out how to make it so that you don't teleport if you jump when your under a platform |
so how would i put the concordats in an array and how do i check for collisions? |
Author: | Insectoid [ Wed Mar 09, 2016 3:46 pm ] | ||
Post subject: | RE:I cant figure out how to make it so that you don\'t teleport if you jump when your under a platform | ||
I apologize; I accidentally submitted my post early, and while editing it, the power went out in my town. It didn't come back on for twelve hours! Look up arrays in the Turing Walkthrough. They are incredibly useful and you'll see why in a minute. Look at this line:
In english, this says 'If the player is above the ground and below the platform, move the player on top of the platform'. This is the line that's causing you to teleport when you jump. If you jump underneath the platform, then you are above the ground and below the platform, which satisfies that if statement. I take it you want the player to move on top of the platform if he is inside of it, not just below it. You can check if the player is inside the platform using rectangular collision detection. You can find a tutorial about this in the Turing Walkthrough. Now, you have this same section of code repeated almost exactly five times in your program, which means you need to fix it five times. If you move all your platforms to an array, you can put this code inside a for loop and it will check all of the platforms, but you only need to write the code once. This also makes it really, really easy to add more platforms. Try to get just one platform working properly before you bother with arrays though, or you'll just give yourself a headache. |
Author: | ThePyroManiac [ Wed Mar 09, 2016 4:43 pm ] |
Post subject: | RE:I cant figure out how to make it so that you don\'t teleport if you jump when your under a platform |
Thank you for you help and i'm sorry to hear about the power |
Author: | ThePyroManiac [ Wed Mar 23, 2016 7:50 pm ] | ||
Post subject: | Re: I cant figure out how to make it so that you don't teleport if you jump when your under a platform | ||
I refined the code but couldn't figure out the tutorial. i don't want to sound rude but if you have time could you show me how you would put the coordinates in an array and the collision detection when the cube only has two coordinates "posx and posy". don't worry about it if you don't have time.[/code] |
Author: | Dreadnought [ Thu Mar 24, 2016 1:43 pm ] | ||||||
Post subject: | Re: I cant figure out how to make it so that you don't teleport if you jump when your under a platform | ||||||
The tutorial on arrays is decent, what you want is to convert the code in the section called "Problem 1" to the code in the section called "Problem 2". Here's a simpler example of how its done with an intermediate step.
It works, but its ugly and will only get uglier if I decide to do it for the first 20 primes. So let's put every thing into an array
Aaaaaand it looks just as ugly. But that's okay because we can now shorten it like so
This is much nicer and can easily be scaled to many more primes. Hopefully this helps you see how arrays and loops are an effective way of removing repetitive code. In your case, you actually have variables that are related (i.e. BOX_x1, BOX_y1, BOX_x2 and BOX_y2 go together). One way of putting variables together is to use arrays of arrays, but a better way is to use records (you should read the tutorial on records). |
Author: | ThePyroManiac [ Wed Mar 30, 2016 12:34 pm ] | ||
Post subject: | Re: I cant figure out how to make it so that you don't teleport if you jump when your under a platform | ||
Could you show me how i would make an array by demonstrate an array with this code
|
Author: | Dreadnought [ Wed Mar 30, 2016 2:56 pm ] | ||
Post subject: | Re: I cant figure out how to make it so that you don't teleport if you jump when your under a platform | ||
ThePyroManiac wrote: Could you show me how i would make an array by demonstrate an array with this code
What have you tried so far? You should try it on your own and see how far you get. If you run into issues we'll be happy to help. As I mentioned, the best solution is to put all the information for a box into a record. Then if you want the same behaviour for many boxes you can put their records into an array to reduce repetitive code. |
Author: | ThePyroManiac [ Thu Mar 31, 2016 11:43 am ] |
Post subject: | RE:I cant figure out how to make it so that you don\'t teleport if you jump when your under a platform |
i do not under stand how i would wright the array it would really help if you could demonstrate an array with BOX8 i dont want you to do them all i just want you to show me how to do it. ![]() |
Author: | ThePyroManiac [ Thu Mar 31, 2016 11:53 am ] | ||
Post subject: | Re: I cant figure out how to make it so that you don't teleport if you jump when your under a platform | ||
this is what I've got so far but it doesn't work ? ![]() |
Author: | ThePyroManiac [ Thu Mar 31, 2016 12:45 pm ] | ||
Post subject: | Re: I cant figure out how to make it so that you don't teleport if you jump when your under a platform | ||
ok so i get how to make an array but now i dont get the collisions
PLEASE help |
Author: | Dreadnought [ Thu Mar 31, 2016 1:23 pm ] |
Post subject: | Re: I cant figure out how to make it so that you don't teleport if you jump when your under a platform |
It looks like you renamed some variables, but I don't see an array. As for the collision problems, Insectoid already explained what your issue is. Also, the collision problems are not related to using or not using arrays. We are simply suggesting that you use arrays to cut down on repetitive code. |
Author: | ThePyroManiac [ Thu Mar 31, 2016 1:59 pm ] | ||||
Post subject: | Re: I cant figure out how to make it so that you don't teleport if you jump when your under a platform | ||||
so how do i apply this code
to this
|
Author: | Insectoid [ Thu Mar 31, 2016 3:35 pm ] | ||||
Post subject: | RE:I cant figure out how to make it so that you don\'t teleport if you jump when your under a platform | ||||
This is the sample Dreadnaught posted:
This is your code:
They're pretty much identical, no? So look at how the first example changed to an array, and make the same changes to your code. |
Author: | Dreadnought [ Thu Mar 31, 2016 4:12 pm ] | ||||
Post subject: | Re: I cant figure out how to make it so that you don't teleport if you jump when your under a platform | ||||
Maybe there is some confusion here. I'm not saying that placing the x1, x2, y1, y2 variables for a box into an array will reduce repeated code. At the moment you are repeating code when you don't need to. For example:
Notice how you basically have the same 3 lines repeated with the only changes being which box you are checking. What will happen if you add another 5 or 10 or 20 boxes? Will you just copy the lines and slightly modify each one? Well you can do things that way and I won't stop you. What will happen if you want to modify the behaviour? Will you modify each copy? Again, you can do this and it will work. However, there is a good way to avoid all this repetitive code. What exactly is it that changes in each group of three lines? It's the box's "number". We would like to tell Turing that it should do the same thing multiple times but use different variables each time. The first time it can use BOX1_x1, BOX1_y1, BOX1_x2 and BOX1_y2. The second it can use BOX2_x1, BOX2_y1, BOX2_x2 and BOX2_y2. And so on. In this way, the example with the prime numbers was similar. The repetitive code was
Here we wanted to tell Turing to do the same things multiple times, but use prime1 the first time, prime2 the second time and so on. So what's the solution? Well, an array is a list of variables with a name for the entire list where we can access the the first, second, third, etc variables in the list with numbers. In the example I gave, the list was a list of integers called primes and I told it to number the variables 1 to 5 (hence why I used array 1..5 of int). Then I could access the first variable in primes (effectively prime1) by writing primes(1), and similarly for the other variables. From here, I used a for loop to perform the action (printing "Prime number n is _" once for each variable in the list. In your case you have many boxes that are already numbered and (as far as I can tell) except for the bouncy box, they are treated the same way by your program. So it might make sense to put the boxes into a list and then use for loops to check collisions and draw boxes for all the boxes in your list. This way, you only write the code once even though it gets used many times. Now you could make an array for each of x1, y1, x2 and y2. This would still allow to eliminate a lot of repetitive code. However, it might feel a bit unorganized to have a list of x1's, a list of x2's etc. So if you are want to organise your code even more, it would be nice to bundle these together for each box. One way would be to place these into a list of variables with an array (and yes an array of arrays is a like a list of lists of variables). You might not like this because when we replaces names like x_2 or y_2 by numbers like 3 and 4 we are losing the name and making the code harder to understand. If you have the time and want to learn even more new things, you might want to look into record which solves this proble. But understand that there is no problem with using one array for each of the coordinates of the boxes, it's just a bit disorganised. You probably noticed I ignored the bouncy box. It behaves a little differently from your other boxes, so can can't just have it use the same code as the other boxes. For now I suggest you leave i on its own (unless you want to make other bouncy boxes, in which case you might want to make more arrays. All that being said, using arrays won't change the functionality of your program. But it will help you write code more efficiently and reduce the likelihood of bugs arising from failing to change all instances of code that is repeated. |
Author: | ThePyroManiac [ Fri Apr 01, 2016 8:44 am ] |
Post subject: | Re: I cant figure out how to make it so that you don't teleport if you jump when your under a platform |
ok will do |
Author: | ThePyroManiac [ Fri Apr 01, 2016 8:49 am ] |
Post subject: | RE:I cant figure out how to make it so that you don\'t teleport if you jump when your under a platform |
By the way I just wanted to thank you guys for all you're help. ![]() ![]() ![]() |
Author: | ThePyroManiac [ Fri Apr 01, 2016 11:08 am ] |
Post subject: | Re: I cant figure out how to make it so that you don't teleport if you jump when your under a platform |
I'm going to move onto the collision detection however the Tutorial say Quote: In order to use rectangular collision detection, you must have these pieces of information about both of your rectangles : lowest x value of the rectangle lowest y value of the rectangle greatest x value of the rectangle greatest y value of the rectangle this is a problem because of two things 1st I only have "posx := 20 posy := 400" and 2nd the lowest x value of the rectangle lowest y value of the rectangle greatest x value of the rectangle greatest y value of the rectangle all CHANGE god sake i mean its probable really simple and im just an idiot but please help |
Author: | ThePyroManiac [ Fri Apr 01, 2016 11:11 am ] |
Post subject: | RE:I cant figure out how to make it so that you don\'t teleport if you jump when your under a platform |
BTW im not giving up on the array im just going to take a break |
Author: | Insectoid [ Fri Apr 01, 2016 11:49 am ] |
Post subject: | RE:I cant figure out how to make it so that you don\'t teleport if you jump when your under a platform |
That's what variables are for. Variables change. You don't personally have to know what the values are, just the computer does. Anywhere you need the lowest x values, just use box1_x1. Same for the others. Almost anywhere you need a number, you can use a variable (and 99% of the time you will use a variable). |
Author: | ThePyroManiac [ Fri Apr 01, 2016 12:06 pm ] |
Post subject: | RE:I cant figure out how to make it so that you don\'t teleport if you jump when your under a platform |
i had 15 posts and 37 Bits but then i donated 5 to Dreadnought and now i only have 3 posts and 7 bits ![]() |
Author: | ThePyroManiac [ Fri Apr 01, 2016 12:07 pm ] |
Post subject: | RE:I cant figure out how to make it so that you don\'t teleport if you jump when your under a platform |
and the position of the character only has 1 x and y |
Author: | Dreadnought [ Fri Apr 01, 2016 3:23 pm ] |
Post subject: | Re: I cant figure out how to make it so that you don't teleport if you jump when your under a platform |
ThePyroManiac wrote: and the position of the character only has 1 x and y Yes, but but given this x and y you can work out what the other values you need are. (Hint: Look at how you draw your character.) |
Author: | ThePyroManiac [ Mon Apr 04, 2016 10:49 am ] | ||
Post subject: | Re: I cant figure out how to make it so that you don't teleport if you jump when your under a platform | ||
ok i think i got it
this is just a test but it works so im happy |
Author: | ThePyroManiac [ Mon Apr 04, 2016 11:29 am ] | ||
Post subject: | Re: I cant figure out how to make it so that you don't teleport if you jump when your under a platform | ||
!!I DID IT!! THANKS FOR ALL THE HELP
Now all I need is a goal for the game. any suggestions there are no bad ideas |