SURVIVE - First Blitz Basic Game

-- SURVIVE! --

Here is a simple 2D video game -
the bugs swarm around and the
player (space ship) must run away
from the bugs.  The game ends
when the player gets poisoned
by a bug.

[Image]


Click here to download .zip archive

;---------------------- Starting Up ------------------------------

Graphics 600,450               ; size of screen
SeedRnd MilliSecs()            ; use REALLY random numbers

SetBuffer BackBuffer()	      ; use double buffering to stop flicker

Global player = LoadImage("player.bmp")  ; loads player picture
Global alien = LoadImage("alien.bmp")    ; loads bug picture

MakePic(alien,100,500,1,2,0)    ; Makes a bug at (100,500) 
                                ;  moving at speed (across=1 , down=2)
MakePic(alien,500,100,-1,0,0)   
MakePic(alien,500,500,1,-1,0)   ; More Bugs
MakePic(alien,100,100,0,2,0)
MakePic(alien,500,300,-1,-1,0)
MakePic(alien,300,100,-2,1,0)
MakePic(alien,100,300,0,-1,0)
MakePic(alien,300,500,1,1,0)

Global p.pic = MakePic(player,300,200,0,0,9) ; create the player p

Print "Use arrow keys to avoid the bugs and SURVIVE!"
Print "Press [ENTER] to start"
Input

;--------------------- Playing ------------------------------------

Repeat                       ; the game loop
   moving()
   drawing()
   hitting()
Forever         
 
;------------------------------------------------------------------
;  These are the commands repeated during the game
;  Change these to control movement and other actions
;------------------------------------------------------------------

Function moving()
   If KeyDown(200)           ; up arrow is pressed
      p\y = p\y - 5 
   EndIf
   If KeyDown(203)           ; left arrow
      p\x = p\x - 5 
   EndIf
   If KeyDown(208)           ; down arrow
      p\y = p\y + 5 
   EndIf
   If KeyDown(205)           ; right arrow
      p\x = p\x + 5 
   EndIf
   MoveAll()
End Function


Function drawing()
   Cls                       ; clear the screen (blank)
   DrawAll()                 ; draw all the pictures again
   Flip                      ; display new drawing
End Function


Function hitting()
   h.pic = Hit(p) 
   If h\i = alien          ; if h is NOT NO collision (there IS a collision)
      Cls
      Print "Poisoned ... you lose ..." 
      Input
      End
   EndIf
End Function

;=========================================================================
;  Some complex, technical, standard stuff is below - the game "engine"
;  You probably shouldn't change these commands
;=========================================================================

Type pic
    Field i             ; image pointer
    Field x,y,w,h       ; position (x,y), width, height
    Field a,d           ; movement speed (across, down)
    Field c             ; code for different types of objects
End Type

Function MoveAll()
    Local temp.pic
    Local gw = GraphicsWidth()
    Local gh = GraphicsHeight()
    For temp = Each pic
        temp\x = (gw + temp\x + temp\a) Mod gw
        temp\y = (gh + temp\y + temp\d) Mod gh
    Next
End Function

Function DrawAll()
    Local temp.pic
    For temp = Each pic
       DrawImage temp\i,temp\x,temp\y
    Next
End Function

Function MakePic.pic(img,x,y,a,d,c)  
   Local temp.pic = New pic
   temp\i = img
   temp\x = x
   temp\y = y
   temp\a = a
   temp\d = d
   temp\w = ImageWidth(img)
   temp\h = ImageHeight(img)
   Return temp
End Function

Function Hit.pic(check.pic)
   Local temp.pic
   For temp = Each pic
     If temp<>check 
        If ImagesOverlap(temp\i,temp\x,temp\y,check\i,check\x,check\y)
           Return temp
        EndIf
     EndIf
   Next   
   Return check
End Function

;=======================================================================
; This game is a simple 2D movement game, with several enemies to avoid.
; It demonstrates the basic techniques for 2D games.
;
; Once you understand the commands here (let the teacher explain them)
; try to make the following changes:
;
; (1) Add 4 more enemies, but use a different picture, about the same size.
;
; (2) Change the game so it makes a distinction between the poison enemies
;     (the bugs) and the good enemies (your new ones).  In the hitting()
;     function, the program should respond differently to hitting a bug
;     or hitting the new enemy.  If you hit the new enemy, you WIN!
;     The commands look something like this:
;
;        If h\i = alien
;           cls
;           print "You got poisoned"
;           input
;           end
;        ElseIf h\i = friend
;           cls
;           print "You WIN!!"
;           input
;           end
;        EndIf
;
; Try out this game:  http://www.startinglinks.net/games/frogger.html
; It is called FROGGER.  The goal is to get across the river
; without getting squashed or falline in the water.
; You can make a very simple version of this game as follows:
;
; (3) Make all the bugs start in a horizontal line, and all move at the 
;     same speed across the screen.  This is like one lane of traffic
;     in the FROGGER game.
;
; (4) Start the player at the bottom-center of the screen.
;     End the game whenever the player's y-coordinate is less than 50.
;     Add this to the moving() function:
;
;        If p\y < 50
;           cls
;           print "You WON!"
;           input
;           end
;        EndIf
;
; (5) Add more rows of enemies - like more lanes of traffic.
;     In each case, all the enemies in each row should move at the 
;     same speed.  The various rows can have different speeds.
;     Leave one row in the middle empty, so the frog can rest.
;
; (6) The "frog" cannot move down the screen, so remove the commands
;     that move him downward.  Also, the frog is very slow, so 
;     reduce the speed.
;
; (7) Make the game more challenging by placing the frog at the 
;     bottom left corner, and remove the left-arrow movement,
;     so the frog can only move up and to the right.