arrow key menu

BlitzMax Forums/BlitzMax Programming/arrow key menu

B
 #1
I have searched the forums extensively and I was unable to find a thread that dealt
with my problem.

In my current game I am trying to make it so that when you get near a certain spot in opens up a menu in which you can upgrade your stats, however I am having lots of trouble. :(

when you press the down key it skips from the 1st to the 3rd option and misses the 2nd.

I believe this to be a result of it going to the 2nd one, but you cannot lift your finger off the key fast enough for the computer.

I fixed this problem by throwing in a wait function so it just waits a couple tenths of a second. but i wanted to know if there is a better way to do this.

my second problem is that the inc def stat does not seem to work and I have no idea why.

it is probably just a result of me looking at the same code forever and I need a fresh pair of eyes.

also I want to have it so when you hit the down key it goes down and then waits for you to lift your finger back up until you can press it down again to go to the next selection.


any help would be much appreciated!


here is the code and I will upload a .zip folder which contains everything you need to play the game as well. graphics included.


Graphics 640,480,32
'Graphics 320,240,16


'LOAD TILESET IMAGE AND SET MASK
Global tileset: Timage = LoadImage ("tileset.png")
DrawImage tileset,0,0
SetMaskColor (255,0,255)


'CUT AND LOAD IMAGES FROM TILESET

'MAIN CHARACTER DWARF
Global dwarf=CreateImage(16,16,1,DYNAMICIMAGE|MASKEDIMAGE)
GrabImage dwarf,16,0

'SOLDIER DWARF
Global soldierdwarf=CreateImage(16,16,1,DYNAMICIMAGE|MASKEDIMAGE)
GrabImage soldierdwarf,32,0

'FLOOR IMAGE #1
Global floor1=CreateImage(16,16,1,DYNAMICIMAGE|MASKEDIMAGE)
GrabImage floor1,16*11,16*2

'FLOOR IMAGE #2
Global floor2=CreateImage(16,16,1,DYNAMICIMAGE|MASKEDIMAGE)
GrabImage floor2,16*13,16*3

'HEALTH BAR GREEN
Global healthbargreen=CreateImage(1,1,1,DYNAMICIMAGE|MASKEDIMAGE)
GrabImage healthbargreen,39,170

'HEALTH BAR RED
Global healthbarred=CreateImage(1,1,1,DYNAMICIMAGE|MASKEDIMAGE)
GrabImage healthbarred,87,154

'TREASURE CHEST
Global treasurechest=CreateImage(16,16,1,DYNAMICIMAGE|MASKEDIMAGE)
GrabImage treasurechest,16*2,16*9

'SAVE SCREEN
Global savescreen=CreateImage(32,32,1,DYNAMICIMAGE|MASKEDIMAGE)
GrabImage savescreen,16*11,16*13


'DWARF POWER STATS
Global dwarfatk,dwarfdef,dwarfhp#,dwarfhpmax#,dwarfxp,dwarfper#,dwarflvl,dwarfxptotal
dwarfatk      = 1
dwarfdef      = 2
dwarfhp#      = 20
dwarfhpmax#   = 20
dwarfxp       = 0
dwarflvl      = 1
dwarfxptotal  = 0
dwarfper# = (16/dwarfhpmax#)

Global soldierdwarfatk,soldierdwarfdef,soldierdwarfhealth,soldierdwarfhealthmax,soldierdwarfxp,soldierdwarfper#
soldierdwarfatk        = 3
soldierdwarfdef        = 1
soldierdwarfhealth     = 20
soldierdwarfhealthmax  = 20
soldierdwarfper#       = 0.8


'DWARF VARIABLES
Global dwarfx,dwarfy,soldierdwarfx,soldierdwarfy

dwarfx = 16*30
dwarfy = 16*10

soldierdwarfx = 16*10
soldierdwarfy = 16*10

dwarfmove = 16



'OTHER VARIABLES
Global treasure:Int, arrow:Int
treasure = 0
arrow = 1


'MAIN GAME SO FAR

#ENTRY
'START MAIN LOOP
While Not KeyDown(key_escape)
'CLEAR SCREEN
Cls

'DRAW SQUARE TILES AS GROUND
floor1x=0
floor1y=0
floor2x=16
floor2y=0
For r = 1 To 20
For t = 1 To 40
DrawImage floor1,floor1x,floor1y
'DrawImage floor2,floor2x,floor2y
floor1x:+16
floor2x:+32
Next
floor1x=0
floor2x=16
floor1y:+16
floor2y:+16
Next


'Movement Keys for DWARF
If KeyDown(key_up)     Then dwarfy:-dwarfmove
If KeyDown(key_down)   Then dwarfy:+dwarfmove
If KeyDown(key_left)   Then dwarfx:-dwarfmove
If KeyDown(key_right)  Then dwarfx:+dwarfmove




'ATTACKING
If dwarfhp > 0
If soldierdwarfhealth > 0
If dwarfx = soldierdwarfx And dwarfy = soldierdwarfy And KeyDown(key_right)
	dwarfx:-16
	soldierdwarfhealth:-(dwarfatk-soldierdwarfdef)+1

'FLOATING DAMMAGE NUMBER
	narg = dwarfatk-soldierdwarfdef+1
	DrawText (narg,soldierdwarfx+5,soldierdwarfy-15)
	
	If (soldierdwarfatk-dwarfdef) > 0
		dwarfhp:-(soldierdwarfatk-dwarfdef)
	EndIf
	dwarfxptotal:+1
	dwarfxp:+1
Else
	If dwarfx = soldierdwarfx And dwarfy = soldierdwarfy And KeyDown(key_left)
		dwarfx:+16
		soldierdwarfhealth:-(dwarfatk-soldierdwarfdef)+1
		
'FLOATING DAMMAGE NUMBER
		narg = dwarfatk-soldierdwarfdef+1
		DrawText (narg,soldierdwarfx+5,soldierdwarfy-15)

			If (soldierdwarfatk-dwarfdef) > 0
				dwarfhp:-(soldierdwarfatk-dwarfdef)
			EndIf
			dwarfxptotal:+1
			dwarfxp:+1
	Else
		If dwarfy = soldierdwarfy And dwarfx = soldierdwarfx And KeyDown(key_down)
			dwarfy:-16
			soldierdwarfhealth:-(dwarfatk-soldierdwarfdef)+1
'FLOATING DAMMAGE NUMBER
			narg = dwarfatk-soldierdwarfdef+1
			DrawText (narg,soldierdwarfx+5,soldierdwarfy-15)
			
				If (soldierdwarfatk-dwarfdef) > 0
					dwarfhp:-(soldierdwarfatk-dwarfdef)
				EndIf
				dwarfxptotal:+1
				dwarfxp:+1
		Else
			If dwarfy = soldierdwarfy And dwarfx = soldierdwarfx And KeyDown(key_up)
				dwarfy:+16
				soldierdwarfhealth:-(dwarfatk-soldierdwarfdef)+1
'FLOATING DAMMAGE NUMBER
				narg = dwarfatk-soldierdwarfdef+1
				DrawText (narg,soldierdwarfx+5,soldierdwarfy-15)
					If (soldierdwarfatk-dwarfdef) > 0
						dwarfhp:-(soldierdwarfatk-dwarfdef)
					EndIf
					dwarfxptotal:+1
					dwarfxp:+1
			EndIf
		EndIf
	EndIf
EndIf
EndIf
EndIf


'DWARF CANNOT EXIT VISUAL SCREEN
If dwarfx > 624                         Then dwarfx = 624
If dwarfx < 0                           Then dwarfx = 0
If dwarfy > 304                         Then dwarfy = 304
If dwarfy < 0                           Then dwarfy = 0


'DRAW TREASURECHEST  SAVE SPOT TO SCREEN
DrawImage (treasurechest,16*32,16*10)
If dwarfx = 16*32 And dwarfy = 16*10 And treasure = 0
	treasure = 1
	Goto treasurechest
EndIf


'DRAW SOLDIER DWARF IMAGE TO SCREEN
DrawImage soldierdwarf,soldierdwarfx,soldierdwarfy
DrawImageRect(healthbarred,soldierdwarfx,soldierdwarfy-2,16,1)
DrawImageRect(healthbargreen,soldierdwarfx,soldierdwarfy-2,(soldierdwarfhealth*soldierdwarfper#),1)

'DRAW DWARF IMAGE TO SCREEN
DrawImage dwarf,dwarfx,dwarfy
DrawImageRect(healthbarred,dwarfx,dwarfy-2,16,1)
DrawImageRect(healthbargreen,dwarfx,dwarfy-2,dwarfhp#*dwarfper#,1)


'DRAW STATS TO SCREEN
DrawText ("X: 16*" + dwarfx/16 + " Y: 16*" + dwarfy/16,500,0)
DrawText ("Dwarf Warrior" + "  lvl: " + dwarflvl,0,320)
DrawText ("HP: " + dwarfhp#,0,340)
DrawText ("ATK: " + dwarfatk,0,360)
DrawText ("DEF: " + dwarfdef,0,380)
DrawText ("XP: " + dwarfxp,0,400)

'DWARF LEVELS
If dwarfxptotal > 0     And dwarfxptotal < 50    Then dwarflvl = 1
If dwarfxptotal > 50    And dwarfxptotal < 100    Then dwarflvl = 2
If dwarfxptotal > 100    And dwarfxptotal < 250    Then dwarflvl = 3
If dwarfxptotal > 250    And dwarfxptotal < 310   Then dwarflvl = 4
If dwarfxptotal > 310   And dwarfxptotal < 390   Then dwarflvl = 5
If dwarfxptotal > 390   And dwarfxptotal < 470   Then dwarflvl = 6


'DWARF HP COSTS
If dwarflvl = 1 Then hpcost = 10
If dwarflvl = 2 Then hpcost = 20
If dwarflvl = 3 Then hpcost = 35
If dwarflvl = 4 Then hpcost = 50
If dwarflvl = 5 Then hpcost = 70
If dwarflvl = 6 Then hpcost = 95


'DWARF ATK COSTS
If dwarflvl = 1 Then atkcost = 5
If dwarflvl = 2 Then atkcost = 10
If dwarflvl = 3 Then atkcost = 17
If dwarflvl = 4 Then atkcost = 25
If dwarflvl = 5 Then atkcost = 40
If dwarflvl = 6 Then atkcost = 60


'DWARF DEF COSTS
If dwarflvl = 1 Then defcost = 5
If dwarflvl = 2 Then defcost = 10
If dwarflvl = 3 Then defcost = 17
If dwarflvl = 4 Then defcost = 25
If dwarflvl = 5 Then defcost = 40
If dwarflvl = 6 Then defcost = 60

DrawText ("X: 16*" + dwarfx/16 + " Y: 16*" + dwarfy/16,500,0)
DrawText ("Dwarf Warrior" + "  lvl: " + dwarflvl,0,320)
DrawText ("HP: " + dwarfhp,0,340)
DrawText ("ATK: " + dwarfatk,0,360)
DrawText ("DEF: " + dwarfdef,0,380)
DrawText ("XP: " + dwarfxp,0,400)
If dwarfhp# < 100 And dwarfhp# > 9
	SetColor (1,1,1)
	DrawRect (50,340,300,15)
	SetColor (255,255,255)
Else
	If dwarfhp# < 10
		SetColor (1,1,1)
		DrawRect (40,340,300,15)
		SetColor (255,255,255)
	Else
		If dwarfhp# > 100 And dwarfhp# < 999
			SetColor (1,1,1)
			DrawRect (58,340,300,15)
			SetColor (255,255,255)
		EndIf
	EndIf
EndIf


shortwait(5)

'REGENERATE SOLDIERDWARFS HEALTH
If KeyDown(key_h) Then soldierdwarfhealth = soldierdwarfhealthmax

'DEVELOPER XP CHEAT
If KeyDown(key_q) And KeyDown(key_w) And KeyDown(key_e) And KeyDown(key_r) Then dwarfxp:+1000

Flip
Wend
End

'TREASURE CHEST SAVE SCREEN
#treasurechest

While treasure = 1
Cls


'shortwait(4)
SetScale (20,10)
DrawImage (savescreen,0,0)
SetScale (2,2)
DrawText ("Treasure Chest",200,10)
SetScale (1,1)
DrawText ("Space to EXIT",220,280)
DrawText ("XP: " + dwarfxp,20,30)
DrawText ("HP  + 1",40,80)
	DrawText ("Cost " +  hpcost,100,80)
DrawText ("ATK + 1",40,100)
	DrawText ("Cost " + atkcost,100,100)
DrawText ("DEF + 1",40,120)
	DrawText ("Cost " + defcost,100,120)

DrawText (arrow,200,280)

If arrow = 1
	DrawText ("<-",180,80)
	If KeyDown(key_down)
		arrow = 2
	Else
		If KeyDown(key_enter) And dwarfxp > hpcost-1
			dwarfhp#:+1
			dwarfhpmax#:+1
			dwarfxp:-hpcost
		EndIf
	EndIf
EndIf

If arrow = 2
	shortwait(5)
	DrawText ("<-",180,100)
	If KeyDown(key_down)
		arrow = 3
	Else
		If KeyDown(key_up)
			arrow = 1
		Else
			If KeyDown(key_enter) And dwarfxp > atkcost-1
				dwarfatk:+1
				dwarfxp:-atkcost
			EndIf
		EndIf
	EndIf
EndIf


If arrow = 3
	DrawText ("<-",180,120)
	If KeyDown(key_up)
		arrow = 2
		If KeyDown(key_enter) And dwarfxp > defcost-1
			dwarfdef:+1
			dwarfxp:-defcost
		EndIf
	EndIf
EndIf


'DRAW STATS TO SCREEN
DrawText ("X: 16*" + dwarfx/16 + " Y: 16*" + dwarfy/16,500,0)
DrawText ("Dwarf Warrior" + "  lvl: " + dwarflvl,0,320)
DrawText ("HP: " + dwarfhp,0,340)
DrawText ("ATK: " + dwarfatk,0,360)
DrawText ("DEF: " + dwarfdef,0,380)
DrawText ("XP: " + dwarfxp,0,400)


If KeyDown(key_space)
	dwarfy = 16*11
	treasure = 0
	shortwait(5)
	Goto ENTRY
EndIf
Flip
Wend





Function waitsec(W)
timer = CreateTimer (1)
For i = 1 To W
WaitTimer(timer)
Next
EndFunction

Function shortwait(E)
timer = CreateTimer (E)
WaitTimer(timer)
EndFunction

UPDATED TO CODE BOX!


thanks in advanced for all the help.


.zip here

B

Use KeyHit instead of KeyDown.

Or, use a key repeat rate to limit your responses to KeyDown:

Const KEY_REPEAT_RATE:int = 150 ' in ms
Global lastKeyDownTime:int

While(true)
   If KeyDown(KEY_UP) And Millisecs() > lastKeyDownTime + KEY_REPEAT_RATE
      lastKeyDownTime = MilliSecs()
      DoStuff()
   EndIf
Wend


PS. I'd also recommend not using Goto.... Ever! ;)

just another alternative:
Graphics 640,480
'Graphics 320,240,16


'LOAD TILESET IMAGE AND SET MASK
Global tileset: Timage = LoadImage ("tileset.png")
DrawImage tileset,0,0
SetMaskColor (255,0,255)


'CUT AND LOAD IMAGES FROM TILESET

'MAIN CHARACTER DWARF
Global dwarf=CreateImage(16,16,1,DYNAMICIMAGE|MASKEDIMAGE)
GrabImage dwarf,16,0

'SOLDIER DWARF
Global soldierdwarf=CreateImage(16,16,1,DYNAMICIMAGE|MASKEDIMAGE)
GrabImage soldierdwarf,32,0

'FLOOR IMAGE #1
Global floor1=CreateImage(16,16,1,DYNAMICIMAGE|MASKEDIMAGE)
GrabImage floor1,16*11,16*2

'FLOOR IMAGE #2
Global floor2=CreateImage(16,16,1,DYNAMICIMAGE|MASKEDIMAGE)
GrabImage floor2,16*13,16*3

'HEALTH BAR GREEN
Global healthbargreen=CreateImage(1,1,1,DYNAMICIMAGE|MASKEDIMAGE)
GrabImage healthbargreen,39,170

'HEALTH BAR RED
Global healthbarred=CreateImage(1,1,1,DYNAMICIMAGE|MASKEDIMAGE)
GrabImage healthbarred,87,154

'TREASURE CHEST
Global treasurechest=CreateImage(16,16,1,DYNAMICIMAGE|MASKEDIMAGE)
GrabImage treasurechest,16*2,16*9

'SAVE SCREEN
Global savescreen=CreateImage(32,32,1,DYNAMICIMAGE|MASKEDIMAGE)
GrabImage savescreen,16*11,16*13


'DWARF POWER STATS
Global dwarfatk,dwarfdef,dwarfhp#,dwarfhpmax#,dwarfxp,dwarfper#,dwarflvl,dwarfxptotal
dwarfatk      = 1
dwarfdef      = 2
dwarfhp#      = 20
dwarfhpmax#   = 20
dwarfxp       = 0
dwarflvl      = 1
dwarfxptotal  = 0
dwarfper# = (16/dwarfhpmax#)

Global soldierdwarfatk,soldierdwarfdef,soldierdwarfhealth,soldierdwarfhealthmax,soldierdwarfxp,soldierdwarfper#
soldierdwarfatk        = 3
soldierdwarfdef        = 1
soldierdwarfhealth     = 20
soldierdwarfhealthmax  = 20
soldierdwarfper#       = 0.8


'DWARF VARIABLES
Global dwarfx,dwarfy,soldierdwarfx,soldierdwarfy

dwarfx = 16*30
dwarfy = 16*10

soldierdwarfx = 16*10
soldierdwarfy = 16*10

dwarfmove = 16

Global wait% = 30 '*************************************************
Global counter% = 0 '***********************************************

'OTHER VARIABLES
Global treasure:Int, arrow:Int
treasure = 0
arrow = 1


'MAIN GAME SO FAR

#ENTRY
'START MAIN LOOP
While Not KeyDown(key_escape)
'CLEAR SCREEN
Cls

'DRAW SQUARE TILES AS GROUND
floor1x=0
floor1y=0
floor2x=16
floor2y=0
For r = 1 To 20
For t = 1 To 40
DrawImage floor1,floor1x,floor1y
'DrawImage floor2,floor2x,floor2y
floor1x:+16
floor2x:+32
Next
floor1x=0
floor2x=16
floor1y:+16
floor2y:+16
Next


'Movement Keys for DWARF
If KeyDown(key_up)     Then dwarfy:-dwarfmove
If KeyDown(key_down)   Then dwarfy:+dwarfmove
If KeyDown(key_left)   Then dwarfx:-dwarfmove
If KeyDown(key_right)  Then dwarfx:+dwarfmove




'ATTACKING
If dwarfhp > 0
If soldierdwarfhealth > 0
If dwarfx = soldierdwarfx And dwarfy = soldierdwarfy And KeyDown(key_right)
	dwarfx:-16
	soldierdwarfhealth:-(dwarfatk-soldierdwarfdef)+1

'FLOATING DAMMAGE NUMBER
	narg = dwarfatk-soldierdwarfdef+1
	DrawText (narg,soldierdwarfx+5,soldierdwarfy-15)
	
	If (soldierdwarfatk-dwarfdef) > 0
		dwarfhp:-(soldierdwarfatk-dwarfdef)
	EndIf
	dwarfxptotal:+1
	dwarfxp:+1
Else
	If dwarfx = soldierdwarfx And dwarfy = soldierdwarfy And KeyDown(key_left)
		dwarfx:+16
		soldierdwarfhealth:-(dwarfatk-soldierdwarfdef)+1
		
'FLOATING DAMMAGE NUMBER
		narg = dwarfatk-soldierdwarfdef+1
		DrawText (narg,soldierdwarfx+5,soldierdwarfy-15)

			If (soldierdwarfatk-dwarfdef) > 0
				dwarfhp:-(soldierdwarfatk-dwarfdef)
			EndIf
			dwarfxptotal:+1
			dwarfxp:+1
	Else
		If dwarfy = soldierdwarfy And dwarfx = soldierdwarfx And KeyDown(key_down)
			dwarfy:-16
			soldierdwarfhealth:-(dwarfatk-soldierdwarfdef)+1
'FLOATING DAMMAGE NUMBER
			narg = dwarfatk-soldierdwarfdef+1
			DrawText (narg,soldierdwarfx+5,soldierdwarfy-15)
			
				If (soldierdwarfatk-dwarfdef) > 0
					dwarfhp:-(soldierdwarfatk-dwarfdef)
				EndIf
				dwarfxptotal:+1
				dwarfxp:+1
		Else
			If dwarfy = soldierdwarfy And dwarfx = soldierdwarfx And KeyDown(key_up)
				dwarfy:+16
				soldierdwarfhealth:-(dwarfatk-soldierdwarfdef)+1
'FLOATING DAMMAGE NUMBER
				narg = dwarfatk-soldierdwarfdef+1
				DrawText (narg,soldierdwarfx+5,soldierdwarfy-15)
					If (soldierdwarfatk-dwarfdef) > 0
						dwarfhp:-(soldierdwarfatk-dwarfdef)
					EndIf
					dwarfxptotal:+1
					dwarfxp:+1
			EndIf
		EndIf
	EndIf
EndIf
EndIf
EndIf


'DWARF CANNOT EXIT VISUAL SCREEN
If dwarfx > 624                         Then dwarfx = 624
If dwarfx < 0                           Then dwarfx = 0
If dwarfy > 304                         Then dwarfy = 304
If dwarfy < 0                           Then dwarfy = 0


'DRAW TREASURECHEST  SAVE SPOT TO SCREEN
DrawImage (treasurechest,16*32,16*10)
If dwarfx = 16*32 And dwarfy = 16*10 And treasure = 0
	treasure = 1
	Goto treasurechest
EndIf


'DRAW SOLDIER DWARF IMAGE TO SCREEN
DrawImage soldierdwarf,soldierdwarfx,soldierdwarfy
DrawImageRect(healthbarred,soldierdwarfx,soldierdwarfy-2,16,1)
DrawImageRect(healthbargreen,soldierdwarfx,soldierdwarfy-2,(soldierdwarfhealth*soldierdwarfper#),1)

'DRAW DWARF IMAGE TO SCREEN
DrawImage dwarf,dwarfx,dwarfy
DrawImageRect(healthbarred,dwarfx,dwarfy-2,16,1)
DrawImageRect(healthbargreen,dwarfx,dwarfy-2,dwarfhp#*dwarfper#,1)


'DRAW STATS TO SCREEN
DrawText ("X: 16*" + dwarfx/16 + " Y: 16*" + dwarfy/16,500,0)
DrawText ("Dwarf Warrior" + "  lvl: " + dwarflvl,0,320)
DrawText ("HP: " + dwarfhp#,0,340)
DrawText ("ATK: " + dwarfatk,0,360)
DrawText ("DEF: " + dwarfdef,0,380)
DrawText ("XP: " + dwarfxp,0,400)

'DWARF LEVELS
If dwarfxptotal > 0     And dwarfxptotal < 50    Then dwarflvl = 1
If dwarfxptotal > 50    And dwarfxptotal < 100    Then dwarflvl = 2
If dwarfxptotal > 100    And dwarfxptotal < 250    Then dwarflvl = 3
If dwarfxptotal > 250    And dwarfxptotal < 310   Then dwarflvl = 4
If dwarfxptotal > 310   And dwarfxptotal < 390   Then dwarflvl = 5
If dwarfxptotal > 390   And dwarfxptotal < 470   Then dwarflvl = 6


'DWARF HP COSTS
If dwarflvl = 1 Then hpcost = 10
If dwarflvl = 2 Then hpcost = 20
If dwarflvl = 3 Then hpcost = 35
If dwarflvl = 4 Then hpcost = 50
If dwarflvl = 5 Then hpcost = 70
If dwarflvl = 6 Then hpcost = 95


'DWARF ATK COSTS
If dwarflvl = 1 Then atkcost = 5
If dwarflvl = 2 Then atkcost = 10
If dwarflvl = 3 Then atkcost = 17
If dwarflvl = 4 Then atkcost = 25
If dwarflvl = 5 Then atkcost = 40
If dwarflvl = 6 Then atkcost = 60


'DWARF DEF COSTS
If dwarflvl = 1 Then defcost = 5
If dwarflvl = 2 Then defcost = 10
If dwarflvl = 3 Then defcost = 17
If dwarflvl = 4 Then defcost = 25
If dwarflvl = 5 Then defcost = 40
If dwarflvl = 6 Then defcost = 60

DrawText ("X: 16*" + dwarfx/16 + " Y: 16*" + dwarfy/16,500,0)
DrawText ("Dwarf Warrior" + "  lvl: " + dwarflvl,0,320)
DrawText ("HP: " + dwarfhp,0,340)
DrawText ("ATK: " + dwarfatk,0,360)
DrawText ("DEF: " + dwarfdef,0,380)
DrawText ("XP: " + dwarfxp,0,400)
If dwarfhp# < 100 And dwarfhp# > 9
	SetColor (1,1,1)
	DrawRect (50,340,300,15)
	SetColor (255,255,255)
Else
	If dwarfhp# < 10
		SetColor (1,1,1)
		DrawRect (40,340,300,15)
		SetColor (255,255,255)
	Else
		If dwarfhp# > 100 And dwarfhp# < 999
			SetColor (1,1,1)
			DrawRect (58,340,300,15)
			SetColor (255,255,255)
		EndIf
	EndIf
EndIf



'REGENERATE SOLDIERDWARFS HEALTH
If KeyDown(key_h) Then soldierdwarfhealth = soldierdwarfhealthmax

'DEVELOPER XP CHEAT
If KeyDown(key_q) And KeyDown(key_w) And KeyDown(key_e) And KeyDown(key_r) Then dwarfxp:+1000

Flip
Wend
End

'TREASURE CHEST SAVE SCREEN
#treasurechest

While treasure = 1
Cls


'shortwait(4)
SetScale (20,10)
DrawImage (savescreen,0,0)
SetScale (2,2)
DrawText ("Treasure Chest",200,10)
SetScale (1,1)
DrawText ("Space to EXIT",220,280)
DrawText ("XP: " + dwarfxp,20,30)
DrawText ("HP  + 1",40,80)
	DrawText ("Cost " +  hpcost,100,80)
DrawText ("ATK + 1",40,100)
	DrawText ("Cost " + atkcost,100,100)
DrawText ("DEF + 1",40,120)
	DrawText ("Cost " + defcost,100,120)

DrawText (arrow,200,280)
'**************************************************************************************************************
If Not waiting()
	Local key:Int = KeyDown(key_down)-KeyDown(key_up)
	If key Then
		arrow:+ key
		If arrow < 1 Then arrow = 1
		If arrow > 3 Then arrow = 3
		counter = wait
	EndIf
EndIf
DrawText ("<-",180,60+20*arrow)

If KeyDown(key_enter)
	Select arrow
		Case	1
			
			If dwarfxp > hpcost-1
				dwarfhp#:+1
				dwarfhpmax#:+1
				dwarfxp:-hpcost
			EndIf
		Case 2

			If dwarfxp > atkcost-1
				dwarfatk:+1
				dwarfxp:-atkcost
			EndIf
		Case 3
			If dwarfxp > defcost-1
				dwarfdef:+1
				dwarfxp:-defcost
			EndIf
	End Select
EndIf
'****************************************************************************************************

'DRAW STATS TO SCREEN
DrawText ("X: 16*" + dwarfx/16 + " Y: 16*" + dwarfy/16,500,0)
DrawText ("Dwarf Warrior" + "  lvl: " + dwarflvl,0,320)
DrawText ("HP: " + dwarfhp,0,340)
DrawText ("ATK: " + dwarfatk,0,360)
DrawText ("DEF: " + dwarfdef,0,380)
DrawText ("XP: " + dwarfxp,0,400)


If KeyDown(key_space)
	dwarfy = 16*11
	treasure = 0
	Goto ENTRY
EndIf
Flip
Wend
'*************************************************************
Function waiting%()
 If counter > 0 Then counter :-1
 Return counter
End Function
'*****************************************************************



and yes find an alternative to your goto.

So many globals :(

B
 #7
Thanks for all the help!

I am pretty new to this particular language so I understand that I have been making some big no no's.

if I may ask:

why no globals?
what is an alternative?

why no goto's?
what is an alternative?

should i just have everything in the same loop, and use variables to in a way 'unlock' things in place of using goto's?

why no globals?
I don't think it was said that you should have no globals, it's the way your program is setup that is simply beginner-level.

I think I heard this on the forums.. "If you can't do it without Gotos you must be doing something wrong."
For one, you can't use them in SuperStrict (or Strict?) - which you should be using.

He means 'alternative' as in, find another solution that does not involve using Gotos.

here is one way of doing it:
Graphics 640,480
'Graphics 320,240,16


'LOAD TILESET IMAGE AND SET MASK
Global tileset: Timage = LoadImage ("tileset.png")
DrawImage tileset,0,0
SetMaskColor (255,0,255)


'CUT AND LOAD IMAGES FROM TILESET

'MAIN CHARACTER DWARF
Global dwarf=CreateImage(16,16,1,DYNAMICIMAGE|MASKEDIMAGE)
GrabImage dwarf,16,0

'SOLDIER DWARF
Global soldierdwarf=CreateImage(16,16,1,DYNAMICIMAGE|MASKEDIMAGE)
GrabImage soldierdwarf,32,0

'FLOOR IMAGE #1
Global floor1=CreateImage(16,16,1,DYNAMICIMAGE|MASKEDIMAGE)
GrabImage floor1,16*11,16*2

'FLOOR IMAGE #2
Global floor2=CreateImage(16,16,1,DYNAMICIMAGE|MASKEDIMAGE)
GrabImage floor2,16*13,16*3

'HEALTH BAR GREEN
Global healthbargreen=CreateImage(1,1,1,DYNAMICIMAGE|MASKEDIMAGE)
GrabImage healthbargreen,39,170

'HEALTH BAR RED
Global healthbarred=CreateImage(1,1,1,DYNAMICIMAGE|MASKEDIMAGE)
GrabImage healthbarred,87,154

'TREASURE CHEST
Global treasurechest=CreateImage(16,16,1,DYNAMICIMAGE|MASKEDIMAGE)
GrabImage treasurechest,16*2,16*9

'SAVE SCREEN
Global savescreen=CreateImage(32,32,1,DYNAMICIMAGE|MASKEDIMAGE)
GrabImage savescreen,16*11,16*13


'DWARF POWER STATS
Global dwarfatk,dwarfdef,dwarfhp#,dwarfhpmax#,dwarfxp,dwarfper#,dwarflvl,dwarfxptotal
dwarfatk      = 1
dwarfdef      = 2
dwarfhp#      = 20
dwarfhpmax#   = 20
dwarfxp       = 0
dwarflvl      = 1
dwarfxptotal  = 0
dwarfper# = (16/dwarfhpmax#)

Global soldierdwarfatk,soldierdwarfdef,soldierdwarfhealth,soldierdwarfhealthmax,soldierdwarfxp,soldierdwarfper#
soldierdwarfatk        = 3
soldierdwarfdef        = 1
soldierdwarfhealth     = 20
soldierdwarfhealthmax  = 20
soldierdwarfper#       = 0.8


'DWARF VARIABLES
Global dwarfx,dwarfy,soldierdwarfx,soldierdwarfy

dwarfx = 16*30
dwarfy = 16*10

soldierdwarfx = 16*10
soldierdwarfy = 16*10

dwarfmove = 16

Global wait% = 20 '*************************************************
Global counter% = 0 '***********************************************

'OTHER VARIABLES
Global treasure:Int, arrow:Int
treasure = 0
arrow = 1


'MAIN GAME SO FAR

Repeat '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
	'START MAIN LOOP
	While Not KeyDown(key_escape)
	'CLEAR SCREEN
	Cls
	
	'DRAW SQUARE TILES AS GROUND
	floor1x=0
	floor1y=0
	floor2x=16
	floor2y=0
	For r = 1 To 20
	For t = 1 To 40
	DrawImage floor1,floor1x,floor1y
	'DrawImage floor2,floor2x,floor2y
	floor1x:+16
	floor2x:+32
	Next
	floor1x=0
	floor2x=16
	floor1y:+16
	floor2y:+16
	Next
	
	
	'Movement Keys for DWARF
	If KeyDown(key_up)     Then dwarfy:-dwarfmove
	If KeyDown(key_down)   Then dwarfy:+dwarfmove
	If KeyDown(key_left)   Then dwarfx:-dwarfmove
	If KeyDown(key_right)  Then dwarfx:+dwarfmove
	
	
	
	
	'ATTACKING
	If dwarfhp > 0
	If soldierdwarfhealth > 0
	If dwarfx = soldierdwarfx And dwarfy = soldierdwarfy And KeyDown(key_right)
		dwarfx:-16
		soldierdwarfhealth:-(dwarfatk-soldierdwarfdef)+1
	
	'FLOATING DAMMAGE NUMBER
		narg = dwarfatk-soldierdwarfdef+1
		DrawText (narg,soldierdwarfx+5,soldierdwarfy-15)
		
		If (soldierdwarfatk-dwarfdef) > 0
			dwarfhp:-(soldierdwarfatk-dwarfdef)
		EndIf
		dwarfxptotal:+1
		dwarfxp:+1
	Else
		If dwarfx = soldierdwarfx And dwarfy = soldierdwarfy And KeyDown(key_left)
			dwarfx:+16
			soldierdwarfhealth:-(dwarfatk-soldierdwarfdef)+1
			
	'FLOATING DAMMAGE NUMBER
			narg = dwarfatk-soldierdwarfdef+1
			DrawText (narg,soldierdwarfx+5,soldierdwarfy-15)
	
				If (soldierdwarfatk-dwarfdef) > 0
					dwarfhp:-(soldierdwarfatk-dwarfdef)
				EndIf
				dwarfxptotal:+1
				dwarfxp:+1
		Else
			If dwarfy = soldierdwarfy And dwarfx = soldierdwarfx And KeyDown(key_down)
				dwarfy:-16
				soldierdwarfhealth:-(dwarfatk-soldierdwarfdef)+1
	'FLOATING DAMMAGE NUMBER
				narg = dwarfatk-soldierdwarfdef+1
				DrawText (narg,soldierdwarfx+5,soldierdwarfy-15)
				
					If (soldierdwarfatk-dwarfdef) > 0
						dwarfhp:-(soldierdwarfatk-dwarfdef)
					EndIf
					dwarfxptotal:+1
					dwarfxp:+1
			Else
				If dwarfy = soldierdwarfy And dwarfx = soldierdwarfx And KeyDown(key_up)
					dwarfy:+16
					soldierdwarfhealth:-(dwarfatk-soldierdwarfdef)+1
	'FLOATING DAMMAGE NUMBER
					narg = dwarfatk-soldierdwarfdef+1
					DrawText (narg,soldierdwarfx+5,soldierdwarfy-15)
						If (soldierdwarfatk-dwarfdef) > 0
							dwarfhp:-(soldierdwarfatk-dwarfdef)
						EndIf
						dwarfxptotal:+1
						dwarfxp:+1
				EndIf
			EndIf
		EndIf
	EndIf
	EndIf
	EndIf
	
	
	'DWARF CANNOT EXIT VISUAL SCREEN
	If dwarfx > 624                         Then dwarfx = 624
	If dwarfx < 0                           Then dwarfx = 0
	If dwarfy > 304                         Then dwarfy = 304
	If dwarfy < 0                           Then dwarfy = 0
	
	
	'DRAW TREASURECHEST  SAVE SPOT TO SCREEN
	DrawImage (treasurechest,16*32,16*10)
	If dwarfx = 16*32 And dwarfy = 16*10 And treasure = 0
		treasure = 1
		Goto treasurechest
	EndIf
	
	
	'DRAW SOLDIER DWARF IMAGE TO SCREEN
	DrawImage soldierdwarf,soldierdwarfx,soldierdwarfy
	DrawImageRect(healthbarred,soldierdwarfx,soldierdwarfy-2,16,1)
	DrawImageRect(healthbargreen,soldierdwarfx,soldierdwarfy-2,(soldierdwarfhealth*soldierdwarfper#),1)
	
	'DRAW DWARF IMAGE TO SCREEN
	DrawImage dwarf,dwarfx,dwarfy
	DrawImageRect(healthbarred,dwarfx,dwarfy-2,16,1)
	DrawImageRect(healthbargreen,dwarfx,dwarfy-2,dwarfhp#*dwarfper#,1)
	
	
	'DRAW STATS TO SCREEN
	DrawText ("X: 16*" + dwarfx/16 + " Y: 16*" + dwarfy/16,500,0)
	DrawText ("Dwarf Warrior" + "  lvl: " + dwarflvl,0,320)
	DrawText ("HP: " + dwarfhp#,0,340)
	DrawText ("ATK: " + dwarfatk,0,360)
	DrawText ("DEF: " + dwarfdef,0,380)
	DrawText ("XP: " + dwarfxp,0,400)
	
	'DWARF LEVELS
	If dwarfxptotal > 0     And dwarfxptotal < 50    Then dwarflvl = 1
	If dwarfxptotal > 50    And dwarfxptotal < 100    Then dwarflvl = 2
	If dwarfxptotal > 100    And dwarfxptotal < 250    Then dwarflvl = 3
	If dwarfxptotal > 250    And dwarfxptotal < 310   Then dwarflvl = 4
	If dwarfxptotal > 310   And dwarfxptotal < 390   Then dwarflvl = 5
	If dwarfxptotal > 390   And dwarfxptotal < 470   Then dwarflvl = 6
	
	
	'DWARF HP COSTS
	If dwarflvl = 1 Then hpcost = 10
	If dwarflvl = 2 Then hpcost = 20
	If dwarflvl = 3 Then hpcost = 35
	If dwarflvl = 4 Then hpcost = 50
	If dwarflvl = 5 Then hpcost = 70
	If dwarflvl = 6 Then hpcost = 95
	
	
	'DWARF ATK COSTS
	If dwarflvl = 1 Then atkcost = 5
	If dwarflvl = 2 Then atkcost = 10
	If dwarflvl = 3 Then atkcost = 17
	If dwarflvl = 4 Then atkcost = 25
	If dwarflvl = 5 Then atkcost = 40
	If dwarflvl = 6 Then atkcost = 60
	
	
	'DWARF DEF COSTS
	If dwarflvl = 1 Then defcost = 5
	If dwarflvl = 2 Then defcost = 10
	If dwarflvl = 3 Then defcost = 17
	If dwarflvl = 4 Then defcost = 25
	If dwarflvl = 5 Then defcost = 40
	If dwarflvl = 6 Then defcost = 60
	
	DrawText ("X: 16*" + dwarfx/16 + " Y: 16*" + dwarfy/16,500,0)
	DrawText ("Dwarf Warrior" + "  lvl: " + dwarflvl,0,320)
	DrawText ("HP: " + dwarfhp,0,340)
	DrawText ("ATK: " + dwarfatk,0,360)
	DrawText ("DEF: " + dwarfdef,0,380)
	DrawText ("XP: " + dwarfxp,0,400)
	If dwarfhp# < 100 And dwarfhp# > 9
		SetColor (1,1,1)
		DrawRect (50,340,300,15)
		SetColor (255,255,255)
	Else
		If dwarfhp# < 10
			SetColor (1,1,1)
			DrawRect (40,340,300,15)
			SetColor (255,255,255)
		Else
			If dwarfhp# > 100 And dwarfhp# < 999
				SetColor (1,1,1)
				DrawRect (58,340,300,15)
				SetColor (255,255,255)
			EndIf
		EndIf
	EndIf
	
	
	
	'REGENERATE SOLDIERDWARFS HEALTH
	If KeyDown(key_h) Then soldierdwarfhealth = soldierdwarfhealthmax
	
	'DEVELOPER XP CHEAT
	If KeyDown(key_q) And KeyDown(key_w) And KeyDown(key_e) And KeyDown(key_r) Then dwarfxp:+1000
	
	Flip
	Wend
	End
	
	'TREASURE CHEST SAVE SCREEN
	#treasurechest
	
	While treasure = 1
		Cls
		
		
		'shortwait(4)
		SetScale (20,10)
		DrawImage (savescreen,0,0)
		SetScale (2,2)
		DrawText ("Treasure Chest",200,10)
		SetScale (1,1)
		DrawText ("Space to EXIT",220,280)
		DrawText ("XP: " + dwarfxp,20,30)
		DrawText ("HP  + 1",40,80)
			DrawText ("Cost " +  hpcost,100,80)
		DrawText ("ATK + 1",40,100)
			DrawText ("Cost " + atkcost,100,100)
		DrawText ("DEF + 1",40,120)
			DrawText ("Cost " + defcost,100,120)
		
		DrawText (arrow,200,280)
		'**************************************************************************************************************
		If Not waiting()
			Local key:Int = KeyDown(key_down)-KeyDown(key_up)
			If key Then
				arrow:+ key
				If arrow < 1 Then arrow = 1
				If arrow > 3 Then arrow = 3
				counter = wait
			EndIf
		EndIf
		DrawText ("<-",180,60+20*arrow)
		
		If KeyDown(key_enter)
			Select arrow
				Case	1
					
					If dwarfxp > hpcost-1
						dwarfhp#:+1
						dwarfhpmax#:+1
						dwarfxp:-hpcost
					EndIf
				Case 2
		
					If dwarfxp > atkcost-1
						dwarfatk:+1
						dwarfxp:-atkcost
					EndIf
				Case 3
					If dwarfxp > defcost-1
						dwarfdef:+1
						dwarfxp:-defcost
					EndIf
			End Select
		EndIf
		'****************************************************************************************************
		
		'DRAW STATS TO SCREEN
		DrawText ("X: 16*" + dwarfx/16 + " Y: 16*" + dwarfy/16,500,0)
		DrawText ("Dwarf Warrior" + "  lvl: " + dwarflvl,0,320)
		DrawText ("HP: " + dwarfhp,0,340)
		DrawText ("ATK: " + dwarfatk,0,360)
		DrawText ("DEF: " + dwarfdef,0,380)
		DrawText ("XP: " + dwarfxp,0,400)
		
		
		If KeyDown(key_space)
			dwarfy = 16*11
			treasure = 0
			Exit '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
		EndIf
		Flip
	Wend
Forever '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
'*************************************************************

Function waiting%()
 If counter > 0 Then counter :-1
 Return counter
End Function
'*****************************************************************


it helps to learn oop, it will make your life so much easier.
if interested. look at the oop tutorial here:
http://www.blitzmax.com/Community/posts.php?topic=59233
have you looked at the programming blitzmax tutorial here:
http://www.blitzmax.com/Community/posts.php?topic=42519
if you have not, I recommend reading this first.

@B: With regards to the Globals comment, it's generally considered best practice to avoid them wherever possible. Have a read of this page.

The problem with using goto is that your code can easily end up as a tangled, spaghetti-like mess of code that's extremely hard to debug. Goto is almost never actually required, as the problem can usually be rewritten so that it is a) not needed, and b) easier to read/follow. I don't think I've actually used Goto since the Commodore 64 BASIC days, and even then I used it as a glorified jump table in one specific place in an adventure game I was writing.

As Jesse said, getting your head around some basic OO concepts will make your life a whole lot easier in the long run, so I'd recommend you have a read through the links he posted.

I also recommend getting into the habit of always writing "SuperStrict" on the first line of any BlitzMax code you write (I wish it was the default TBH).

Anyway, I hope this helps. :)

Muttley

@Everyone
thanks for all the help ill have to take a look at what SuperStrict means because I have no idea what it is.

i will definitely check out all the links that were provided.

Thanks again for solving my problem with the arrow keys, and i learned how some basic
blitz coding rules along the way.

thanks again! :)

B