
-----------------------------------
Gackt
Fri Jan 04, 2008 10:10 am

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.

-----------------------------------
LaZ3R
Fri Jan 04, 2008 11:40 am

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:

if x > ballx - 5 and x < ballx + 5 then
hit , blah blah blah
end if

You're not comparing the right stuff.

-----------------------------------
LaZ3R
Fri Jan 04, 2008 11:41 am

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
Fri Jan 04, 2008 5:34 pm

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 = BallY - 5 and y = BallX2 - 5 and x = BallY2 - 5 and y = BallX3 - 5 and x = BallY3 - 5 and y = BallX4 - 5 and x = BallY4 - 5 and y = BallX5 - 5 and x = BallY5 - 5 and y = BallX6 - 5 and x = BallY6 - 5 and y = BallX7 - 5 and x = BallY7 - 5 and y = BallX8 - 5 and x = BallY8 - 5 and y = BallX9 - 5 and x = BallY9 - 5 and y = BallX10 - 5 and x = BallY10 - 5 and y = BallX11 - 5 and x = BallY11 - 5 and y = BallX12 - 5 and x = BallY12 - 5 and y 