Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Can't find error in small program

I'M getting the following error when I try to compile this code: "'Function' can only appear in main program."

[code];Draw a ship which can be moved and killed

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
Field hitpoints
Field shipstring$
End Type


;INITIALIZATION SECTION
Global cont = 1
Global player.ship = New ship
playerx = STARTX
playery = STARTY
playerhitpoints = STARTHITPOINTS
playershipstring = SHIP$


;Game loop
While cont = 1
Cls
Text playerx, playery, playershipstring$

TestInput()
DrawHUD()
Wend
;End of loop


;FUNCTION TextInput() - changes the direction or hit points of the player
Function TestInput()

;If player presses left, move him left.
If KeyHit(LEFTKEY)
playerx = playerx - 3
If playerx <= 0
playerx = 10


EndIf
EndIf

;If player presses right, move him right.
If KeyHit(RIGHTKEY)
playerx = playerx + 3

If playerx >= 385
playerx = 380
EndIf
EndIf

;If player presses up, move him up
If KeyHit(UPKEY)

playery = playery - 3
If playery <= 0
playery = 10
EndIf
EndIf

;If player presses down, move him down.
If KeyHit(DOWNKEY)

playery = playery + 3
If playery >= 285
playery = 280
EndIf
EndIf

;If player presses spacebar, remove a hit point

If KeyHit(SPACEBAR)

playerhitpoints = playerhitpoints - 1
If playerhitpoints <= 0
cont = 0
EndIf
EndIf

;If player presses Esc, set cont to 0, and exit the game
If KeyHit(ESCKEY)
cont = 0
EndIf


;Function DrawHUD() - draws the user's info in top Right of the screen
Function DrawHUD()
Text 260, 10, "X position: " + playerx
Text 260, 20, "Y positoin: " + playery
Text 260, 30, "Hitpoints: " + playerhitpoints
End Function[/code]

Comments

Sign In or Register to comment.