Computer Science Canada Problem with using (i)'s in For loops |
Author: | Ethan3210 [ Wed Jan 21, 2009 4:46 pm ] | ||||||
Post subject: | Problem with using (i)'s in For loops | ||||||
Ok, so I'm trying to make a game for my ISU in computers (and I'm trying to make a breakout rip-off. So I start working, everything's going good, but then I get to a problem. Getting all the boxes on the screen using arrays. Here's what I had before I tried using arrays:
That's just for the boxes, don't worry about the rest. So that works fine, and then my friend tells me that collision detection would be very hard do to for all 99 of those boxes. 'Cause when you hit the box with the ball, the box disappears, right? It would work fine, but I noticed that if when my ball hits a box, and I try to draw a box over it, it would be too hard to do(?). So I change my program to a for loop, using the same variables. And then there's a few problems...
And all that does is draw 99 white boxes on a white screen, which isn't what my coding says it should do, right? So yeah, I need to have this fixed by TOMMORROW or else I get a 0 on my project. So someone help please? D: Mod Edit: Syntax tags are for code not quote tags:)
|
Author: | saltpro15 [ Wed Jan 21, 2009 5:14 pm ] |
Post subject: | RE:Problem with using (i)\'s in For loops |
instead of using c(i) just make c a Rand.Int (1,99) and put c in the place of c(i), should work fine |
Author: | isaiahk9 [ Wed Jan 21, 2009 5:22 pm ] | ||||
Post subject: | RE:Problem with using (i)\'s in For loops | ||||
Wow, 0% if the program doesn't work? In my class, you can get up to an 85% even if it doesn't work. Although I'm not sure about the white color yet, but here is what I've come up with so far : In your first for loop, initializing (giving a value to) x1, x2, y1, y2 : you are giving all those variables the same value. So all the boxes are being drawn on top of each other. To fix this, you could go a something like this (although this code only works for about 20 boxes, so you would need to make the boxes smaller) (once you've fixed the colors) :
. . . inside a for loop. That should draw many boxes in a row on top of the screen. Now you need help fixing colors. Is there anything else missing in your game? PS : Welcome to compsci Mod Edit: Remember to use syntax tags! Thanks
|
Author: | Ethan3210 [ Wed Jan 21, 2009 5:53 pm ] | ||
Post subject: | Re: RE:Problem with using (i)\'s in For loops | ||
isaiahk9 @ Wed Jan 21, 2009 5:22 pm wrote: Wow, 0% if the program doesn't work? In my class, you can get up to an 85% even if it doesn't work.
Although I'm not sure about the white color yet, but here is what I've come up with so far : In your first for loop, initializing (giving a value to) x1, x2, y1, y2 : you are giving all those variables the same value. So all the boxes are being drawn on top of each other. To fix this, you could go a something like this (although this code only works for about 20 boxes, so you would need to make the boxes smaller) (once you've fixed the colors) : x1(i) := 5 * i x2(i) := (5 * i) + 5 y1(i) := 500 y2(i) := 510 . . . inside a for loop. That should draw many boxes in a row on top of the screen. Now you need help fixing colors. Is there anything else missing in your game? PS : Welcome to compsci I fixed the white box stuff. I forgot to resize the screen, it was making the boxes way above the program. xD Now I have...
It works... sorta. The boxes are too small, and it doesn't relocate to a new y coordinate once it gets greater than 570. So, I'll look into that. Thanks though. |
Author: | Ethan3210 [ Wed Jan 21, 2009 5:56 pm ] |
Post subject: | Re: RE:Problem with using (i)\'s in For loops |
saltpro15 @ Wed Jan 21, 2009 5:14 pm wrote: instead of using c(i) just make c a Rand.Int (1,99) and put c in the place of c(i), should work fine
'c' is the colour of the boxes, which is unimportant to me right now.(?) I don't understand what you're getting at. xD |
Author: | saltpro15 [ Wed Jan 21, 2009 5:58 pm ] |
Post subject: | RE:Problem with using (i)\'s in For loops |
lol my bad, I misunderstood what you were asking help with |
Author: | Ethan3210 [ Wed Jan 21, 2009 5:59 pm ] |
Post subject: | Re: RE:Problem with using (i)\'s in For loops |
saltpro15 @ Wed Jan 21, 2009 5:58 pm wrote: lol my bad, I misunderstood what you were asking help with
Ok, E for effort! xD Thanks. |
Author: | saltpro15 [ Wed Jan 21, 2009 6:06 pm ] |
Post subject: | Re: Problem with using (i)'s in For loops |
Quote: And all that does is draw 99 white boxes on a white screen, which isn't what my coding says it should do, right? that was what I read, probably should have gone through the whole thing |
Author: | isaiahk9 [ Wed Jan 21, 2009 6:08 pm ] | ||||
Post subject: | RE:Problem with using (i)\'s in For loops | ||||
If the boxes are too small, instead of going like this in your first for loop :
. . . go like this :
And I think it would be perfectly fine (and a lot easier) if you just had fewer than 99 boxes. Mod Edit: Syntax tags |
Author: | Ethan3210 [ Wed Jan 21, 2009 6:13 pm ] |
Post subject: | Re: RE:Problem with using (i)\'s in For loops |
isaiahk9 @ Wed Jan 21, 2009 6:08 pm wrote: If the boxes are too small, instead of going like this in your first for loop :
x1 (i) := 25 * i x2 (i) := (25 * i) + 5 y1 (i) := 500 y2 (i) := 510 . . . go like this : x1 (i) := 25 * i x2 (i) := (25 * i) + 25 y1 (i) := 500 y2 (i) := 510 And I think it would be perfectly fine (and a lot easier) if you just had fewer than 99 boxes. Ok, I'll make it less than 99 boxes, but it has to be at least 2 rows, which brings us to the row problem again. How about I just give you the whole game code? (well, the level 1 code)? |
Author: | Ethan3210 [ Wed Jan 21, 2009 6:35 pm ] | ||
Post subject: | Re: Problem with using (i)'s in For loops | ||
I got it!
Only thing left is to make the boxes wide enough to fit across the screen... Mod Edit: Typo in the syntax tag fixed |
Author: | Ethan3210 [ Wed Jan 21, 2009 7:04 pm ] |
Post subject: | Re: Problem with using (i)'s in For loops |
Here's my Breakout rip-off so far. I need to get collision detection working, and the tutorial needs to return to the menu when it ends. Other than that, not much needs to be fixed. |
Author: | isaiahk9 [ Wed Jan 21, 2009 8:10 pm ] | ||||||
Post subject: | Re: Problem with using (i)'s in For loops | ||||||
Huzzah! Now at least you will get some marks. When you want the program to just go back to the menu, when the tutorial button is clicked/key is pressed, just go :
It seems kinda stupid that if your teacher can't help solve your problem, you get docked marks. Oh well. As for collision detection, in your master loop, you might want to go something a-like this (master loop refers to your gameloop) :
And when you are drawing the boxes, go a-like this in your for loop :
|
Author: | Ethan3210 [ Wed Jan 21, 2009 10:53 pm ] | ||||||
Post subject: | Re: Problem with using (i)'s in For loops | ||||||
isaiahk9 @ Wed Jan 21, 2009 8:10 pm wrote: Huzzah! Now at least you will get some marks.
When you want the program to just go back to the menu, when the tutorial button is clicked/key is pressed, just go :
It seems kinda stupid that if your teacher can't help solve your problem, you get docked marks. Oh well. As for collision detection, in your master loop, you might want to go something a-like this (master loop refers to your gameloop) :
And when you are drawing the boxes, go a-like this in your for loop :
For the include part, I've tried that, I always get an error that says "Recursive include of "menu.t"... As for the collision detection, it sorta worked, but now the ball keeps hitting invisible walls... so umm yeah. >.< I hope he still passes me for this... |
Author: | isaiahk9 [ Thu Jan 22, 2009 7:08 am ] | ||||
Post subject: | RE:Problem with using (i)\'s in For loops | ||||
You could've mentioned you have recurrsion. It means that fileA.t is calling fileB.t which is calling fileA.t It means it is just repetiitively calling itself. If you wanted to get rid of that, then you could search "recurrsion" in the Turing help forum. As for hitting inbisible walls, it means that it is hitting boxes that are no longer being drawn. It just means that in this piece of code :
You should go like this :
That should work. He should still pass you if he is anything fair. Good luck on your exam today by the way, should be easy if it is anything like last year's. |
Author: | Ethan3210 [ Thu Jan 22, 2009 8:52 am ] | ||||
Post subject: | Re: RE:Problem with using (i)\'s in For loops | ||||
isaiahk9 @ Thu Jan 22, 2009 7:08 am wrote: You could've mentioned you have recurrsion. It means that fileA.t is calling fileB.t which is calling fileA.t It means it is just repetiitively calling itself. If you wanted to get rid of that, then you could search "recurrsion" in the Turing help forum.
As for hitting inbisible walls, it means that it is hitting boxes that are no longer being drawn. It just means that in this piece of code :
You should go like this :
That should work. He should still pass you if he is anything fair. Good luck on your exam today by the way, should be easy if it is anything like last year's. Yeah, that worked. Thanks. But now, the ball is still going through some of the boxes. Oh well. x) |