Computer Science Canada Objects |
Author: | mike200015 [ Thu Apr 14, 2005 1:15 pm ] |
Post subject: | Objects |
I was wondering how to make objects in turing, or if there is a tutorial about it? |
Author: | jamonathin [ Thu Apr 14, 2005 3:06 pm ] |
Post subject: | |
Does this answer your question? http://www.compsci.ca/v2/viewtopic.php?t=8349&highlight=object |
Author: | Tony [ Thu Apr 14, 2005 3:19 pm ] | ||
Post subject: | |||
I think he might be looking for
|
Author: | Cervantes [ Thu Apr 14, 2005 5:20 pm ] | ||
Post subject: | |||
Or perhaps records and types?
Search the tutorials for whichever you're looking for. |
Author: | mike200015 [ Thu Apr 14, 2005 10:15 pm ] | ||
Post subject: | |||
jamonathin wrote: Does this answer your question? http://www.compsci.ca/v2/viewtopic.php?t=8349&highlight=object
That tutorial helped alot. Im adding a blockout/bustout.. watever its called game, to my pong game. so i have 156 blocks that draw on the screen each with a random colour.. and to do that i made a record for the x,y and an array of it. So wat i need to do now is make the block dissapear when the ball hits it. But i dont know how to go about doing that. Heres the blockout part that i have so far, with bricks and ball and paddle: There is also a few other problems with it: 1. When the paddle is moving and the ball hits it, the ball sometimes stays on the paddle and slides with it. 2. Sometimes the ball gets stuck inbetween the bricks and doesnt come out. 3. The ball sometimes slides along the bricks. Also if there is a better way of doing this than the way i did. If anyone can help I'd appreciate it!
|
Author: | jamonathin [ Fri Apr 15, 2005 7:59 am ] | ||||
Post subject: | |||||
What I suggest doing is making a "hit" variable (int) in your "type". Assign all 156 "hit"s to 0, making all of them not hit. When the ball does hit that block, then make "hit" 1. When you go to redraw all of the blocks, use an if statement like this
Now what I suggest for determining if the blocks are beign hit is a for loop such as this:
The reason they're in two 'if' statements is because if the ball hits a corner, it will bounce off both sides (top and side). |
Author: | mike200015 [ Fri Apr 15, 2005 1:42 pm ] |
Post subject: | |
so when the ball hits the block, and the hit is set to 1, then do i redraw the block in the bakground colour.. or do i somehow delete it from the array or something?? |
Author: | jamonathin [ Fri Apr 15, 2005 1:48 pm ] |
Post subject: | |
use a for loop in when you draw all the boxes. And check every hit, and if the hit on any of the blocks = 1 then dont draw the box. |
Author: | mike200015 [ Fri Apr 15, 2005 3:24 pm ] | ||
Post subject: | |||
how do i check which block the ball hit, im using a case for the ball to bounce off:
i made the hits record and set them all to 0, now i need to set to 1 when the ball hits the block, but how do i check which block the ball hit? |
Author: | jamonathin [ Fri Apr 15, 2005 3:40 pm ] | ||
Post subject: | |||
well, what you can do is check coordinates. Since the ball hits at the tip, you can use the x-value of the ball to determine which block is it. Now for the y-value, you need to check the radius of the ball and the location of the block. Basically if the y-value of the ball + the radius of the ball is equal to the y-value of the block then. . . But, if that doesn't work, then check if the difference between the 2 co-ordinates is less than, 4 or so then. So . . .
I've never tried this method however, and I'm not on turing so i dont know if it will work. It sounds like it will work, but if it doesn't, juss lemme know. |
Author: | mike200015 [ Fri Apr 15, 2005 4:30 pm ] | ||||
Post subject: | |||||
ok.. so.. jamonathin your code worked sort of, not totaly, i had to add sum stuff to it, but it still doesnt work right heres the code: add it in either before or after the case section in my game ^: i changed the case a little bit, so heres the new case part, switch it for the case thats in the code/my game up there ^^:
now add this part either after or before the case in the game:
Problems with the ball + block hit detection (code right above^): 1. When the ball hits the blocks on the side, they dont dissapear. 2. When the ball hits some blocks sort of straight up, it keeps going up and erases all of them, it doesnt really deflect off. |
Author: | Cervantes [ Fri Apr 15, 2005 7:28 pm ] |
Post subject: | |
You know, guys, you could use a boolean variable instead of an integer. It just goes better with these situations. Also, I recommend using coordinate collision detection here. Avoid whatdotcolour! ![]() |
Author: | mike200015 [ Fri Apr 15, 2005 7:50 pm ] |
Post subject: | |
for the whole blockout part of my game? Also, can u help wit the question in my last post ^. |
Author: | mike200015 [ Fri Apr 15, 2005 10:04 pm ] | ||
Post subject: | |||
i tried putting in the coordinate detection instead of color.. but it doesnt work well, im prolly doing it wrong, this is wat i put in:
|
Author: | Cervantes [ Sat Apr 16, 2005 6:59 am ] |
Post subject: | |
check here: http://www.compsci.ca/v2/viewtopic.php?t=75 The difference is that you want to detect collisions between a circle and a rectangle. It's easy enough: just change x2 - s to block (i).x and change x2 + s to block(i).x + blockWidth. Same kind of thing for the y's. If you can't get it, ask again. But give it a shot first. |
Author: | mike200015 [ Sat Apr 16, 2005 4:48 pm ] |
Post subject: | |
i have that in the code right above. but it doesnt detect right, with the circle, i need it to check around the whole circle, and i thought i did that in the code right above, but i dunno wat i need to change with it. |
Author: | Cervantes [ Sat Apr 16, 2005 5:49 pm ] |
Post subject: | |
mike200015 wrote: i have that in the code right above.
Not quite. You are checking if the upper left corner of the box that contains the ball is inside the block, or if the bottom right corner of the box that contains the ball is inside the block. |
Author: | mike200015 [ Sat Apr 16, 2005 6:04 pm ] |
Post subject: | |
lol.. ? wat you mean by that, instead of checking a circular area, its checking more of a square?.. and also how would i change it then to make it check the whole circle area? ![]() |
Author: | Cervantes [ Sat Apr 16, 2005 7:04 pm ] |
Post subject: | |
mike200015 wrote: lol.. ? wat you mean by that, instead of checking a circular area, its checking more of a square?
No. I mean it's checking only the top left corner and the bottom right corner of the ball. mike200015 wrote: and also how would i change it then to make it check the whole circle area? ![]() You don't want to check the whole circle area. That would involve an infinate number of calculations, because there are infinate number of infinately small points that make up your circle. But obviously you wouldn't check all of them, you'd only check every different pixel. That's still ridiculous (remember you're comparing all these points on the circle to a large number of blocks), and also still unnecessary. You only need to check four points: the top of the ball, the bottom of the ball, the left of the ball, and the right of the ball. However, were the blocks to be angled, you might need to check the point on the circumfrence at angle 37° or whatever it may be. Fortunately, the blocks are not angled: their base lies parallel to the x axis and their upright sides are parallel to the y axis. (I assume this is true.) That means a little less work and confusion for you. And that makes you a happy camper. Cervantes |