Game crashing when I try to exit using esc

BlitzMax Forums/BlitzMax Beginners Area/Game crashing when I try to exit using esc

Zacho(Posted 2011) [#1]
Does anyone know why? I am in a While wend loop


GfK(Posted 2011) [#2]
Not without seeing code, and an elaboration on "crashing".


Zacho(Posted 2011) [#3]
The code is pretty simple, its just that I cannot exit out of my program without using ctrl + alt + delete everytime

'MEGA MAN REMAKE
Graphics 800,600
'AppTitle = "MegaMan [{Gam3rs Unit3}: ZaChO]"
AutoMidHandle(True)

Const Gravity:Float = 0.2


Global Jump:Int = 1
Global JumpHeight:Float = 3.7
Global CanJump:Int = 1
Global Falling:Int = 0




Type MegaMan 'idle
	Field x,y
	Field frame
EndType




SetMaskColor(0,128,128)


'LOAD IMAGES
Global megaIdle:TImage=LoadAnimImage("C:/Users/Zachary/Pictures/Mega Man/megaIdle.bmp",30,36,0,3)
Global megaJump:TImage=LoadImage("C:/Users/Zachary/Pictures/Mega Man/megaJump.bmp")
Global megaRR:TImage=LoadAnimImage("C:/Users/Zachary/Pictures/Mega Man/megaRR.bmp",30,36,0,3)
Global megaRL:TImage=LoadAnimImage("C:/Users/Zachary/Pictures/Mega Man/megaRL.bmp",30,36,0,3)


Global player:MegaMan = New MegaMan 'idle
	player.x = 400
	player.y = 500
	player.frame = 0



While Not KeyHit(ESC) Or AppTerminate()
Cls	
		Movement ()
		Draw ()
		DoJump ()
Flip 
Wend 


Function Draw ()

	If Jump = 1
		DrawImage megaJump:TImage,player.x,player.y,player.frame
	ElseIf Jump = 0 And MR = 0 And ML = 0
		DrawImage megaIdle:TImage,player.x,player.y,player.frame
	ElseIf Jump = 0 And MR = 1
		DrawImage megaRR:TImage,player.x,player.y,player.frame
	ElseIf Jump = 0 And ML = 1
		DrawImage megaRL:TImage,player.x,player.y,player.frame
	EndIf 	
EndFunction 
 
Function DoJump ()


	If KeyHit(KEY_SPACE) 
		Jump = 1
		CanJump = 0
	End If
	
	If Jump = 1
		player.y:-JumpHeight
		JumpHeight:-Gravity
		If JumpHeight <= - 1.0 
			Falling = 1
		EndIf
	End If
	
	If Falling = 1
		player.y:+3.2
		
			If player.y >= 500
						Jump = 0                        
						Falling = 0
						CanJump = 1
						JumpHeight = 3.7
			EndIf 
	EndIf 
End Function

Function Movement ()
	If KeyDown (KEY_RIGHT)
		MR = 1
		player.x:+3
	EndIf
	
	If KeyDown (KEY_LEFT)
		ML = 1
		player.x:-3
	EndIf
	MR = 0
	ML = 0 
EndFunction 	
	



Brucey(Posted 2011) [#4]
'ESC' is not a valid variable.

Use Strict or SuperStrict at the top of your code... it will help you write better programs.


Zacho(Posted 2011) [#5]
Oh duh! ahah yes I know about strict, i just wanted to get my physics out of the way, thanks guys

i feel so dumb ;p haha


Warner(Posted 2011) [#6]
Without brackets, the Not only applies to the first expression, try this instead:
While Not(KeyHit(27) Or AppTerminate())

Beside ALT+CTRL+DEL, there is a red button in the IDE that stops your program.

Last edited 2011