hey
when i started out this annoyed me a lot so thought i would post a little snippet for people who are having same problem. hope it helps!!
control using arrow keys and return key when hit object
kR
`basic seup code
sync on
sync rate 30
set display mode 800,600,32
hide mouse
`make an array for each keyboard key
dim key(250) : dim oldkey(250)
`player object
make object cube 1,20
set object collision to polygons 1
`NPC
make object cylinder 2,50
position object 2,200,0,200
set object collision to polygons 1
`variable for collision detec
coll=0
`var for stopping movememnt when talk box is up
nomove=0
`start loop
do
`for/next loop to store number for each key
for a = 1 to 250
if key(a) = 1 then oldkey(a) = 1
if keystate(a) = 1 and oldkey(a) = 0 : key(a) = 1 : else : key(a) = 0 : endif
if keystate(a) = 0 then oldkey(a) = 0
next a
`stores angle of object 1
aY#= object angle y(1)
`if up etc is pressed and box os gone move: nomove is on when talk box is up
if Upkey()=1 and nomove=0
XTest# = Newxvalue(X#,aY#,20)
ZTest# = Newzvalue(Z#,aY#,20)
Move object 1,10
endif
if Downkey()=1 and nomove=0
XTest# = Newxvalue(X#,aY#,20)
ZTest# = Newzvalue(Z#,aY#,20)
Move object 1,-6
endif
If Leftkey()=1 and nomove=0
Yrotate object 1,Wrapvalue(aY#-10)
Endif
If Rightkey()=1 and nomove=0
Yrotate object 1,Wrapvalue(aY#+10)
Endif
`simple collision between obj 1 and 2
If Object collision(1,2)>0
`stop walking thru object
Position object 1,X#,0,Z#
`increments var 'col'
inc coll
Endif
`when coll is greter than 0 and returnkey is 1 then goto var selectt
if coll>0 and key(28)=1 then selectt=1
`the var selectt is the talk box, just 2 layers of 2D boxes
if selectt = 1
`b=1 is to make selections work smothly (is just b cos i felt like it)
b=1
` coll=0
nomove=1
ink rgb(255,255,255),0
box 100,100,425,250
ink rgb(0,0,128),0
box 102,102,423,248
ink rgb(255,255,255),0
text 120,120,"u alright?"
ink rgb(255,255,255),0
text 150,150,"Yes"
ink rgb(128,128,128),0
text 150,170,"No"
endif
if selectt = 2
b=1
` coll=0
nomove=1
ink rgb(255,255,255),0
box 100,100,425,250
ink rgb(0,0,128),0
box 102,102,423,248
ink rgb(255,255,255),0
text 120,120,"u alright?"
ink rgb(128,128,128),0
text 150,150,"Yes"
ink rgb(255,255,255),0
text 150,170,"No"
endif
` up and down key selections
`downkeys
if key(208) and b=1
inc selectt,1
if selectt > 2 then selectt = 2
endif
`upkeys
if key(200) and b=1
dec selectt,1
if selectt < 1 then selectt = 1
endif
`kill movement if box is up (nomove)
if Upkey()=1 and nomove=1
XTest# = Newxvalue(X#,aY#,0)
ZTest# = Newzvalue(Z#,aY#,0)
` Move object 1,0
endif
if Downkey()=1 and nomove=1
XTest# = Newxvalue(X#,aY#,0)
ZTest# = Newzvalue(Z#,aY#,0)
` Move object 1,0
endif
If Leftkey()=1 and nomove=1
Yrotate object 1,Wrapvalue(aY#-0)
Endif
If Rightkey()=1 and nomove=1
Yrotate object 1,Wrapvalue(aY#+0)
Endif
`the below controls what happens when yes/no is selected
`key(28) is another way or writing returnkey(), used as works for one press with the for/next at top
`happens if yes is selelcted
if selectt=1 and key(28)=1
b=0
`[insert extra code, new box, event, whatever]
`making the below 0 will turn boxes off and bring movement back
nomove=0
selectt=0
endif
`switches everyhting off if no pressed
if selectt=2 and key(28)=1
b=0
nomove=0
selectt=0
endif
` store cylinder positions
X2# = object position x(2)
Y2# = object position y(2)
Z2# = object position z(2)
`this formula monitors distance from the cylinder - standard distance formula not as scary as it looks
dist# = sqrt((X#-X2#)^2+(Y#-Y2#)^2+(Z#-Z2#)^2)
`if the distance is greater than 50 then coll is 0, so if u hit object and walk away and press enter box doesnt show up
if dist#>60 then coll=0
`debug - displays distance and value of coll for debug purposes
ink rgb(255,255,255),0
text 50,50,str$(coll)
text 50,80,str$(dist#)
`camera stuff
cZ# = Newzvalue(Z#,aY#-180,100)
cX# = Newxvalue(X#,aY#-180,100)
Position Camera cX#,75,cZ#
`object 1 position
X# = Object position x(1)
Z# = Object position z(1)
Point camera X#,50,Z#
Rem Refresh Screen
Sync
loop
kR