Computer Science Canada Falling Ball Game. |
Author: | Gackt [ Fri Jan 04, 2008 10:10 am ] |
Post subject: | Falling Ball Game. |
Alright. I'm Making A Game Where Random Balls Fall Down From The Screen And You Half To Avoid Them With Your Mouse. Is This Possible With The Mousewhere Command? View.Set ("graphics:500;400,position:center;center,nobuttonbar,title:View.Set tut") var BallX, BallY : int var x, y, button : int BallX := 50 BallY := 400 drawfill (1, 1, black, black) loop % Mouse Coordinates mousewhere (x, y, button) locate (1, 1) if button = 0 then colour (brightgreen) colorback (black) put x : 4, y : 4, " Button up " else put x : 4, y : 4, " Button down" end if % Drawing Of The Ball's drawfilloval (BallX, BallY, 5, 5, white) delay (10) drawfilloval (BallX, BallY, 5, 5, black) BallY := BallY - 2 % When You Hit The Ball if button = BallX then cls put " Epic Fail " end if end loop But For somereason it doesn't work. Am I doing it wrong? Tell me the right way to do it. |
Author: | LaZ3R [ Fri Jan 04, 2008 11:40 am ] | ||
Post subject: | RE:Falling Ball Game. | ||
... It's simple hit detection... Why are you comparing the value of the button which is 1 (When pressed), with the COORDINATE of the ballx position??? You're comparing two things which have nothing to do with eachother... You need to compare the x and y of the mouse with the x and y of the ball each time through the loop. You need to factor in the radius of the ball. so:
You're not comparing the right stuff. |
Author: | LaZ3R [ Fri Jan 04, 2008 11:41 am ] |
Post subject: | RE:Falling Ball Game. |
By the way, once you figured out how to fix this (even though I basically just told you), you'll need to fix the end of your loop as well. What happens right now is it'll simply stutter the screen, and you won't see your "Epic Fail" text. Make it exit the loop and display Epic Fail outside of it, or put a delay at least. |
Author: | Gackt [ Fri Jan 04, 2008 5:34 pm ] |
Post subject: | Re: Falling Ball Game. |
Update.... [syntax=""] View.Set ("graphics:500;400,position:center;center,nobuttonbar,title:View.Set tut") var BallX, BallY : int var BallX2, BallY2 : int var BallX3, BallY3 : int var BallX4, BallY4 : int var BallX5, BallY5 : int var BallX6, BallY6 : int var BallX7, BallY7 : int var BallX8, BallY8 : int var BallX9, BallY9 : int var BallX10, BallY10 : int var BallX11, BallY11 : int var BallX12, BallY12 : int var Speed : int var x, y, button : int BallX := 50 BallY := 400 BallX2 := 10 BallY2 := 400 BallX3 := 20 BallY3 := 400 BallX4 := 70 BallY4 := 400 BallX5 := 90 BallY5 := 400 BallX6 := 400 BallY6 := 400 BallX7 := 460 BallY7 := 400 BallX8 := 480 BallY8 := 400 BallX9 := 120 BallY9 := 400 BallX10 := 320 BallY10 := 400 BallX11 := 280 BallY11 := 400 BallX12 := 180 BallY12 := 400 drawfill (1, 1, black, black) loop % Mouse Coordinates mousewhere (x, y, button) locate (1, 1) if button = 0 then colour (brightgreen) colorback (black) put x : 4, y : 4, " Button up " else put x : 4, y : 4, " Button down" end if % Drawing Of The Ball's drawfilloval (BallX, BallY, 5, 5, white) drawfilloval (BallX2, BallY2, 5, 5, white) drawfilloval (BallX3, BallY3, 5, 5, white) drawfilloval (BallX4, BallY4, 5, 5, white) drawfilloval (BallX5, BallY5, 5, 5, white) drawfilloval (BallX6, BallY6, 5, 5, white) drawfilloval (BallX7, BallY7, 5, 5, white) drawfilloval (BallX8, BallY8, 5, 5, white) drawfilloval (BallX9, BallY9, 5, 5, white) drawfilloval (BallX10, BallY10, 5, 5, white) drawfilloval (BallX11, BallY11, 5, 5, white) drawfilloval (BallX12, BallY12, 5, 5, white) delay (10) drawfilloval (BallX, BallY, 5, 5, black) drawfilloval (BallX2, BallY2, 5, 5, black) drawfilloval (BallX3, BallY3, 5, 5, black) drawfilloval (BallX4, BallY4, 5, 5, black) drawfilloval (BallX5, BallY5, 5, 5, black) drawfilloval (BallX6, BallY6, 5, 5, black) drawfilloval (BallX7, BallY7, 5, 5, black) drawfilloval (BallX8, BallY8, 5, 5, black) drawfilloval (BallX9, BallY9, 5, 5, black) drawfilloval (BallX10, BallY10, 5, 5, black) drawfilloval (BallX11, BallY11, 5, 5, black) drawfilloval (BallX12, BallY12, 5, 5, black) randomize randint (Speed, 1, 6) BallY := BallY - Speed BallY2 := BallY2 - Speed BallY3 := BallY3 - Speed BallY4 := BallY4 - Speed BallY5 := BallY5 - Speed BallY6 := BallY6 - Speed BallY7 := BallY7 - Speed BallY8 := BallY8 - Speed BallY9 := BallY8 - Speed BallY10 := BallY10 - Speed BallY11 := BallY11 - Speed BallY12 := BallY12 - Speed % When You Hit The Ball if x >= BallX - 5 and x <= BallX + 5 and y >= BallY - 5 and y <= BallY + 5 then exit elsif x >= BallX2 - 5 and x <= BallX2 + 5 and y >= BallY2 - 5 and y <= BallY2 + 5 then exit elsif x >= BallX3 - 5 and x <= BallX3 + 5 and y >= BallY3 - 5 and y <= BallY3 + 5 then exit elsif x >= BallX4 - 5 and x <= BallX4 + 5 and y >= BallY4 - 5 and y <= BallY4 + 5 then exit elsif x >= BallX5 - 5 and x <= BallX5 + 5 and y >= BallY5 - 5 and y <= BallY5 + 5 then exit elsif x >= BallX6 - 5 and x <= BallX6 + 5 and y >= BallY6 - 5 and y <= BallY6 + 5 then exit elsif x >= BallX7 - 5 and x <= BallX7 + 5 and y >= BallY7 - 5 and y <= BallY7 + 5 then exit elsif x >= BallX8 - 5 and x <= BallX8 + 5 and y >= BallY8 - 5 and y <= BallY8 + 5 then exit elsif x >= BallX9 - 5 and x <= BallX9 + 5 and y >= BallY9 - 5 and y <= BallY9 + 5 then exit elsif x >= BallX10 - 5 and x <= BallX10 + 5 and y >= BallY10 - 5 and y <= BallY10 + 5 then exit elsif x >= BallX11 - 5 and x <= BallX11 + 5 and y >= BallY11 - 5 and y <= BallY11 + 5 then exit elsif x >= BallX12 - 5 and x <= BallX12 + 5 and y >= BallY12 - 5 and y <= BallY12 + 5 then exit end if end loop put " Epic Fail " [/syntax] |
Author: | Kharybdis [ Fri Jan 04, 2008 6:18 pm ] |
Post subject: | Re: Falling Ball Game. |
uh..... a little sketchy, but good job...! |
Author: | HeavenAgain [ Fri Jan 04, 2008 6:21 pm ] |
Post subject: | RE:Falling Ball Game. |
when you see so many codes repeated, it does not mean a good job..... try array + loops |
Author: | Sean [ Fri Jan 04, 2008 9:14 pm ] | ||||
Post subject: | Re: Falling Ball Game. | ||||
Loops are required! Suggestion: You used this..
Where you could of made this switch and saved drawing the background..
|
Author: | Kharybdis [ Fri Jan 04, 2008 10:25 pm ] |
Post subject: | Re: RE:Falling Ball Game. |
HeavenAgain @ Fri Jan 04, 2008 6:21 pm wrote: when you see so many codes repeated, it does not mean a good job.....
try array + loops ..... it IS a bit repetitive. i got a headache looking through all the code. |
Author: | Gooie [ Sat Jan 05, 2008 12:39 am ] |
Post subject: | Re: Falling Ball Game. |
It would be fun if it looped, if there were more balls, and if my eyes didn't fall out when I looked at the code. |
Author: | Gackt [ Sat Jan 05, 2008 11:24 am ] |
Post subject: | Re: Falling Ball Game. |
So... do i loop the drawing of the ball and have a random variable for BallX or something? and randomize it so it comes in a different place each time or what? |
Author: | Gackt [ Sun Jan 06, 2008 12:41 pm ] |
Post subject: | RE:Falling Ball Game. |
Alright, Sorry for being such an idiot. But how would I make it so that Random balls just keep falling down repeatedly? |
Author: | LaZ3R [ Sun Jan 06, 2008 4:19 pm ] |
Post subject: | Re: Falling Ball Game. |
Most simplist way you can make this program is by learning how to use arrays... This straight path of balls all falling down at same intervals and speeds is kind of easy and boring. You need to check each time through the loop if the ball is at the bottom of the screen, and if it is, simply move it too the top. |
Author: | Gackt [ Sun Jan 06, 2008 6:21 pm ] | ||
Post subject: | Re: Falling Ball Game. | ||
Alright, i tried to make one with an array, But Sigh, it doesnt work. I didnt understand the tutorial for Arrays because they only showed an array with Text as an output not shapes. So i tried this. EPIC PHAIL...
|
Author: | Clayton [ Mon Jan 07, 2008 4:00 pm ] |
Post subject: | RE:Falling Ball Game. |
Using an array of integers is exactly the same as using them for strings, why should it be different? |
Author: | Gackt [ Mon Jan 07, 2008 7:22 pm ] |
Post subject: | RE:Falling Ball Game. |
I have no clue why my array didnt work >.> Thats what im trying to get at.. |
Author: | Gackt [ Tue Jan 08, 2008 10:18 am ] |
Post subject: | RE:Falling Ball Game. |
Well, To Sum Up My Problems, All I really need help on is how to make multiple random balls falling down from the screen. Can any one help me on that? Please |