
-----------------------------------
Raknarg
Thu Mar 24, 2011 6:59 am

Awsome yet lagging shooting game
-----------------------------------
I'm basically trying to make a kind of simple simple shooting game (for kicks, really) and it works fine.  I'm using a flexible array for the bullets. For this, I add one to the upper limit of the array every time it shoots. There's just this one issue; I can't figure out how to stop the bullets existance, because eventually the amount of objects on the screen piles up so high, it starts to lag really bad.
I've tried to increase the lower bound of the array when the bullet is dead. However, if I do that, the game crashes after a few seconds.
Any ideas appreciated :)
If anything needs clearing up, just ask.

p.s. Thank you to Clayton, for giving me the ability to do such a thing. I never would've found out about flexible arrays without that tutorial :)



setscreen ("offscreenonly,graphics:1000;500")
var bullets, bulletsy, bullets2, bulletsy2 : flexible array 1 .. 0 of int
var deadbullet : flexible array 1 .. 0 of boolean
var enemy, enemyy : array 1 .. 5 of int
var windowy : array 1 .. 3 of int := init (201, 205, 201)
var windowx : array 1 .. 3 of int := init (11, 11, 16)
var trigger : array char of boolean
var counter : int := 50
var y : int := 200
var score := 0
var scorefont : int := Font.New ("Ariel:10")


for i : 1 .. 5
    enemy (i) := Rand.Int (maxx, maxx + 200)
    enemyy (i) := Rand.Int (0, maxy - 10)
end for

loop

    Input.KeyDown (trigger)

    if trigger ('g') and counter >= 50 then
        new bullets, upper (bullets) + 1
        new bulletsy, upper (bulletsy) + 1
        new deadbullet, upper (deadbullet) + 1
        bullets (upper (bullets)) := 0
        bulletsy (upper (bullets)) := y
        counter := 0
    end if

    if trigger (KEY_UP_ARROW) and y = 0 then
        y := y - 2
        windowy (1) := windowy (1) - 2
        windowy (2) := windowy (2) - 2
        windowy (3) := windowy (3) - 2
    end if
    
    colorback(7)

    Draw.FillBox (0, y - 5, 10, y + 5, darkgrey)
    Draw.FillBox (11, y - 5, 16, windowy (3), darkgrey)
    Draw.FillBox (17, y - 4, 20, windowy (3) - 1, green)
    Draw.FillPolygon (windowx, windowy, 3, cyan)

    for i : lower (bullets) .. upper (bullets)
        for j : 1 .. 5
            if ((bullets (i) < enemy (j) - 5 and bullets (i) > enemy (j) + 5) and
                    (bulletsy (i) >= enemyy (j) - 3 and bulletsy (i)  maxx then
                deadbullet (i) := true
                bullets (i) := 10000
            else
                deadbullet (i) := false
            end if
        end for

        if deadbullet (i) not= true then
            bullets (i) := bullets (i) + 3
            Draw.FillOval (bullets (i), bulletsy (i), 3, 3, brightgreen)
        end if

    end for

    for i : 1 .. 5

        enemy (i) := enemy (i) - 1

        Draw.FillBox (enemy (i), enemyy (i), enemy (i) + 10, enemyy (i) + 10, 12)

        for j : 1 .. upper (bullets)
            if ((bullets (j) < enemy (i) + 5 and bullets (j) > enemy (i) - 5) and
                    (bulletsy (j) >= enemyy (i) - 3 and bulletsy (j) 