Computer Science Canada Add Boundaries |
Author: | SunsFan13 [ Tue Apr 08, 2008 9:41 am ] | ||
Post subject: | Add Boundaries | ||
Hey again. How would I go about adding boundaries to the following program? As it is right now, the 'balls' just go right off the screen until you bring them back.. I know, or think, its something to do with maxx and maxy. Help me out here? ![]() Thanks, -Chris
|
Author: | BigBear [ Tue Apr 08, 2008 10:15 am ] |
Post subject: | Re: Add Boundaries |
First I would suggest not using process except for music and only for that in older versions because multiple process randomly run one or the other so the outcome of the program can be different every time. Instead you should have one loop that gets the input for both players and moves both the balls with 2 if statements. Here is a full explanation http://compsci.ca/v3/viewtopic.php?t=7842 Now the boundaries part, when you move the circles around you know where there are. For example ball1 starts in the middle and if you go left then it is one pixel left of the center. To make sure they do not leave the screen you need to only move Left - if they are not right next to the left side of the screen Right - if they are not right next to the right edge of the screen Up - if they are not at the top of the screen Down - if they are not at the bottom of your screen So now you have to put the above into if statements when you check to see what key they entered. Note: left side of screen is 0, right side of screen is maxx (or maxx minus something), top of screen is maxxy and bottom is 0. You still need to figure out when which part is at 0 or a maxx/maxy of the screen. Hope this helps. |
Author: | SunsFan13 [ Wed Apr 09, 2008 3:39 pm ] |
Post subject: | Re: Add Boundaries |
Yeah, got it. Thanks Bear. .. Last part I gotta figure out is how to get it to display something (ie. "You Win") when one ball hits the second ball. |
Author: | BigBear [ Wed Apr 09, 2008 4:12 pm ] |
Post subject: | Re: Add Boundaries |
Well that seem like a weird win condition especially if it is a two player game. You meant when one user controlled circle get a randomly placed non-movable circle right? A race to the circle sounds interesting. Same type of thing collision detection check to see if the coordinates of the user controlled circle is inside the coordinates of the non-movable circle. I am sure you can figure it out because you solved the first problem with very little help. There a many tutorials on collision detection you should check out. |
Author: | Sean [ Wed Apr 09, 2008 4:16 pm ] |
Post subject: | Re: Add Boundaries |
If you are building the game as a race to the other dot between both players, you will want to check the x and y position of both dots, and see which one matches the destination dot. You will need to do a comparison between the x and y co-ordinates of the player to the dot in one if statement. In your if statement, you will need a put statement with the desired message. You may run into trouble where both equal it, and will have both messages appearing. |
Author: | Tallguy [ Wed Apr 16, 2008 8:39 am ] |
Post subject: | RE:Add Boundaries |
use a for statement for ur maxx maxy etc, and if the ball enters the set distances the balls bounce back, this is one of the simplest ways |
Author: | andrew. [ Sat Apr 19, 2008 8:54 am ] | ||
Post subject: | RE:Add Boundaries | ||
Do it like this:
I also got rid of your forks. You shouldn't use those unless you want background music. |