Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Falling Ball Game.
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Gackt




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
LaZ3R




PostPosted: 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




PostPosted: 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




PostPosted: 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]
Kharybdis




PostPosted: Fri Jan 04, 2008 6:18 pm   Post subject: Re: Falling Ball Game.

uh..... a little sketchy, but good job...!
HeavenAgain




PostPosted: 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




PostPosted: 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




PostPosted: 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
Sponsor
sponsor
Gooie




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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..
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 16 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: