hope this gets some beginners like myself on the right track....
DBP, small bit of comments inside code, not perfect and I am sure there are better ways to accomplished things I have done. Also, might be extra do nothing code in there since this is a watered down version of my current project... GL
REM Project: rpg snippet
REM Created: 07/15/05 3:09:46 PM
REM
REM ***** Main Source File *****
REM
randomize timer()
set display mode 1280,1024,16
sync on:sync rate 60
screen_w=screen width()
screen_h=screen height()
hitbarpos=(screen_w/2)-150
stmbarpos=hitbarpos+250
`load images
`load image "texture.bmp",99
`Matrix commands
make matrix 1,500,500,100,100
randomize matrix 1,1
`prepare matrix texture 1,99,1,1
`SET MATRIX 1, 0, 0,1, 1,1, 1, 1
`Terrain via height map instead of matrix
`make terrain 1,"heightmap1.bmp"
`texture terrain 1,99
fog on
fog color 0,0,0
fog distance 250
`main player
make object box 1,.5,.5,.5
position object 1,250,1,250
`starting ambient light settings
sml_x=20
type character
maxhealth as float
mana as integer
health as integer
dmg as float
heal as float
hth as float
stm as integer
maxstm as float
burn as float
endtype
global dim player(1)as character
player(0).maxhealth=100
player(0).mana=100
player(0).health=100
player(0).dmg=0.0
player(0).heal=0.0
player(0).hth=0.0
player(0).stm=100
player(0).maxstm=100
player(0).burn=0.0
type monster
mon_maxhealth as float
mon_mana as integer
mon_health as integer
mon_dmg as float
mon_heal as float
mon_hth as float
mon_stm as integer
mon_maxstm as float
mon_burn as float
mon_barmin as integer
mon_barmax as integer
mon_barmax1 as integer
endtype
mon_1=5
global dim mon(mon_1)as monster
for m = 1 to mon_1
mon(m).mon_maxhealth=100
mon(m).mon_mana=100
mon(m).mon_health=100
mon(m).mon_dmg=0.0
mon(m).mon_heal=0.0
mon(m).mon_hth=0.0
mon(m).mon_stm=100
mon(m).mon_maxstm=100
mon(m).mon_burn=0.0
mon(m).mon_barmin=hitbarpos
mon(m).mon_barmax=mon(m).mon_barmin+200
mon(m).mon_barmax1=mon(m).mon_barmax-mon(m).mon_barmin
next m
for m1 = 2001 to 2005
make object box m1,2.5,2.75,2.5
color object m1,rnd(255)
position object m1,rnd(500),20,rnd(500)
mon_y#=get ground height(1,object position x(m1),object position z(m1))
position object m1,object position x(m1),mon_y#+20,object position z(m1)
next m1
hitbarmin=hitbarpos:stmbarmin=stmbarpos
hitbarmax=hitbarmin+220:stmbarmax#=stmbarmin+220:stmbarmax2=stmbarmax#
hitbarmax1=hitbarmax-hitbarmin:hitbar_max=hitbarmin+220
stmbarmax1=300
`controls on player
s#=.3 : `forward/backward movement speed
a#=.3 : `used for other speed settings not in this snippet
ar#=.6 :` turn speed
dist#=5 : ` distance camera behind player
height#=2: ` height above player
smooth=1 : ` smoothing value
`************************* overhead camera setup****************************
Make Camera 2
Color Backdrop 2,RGB(255,255,255)
Position camera 2,0,0,0
Point camera 2,0,0,0
Xrotate camera 2,90
Set Camera Range 2,2,500
do
fps=screen fps()
time=timer()
if ks<>0 then gosub menu
gosub playercontrols
gosub attack
gosub damage
`************* overhead camera ingame view **********************************
Set Camera View 2,1000,10,1250,260:`1000 left 10 top 1250 right 260 bottom to make square
Position camera 2,object position x(1),object position y(1)+20,object position z(1)
Point camera 2,object position x(1),object position y(1),object position z(1)
`*******************************************************************************
`*************************** player status bars *******************************
`*******************************************************************************
ink rgb(255,0,0),1
box hitbarmin,937,hitbarmax,965
ink rgb(0,0,255),0
box stmbarmin,937,stmbarmax#,965
if player(0).health>player(0).maxhealth+1
player(0).health=player(0).maxhealth
endif
if hitbarmax>hitbar_max+1
hitbarmax=hitbar_max
endif
opx#=object position x(1)
opy#=object position y(1)
opz#=object position z(1)
set ambient light sml_x
ks=scancode()
`mouse controls x,y
mx=mousex()
my=mousey()
remstart
set cursor 0,0
set text size 12
ink rgb(255,255,255),1
print "Player Movement is AWSD / Z&C for strafe style movement" ;
set cursor 0,15
print "When monster is within range (distance < 10) press left mouse to attack " ;
set cursor 0,30
print "Q key is sprint - once to turn on/ again to turn off " ;
set cursor 0,45
print "R key is auto run - once on / once off or s key " ;
set cursor 0,60
print "keystroke number "; ks
remend
print "fps "; fps
y#=get ground height(1,object position x(1),object position z(1))
position object 1,object position x(1),y#+.5,object position z(1)
set camera range 1,1500
set camera fov 45
sync
loop
menu:
`**************************************************************************
`****************** AMBIENT LIGHT SETTINGS + INC - DEC **************
`**************************************************************************
if keystate(13) then sml_x=sml_x+1
if keystate(12) then sml_x=sml_x-1
return
`*************************************************************
`************** PLAYER ATTACKING ***************************
`*************************************************************
attack:
xa#=opx#:ya#=opy#:za#=opz#
for m1 = 2001 to 2005
mon_opx#=object position x(m1)
mon_opy#=object position y(m1)
mon_opz#=object position z(m1)
xb#=mon_opx#:yb#=mon_opy#:zb#=mon_opz#
`d#=sqrt((xa#-xb#)*(xa#-xb#) + (ya#-yb#)*(ya#-yb#) + (za#-zb#)*(za#-zb#)):` distance formula
d#=sqrt((xa#-xb#)^2 + (za#-zb#)^2):` distance formula without y value consideration
if d#<100 and d#>3 then point object m1, opx#,mon_opy#,opz#
if d#<100 and d#>2 then move object m1,.1
mon_y#=get ground height(1,object position x(m1),object position z(m1)):`good code
position object m1,object position x(m1),mon_y#+2,object position z(m1):`good code
next m1
return
`************************************************************
`************* PLAYER DAMAGE ******************************
`************************************************************
damage:
item_1=PICK OBJECT(mx, my, 2, 2010)
item_1d= get pick distance()
if mouseclick()=1 and item_1d<10
mc1=2
endif
item_2=item_1
if item_2=2000 then m2=0
if item_2=2001 then m2=1
if item_2=2002 then m2=2
if item_2=2003 then m2=3
if item_2=2004 then m2=4
if item_2=2005 then m2=5
ink rgb(255,0,0),0
box mon(m2).mon_barmin,120,mon(m2).mon_barmax,140
set cursor 0,85
set text size 20
print "monster health"; mon(m2).mon_health
print "distance "; item_1d
if mc1>1 and mouseclick()=0
ph=rnd(25)
pl_hit=ph
mon(m2).mon_dmg=mon(m2).mon_barmax1/mon(m2).mon_maxhealth
monhitbardmg=(ph*mon(m2).mon_dmg)*1
mon(m2).mon_barmax=mon(m2).mon_barmax-monhitbardmg
mon(m2).mon_health =mon(m2).mon_health-ph
if mon(m2).mon_health<1
mon(m2).mon_health=0
hide object item_2
mon(m2).mon_barmin=mon(m2).mon_barmin-1
endif
mc1=0:ph=0
ma=rnd(10)
monsterattack=ma
player(0).dmg=hitbarmax1/player(0).maxhealth
hitbardmg=(monsterattack*player(0).dmg)*1
hitbarmax=hitbarmax-hitbardmg
player(0).health =player(0).health-monsterattack
if player(0).health<1 then player(0).health=0
mc1=0:ma=0
endif
return
`***************************************************************************
`********** BASIC "PLAYER" CONTROLS ***********
`***************************************************************************
playercontrols:
`******************************************************************************
`********************* HEALING POTION H KEY ******************************
`******************************************************************************
if ks=35 then heal_1=1+1
if ks<>35 and heal_1>1
player(0).heal=20
player(0).hth=hitbarmax1/player(0).maxhealth
hitbarheal=(player(0).heal*player(0).hth)*1
hitbarmax=hitbarmax+hitbarheal
player(0).health=player(0).health+player(0).heal
heal_1=0
endif
`***********************************************************************
`****************************** PLAYER MOVEMENT *********************
`***********************************************************************
if keystate(44) then move object left 1,s#
if keystate(46) then move object right 1,s#
`if mouseclick()=2 then move object 1,s#
if keystate(17) then move object 1,s#
if upkey()=1 then move object 1,s#
if keystate(31) then move object 1,-s#
if downkey()=1 then move object 1,-s#
if keystate(30) then yrotate object 1,wrapvalue(object angle y(1)-ar#)
if leftkey()=1 then yrotate object 1,wrapvalue(object angle y(1)-ar#)
if keystate(32) then yrotate object 1,wrapvalue(object angle y(1)+ar#)
if rightkey()=1 then yrotate object 1,wrapvalue(object angle y(1)+ar#)
set camera to follow object position x(1),object position y(1),object position z(1),object angle y(1),dist#,height#,smooth,0
`*****************************************************************************
`********* PLAYER SPEED BOOST/SPRINT -> Q KEY *******
`********* FASTER THAN RUNNING AND REDUCES PLAYER STAMINA *******
`*****************************************************************************
if ks=16 and player(0).stm>1
run1=1
ts = timer()
endif
if ks<>16 and run1=1
a#=1:s#=.5
stmburn#=1
player(0).burn=stmbarmax1/player(0).maxstm
stmbarburn#=(stmburn#*player(0).burn)*1
stmbarmax#=stmbarmax#-stmbarburn#/5
player(0).stm =(stmbarmax#-stmbarmin)/stmbarburn#
endif
if stmbarmax#<stmbarmin then stmbarmax# =stmbarmin
if player(0).stm<1
run1=0
endif
`*************************************************************************
`********* SECOND KEYSTROKE RETURNS SPEED TO NORMAL *******
`********* RECAPTURES LOST STAMINA *******
`*************************************************************************
if ks=16 and a#=1
run1=0
ts1 = timer()
endif
if ks<>16 and run1=0
a#=.3:s#=.3
stmburn#=1
player(0).burn=stmbarmax1/player(0).maxstm
stmbarburn#=(stmburn#*player(0).burn)*1
stmbarmax#=stmbarmax#+stmbarburn#/9
player(0).stm =(stmbarmax#-stmbarmin)/stmbarburn#
endif
if stmbarmax#>stmbarmax2
stmbarmax#=stmbarmax2
run1=2
endif
`**************************************************************************
`*************** AUTO RUN FEATURE -> R key *************
`**************************************************************************
if ks=19 and auto_run=0
auto_run=1:ar=0:ar1=1
ar_time=timer()
endif
if ks<>19 and auto_run=1
ar=1
endif
if ar=1 and auto_run=1
move object 1,s#
endif
`**************************************************************************************
`************** SECOND KEYSTROKE TURNS OFF / MOVE BACKWARDS ALSO TURNS OFF *********
`**************************************************************************************
if ks=19 and ar=1
ar1=0
ar_time1=timer()
endif
if ks<>19 and ar_time1>ar_time
auto_run=0
ar=0
endif
if ks=31 and auto_run=1
auto_run=0
endif
`*****************************************************************
`***********************mouse wheel camera ******************
`*****************************************************************
checkmw=mousemovez()
if checkmw>1
mou_wm=mou_wm-1
endif
if checkmw<-1
mou_wm=mou_wm+1
endif
dist#=mou_wm
if mou_wm<5 then mou_wm=5
if mou_wm>100 then mou_wm=100
checkmw=0
return