Friday, 14 June 2013

Third Level

Today, I worked on my third level. The third level incorporates a shoot button which allows you to actually destroy some of the balls that you are trying to avoid. So far, I have completed the basic bullet animation when activated and I have figured out how to involve procedures within the code for this to be more effective. Next steps are to finish the collision check for the bullet and bouncing ball and make it more aesthetically pleasing to look at.
My Code :View.Set ("graphics:1000;500,buttonbar,offscreenonly")
var BoxX1, BoxX2, BoxY1, BoxY2, BallRadius, move, BallRand, Color, font1, font2, font3, font4 : int
var BallPlayerX, BallPlayerY, BallPlayerRadius : int
BallPlayerX := maxx div 2
BallPlayerY := maxy div 10
BallPlayerRadius := 4
var chars : array char of boolean
BoxX1 := maxx div 2
BoxX2 := maxx div 2.1
BoxY1 := maxy div 10
BoxY2 := maxy div 8
BallRadius := 12
Color := brightred
BallRadius := 12
var BallX : array 1 .. 100 of int % Array of 10 Balls for x position
var BallY : array 1 .. 100 of int % Array of 10 Balls, for y position
var Ball2X : array 1 .. 100 of int
var Ball2Y : array 1 .. 100 of int
var NumBall : int := 1
var NumBall2 : int := 1
randint (BallX (NumBall), 0, maxx) %X Position
randint (BallY (NumBall), 0, maxy) %Y Position
randint (Ball2X (NumBall2), 0, maxx) %X Position for second level
randint (Ball2Y (NumBall2), 0, maxy) %Y Position for second level
var BallXV : array 1 .. 100 of int
NumBall2 := 1
var Ballx : array 1 .. 1000 of int
var Bally : array 1 .. 1000 of int
randint (Ballx (NumBall2), 0, maxx)
randint (Bally (NumBall2), 0, maxy)
var Balldirx : array 1 .. 1000 of int
var Balldiry : array 1 .. 1000 of int
Balldirx (1) := -1
Balldiry (1) := 1
var Bulletx, Bullety : int
Bulletx := maxx div 2.05
Bullety := maxy div 9
proc Shoot

end Shoot
loop
    View.Update
    cls
    for d : 1 .. NumBall2
        drawfilloval (Ballx (d), Bally (d), BallRadius, BallRadius, red)
        Ballx (d) := Ballx (d) + Balldirx (d)
        if Ballx (d) - 9 = 9 then
            Balldirx (d) := Balldirx (d) * -1
        elsif Ballx (d) + BallRadius >= maxx - BallRadius
                then
            Balldirx (d) := -1 * Balldirx (d)
            NumBall2 := NumBall2 + 1
            randint (Ballx (NumBall2), 0, maxx)
            randint (Bally (NumBall2), 0, maxy)
            Balldirx (NumBall2) := -1
            Balldiry (NumBall2) := 1
        end if
        Bally (d) := Bally (d) + Balldiry (d)
        if Bally (d) >= maxy - BallRadius
                then
            Balldiry (d) := -1 * Balldiry (d)
        elsif Bally (d) <= BallRadius
                then
            Balldiry (d) := 1
        end if
        if Color = brightred and BoxX2 <= Ballx (d) + BallRadius and BoxX1 >= Ballx (d) - BallRadius and BoxY1 <= Bally (d) + BallRadius and BoxY2 >= Bally (d) - BallRadius
                then
            delay (200)
        end if
    end for
    if Time.Elapsed > 20000
            then
        cls
        exit
    end if
    drawfillbox (BoxX1, BoxY1, BoxX2, BoxY2, Color)
    drawfilloval (Bulletx, Bullety, 4, 4, blue)
    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) and BallPlayerY + BallPlayerRadius <= maxy and BoxY2 <= maxy
            then
        BoxY1 := BoxY1 + 1
        BoxY2 := BoxY2 + 1
        BallPlayerY := BallPlayerY + 1
        Bullety := Bullety + 1
    elsif chars (KEY_DOWN_ARROW) and BallPlayerY - BallPlayerRadius >= 0 and BoxY1 >= 0
            then
        BallPlayerY := BallPlayerY - 1
        BoxY1 := BoxY1 - 1
        BoxY2 := BoxY2 - 1
        Bullety := Bullety - 1
    elsif chars (KEY_RIGHT_ARROW) and BallPlayerX + BallPlayerRadius <= maxx and BoxX1 <= maxx
            then
        BoxX1 := BoxX1 + 1
        BoxX2 := BoxX2 + 1
        BallPlayerX := BallPlayerX + 1
        Bulletx := Bulletx + 1
    elsif chars (KEY_LEFT_ARROW) and BallPlayerX - BallPlayerRadius >= 0 and BoxX2 >= 0
            then
        BallPlayerX := BallPlayerX - 1
        BoxX2 := BoxX2 - 1
        BoxX1 := BoxX1 - 1
        Bulletx := Bulletx - 1
    end if
    if chars (KEY_LEFT_ARROW) and chars (KEY_UP_ARROW) and BallPlayerX - BallPlayerRadius >= 0 and BallPlayerY + BallPlayerRadius <= maxy and BoxX2 >= 0 and BoxY2 <= maxy
            then
        delay (2)
        BallPlayerX := BallPlayerX - 1
        BallPlayerY := BallPlayerY + 1
        BoxX2 := BoxX2 - 1
        BoxX1 := BoxX1 - 1
        BoxY1 := BoxY1 + 1
        BoxY2 := BoxY2 + 1
        Bulletx := Bulletx - 1
        Bullety := Bullety + 1
    end if
    if chars (KEY_RIGHT_ARROW) and chars (KEY_UP_ARROW) and BallPlayerY + BallPlayerRadius <= maxy and BallPlayerX + BallPlayerRadius <= maxx and BoxY2 <= maxy and BoxX1 <= maxx
            then
        delay (2)
        BallPlayerX := BallPlayerX + 1
        BallPlayerY := BallPlayerY + 1
        BoxX2 := BoxX2 + 1
        BoxX1 := BoxX1 + 1
        BoxY1 := BoxY1 + 1
        BoxY2 := BoxY2 + 1
        Bulletx := Bulletx + 1
        Bullety := Bullety + 1
    end if
    if chars (KEY_RIGHT_ARROW) and chars (KEY_DOWN_ARROW) and BallPlayerX + BallPlayerRadius <= maxx and BallPlayerY - BallPlayerRadius >= 0 and BoxX1 <= maxx and BoxY1 >= 0
            then
        delay (2)
        BallPlayerX := BallPlayerX + 1
        BallPlayerY := BallPlayerY - 1
        BoxX2 := BoxX2 + 1
        BoxX1 := BoxX1 + 1
        BoxY1 := BoxY1 - 1
        BoxY2 := BoxY2 - 1
        Bulletx := Bulletx + 1
        Bullety := Bullety - 1
    end if
    if chars (KEY_LEFT_ARROW) and chars (KEY_DOWN_ARROW) and BallPlayerY - BallPlayerRadius >= 0 and BallPlayerX - BallPlayerRadius >= 0 and BoxY1 >= 0 and BoxX2 >= 0
            then
        delay (2)
        BallPlayerX := BallPlayerX - 1
        BallPlayerY := BallPlayerY - 1
        BoxX2 := BoxX2 - 1
        BoxX1 := BoxX1 - 1
        BoxY1 := BoxY1 - 1
        BoxY2 := BoxY2 - 1
        Bulletx := Bulletx - 1
        Bullety := Bullety - 1
    end if
    if
            chars ('g')
            then
        Color := black
    end if
    if chars ('r')
            then
        Color := brightred
    end if
    if chars ('s')
            then
        loop
        cls  
        drawfilloval (Bulletx, Bullety, 4, 4, blue)
            Bullety := Bullety + 1
         

            drawfillbox (BoxX1, BoxY1, BoxX2, BoxY2, Color)
            for d : 1 .. NumBall2
                drawfilloval (Ballx (d), Bally (d), BallRadius, BallRadius, red)
                Ballx (d) := Ballx (d) + Balldirx (d)
                if Ballx (d) - 9 = 9 then
                    Balldirx (d) := Balldirx (d) * -1
                elsif Ballx (d) + BallRadius >= maxx - BallRadius
                        then
                    Balldirx (d) := -1 * Balldirx (d)
                    NumBall2 := NumBall2 + 1
                    randint (Ballx (NumBall2), 0, maxx)
                    randint (Bally (NumBall2), 0, maxy)
                    Balldirx (NumBall2) := -1
                    Balldiry (NumBall2) := 1
                end if
                Bally (d) := Bally (d) + Balldiry (d)
                if Bally (d) >= maxy - BallRadius
                        then
                    Balldiry (d) := -1 * Balldiry (d)
                elsif Bally (d) <= BallRadius
                        then
                    Balldiry (d) := 1
                end if
                if Color = brightred and BoxX2 <= Ballx (d) + BallRadius and BoxX1 >= Ballx (d) - BallRadius and BoxY1 <= Bally (d) + BallRadius and BoxY2 >= Bally (d) - BallRadius
                        then
                    delay (200)
                end if
            end for

            View.Update
        end loop
    end if

end loop
put "Game has exited"

No comments:

Post a Comment