Hello, I am making a very simple low graphic RPG type game. I have tried several times to make this same game but always run into a problem eventually because I can not write organized code or think of better ways to create variables. Are header files good for organization? Like one header file would be monsters, one header would be items? The last time I tried to use header files I failed. Can anyone give me a few good tips on this please. Check my code out also so you can see what I am talking about, can you give me suggestions on how to create a structured/organized code.
type players
x as float
y as float
map as integer
class as integer
target as integer
inv as integer
name as string
desc as string
password as string
endtype
global dim player(100,100) as players
type npcs
x as float
y as float
size as integer
aggro as integer
quest as integer
name as string
desc as string
endtype
global dim npc(1000) as npcs
type maps
obj as integer
ext as integer
npc as integer
name as string
desc as string
endtype
global dim map(1000, 100, 5) as maps
type objects
size as integer
shape as integer
color as integer
kind as integer
weight as integer
static as integer
action as integer
name as string
desc as string
endtype
global dim object(1000) as objects
global mx# as float
global my# as float
global buttonclick as integer
remstart
START OF THE MAIN SECTION START SCREEN / MAKE PLAYER
remend
num=1 rem player number
mapnum=1 rem map number
loadvariable=0 rem load variables into memory
loadplayer=0 rem if load player = 1 then execute the load THIS WILL BE ADDED AT SOME POINT, not now
player(num).x = 100
player(num).y = 100
player(num).name = "Sid"
mx#=100
my#=100
remstart
text 0, 0, "WELCOME TO dotRPG"
set cursor 25,25
input "Account Name: ",player(num).name
set cursor 25,50
input "Class: ",player(num).class
cls
remend
sync on
sync rate 60
do
if loadvariable=0 then gosub _loadvars
cls
ink rgb (255,255,255), rgb(0,0,0)
gosub _createmap
gosub _createhud
gosub _controlplayer
sync
loop
_createmap:
line 10, 30, 400, 30 rem top
line 10, 30, 10, 300 rem left
line 400, 30, 400, 300 rem right
line 10, 300, 400, 300 rem bottom
gen=0
for i=1 to 100
if map(mapnum, i).obj>=1
gen=map(mapnum, i).obj
if object(gen).color=1 then ink rgb(255,255,255), rgb(0,0,0) rem white object
if object(gen).color=2 then ink rgb(139,69,19), rgb(0,0,0) rem brown
if object(gen).color=3 then ink rgb(0, 0, 255), rgb(0,0,0) rem blue
if object(gen).shape=1 rem SQAURE OBJECT
genx = map(mapnum, i, 1).obj
geny = map(mapnum, i, 2).obj
gensize = object(gen).size
line genx, geny, genx+gensize, geny
line genx, geny, genx, geny+gensize
line genx, geny+gensize, genx+gensize, geny+gensize
line genx+gensize, geny, genx+gensize, geny+gensize
map(mapnum, i, 3).obj=genx+gensize/2
map(mapnum, i, 4).obj=geny+gensize/2
endif
if object(gen).shape=2 rem OVAL OBJECT
ellipse map(mapnum, i, 1).obj, map(mapnum, i, 2).obj, object(gen).size, object(gen).size/2
map(mapnum, i, 3).obj=map(mapnum, i, 1).obj
map(mapnum, i, 4).obj=map(mapnum, i, 2).obj
endif
endif
next i
ink rgb(255,255,255), rgb(0,0,0)
gen=0
for i=1 to 100
if map(mapnum, i).npc>=1
gen=map(mapnum, i).npc
if npc(gen).aggro=1 then ink rgb(0,255,0), rgb(0,0,0) rem unaggro non-fight green
if npc(gen).aggro=2 then ink rgb(255,0,0), rgb(0,0,0) rem aggro red
if npc(gen).aggro=3 then ink rgb(255,255,0), rgb(0,0,0) rem unaggro fight yellow
circle map(mapnum, i, 1).npc, map(mapnum, i, 2).npc, npc(map(mapnum, i).npc).size
map(mapnum, i, 3).npc=map(mapnum, i, 1).npc
map(mapnum, i, 4).npc=map(mapnum, i, 2).npc
endif
next i
ink rgb(255,255,255), rgb(0,0,0)
return
_createhud:
makebox(410, 265, "Chat", 1)
makebox(450, 265, "Skills", 2)
makebox(505, 265, "Inventory", 3)
makebox(585, 265, "Close", 0)
rem make a chat box area
if buttonclick=1
text 410, 30, "Chat is open"
endif
rem make skills box
if buttonclick=2
text 410, 30, "Skills are open"
endif
rem make inventory/gear
if buttonclick=3
text 410, 30, "Inventory is open"
endif
rem make store frame
if buttonclick=4
endif
rem make player hp/sp area
text 0, 310, player(num).name
text text width (player(num).name)+5, 310, "HP"
text text width (player(num).name+"hp")+10, 310, "MP"
rem this is the target npc/player area
if mouseclick()=4 then player(num).target=0 : player(num, 1).target=0
if player(num).target > 0
if player(num, 1).target=1 rem a npc is being targeted
text 0, 325, npc(player(num).target).name
text text width (npc(player(num).target).name)+5, 325, "HP"
text text width (npc(player(num).target).name+"hp")+10, 325, "MP"
endif
if player(num, 1).target=2 rem a player is being targeted
text 0, 325, player(player(num).target).name
text text width (player(player(num).target).name)+5, 325, "HP"
text text width (player(player(num).target).name+"hp")+10, 325, "MP"
endif
endif
return
_controlplayer:
ink rgb(255,255,255), rgb(0,0,0)
if player(num).class=1 then ink rgb(255,0,0), rgb(0,0,0) rem color player red
circle player(num).x, player(num).y, 5
if mouseclick()=1 and mousex()<400 and mousey()<300
mx#=mousex()
my#=mousey()
endif
rem continue to move the player if they have not made it to click point.
oldx#=player(num).x
oldy#=player(num).y
if player(num).x<mx# then inc player(num).x, 1
if player(num).x>mx# then dec player(num).x, 1
if player(num).y<my# then inc player(num).y, 1
if player(num).y>my# then dec player(num).y, 1
rem check for static objects
for i=1 to 100
if map(mapnum, i).obj>=1
distx#=player(num).x-map(mapnum, i, 3).obj
disty#=player(num).y-map(mapnum, i, 4).obj
dist#=SQRT((distx#*distx#)+(disty#*disty#))
modistx#=mousex()-map(mapnum, i, 3).obj
modisty#=mousey()-map(mapnum, i, 4).obj
modist#=SQRT((modistx#*modistx#)+(modisty#*modisty#))
rem being to close to static objects
if dist#<object(map(mapnum, i).obj).size+2 and object(map(mapnum, i).obj).static=1 then player(num).x=oldx# : player(num).y=oldy#
rem scroll over
if modist#<object(map(mapnum, i).obj).size then text mousex()-15, mousey()-20, object(map(mapnum, i).obj).name
rem interact with and object
if dist#<object(map(mapnum, i).obj).size+5 and modist#<object(map(mapnum, i).obj).size and mouseclick()=1
text 0, 0, object(map(mapnum, i).obj).name+": "+object(map(mapnum, i).obj).desc
endif
rem perform action to an object, like pickup items
if dist#<object(map(mapnum, i).obj).size+5 and modist#<object(map(mapnum, i).obj).size and mouseclick()=2
if object(map(mapnum, i).obj).action>0 then gosub _itemactions
if object(map(mapnum, i).obj).action=0 then text 0, 0, "There is no action to perform here"
endif
rem targeting function
if modist#<object(map(mapnum, i).obj).size and dist#<object(map(mapnum, i).obj).size+20 and mouseclick()=4
text 0, 0, "Objects cannot be targeted!"
endif
endif
next i
rem check for npcs
for i=1 to 100
if map(mapnum, i).npc>=1
distx#=player(num).x-map(mapnum, i, 3).npc
disty#=player(num).y-map(mapnum, i, 4).npc
dist#=SQRT((distx#*distx#)+(disty#*disty#))
medistx#=mousex()-map(mapnum, i, 3).npc
medisty#=mousey()-map(mapnum, i, 4).npc
medist#=SQRT((medistx#*medistx#)+(medisty#*medisty#))
rem being to close to an npc
if dist#<npc(map(mapnum, i).npc).size+2 then player(num).x=oldx# : player(num).y=oldy#
rem scroll over
if medist#<npc(map(mapnum, i).npc).size then text mousex()-15, mousey()-20, npc(map(mapnum, i).npc).name
rem interact with and object
if dist#<npc(map(mapnum, i).npc).size+5 and medist#<npc(map(mapnum, i).npc).size and mouseclick()=1
text 0, 0, npc(map(mapnum, i).npc).name+": "+npc(map(mapnum, i).npc).desc
endif
rem perform action with an npc, this could start a fight
if dist#<npc(map(mapnum, i).npc).size+5 and medist#<npc(map(mapnum, i).npc).size and mouseclick()=2
text 0, 0, "You are performing an action"
endif
rem make a targeting function
if medist#<npc(map(mapnum, i).npc).size and dist#<npc(map(mapnum, i).npc).size+20 and mouseclick()=4
text 0, 0, "You target "+npc(map(mapnum, i).npc).name
player(num).target=map(mapnum, i).npc
player(num,1).target=1
endif
endif
next i
rem check for player
for i=1 to 100
if player(i).map=player(num).map
distx#=player(num).x-player(i).x
disty#=player(num).y-player(i).y
dist#=SQRT((distx#*distx#)+(disty#*disty#))
mpdistx#=mousex()-player(i).x
mpdisty#=mousey()-player(i).y
mpdist#=SQRT((mpdistx#*mpdistx#)+(mpdisty#*mpdisty#))
rem all players can be walked through
rem scroll over
if mpdist#<5 and i<>num then text mousex()-15, mousey()-20, player(i).name
rem interact with and object
if dist#<5 and i<>num and mouseclick()=1
text 0, 0, player(i).name+": "+player(i).desc
endif
rem perform action with an npc, this could start a fight
if dist#<5 and i<>num and mouseclick()=2
rem do level checks and other checks to see if target can be hit
endif
rem make a targeting function
if mpdist#<5 and i<>num and dist#<20 and mouseclick()=4
text 0, 0, "You target "+player(i).name
player(num).target=i
player(num,1).target=2
endif
if mpdist#<5 and i=num and mouseclick()=4
text 0, 0, "You target yourself!"
player(num).target=i
player(num,1).target=2
endif
endif
next i
rem make sure the guy stays in the map
if player(num).x>397 or player(num).x<15 or player(num).y<33 or player(num).y>297 then player(num).x=oldx# : player(num).y=oldy#
return
_loadvars:
rem maps_____maps_____maps____maps
map(1).name="Rookie Hall"
map(1).desc="The area is indoors. There seems to be a door to the north."
map(1, 1).obj=1
map(1,1,1).obj=50
map(1,1,2).obj=50
map(1, 2).obj=2
map(1,2,1).obj=200
map(1,2,2).obj=30
map(1,2,5).obj=2
map(1, 1).npc=1
map(1,1,1).npc=375
map(1,1,2).npc=275
map(2).name="Town Hall"
map(2).desc="The area is outdoors. A door is on a wall to the south."
map(2, 1).obj=2
map(2,1,1).obj=200
map(2,1,2).obj=280
map(2,1,5).obj=1
rem obj_____obj_____obj_____obj
remstart
remend
rem This object is the rookie sign. It just states that the player is in the rookie room.
object(1).size=10
object(1).shape=1
object(1).color=2
object(1).kind=1
object(1).weight=1000
object(1).static=1
object(1).name="Sign"
object(1).desc="An arrow pointing north. In bold letters the words Khronos Town is written."
object(2).size=20
object(2).shape=1
object(2).color=3
object(2).kind=1
object(2).weight=1000
object(2).static=0
object(2).name="Door"
object(2).desc="This is a door."
object(2).action=1
remstart
npc____npc____npc___npc
remend
npc(1).aggro=1
npc(1).size=5
npc(1).name="Samuel"
npc(1).desc="I need someone to hunt cows."
npc(1).quest=1
return
_itemactions:
rem enter a door/portal
if object(map(mapnum,i).obj).action=1
checker=map(mapnum, i, 5).obj
for j=1 to 100
if map(checker, j, 5).obj=mapnum
player(num).x=map(checker, j, 1).obj
player(num).y=map(checker, j, 2).obj
mx#=player(num).x
my#=player(num).y
j=100
endif
next j
mapnum=checker
endif
return
function makebox(x, y, t$, num)
if mousex()<=x+text width(t$) and mousex()>=x and mousey()<=y+text height(t$) and mousey()>y
box x,y,x+text width(t$),y+text height(t$),rgb(255,255,255),rgb(255,255,255),rgb(255,255,255),rgb(255,255,255)
ink rgb(0,0,0),rgb(255,255,255)
text x,y,t$
if mouseclick()=1 then buttonclick=num
else
box x,y,x+text width(t$),y+text height(t$),rgb(255,0,0),rgb(255,0,0),rgb(255,0,0),rgb(255,0,0)
ink rgb(0,0,0),rgb(255,0,0)
text x,y,t$
endif
ink rgb(255,255,255), rgb(0,0,0)
endfunction
function freemapobj(map, free, replace)
rem this function will be used to create an object on the map, in the mouseclick area-when clicked this space needs to be freed
endfunction
mfield