Quick March
Forum » Games / Showcase » Quick March
started by: FuzzyFuzzy
on: 1252836919|%e %b %Y, %H:%M %Z|agohover
number of posts: 3
rss icon RSS: new posts
summary:
My first game!
Quick March
FuzzyFuzzy 1252836919|%e %b %Y, %H:%M %Z|agohover

After making my first game a month a go i have just had the time to put it up (sorry about the delay!). You are the filled circle and you must avoid all the other circles using the arrow keys (it will start after three seconds). The code is quite messy at the moment, when I get the time I will tidy it up and maybe put in a start screen.

EDIT: forgot to post the code (DOH!)

setFPS 60

Global sw = getScreenWidth()
Global sh = getScreenHeight()

Global startTime      :;start time
Global time           :;elapsed time
Global scoreb         :;score from destroying ast
Global intervalH      :;max interval
Global intervalL      :;min interval
Global nextAsteroid   :;time of next asteroid
Global asteroidSpeed  :;speed of asteroids

Constant RADIUS = 15
Constant SPEED = 3
Constant POINTS_KILL = 60

Type Obj
   x
   y
EndType

Type Enemy as Obj
    dir
    alv
EndType

Dim player as Obj
Dim Asteroid(20) as Enemy

init()

Do
    updatePlayer()
   createAsteroid()
   updateAsteroid()
   collision()
    Cls 0
        score()
        drawObj()
    Sync
Loop

;work out the score and time elapsed
PSub score()
    time = (timer() - startTime) / 1000
   Print scoreb + time
   Print time
EndPsub

;init game
PSub init()
    player.x = sw / 2                              :;center player
    player.y = sh / 2

   intervalL = 2                                  :;set correct intervals for ast
   intervalH = 3

   nextAsteroid = 3                               :;set time of first asteroid to 3secs
   asteroidSpeed = 2                              :;reset ast speed
   scoreb = 0                                     :;reset score
   startTime = timer()                            :;reset start time
EndPsub

;draw objs
PSub drawObj()
    Circle player.x, player.y, RADIUS, 1            :;draw player
   For i = 0 to GetArrayElements( Asteroid(), 1 )
       If Asteroid(i).alv = true then Circle Asteroid(i).x, Asteroid(i).y, RADIUS, 0
   Next i
EndPSub

;update pos of player
PSub updatePlayer()
    If leftKey() then player.x = player.x - speed
    If rightKey() then player.x = player.x + speed
    If upKey() then player.y = player.y - speed
    If downKey() then player.y = player.y + speed
    If player.x <= 0 or player.x >= sw or player.y <= 0 or player.y >= sh then gameOver() :;check pos of player
EndPSub

;display screen when dead
Function gameOver()
    Cls 0
        centerText sw / 2, sh / 2 - 10, "You have Died"
        centerText sw / 2, sh / 2 + 10, "Press any key to continue"
        centerText sw /2, sh /2 + 30, "Your score was: " + str$(time + scoreb)
    Sync

    waitNokey
    flushKeys
    waitKey
    flushKeys

    Cls 0
        centerText sw / 2, sh / 2, "Do you want to Play Again (Y/N)"
    Sync

    Do
        If keyState(21)
         For i = 0 to getArrayElements( Asteroid(), 1 )
             If Asteroid(i).alv then Asteroid(i).alv = false
         Next i
            init()
         ExitFunction
      EndIf
        If keyState(49) then End
    Loop
EndFunction

;create asteoriods
PSub createAsteroid()
    If time >= nextAsteroid
       cell = getFreeCell( Asteroid() )

       Asteroid(cell).alv = true
       Select rndRange(1,4)                :;randomly decide dir for ast
           Case 1                 :;if right
               Asteroid(cell).y = player.y :;align ast with player
               Asteroid(cell).x = 0        :;place at side of screen
               Asteroid(cell).dir = 1 :;set var to correct dir

            Case 2                 :;if up
               Asteroid(cell).x = player.x
               Asteroid(cell).y = 0
               Asteroid(cell).dir = 2

            Case 3                 :;if left
               Asteroid(cell).y = player.y
               Asteroid(cell).x = sw
               Asteroid(cell).dir = 3

            Case 4                 :;if right
               Asteroid(cell).x = player.x
               Asteroid(cell).y = sh
               Asteroid(cell).dir = 4
       EndSelect

       nextAsteroid = rndRange(intervalL, intervalH) + time :;decide time for next ast
       Select rnd(1)                                        :;increse diffuculty
            Case 1
                intervalL = intervalL - 3
                If intervalL <= 0 then intervalL = 0

            Case 2
                intervalH = intervalH - 3
                If intervalH < intervalL then inc intervalH
       EndSelect
     EndIf
EndPSub

;update asts
PSub updateAsteroid()
    For i = 0 to getArrayElements( Asteroid(), 1 )
        If Asteroid(i).alv = true
            Select Asteroid(i).dir
                Case 2
                    Asteroid(i).y = Asteroid(i).y + asteroidSpeed:;move ast

                    If Asteroid(i).y >= sh              :;check if still on screen
                          Asteroid(i).alv = false          :;if not destroy ast
                       scoreb = scoreb + POINTS_KILL    :;increase points
                       inc asteroidSpeed                :;and speed of asteroids
                    EndIf

                Case 4
                    Asteroid(i).y = Asteroid(i).y - asteroidSpeed

                    If Asteroid(i).y <= 0
                       Asteroid(i).alv = false
                       scoreb = scoreb + POINTS_KILL
                       inc asteroidSpeed
                    EndIf

                Case 3
                    Asteroid(i).x = Asteroid(i).x - asteroidSpeed

                    If Asteroid(i).x <= 0
                       Asteroid(i).alv = false
                       scoreb = scoreb + POINTS_KILL
                       inc asteroidSpeed
                    EndIf

                Case 1
                    Asteroid(i).x = Asteroid(i).x + asteroidSpeed

                    If Asteroid(i).x >= sw
                       Asteroid(i).alv = false
                       scoreb = scoreb + POINTS_KILL
                       inc asteroidSpeed
                    EndIf

              EndSelect
          EndIf
     Next i
EndPsub

;see if a collision has occured
PSub collision()
    For i = 0 to getArrayElements( Asteroid(), 1 )
        If Asteroid(i).alv
           If CirclesIntersect(Asteroid(i).x, Asteroid(i).y, RADIUS, player.x, player.y, RADIUS) then gameOver()
        EndIf
    Next i
EndPSub
last edited on 1252836977|%e %b %Y, %H:%M %Z|agohover by Fuzzy + show more
unfold Quick March by FuzzyFuzzy, 1252836919|%e %b %Y, %H:%M %Z|agohover
Re: Quick March
u9u9 1252859256|%e %b %Y, %H:%M %Z|agohover

I like it. Not bad for a first. I was thinking instead of the balls going so much faster so quickly, you could instead have many of them and the player would have to navigate between all the balls. You could have the number of balls on screen increase slowly. Or they could bounce back and forth after they appear. They would probably have to be smaller though.

unfold Re: Quick March by u9u9, 1252859256|%e %b %Y, %H:%M %Z|agohover
Re: Quick March
FuzzyFuzzy 1252945823|%e %b %Y, %H:%M %Z|agohover

The original plan was for there to be more balls on screen. I might make a version which does that. I also like the idea of balls bouncing around.

unfold Re: Quick March by FuzzyFuzzy, 1252945823|%e %b %Y, %H:%M %Z|agohover
new post