Posted: 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
% 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.
Sponsor Sponsor
LaZ3R
Posted: 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:
code:
if x > ballx - 5 and x < ballx + 5 then
hit , blah blah blah
end if
You're not comparing the right stuff.
LaZ3R
Posted: 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.
Gackt
Posted: 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
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
% 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]
Kharybdis
Posted: Fri Jan 04, 2008 6:18 pm Post subject: Re: Falling Ball Game.
uh..... a little sketchy, but good job...!
HeavenAgain
Posted: 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
Sean
Posted: Fri Jan 04, 2008 9:14 pm Post subject: Re: Falling Ball Game.
Loops are required!
Suggestion: You used this..
code:
drawfill (1,1,black,black)
Where you could of made this switch and saved drawing the background..
code:
colourback (black)
colour (Text Colour ID if Changing)
cls
Kharybdis
Posted: 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.
Sponsor Sponsor
Gooie
Posted: 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.
Gackt
Posted: 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?
Gackt
Posted: 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?
LaZ3R
Posted: 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.
Gackt
Posted: 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...
code:
var BallX : array 1 .. 50 of int
for i : 1 .. upper(BallX)
drawfilloval(BallX,400,5,5,white)
delay(10)
drawfilloval(BallX,400,5,5,black)
end for
Clayton
Posted: 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?
Gackt
Posted: 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..