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.
UPDATED TO CODE BOX!
thanks in advanced for all the help.
.zip here
B
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