Code: Select all
Graphics 400, 300
;Constants
Const STARTHITPOINTS = 3
Const SHIP$ = "<-*->"
Const ESCKEY = 1, SPACEBAR = 57, UPKEY = 200, LEFTKEY = 203, DOWNKEY = 208, RIGHTKEY = 205
Const STARTX = 200, STARTY = 150
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;TYPES
Type ship
Field x,y ;location
Field hitpoints ; ship's hit points
Field directionx
Field directiony
Field shipstring$
End Type
Type badship
Field x,y ;location
Field hitpoints ; ship's hit points
Field directionx
Field directiony
Field shipstring$
End Type
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SeedRnd MilliSecs()
For enemycounter = 0 To 99; ;100 new ships
enemy.badship = New badship
enemy\x = Rand(1, 640)
enemy\y = Rand(1, 480)
enemy\hitpoints = 3
enemy\x = enemy\x + enemy\directionx
enemy\y = enemy\y + enemy\directiony
Next
For enemyships.badship = Each badship
If hitpoints <= 0
Delete enemyships
EndIf
Next
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;INITIALIZATION SECTION
Global cont = 1
Global player.ship = New ship
player\x = STARTX
player\y = STARTY
player\hitpoints = STARTHITPOINTS
player\shipstring = SHIP$
enemy\directionx = Rand(-3,3)
enemy\directiony = Rand(-3,3)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;draws the hud
Function DrawHUD()
Text 260, 10, "X position: " + player\x
Text 260, 20, "Y position: " + player\y
Text 260, 30, "Hitpoints: " + player\hitpoints
End Function
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;move the creature randdomly & feed
Function TestInput()
;if player presses left, move him left.
If KeyHit(LEFTKEY)
player\x = player\x - 3
If player\x <0>= 385
player\x = 380
EndIf
EndIf
;if player presses up, move him up.
If KeyHit(UPKEY)
player\y = player\y - 3
If player\y <0>= 285
player\y = 280
EndIf
EndIf
;if player presses spacebar, remove hit point
If KeyHit(SPACEBAR)
player\hitpoints = player\hitpoints -1
If player\hitpoints <=0
cont = 0
EndIf
EndIf
;if player presses Esc, set cont to 0, and exit the game
If KeyHit(ESCKEY)
cont = 0
EndIf
End Function
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Game loop
While cont = 1
Cls
Text player\x, player\y, player\shipstring$
TestInput()
DrawHUD()
Flip()
Wend
;End of loop