
-----------------------------------
Zampano
Fri Nov 30, 2007 10:13 am

Gravityball
-----------------------------------
Here's a small yet fun gravity game.
Hold your mouse over the black ball to hit it and send it flying. Hit the ball on one side to send it in the opposite direction.
Try to hit the coloured balls with the black one to gain points.
Use the 'n' key to stop the ball if it travels erratically.
Beware that every miss deducts points from your score, and if you reach 0 points, it's game over (you won't be able to shoot).

setscreen ("offscreenonly") %eliminatflickering
var x, y, xinc, yinc, mousex, mousey, button, score, radius, ballx, bally : int %declare all variables
var chars : array char of boolean %creates an array to store keyboard input
%initialize values
score := 10
x := 50
y := 50
xinc := 3
yinc := 15
radius := 25
ballx := 200
bally := 200

%instruction
put "Shoot the ball with the space button and the mouse to gain more points and experiment with gravity."
put "Points count as bullets. More are awarded for hitting the coloured ball witht the black one."
put "Press space to shoot with your mouse over the ball. Press 'n' to stop the ball if it gets out of control."
put "Press any key to start."
View.Update %update screen with instructions
Input.Pause
cls %clear
drawfilloval (ballx, bally, 20, 20, Rand.Int (1, 15))
loop
    locatexy (1, maxy - 10) %locate the score text at a sing point consistently
    put score % put the score
    Input.KeyDown (chars) %indicate to the computer to use the chars array for input
    drawfilloval (x, y, radius, radius, 0) %draw an erase circle
    %move the ball coordinates
    x := x + xinc
    y := y + yinc
    %collision detection with walls
    if x - radius = maxx then
        xinc := xinc * -1 + 1
        x := maxx - radius
    end if
    if y - radius = maxy then
        yinc := yinc * -1
        y := maxy - radius
    end if
    drawfilloval (x, y, 25, 25, 7) %draw a new circle
    View.Update %update with the ball
    if Math.Distance (x, y, ballx, bally)  0 then
            if whatdotcolour (mousex, mousey) = 7 then
                score := score + 5
                if mousex > x then
                    xinc := xinc - Rand.Int (1, 5)
                else
                    xinc := xinc + Rand.Int (1, 5)
                end if
                if mousey > y then
                    yinc := yinc - Rand.Int (1, 10)
                else
                    yinc := yinc + Rand.Int (1, 10)
                end if
            elsif score >= 1 then
                score := score - 1
            end if
        end if
    elsif chars ('n') then
        xinc := 0
        yinc := 0
    end if
end loop


-----------------------------------
Degensquared
Fri Nov 30, 2007 10:40 pm

RE:Gravityball
-----------------------------------
pretty good! I like how simply implemented it is :D
