Okay, I am hoping to make a *small* RPG game. Here is the code:
dim pp(1,1)
dim grid(22,8)
dim monsters(399,3)
dim monstername$(399)
dim monsterpos(2,1)
dim xp(1)
dim hp(1)
dim numtypes$(2)
dim inventory$(10)
dim itemname$(400)
dim monsternum(40,40)
xp(0) = 0
randomize timer()
`rat
monstername$(100) = "Rat"
monsters(100,1) = 1
monsters(100,2) = 3
monsters(100,3) = 10
`giant rat
monstername$(101) = "Giant Rat"
monsters(101,1) = 2
monsters(101,2) = 6
monsters(101,3) = 20
`nothing
numtypes$(0) = "nothing"
`wall
numtypes$(1) = "wall"
`m. healing potion
itemname$(300) = "Mild Healing Potion"
sync on
hp(1) = 20
u = 1
for y = 0 to 8
for x = 0 to 22
read a
if a = 1
ink rgb(255,255,255),0
box x*25,y*25,(x+1)*25,(y+1)*25
endif
if a > 99
ink rgb(0,255,0),0
box x*25,y*25,(x+1)*25,(y+1)*25
endif
if a > 299
ink rgb(0,0,255),0
box x*25,y*25,(x+1)*25,(y+1)*25
endif
grid(x,y) = a
if a > 99 and a < 300
monsterpos(u,0) = x
monsterpos(u,1) = y
monsternum(x,y) = 1
u = u + 1
endif
next x
next y
sync
x=25
y=25
lv = 1
hp = 20
mxhp = 20
ink rgb(255,0,0),0
push = 0
start:
`*************MAIN LOOP*******************
do
hp = hp(1)
ink rgb(255,0,0),0
box x,y,x+25,y+25
gosub movement
if scancode()=0 then push = 0
pp(1,0) = x
pp(1,1) = y
ink rgb(255,255,255),0
gosub display_steps
gosub display_menu
gosub display_stats
sync
ink 0,0
box 5,210,639,479
loop
`end main loop
room1:
data 1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1
data 1,0,1,0,1,0 ,0,1,1,0,1,1,1,0,0,0 ,0,1,1,0,0,1,1
data 1,0,0,0,0,0 ,1,1,0,0,0,0,0,0,0,0 ,0,1,1,0,0,0,0
data 1,0,0,0,1,00 ,0,0,0,1,1,1,1,0,0,0 ,0,0,0,1,1,0,1
data 1,1,1,1,1,1 ,1,0,1,1,1,1,0,0,0,100,0,0,0,0,1,0,1
data 1,1,0,0,0,0 ,1,0,1,1,1,0,0,0,0,0 ,0,0,0,0,0,0,1
data 1,1,1,1,0,300,0,0,0,0,1,0,0,0,0,0 ,0,0,0,1,1,0,1
data 1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1
display_stats:
text 10, 300, "HP: " + str$(hp) + "/" + str$(mxhp)
text 10, 315, "XP: " + str$(xp(0) )
text 10, 330, "LV: " + str$(lv)
return
display_steps:
if x > 25
if grid(gridvalue(x-50),gridvalue(y)) < 2
temp$ = numtypes$((grid(gridvalue(x-50), gridvalue(y))))
else
temp$ = monstername$((grid(gridvalue(x+50), gridvalue(y))))
endif
endif
if x > 25 then text 180,300, "2 Steps to the Left: " + temp$
if x < 625
if grid(gridvalue(x+50),gridvalue(y)) < 2
temp$ = numtypes$((grid(gridvalue(x+50), gridvalue(y))))
else
temp$ = monstername$((grid(gridvalue(x+50), gridvalue(y))))
endif
endif
if x < 625 then text 180,315, "2 Steps to the Right: " + temp$
if y > 25
if grid(gridvalue(x),gridvalue(y-50)) < 2
temp$ = numtypes$((grid(gridvalue(x), gridvalue(y-50))))
else
temp$ = monstername$((grid(gridvalue(x), gridvalue(y-50))))
endif
endif
if y > 25 then text 180,330, "2 Steps Up: " + temp$
if y < 450
if grid(gridvalue(x),gridvalue(y+50)) < 2
temp$ = numtypes$((grid(gridvalue(x), gridvalue(y+50))))
else
temp$ = monstername$((grid(gridvalue(x), gridvalue(y+50))))
endif
endif
if y < 450 then text 180,345, "2 Steps Down: " + temp$
`******************END OF TWO STEP*************************
if x > 0
if grid(gridvalue(x-25),gridvalue(y)) < 2
temp$ = numtypes$((grid(gridvalue(x-25), gridvalue(y))))
else
temp$ = monstername$((grid(gridvalue(x-25), gridvalue(y))))
endif
endif
if x > 0 then text 180,370, "1 Step to the Left: " + temp$
if x < 650
if grid(gridvalue(x+25),gridvalue(y)) < 2
temp$ = numtypes$((grid(gridvalue(x+25), gridvalue(y))))
else
temp$ = monstername$((grid(gridvalue(x+25), gridvalue(y))))
endif
endif
if x < 650 then text 180,385, "1 Steps to the Right: " + temp$
if y > 0
if grid(gridvalue(x),gridvalue(y-25)) < 2
temp$ = numtypes$((grid(gridvalue(x), gridvalue(y-25))))
else
temp$ = monstername$((grid(gridvalue(x), gridvalue(y-25))))
endif
endif
if y > 0 then text 180,400, "1 Steps Up: " + temp$
if y < 475
if grid(gridvalue(x),gridvalue(y+25)) < 2
temp$ = numtypes$((grid(gridvalue(x), gridvalue(y+25))))
else
temp$ = monstername$((grid(gridvalue(x), gridvalue(y+25))))
endif
endif
if y < 475 then text 180,415, "1 Steps Down: " + temp$
return
display_menu:
text 450,300,"MENU"
text 450,315,"(I)nventory"
text 450,330,"(S)earch"
text 450,345,"S(k)ills"
return
movement:
if leftkey()=1 and push = 0
if grid(gridvalue(x)-1,gridvalue(y)) = 0
ink 0,0
box x,y,x+25,y+25
x = x - 25
ink rgb(255,0,0),0
push = 1
endif
if grid(gridvalue(x)-1,gridvalue(y)) > 99 and grid(gridvalue(x)-1,gridvalue(y)) < 299
ink 0,0
x = x - 25
box x,y,x+25,y+25
ink rgb(255,0,0),0
push = 1
mlv = monsters(grid(gridvalue(x), gridvalue(y)), 1)
mhp = monsters(grid(gridvalue(x), gridvalue(y)), 2)
mxp = monsters(grid(gridvalue(x), gridvalue(y)), 3)
mn$ = monstername$(grid(gridvalue(x), gridvalue(y)))
hp = monstercombat(lv,hp,mlv,mhp,mxp,mn$,"left")
endif
if grid(gridvalue(x)-1,gridvalue(y)) > 299
getitem(grid(gridvalue(x)-1,gridvalue(y)))
endif
endif
if rightkey()=1 and push = 0
if grid(gridvalue(x)+1,gridvalue(y)) = 0
ink 0,0
box x,y,x+25,y+25
ink rgb(255,0,0),0
x = x + 25
push = 1
endif
if grid(gridvalue(x)+1,gridvalue(y)) > 99 and grid(gridvalue(x)-1,gridvalue(y)) < 299
ink 0,0
x = x + 25
box x,y,x+25,y+25
ink rgb(255,0,0),0
push = 1
mlv = monsters(grid(gridvalue(x), gridvalue(y)), 1)
mhp = monsters(grid(gridvalue(x), gridvalue(y)), 2)
mxp = monsters(grid(gridvalue(x), gridvalue(y)), 3)
mn$ = monstername$(grid(gridvalue(x), gridvalue(y)))
hp = monstercombat(lv,hp,mlv,mhp,mxp,mn$,"right")
endif
if grid(gridvalue(x)-1,gridvalue(y)) > 299
getitem(grid(gridvalue(x)-1,gridvalue(y)))
endif
endif
if downkey()=1 and push = 0
if grid(gridvalue(x),gridvalue(y)+1) = 0
ink 0,0
box x,y,x+25,y+25
ink rgb(255,0,0),0
y = y + 25
push = 1
endif
if grid(gridvalue(x),gridvalue(y)+1) > 99 and grid(gridvalue(x),gridvalue(y)+1) < 299
ink 0,0
y = y + 25
box x,y,x+25,y+25
ink rgb(255,0,0),0
push = 1
mlv = monsters(grid(gridvalue(x), gridvalue(y)), 1)
mhp = monsters(grid(gridvalue(x), gridvalue(y)), 2)
mxp = monsters(grid(gridvalue(x), gridvalue(y)), 3)
mn$ = monstername$(grid(gridvalue(x), gridvalue(y)))
hp = monstercombat(lv,hp,mlv,mhp,mxp,mn$,"down")
endif
if grid(gridvalue(x),gridvalue(y+1)) > 299
getitem(grid(gridvalue(x),gridvalue(y)+1))
endif
endif
if upkey()=1 and push = 0
if grid(gridvalue(x),gridvalue(y)-1) = 0
ink 0,0
box x,y,x+25,y+25
ink rgb(255,0,0),0
y = y - 25
push = 1
endif
if grid(gridvalue(x),gridvalue(y)-1) > 99 and grid(gridvalue(x),gridvalue(y)-1) < 299
ink 0,0
y = y - 25
box x,y,x+25,y+25
ink rgb(255,0,0),0
push = 1
mlv = monsters(grid(gridvalue(x), gridvalue(y)), 1)
mhp = monsters(grid(gridvalue(x), gridvalue(y)), 2)
mxp = monsters(grid(gridvalue(x), gridvalue(y)), 3)
mn$ = monstername$(grid(gridvalue(x), gridvalue(y)))
hp = monstercombat(lv,hp,mlv,mhp,mxp,mn$,"up")
endif
if grid(gridvalue(x)-1,gridvalue(y)) > 299
getitem(grid(gridvalue(x),gridvalue(y)-1))
endif
endif
if inkey$()="i"
ink 0,0
box 5,210,639,479
ink rgb(255,255,255),0
displayinventory()
endif
return
goto start
function monstercombat(lv,hp,mlv,mhp,mxp,mname$,keypress$)
aord = 0
defend = 0
mdefend = 0
do
ink rgb(255,255,255),0
text 10,210,"The " + mname$ + " attacks you!"
text 10,225,"Your Turn"
set cursor 10,240
`take player input
input "Attack(1) or Defend(2)?",aord
`attack
if aord = 1
text 10,255,"You punch the " + mname$ + "."
if rnd(1) = 0
text 10,270,"You miss."
else
r = rnd(lv)+ (rnd(1) * (lv/2))
text 10,270,"You deal " + str$(r) + " damage to the " + mname$ + "."
mhp = mhp - r
if mdefend = 1 and rnd(1) = 1
if r < 1 then r = 1
r2 = rnd(r-1)+lv
text 10,285,"But, it defends itself against " + str$(r2) + " damage."
mhp = mhp + r2
endif
text 10,300,"The " + mname$ + " has " + str$(mhp) + " health remaining."
endif
endif
`defend
if aord <> 1
ink rgb(255,255,255),0
defend = 1
text 10,255,"You defend yourself."
r = rnd(1)
if r = 1
text 10,270,"You also manage to deal 1 damage to the rat."
mhp = mhp - 1
text 10,285,"The rat now has " + str$(mhp) + " health."
endif
endif
`monster dead
if mhp = 0 or mhp < 0
text 10,400,"You have defeated the " + mname$ + "."
text 10,430,"You gain " + str$(mxp) + " experience points."
xp(0) = xp(0) + mxp
text 10,445,"Congratulations"
text 10,460,"Press any key to continue"
`check for monster deletion
if keypress$ = "up"
px = pp(1,0)/25
py = pp(1,1)/25 - 1
deletemonster(px,py)
endif
if keypress$ = "down"
px = pp(1,0)/25
py = pp(1,1)/25 + 1
deletemonster(px,py)
endif
if keypress$ = "left"
px = pp(1,0)/25 - 1
py = pp(1,1)/25
deletemonster(px,py)
endif
if keypress$ = "right"
px = pp(1,0)/25 + 1
py = pp(1,1)/25
deletemonster(px,py)
endif
suspend for key
ink 0,0
box 5,205,639,479
hp(1) = hp
exitfunction
endif
mdefend = 0
wait 500
`monster turn
text 10,315,mname$ +"'s Turn"
`monster defend
if mhp < monsters(2,3)/3
mdefend = 1
r = rnd(1)
if r = 1
text 10,330,"The " + mname$ + " deals 1 damage to you. You have " + str$(hp-1) + " health."
hp = hp - 1
text 10,345,"You are not able to defend"
endif
text 10,360,"It defends itself"
`monster attack
else
if rnd(1) = 1
r = rnd(mlv)+ (rnd(1) * (mlv/2))
text 10,330,"The " + mname$ + " deals " + str$(r) + " damage to you."
hp = hp - r
if defend = 1 and rnd(1) = 1
if r > 0
r2 = rnd(r-1)+lv
else
r2 = rnd(r)+lv
endif
text 10,345,"But, you defend yourself against " + str$(r2) + " damage."
hp = hp + r2
endif
text 10,360,"You have " + str$(hp) + " heath remaining"
else
text 10,330,"The " + mname$ + " misses you."
endif
endif
if hp = 0 or hp < 0
text 10,400,"You have been defeated by the " + mname$ + "."
text 10,415,"You Lose"
text 10,430,"Press any key to continue"
suspend for key
end
endif
suspend for key
sync
ink 0,0
box 5,205,639,479
defend = 0
loop
endfunction
function gridvalue(num)
num = num / 25
endfunction num
function deletemonster(x,y)
x = x * 25
y = y * 25
ink 0,0
box x,y,x+25,y+25
ink rgb(255,0,0),0
gx = x / 25
gy = y / 25
grid(gx-1,gy-1) = 0
endfunction
function displayinventory()
ink rgb(255,255,255),0
text 10,280,"INVENTORY [PRESS L TO LEAVE]"
for inven = 1 to 10
if inventory$(inven) = ""
text 10,280+(15*inven), str$(inven) + ": Nothing"
else
text 10,280 + (15 * inven), str$(inven) + ": " + inventory$(inven)
endif
next inven
do
if inkey$()="l" then exitfunction
sync
loop
endfunction
function getitem(itemnum)
ink rgb(255,255,255),0
name$ = itemname$(itemnum)
text 20,280,"You see a " + name$ + "."
set cursor 20,295
input "Would you like to pick it up?",question$
if question$ = "y"
for invencheck = 1 to 10
if inventory$ = ""
exit
else
if invencheck = 10
text 20,310,"You have no room to pick it up"
endif
endif
next invencheck
inventory$(invencheck) = name$
endif
if question$ = "n"
text 20,310,"You don't pick up the item."
endif
suspend for key
endfunction
It's quite lengthy, but most of it doesn't apply in this case.
Here is the combat function:
function monstercombat(lv,hp,mlv,mhp,mxp,mname$,keypress$)
aord = 0
defend = 0
mdefend = 0
do
ink rgb(255,255,255),0
text 10,210,"The " + mname$ + " attacks you!"
text 10,225,"Your Turn"
set cursor 10,240
`take player input
input "Attack(1) or Defend(2)?",aord
`attack
if aord = 1
text 10,255,"You punch the " + mname$ + "."
if rnd(1) = 0
text 10,270,"You miss."
else
r = rnd(lv)+ (rnd(1) * (lv/2))
text 10,270,"You deal " + str$(r) + " damage to the " + mname$ + "."
mhp = mhp - r
if mdefend = 1 and rnd(1) = 1
if r < 1 then r = 1
r2 = rnd(r-1)+lv
text 10,285,"But, it defends itself against " + str$(r2) + " damage."
mhp = mhp + r2
endif
text 10,300,"The " + mname$ + " has " + str$(mhp) + " health remaining."
endif
endif
`defend
if aord <> 1
ink rgb(255,255,255),0
defend = 1
text 10,255,"You defend yourself."
r = rnd(1)
if r = 1
text 10,270,"You also manage to deal 1 damage to the rat."
mhp = mhp - 1
text 10,285,"The rat now has " + str$(mhp) + " health."
endif
endif
`monster dead
if mhp = 0 or mhp < 0
text 10,400,"You have defeated the " + mname$ + "."
text 10,430,"You gain " + str$(mxp) + " experience points."
xp(0) = xp(0) + mxp
text 10,445,"Congratulations"
text 10,460,"Press any key to continue"
`check for monster deletion
if keypress$ = "up"
px = pp(1,0)/25
py = pp(1,1)/25 - 1
deletemonster(px,py)
endif
if keypress$ = "down"
px = pp(1,0)/25
py = pp(1,1)/25 + 1
deletemonster(px,py)
endif
if keypress$ = "left"
px = pp(1,0)/25 - 1
py = pp(1,1)/25
deletemonster(px,py)
endif
if keypress$ = "right"
px = pp(1,0)/25 + 1
py = pp(1,1)/25
deletemonster(px,py)
endif
suspend for key
ink 0,0
box 5,205,639,479
hp(1) = hp
exitfunction
endif
mdefend = 0
wait 500
`monster turn
text 10,315,mname$ +"'s Turn"
`monster defend
if mhp < monsters(2,3)/3
mdefend = 1
r = rnd(1)
if r = 1
text 10,330,"The " + mname$ + " deals 1 damage to you. You have " + str$(hp-1) + " health."
hp = hp - 1
text 10,345,"You are not able to defend"
endif
text 10,360,"It defends itself"
`monster attack
else
if rnd(1) = 1
r = rnd(mlv)+ (rnd(1) * (mlv/2))
text 10,330,"The " + mname$ + " deals " + str$(r) + " damage to you."
hp = hp - r
if defend = 1 and rnd(1) = 1
if r > 0
r2 = rnd(r-1)+lv
else
r2 = rnd(r)+lv
endif
text 10,345,"But, you defend yourself against " + str$(r2) + " damage."
hp = hp + r2
endif
text 10,360,"You have " + str$(hp) + " heath remaining"
else
text 10,330,"The " + mname$ + " misses you."
endif
endif
if hp = 0 or hp < 0
text 10,400,"You have been defeated by the " + mname$ + "."
text 10,415,"You Lose"
text 10,430,"Press any key to continue"
suspend for key
end
endif
suspend for key
sync
ink 0,0
box 5,205,639,479
defend = 0
loop
endfunction
The only thing needed in there is:
...
`monster dead
if mhp = 0 or mhp < 0
text 10,400,"You have defeated the " + mname$ + "."
text 10,430,"You gain " + str$(mxp) + " experience points."
xp(0) = xp(0) + mxp
text 10,445,"Congratulations"
text 10,460,"Press any key to continue"
`check for monster deletion
if keypress$ = "up"
px = pp(1,0)/25
py = pp(1,1)/25 - 1
deletemonster(px,py)
endif
if keypress$ = "down"
px = pp(1,0)/25
py = pp(1,1)/25 + 1
deletemonster(px,py)
endif
if keypress$ = "left"
px = pp(1,0)/25 - 1
py = pp(1,1)/25
deletemonster(px,py)
endif
if keypress$ = "right"
px = pp(1,0)/25 + 1
py = pp(1,1)/25
deletemonster(px,py)
endif
...
The movement code is:
movement:
if leftkey()=1 and push = 0
if grid(gridvalue(x)-1,gridvalue(y)) = 0
ink 0,0
box x,y,x+25,y+25
x = x - 25
ink rgb(255,0,0),0
push = 1
endif
if grid(gridvalue(x)-1,gridvalue(y)) > 99 and grid(gridvalue(x)-1,gridvalue(y)) < 299
ink 0,0
x = x - 25
box x,y,x+25,y+25
ink rgb(255,0,0),0
push = 1
mlv = monsters(grid(gridvalue(x), gridvalue(y)), 1)
mhp = monsters(grid(gridvalue(x), gridvalue(y)), 2)
mxp = monsters(grid(gridvalue(x), gridvalue(y)), 3)
mn$ = monstername$(grid(gridvalue(x), gridvalue(y)))
hp = monstercombat(lv,hp,mlv,mhp,mxp,mn$,"left")
endif
if grid(gridvalue(x)-1,gridvalue(y)) > 299
getitem(grid(gridvalue(x)-1,gridvalue(y)))
endif
endif
if rightkey()=1 and push = 0
if grid(gridvalue(x)+1,gridvalue(y)) = 0
ink 0,0
box x,y,x+25,y+25
ink rgb(255,0,0),0
x = x + 25
push = 1
endif
if grid(gridvalue(x)+1,gridvalue(y)) > 99 and grid(gridvalue(x)-1,gridvalue(y)) < 299
ink 0,0
x = x + 25
box x,y,x+25,y+25
ink rgb(255,0,0),0
push = 1
mlv = monsters(grid(gridvalue(x), gridvalue(y)), 1)
mhp = monsters(grid(gridvalue(x), gridvalue(y)), 2)
mxp = monsters(grid(gridvalue(x), gridvalue(y)), 3)
mn$ = monstername$(grid(gridvalue(x), gridvalue(y)))
hp = monstercombat(lv,hp,mlv,mhp,mxp,mn$,"right")
endif
if grid(gridvalue(x)-1,gridvalue(y)) > 299
getitem(grid(gridvalue(x)-1,gridvalue(y)))
endif
endif
if downkey()=1 and push = 0
if grid(gridvalue(x),gridvalue(y)+1) = 0
ink 0,0
box x,y,x+25,y+25
ink rgb(255,0,0),0
y = y + 25
push = 1
endif
if grid(gridvalue(x),gridvalue(y)+1) > 99 and grid(gridvalue(x),gridvalue(y)+1) < 299
ink 0,0
y = y + 25
box x,y,x+25,y+25
ink rgb(255,0,0),0
push = 1
mlv = monsters(grid(gridvalue(x), gridvalue(y)), 1)
mhp = monsters(grid(gridvalue(x), gridvalue(y)), 2)
mxp = monsters(grid(gridvalue(x), gridvalue(y)), 3)
mn$ = monstername$(grid(gridvalue(x), gridvalue(y)))
hp = monstercombat(lv,hp,mlv,mhp,mxp,mn$,"down")
endif
if grid(gridvalue(x),gridvalue(y+1)) > 299
getitem(grid(gridvalue(x),gridvalue(y)+1))
endif
endif
if upkey()=1 and push = 0
if grid(gridvalue(x),gridvalue(y)-1) = 0
ink 0,0
box x,y,x+25,y+25
ink rgb(255,0,0),0
y = y - 25
push = 1
endif
if grid(gridvalue(x),gridvalue(y)-1) > 99 and grid(gridvalue(x),gridvalue(y)-1) < 299
ink 0,0
y = y - 25
box x,y,x+25,y+25
ink rgb(255,0,0),0
push = 1
mlv = monsters(grid(gridvalue(x), gridvalue(y)), 1)
mhp = monsters(grid(gridvalue(x), gridvalue(y)), 2)
mxp = monsters(grid(gridvalue(x), gridvalue(y)), 3)
mn$ = monstername$(grid(gridvalue(x), gridvalue(y)))
hp = monstercombat(lv,hp,mlv,mhp,mxp,mn$,"up")
endif
if grid(gridvalue(x)-1,gridvalue(y)) > 299
getitem(grid(gridvalue(x),gridvalue(y)-1))
endif
endif
if inkey$()="i"
ink 0,0
box 5,210,639,479
ink rgb(255,255,255),0
displayinventory()
endif
return
Basically, I have a grid system. When a monster is destroyed, the game takes the monsters coordinated on the grid and puts a black square over the monster to delete it. Then it updates the grid so that it knows that there is no monster there. The only problem is that according to the grid, there still is a monster there!
Although I know I will get no replies because of the length of my code, any help would still be much appreciated.
Thank you.
"Computers in the future may weigh no more then
1.5 tons. - Popular Mechanics, 1949