Computer Science Canada Making a cricle follow the x and y of another |
Author: | mobin12 [ Fri Dec 23, 2011 6:49 pm ] | ||
Post subject: | Making a cricle follow the x and y of another | ||
What is it you are trying to achieve? trying to make the red circle to follow the x and y coordinates of the blue circle, no matter what (including time when the blue circle does not move) What is the problem you are having? Can't get the red circle to follow the blue circle around the screen Describe what you have tried to solve this problem <Answer Here> Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) <Answer Here>
Please specify what version of Turing you are using Turing 4.1.1 |
Author: | Insectoid [ Fri Dec 23, 2011 6:58 pm ] |
Post subject: | RE:Making a cricle follow the x and y of another |
Looks to me like you haven't even tried yet. I see no code that uses x2 or y2. |
Author: | mobin12 [ Sat Dec 24, 2011 8:36 am ] |
Post subject: | Re: Making a cricle follow the x and y of another |
i am clueless on how i should approach this problem |
Author: | Insectoid [ Sat Dec 24, 2011 9:13 am ] |
Post subject: | RE:Making a cricle follow the x and y of another |
There are two common ways to approach the problem here. The easy, ugly way: When do you want the red ball to go up? When do you want it to go down? Left? Right? The answer to that question is literally the code to do it. The harder, prettier way: Use trig to calculate where the red ball should travel. I suggest you try the easy way first. |
Author: | ThatGuyYouLove [ Sat Dec 24, 2011 9:52 am ] | ||
Post subject: | Re: Making a cricle follow the x and y of another | ||
I think the easiest way to do this is to divide the screen into quarters around your enemy i.e Blueball(enemy) starts at 7, 7 or x2, y2 then you compare it to yourself and your position, i.e x, y therefore when you detect for where to move...
So if they are past the enemy on either scale, the enemy moves towards them, and if they are even than they do nothing on that axis. |
Author: | Insectoid [ Sat Dec 24, 2011 10:40 am ] |
Post subject: | RE:Making a cricle follow the x and y of another |
You got that backwards bro. That code will make the red ball run away. |
Author: | mobin12 [ Sat Dec 24, 2011 11:21 am ] |
Post subject: | Re: Making a cricle follow the x and y of another |
I WANT THE REDBALL TO MOVE TO THE POSITION OF THE BLUE, EVEN IF THE BLUE BALL IS NOT MOVING. |
Author: | Insectoid [ Sat Dec 24, 2011 12:28 pm ] |
Post subject: | RE:Making a cricle follow the x and y of another |
You didn't answer the questions I asked. Quote: When do you want the red ball to go up? When do you want it to go down? Left? Right? |
Author: | Raknarg [ Sat Dec 24, 2011 12:45 pm ] |
Post subject: | RE:Making a cricle follow the x and y of another |
Here, I'll answer one of those for you. 1: When do you want the red ball to go up? A: When the blue ball is above it. Therefore: When the blue is above the red ball, then you want the red ball to go up. Fairly simple. |
Author: | mobin12 [ Sat Dec 24, 2011 1:44 pm ] |
Post subject: | Re: RE:Making a cricle follow the x and y of another |
yes this is exactly my answer Quote: Here, I'll answer one of those for you.
1: When do you want the red ball to go up? A: When the blue ball is above it. Therefore: When the blue is above the red ball, then you want the red ball to go up. Fairly simple. and when the BLUE is on right of the RED, move the RED right when the BLUE is on left of the RED, move the RED left when the BLUE is on below of the RED, move the RED down same with diagonals. |
Author: | Insectoid [ Sat Dec 24, 2011 2:06 pm ] |
Post subject: | RE:Making a cricle follow the x and y of another |
I guess now the question is, how do you know when the red ball is above the blue ball? And diagonals don't matter. They just happen, when you go left and right at the same time. If you do it right, you won't have to write a single line of code for diagonals. |
Author: | mobin12 [ Sat Dec 24, 2011 4:00 pm ] |
Post subject: | Re: RE:Making a cricle follow the x and y of another |
Quote: I guess now the question is, how do you know when the red ball is above the blue ball?
RIGHT: When x > x2 LEFT: When x < x2 DOWN: When y < y2 UP: When y > y2 |
Author: | mobin12 [ Sat Dec 24, 2011 4:32 pm ] | ||
Post subject: | Re: Making a cricle follow the x and y of another | ||
This is my attempt
|
Author: | Insectoid [ Sat Dec 24, 2011 5:45 pm ] | ||||
Post subject: | RE:Making a cricle follow the x and y of another | ||||
That looks like it should work! Protip:
can be written as
It's the same thing. The 2nd is just nicer to read. |
Author: | mobin12 [ Sat Dec 24, 2011 8:57 pm ] |
Post subject: | RE:Making a cricle follow the x and y of another |
thanks also can you help me with collision dectection |
Author: | Raknarg [ Sun Dec 25, 2011 2:47 pm ] |
Post subject: | RE:Making a cricle follow the x and y of another |
Sure. Have you tried to solve it yet? |
Author: | ThatGuyYouLove [ Mon Dec 26, 2011 12:14 pm ] | ||||||
Post subject: | Re: RE:Making a cricle follow the x and y of another | ||||||
Insectoid @ Sat Dec 24, 2011 10:40 am wrote: You got that backwards bro. That code will make the red ball run away.
LOL thanks bro that's actually kinda funny. For collision detection there are a few ways I can think of off the top of my head.
|
Author: | Velocity [ Tue Dec 27, 2011 9:41 pm ] |
Post subject: | RE:Making a cricle follow the x and y of another |
That seems about, right, ddi you get the answer to your question yet? cause i managed to get another solution. |
Author: | Velocity [ Tue Dec 27, 2011 9:44 pm ] |
Post subject: | RE:Making a cricle follow the x and y of another |
@ insectoid that wasnt a protip (dont mean to judge your all holy and honorable proness) that was just standard procedure or another take of it, or less time consuming, or ... ugh this list can go on forever. |
Author: | Aange10 [ Tue Dec 27, 2011 10:17 pm ] |
Post subject: | Re: RE:Making a cricle follow the x and y of another |
Velocity @ 27/12/2011, 8:44 pm wrote: @ insectoid that wasnt a protip (dont mean to judge your all holy and honorable proness) that was just standard procedure or another take of it, or less time consuming, or ... ugh this list can go on forever.
Actually, it's an operator. Not a procedure. Secondly, if you were smart you'd realize he was being facetious. So, @Velocity Cool story bro, you mad? |
Author: | Insectoid [ Tue Dec 27, 2011 10:47 pm ] |
Post subject: | RE:Making a cricle follow the x and y of another |
Thanks for having my back Aange10. *brofist* Line shamelessly stolen from Tony. I think. |
Author: | chipanpriest [ Thu Dec 29, 2011 10:06 am ] | ||||
Post subject: | Re: Making a cricle follow the x and y of another | ||||
this is literally all you need inside your code somewhere for the enemy to follow your guy the collision code could be something like:
|
Author: | Dreadnought [ Thu Dec 29, 2011 5:12 pm ] | ||
Post subject: | Re: Making a cricle follow the x and y of another | ||
Most of what is posted above seems to be for rectangles (x+radius > x2-radius stuff). (perhaps with the exception of ThatGuyYouLove's second piece of code). If we want to check for collision between two circles (which I think you are) there is an easy and "perfect" way to do it. Basically, check the distance between the centers (this is good since we already know where those are). Think of it like drawing a right angled triangle with the hypotenuse being the line between the centers and the other two sides being along the x and y axes. Since we are dealing with circles, we know that the maximum distance that the two centers can be from each other without the circles overlapping is the sum of the radii. Since the distance between the centers is the hypotenuse of our triangle, we just need to check if the hypotenuse is shorter than the sum of the radii. GOGO PYTHAGOREAN THEOREM! (or just use Math.Distance... same thing) It could look something like this:
That's all you need to check collision between circles. |
Author: | chipanpriest [ Fri Dec 30, 2011 10:38 am ] |
Post subject: | Re: Making a cricle follow the x and y of another |
Dreadnought @ Thu Dec 29, 2011 5:12 pm wrote: GOGO PYTHAGOREAN THEOREM!
lol nice inspector gadget reference |
Author: | mobin12 [ Mon Jan 02, 2012 11:09 am ] | ||
Post subject: | Re: Making a cricle follow the x and y of another | ||
Alright guys if you are wondering what all this is for i will show you the other (big piece) of code for my final game:
|
Author: | mobin12 [ Mon Jan 02, 2012 11:11 am ] |
Post subject: | RE:Making a cricle follow the x and y of another |
all i need now is a health kind of thing for the player, a background, and maybe some gun sounds |
Author: | evildaddy911 [ Mon Jan 02, 2012 4:18 pm ] | ||||
Post subject: | Re: Making a cricle follow the x and y of another | ||||
health bars are very easy, i usually just write
right before the end loop also, where you display the number of shockwaves left, you output "shockwaves" in every scenario, just write
right before the draw commands Also, you can save a few lines there by using "elsif" instead of "end if if", because the if statements are dealing with a single value being a specific number |
Author: | mobin12 [ Tue Jan 03, 2012 12:09 pm ] |
Post subject: | RE:Making a cricle follow the x and y of another |
is 'health' another variable |
Author: | Dreadnought [ Tue Jan 03, 2012 2:27 pm ] |
Post subject: | Re: Making a cricle follow the x and y of another |
Yes, in his case health would be an integer variable representing both health and length (in pixels) of the health bar. |
Author: | evildaddy911 [ Tue Jan 03, 2012 3:17 pm ] | ||||||
Post subject: | Re: Making a cricle follow the x and y of another | ||||||
if your health variable is too large, the you can shrink the bar by using div,
div just means divide with out remainder ( mod ) or decimals ( / ), mostly used when you need an integer if you want it to look a bit better, then use
max_health is another variable too. backgrounds aren't too difficult, use Photoshop, fireworks, Google images, paint etc. to generate an image (make sure to save it as .jpg or .bmp), then,
which draws your picture with the bottom left corner at (0,0) |
Author: | mobin12 [ Tue Jan 03, 2012 8:12 pm ] |
Post subject: | RE:Making a cricle follow the x and y of another |
so for the enemy how do i make it disappear forever? 'cause i got it to disappear but its still there u just cant see it also does the background have to be in a zip along with the code? |
Author: | Dreadnought [ Tue Jan 03, 2012 9:13 pm ] |
Post subject: | Re: Making a cricle follow the x and y of another |
What exactly do you mean when you say "disappear forever"? Because disappearing and not seeing it are basically the same thing in my mind. For your second question, any picture or sound files used by the program must be kept in the same folder (or at least on the same filepath) relative to the program in order to run the program. Making a zipped folder containing everything is a good way to keep everything as a package. |
Author: | Raknarg [ Wed Jan 04, 2012 12:27 pm ] | ||
Post subject: | RE:Making a cricle follow the x and y of another | ||
There is no way to destroy the enemy; What you can do is make it so the program, aftger the enemy is hit, no longer intereacts witht eh enemy. When I say this, it means that you have something keeping track of it. If the enemy is alive, then move him/shoot bullets/drawing/etc. If enemy is dead, then don't do any of those things. Something like this
Thats the basic idea |
Author: | mobin12 [ Fri Jan 06, 2012 7:27 pm ] |
Post subject: | RE:Making a cricle follow the x and y of another |
alright so how would i make an intro and then the player would hit 'enter' and then the game would start |
Author: | Dreadnought [ Fri Jan 06, 2012 8:55 pm ] |
Post subject: | Re: Making a cricle follow the x and y of another |
Well, you have to make an intro screen with graphics obviously (that's not your problem I think). Next you need to check if the user pressed enter. You may be using a loop if the intro screen is animated. In that case you should be able to check for key strokes in the same way you check for WASD and space in you game (using Input.KeyDown). You can also look at the other input functions in the documentation. |
Author: | Raknarg [ Fri Jan 06, 2012 11:07 pm ] | ||
Post subject: | RE:Making a cricle follow the x and y of another | ||
Fairly simple idea:
something like that |
Author: | mobin12 [ Sun Jan 08, 2012 6:15 pm ] |
Post subject: | RE:Making a cricle follow the x and y of another |
ok so i did that know i tried putting the 'intructions loop' in between the 'intro loop' and the 'game loop' but it never showed the intructions pic that i made |
Author: | Dreadnought [ Sun Jan 08, 2012 6:51 pm ] |
Post subject: | Re: Making a cricle follow the x and y of another |
Was it erased immediately by the game? |
Author: | mobin12 [ Mon Jan 09, 2012 10:36 am ] |
Post subject: | RE:Making a cricle follow the x and y of another |
no once i clicked to go to the instrucions it would still show the 'intro pic' and then i would have to click a bit lower to start the game but only i know where to click if other people play they would get confused |
Author: | Dreadnought [ Mon Jan 09, 2012 12:06 pm ] |
Post subject: | Re: Making a cricle follow the x and y of another |
Well, without knowing what your code looks like its hard to be very helpful. I suppose my second guess would be that maybe you forgot to put a View.Update line. |
Author: | mobin12 [ Mon Jan 09, 2012 4:20 pm ] | ||
Post subject: | Re: Making a cricle follow the x and y of another | ||
well actually i tried the 'View.Update' but it didn't work out so well. But anyways here is my code.
|
Author: | mobin12 [ Mon Jan 09, 2012 4:25 pm ] | ||
Post subject: | Re: Making a cricle follow the x and y of another | ||
Here is the part i need help with. The switch from the intro to the instructions.
|
Author: | Dreadnought [ Mon Jan 09, 2012 6:21 pm ] | ||
Post subject: | Re: Making a cricle follow the x and y of another | ||
You have to understand what your code is actually doing.
This stops the onscreen window (the one you see) from receiving output, instead, all output is only sent to an offscreen window (a sort of virtual window in the computer's memory). However, when you call View.Update, the offscreen window is copied to the onscreen window. http://compsci.ca/holtsoft/doc/view_update.html wrote: This can be used to provide smooth, flicker-free animation. Animated objects flicker when the object being animated disappears from the onscreen window for a period of time. By using View.Set ("offscreenonly") / View.Update, the onscreen window is never blank. Instead, the offscreen window drawn over top off the on screen window, replacing it. This means that the on-screen window is never blanked out, eliminating the flickering found in the animation.
This means that if you want to see something, you must call View.Update. In your case, the intro picture is drawn to the onscreen window because it is the first thing ever drawn to the Turing window (this is a special case). The instruction picture is drawn to the offscreen window but not the onscreen one (thus it doesn't show up). Finally, when the game starts, the game loop draw's over the instruction picture in the offscreen window and calls View.update, meaning, the instruction picture is never drawn to the onscreen window. Hope this has cleared up the problem. |
Author: | mobin12 [ Mon Jan 09, 2012 6:39 pm ] |
Post subject: | RE:Making a cricle follow the x and y of another |
so where am i suppposed to put View.Update on the 'intro code' or the 'instructions code'? |
Author: | Dreadnought [ Mon Jan 09, 2012 7:20 pm ] | ||
Post subject: | Re: Making a cricle follow the x and y of another | ||
mobin12 wrote: it never showed the intructions pic that i made Dreadnought wrote:
This stops the onscreen window (the one you see) from receiving outputt, instead, all output is only sent to an offscreen window This means that if you want to see something, you must call View.Update. Where do you draw stuff that you want to see? If you want this stuff to be visible, should you update the screen before or after you draw said stuff? |
Author: | mobin12 [ Wed Jan 11, 2012 8:53 pm ] | ||
Post subject: | Re: Making a cricle follow the x and y of another | ||
Alright guys, thank you very much with all your help So here's my way of thanking you guys (MY CODE):
also it would be very great if anyone could help me with: make a lot more enemies appear in different spots of the ENEMY BAY. Rather then one enemy in the same spot. Thanks a lot guys. |
Author: | Dreadnought [ Wed Jan 11, 2012 9:34 pm ] |
Post subject: | Re: Making a cricle follow the x and y of another |
Nice game. If you want to have enemies spawn in different locations try using Rand.Int (min, max). You can also check if the random spawn location satisfies certain conditions, (for instance, not too close to the player). If you want multiple enemies, you should create an array of enemies (enemy data I mean). Then you cycle through each one when checking for collision. |
Author: | mobin12 [ Thu Jan 12, 2012 10:22 am ] |
Post subject: | RE:Making a cricle follow the x and y of another |
but if i do randint the enemy will appear outside the 'ENEMY BAY'. |
Author: | Dreadnought [ Thu Jan 12, 2012 3:59 pm ] |
Post subject: | Re: Making a cricle follow the x and y of another |
Like I said you might have to check if the new position is allowed. Alternately, it seems your "enemy bay" is just a frame around the playing area (I think but I don't have the background pictures), that's 4 rectangles. All you have to do is randomly select one of the four rectangle and then randomly select a position within the chosen rectangle. |
Author: | Alex C. [ Thu Jan 12, 2012 4:05 pm ] |
Post subject: | RE:Making a cricle follow the x and y of another |
um try this tutorial: http://compsci.ca/v3/viewtopic.php?t=8808 this has alot of links to basic programming |
Author: | mobin12 [ Tue Jan 17, 2012 4:17 pm ] |
Post subject: | RE:Making a cricle follow the x and y of another |
@Alex C. this does not help at all |