Newbie Game Programmers

Moderators: None (Apply to moderate this forum)
Number of threads: 108
Number of posts: 316

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Can't find error in small program Posted by Garrett85 on 7 Mar 2009 at 10:21 AM
I'M getting the following error when I try to compile this code: "'Function' can only appear in main program."

;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
player\x = STARTX
player\y = STARTY
player\hitpoints = STARTHITPOINTS
player\shipstring = SHIP$


;Game loop
While cont = 1
		Cls
		Text player\x, player\y, player\shipstring$
		
		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)
	player\x = player\x - 3
	If player\x <= 0
			player\x = 10


	EndIf
EndIf

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

If player\x >= 385
		player\x = 380
	EndIf
EndIf

;If player presses up, move him up
If KeyHit(UPKEY)
		
		player\y = playery - 3
		If player\y <= 0
			player\y = 10
	EndIf
EndIf

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

		player\y = player\y + 3
		If player\y >= 285
			player\y = 280
	EndIf
EndIf

;If player presses spacebar, remove a 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


;Function DrawHUD() - draws the user's info in top Right of the screen
Function DrawHUD()
		Text 260, 10, "X position: " + player\x
		Text 260, 20, "Y positoin: " + player\y
		Text 260, 30, "Hitpoints: " + player\hitpoints
End Function

Report
Re: Can't find error in small program Posted by mmakrzem on 22 Apr 2009 at 11:48 AM
where is end function for TestInput() ?



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.