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

Username:   Password: 
 RegisterRegister   
 Space Shooting Game
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TheOneTrueGod




PostPosted: Fri Apr 21, 2006 7:38 pm   Post subject: Space Shooting Game

A game I made. I got some of the ideas from a game that someone else on this forum made.

code:

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) <= -maxy then
                BackgroundY (i) := maxy
            end if
        end for

        for q : 1 .. max (max (BulletCount, 1), PowerUpCount)
            if q <= BulletCount then
                for decreasing i : MaxIllusion .. 0
                    drawfilloval (Bulletx (q), Bullety (q) - i * 3, 3, 3, RGB.AddColour (1 - i / MaxIllusion, 1 - i / MaxIllusion, 1 - i / MaxIllusion))
                end for
                Bullety (q) += 10 div dash
                if Bullety (q) >= maxy then
                    Bulletx (q) := Bulletx (BulletCount)
                    Bullety (q) := Bullety (BulletCount)
                    Bullety (q) += 10
                    BulletCount -= 1
                end if
            end if
            for j : 1 .. AsteroidCount
                if q <= BulletCount then
                    if sqrt ((AsteroidX (j) - Bulletx (q)) ** 2 + (AsteroidY (j) - Bullety (q)) ** 2) < AsteroidSize (j) + 5 then
                        AsteroidSize (j) -= 2 * Power
                        Bullety (q) := maxy + 50
                    end if
                end if
                if sqrt ((AsteroidX (j) - x (1)) ** 2 + ((AsteroidY (j) - y (1)) ** 2)) <= AsteroidSize (j) + 10 then
                    lost := true
                end if
                if q = 1 then
                    AsteroidY (j) -= 3 * dash
                    Count (j) += 1
                    Count (j) mod= 360

                    for decreasing i : MaxIllusion .. 0
                        DrawAsteroid (AsteroidX (j), AsteroidY (j) + i * 5, AsteroidSize (j), 7, Count (j), RGB.AddColour (1 - i / MaxIllusion, 1 - i / MaxIllusion, 1 - i / MaxIllusion))
                    end for

                    if AsteroidY (j) <= 0 or AsteroidSize (j) <= 0 then
                        if AsteroidSize (j) <= 0 then
                            Level += 1
                            if PowerUpCount < PowerUpMax then
                                r := Rand.Int (1, 3)
                                PowerUpCount += 1
                                PowerUpX (PowerUpCount) := AsteroidX (j)
                                PowerUpY (PowerUpCount) := AsteroidY (j)
                                if r = 1 then
                                    PowerUpType (PowerUpCount) := "Power"
                                elsif r = 2 then
                                    PowerUpType (PowerUpCount) := "Speed"
                                else
                                    PowerUpType (PowerUpCount) := "Bullets"
                                end if
                            end if
                        end if
                        AsteroidX (j) := AsteroidX (AsteroidCount)
                        AsteroidY (j) := AsteroidY (AsteroidCount)
                        AsteroidSize (j) := AsteroidSize (AsteroidCount)
                        Count (j) := Count (AsteroidCount)
                        AsteroidCount -= 1
                    end if
                end if
            end for
            if q <= PowerUpCount then
                PowerUpY (q) -= 1 * dash
                if PowerUpType (q) = "Power" then
                    Draw.ThickLine (PowerUpX (q) + 10, PowerUpY (q) + 10, PowerUpX (q) - 10, PowerUpY (q) - 10, 3, white)
                    Draw.ThickLine (PowerUpX (q) + 10, PowerUpY (q) - 10, PowerUpX (q) - 10, PowerUpY (q) + 10, 3, white)
                elsif PowerUpType (q) = "Speed" then
                    Draw.ThickLine (PowerUpX (q) + 10, PowerUpY (q), PowerUpX (q) - 10, PowerUpY (q), 3, white)
                    Draw.ThickLine (PowerUpX (q), PowerUpY (q) + 10, PowerUpX (q), PowerUpY (q) - 10, 3, white)
                elsif PowerUpType (q) = "Bullets" then
                    drawfilloval (PowerUpX (q) - 5, PowerUpY (q), 5, 5, white)
                    drawfilloval (PowerUpX (q) + 5, PowerUpY (q), 5, 5, white)
                end if
                if sqrt ((PowerUpX (q) - x (1)) ** 2 + (PowerUpY (q) - y (1)) ** 2) <= 10 + 10 or PowerUpY (q) < 0 then
                    if PowerUpY (q) < 0 then
                    else
                        if PowerUpType (q) = "Power" then
                            Power += 1
                            Bullets -= 1
                        elsif PowerUpType (q) = "Speed" then
                            Speed += 1
                            Power -= 1
                        elsif PowerUpType (q) = "Bullets" then
                            Bullets += 1
                            Speed -= 1
                        end if

                        Bullets := max (min (Bullets, 15), 1)
                        Speed := max (min (Speed, 15), 1)
                        Power := max (min (Power, 15), 1)
                    end if

                    PowerUpX (q) := PowerUpX (PowerUpCount)
                    PowerUpY (q) := PowerUpY (PowerUpCount)
                    PowerUpType (q) := PowerUpType (PowerUpCount)
                    PowerUpCount -= 1
                end if
            end if
        end for

        for decreasing i : MaxIllusion .. 2
            x (i) := x (i - 1)
            y (i) := y (i - 1)
            DrawShip (x (i), y (i), i)
        end for
        locate (1, 1)
        put "Score: ", Level
        DrawShip (x (1), y (1), 0)
        drawfillbox (x (1) - 18, y (1) - 10, x (1) - 16, y (1) - 10 + round (Power / 10 * 20), brightred)
        drawbox (x (1) - 18, y (1) - 10, x (1) - 16, y (1) + 10, white)

        drawfillbox (x (1) + 18, y (1) - 10, x (1) + 16, y (1) - 10 + round (Speed / 15 * 20), yellow)
        drawbox (x (1) + 18, y (1) - 10, x (1) + 16, y (1) + 10, white)
        View.Update
        Time.DelaySinceLast (30)
        cls
        exit when lost
    end loop
end Game

var choice, choice2 : string (1)
var HiScore : int := 0
Text.Colour (white)
loop
    cls
    put "Enter your choice."
    put "1. Start Game"
    put "2. Help"
    put "HiScore this play: ", HiScore
    View.Update
    loop
        loop
            getch (choice)
            exit when choice = '1' or choice = '2'
        end loop
        if choice = '2' then
            put "DEFEND YOURSELF FROM THE FLOATING OCTAGONS"
            put "Move the mouse to move your ship."
            put "Left click to fire."
            put "Right click to dash."
            put ""
            put "X  = Increase in damage, decrease in # of bullets"
            put "+  = Increase in Speed, decrease in damage"
            put "oo = Increase in # of bullets, decrease in speed"
            put ""
            put "Bar on the left of your ship indicates damage level"
            put "Bar on the right of your ship indicates reload speed"
            put ""
            put "Press any key to continue"
            getch (choice2)
        end if

        exit when choice = '1'
    end loop
    Game

    if HiScore < Level then
        HiScore := Level
    end if

    choice := '2'
end loop
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: