
-----------------------------------
TheOneTrueGod
Fri Apr 21, 2006 7:38 pm

Space Shooting Game
-----------------------------------
A game I made.  I got some of the ideas from a game that someone else on this forum made.


const MaxIllusion := 10
const MaxAsteroid := 50
const MaxBullets := 500
const PowerUpMax := 10


View.Set ('graphics:300,600')
View.Set ('offscreenonly')
Mouse.ButtonChoose ('multibutton')
Text.ColourBack (black)
cls

procedure DrawShip (x, y, i : int)
    Draw.ThickLine (x, y, x - 10, y - 15, 3, RGB.AddColour (1 - i / MaxIllusion, 1 - i / MaxIllusion, 1 - i / MaxIllusion))
    Draw.ThickLine (x, y, x + 10, y - 15, 3, RGB.AddColour (1 - i / MaxIllusion, 1 - i / MaxIllusion, 1 - i / MaxIllusion))

    Draw.ThickLine (x, y + 15, x - 10, y - 15, 3, RGB.AddColour (1 - i / MaxIllusion, 1 - i / MaxIllusion, 1 - i / MaxIllusion))
    Draw.ThickLine (x, y + 15, x + 10, y - 15, 3, RGB.AddColour (1 - i / MaxIllusion, 1 - i / MaxIllusion, 1 - i / MaxIllusion))
end DrawShip

procedure DrawAsteroid (x, y, size, sides, count, clr : int)
    for i : 1 .. sides
        Draw.ThickLine (round (x + cosd ((i) * 360 / sides + count) * size), round (y + sind ((i) * 360 / sides + count) * size),
            round (x + cosd ((i + 1) * 360 / sides + count) * size), round (y + sind ((i + 1) * 360 / sides + count) * size), 5, clr)
    end for
end DrawAsteroid

var r, r2 : int := 0
var BackgroundPic, BackgroundY : array 1 .. 3 of int

var x, y : array 1 .. MaxIllusion of int
var keys : array char of boolean
var mx, my, button : int

var Bulletx, Bullety : array 1 .. MaxBullets of int
var BulletCount : int := 0
var Reloading : int := 0

var AsteroidX, AsteroidY, AsteroidSize : array 1 .. MaxAsteroid of int
var Count : array 1 .. MaxAsteroid of int
var AsteroidCount : int

var Level : int

var Power, Speed, Bullets : int

var PowerUpX, PowerUpY : array 1 .. PowerUpMax of int
var PowerUpType : array 1 .. PowerUpMax of string
var PowerUpCount : int

procedure ResetVariables
    for i : 1 .. MaxIllusion
        x (i) := maxx div 2
        y (i) := 15
    end for
    cls
    for j : 1 .. 2
        for i : 1 .. 20
            r := Rand.Int (0, maxx)
            r2 := Rand.Int (0, maxy - 50)
            drawline (r, r2, r, r2 + 50, RGB.AddColour (150 / 255, 150 / 255, 150 / 255))
        end for
        BackgroundPic (j) := Pic.New (0, 0, maxx, maxy)
        cls
        BackgroundY (j) := (j - 1) * (maxy)
    end for
    BulletCount := 0
    AsteroidCount := 0
    Level := 0
    for i : 1 .. MaxAsteroid
        Count (i) := Rand.Int (0, 360)
    end for
    r := 0
    r2 := 0
    Power := 1
    Speed := 1
    Bullets := 1
    PowerUpCount := 0
end ResetVariables

procedure Game
    ResetVariables
    var dash : int := 1
    var lost : boolean := false
    loop
        Input.KeyDown (keys)
        mousewhere (mx, my, button)
        x (1) := mx
        x (1) := max (min (x (1), maxx), 0)

        if button = 100 then
            dash := 2
        else
            dash := 1
        end if

        if button = 1 and Reloading = 0 and BulletCount + Bullets < MaxBullets then
            if Bullets mod 2 = 0 then %Even, they should spread around the centre
                for i : -Bullets .. Bullets by 2
                    if i not= 0 then
                        BulletCount += 1
                        Bulletx (BulletCount) := x (1) + i * 4
                        Bullety (BulletCount) := y (1) - abs (i) * 5
                        Reloading := 20 - Speed
                    end if
                end for
            else
                for i : -Bullets div 2 .. Bullets div 2
                    BulletCount += 1
                    Bulletx (BulletCount) := x (1) + i * 8
                    Bullety (BulletCount) := y (1) - abs (i) * 5
                    Reloading := 20 - Speed
                end for
            end if
        end if

        if Rand.Int (1, max (100 - Level, 50) div dash) = 1 and AsteroidCount < MaxAsteroid then
            AsteroidCount += 1
            AsteroidX (AsteroidCount) := Rand.Int (0, maxx)
            AsteroidSize (AsteroidCount) := 10 + Level * 2
            AsteroidY (AsteroidCount) := maxy + AsteroidSize (AsteroidCount)
        end if

        if Reloading > 0 then
            Reloading -= 1
        end if

        for i : 1 .. 2

            Pic.Draw (BackgroundPic (1), 0, BackgroundY (i), picCopy)
            BackgroundY (i) -= 11 * dash
            if BackgroundY (i) 