`RPG Snippet
autocam off
sync on:sync rate 0
color backdrop rgb(50,50,255)
ink rgb(0,0,0),rgb(0,0,0)
randomize timer()
global StartMenuObject as integer
StartMenuObject=65500
do
rotate camera curveangle(0,camera angle x(),50),curveangle(0,camera angle y(),50),0
if wrapvalue(camera angle x())<0.5 and wrapvalue(camera angle y())<0.5
rotate camera 0,0,0
exit
endif
sync
loop
MaxObject=2
for o=1 to MaxObject
make object plain o+StartMenuObject,50,10
position object o+StartMenuObject,camera position x(),camera position y(),camera position z()+100
disable object zdepth o+StartMenuObject
for r=0 to o-1
if r>0
xrotate object o+StartMenuObject,wrapvalue(object angle x(o+StartMenuObject)+15)
move object down o+StartMenuObject,15
endif
next r
next o
Selected=1
do
if downkey()=1 and Move=0
Selected=Selected+1
if Selected>MaxObject
Selected=MaxObject
else
Move=150
endif
endif
if upkey()=1 and Move=0
Selected=Selected-1
if Selected<1
Selected=1
else
Move=-150
endif
endif
if Move>0
dec Move
for o=1 to MaxObject
xrotate object o+StartMenuObject,wrapvalue(object angle x(o+StartMenuObject)-0.1)
move object up o+StartMenuObject,0.1
next o
endif
if Move<0
inc Move
for o=1 to MaxObject
xrotate object o+StartMenuObject,wrapvalue(object angle x(o+StartMenuObject)+0.1)
move object down o+StartMenuObject,0.1
next o
endif
if returnkey()=1
exit
endif
if keystate(25)=1
exit
Selected=100
endif
sync
loop
for o=1 to MaxObject
delete object o+StartMenuObject
next o
if Selected=2
end
endif
Fog on
Fog distance 15000
Fog Color RGB(100,250,0)
`Light Crap
Set ambient light 70
Color ambient light RGB(200,0,50)
`Set font settings
Set text font "Arial"
Set text size 16
Set text to bold
RemStart
Change this value to change the chance of the enemy casting
magic. Make it bigger to lower the chance and vice versa.
RemEnd
global ChanceOfCast as integer
ChanceOfCast=100
`Set up Map
Make Camera 1
Color Backdrop 1,RGB(10,100,0)
Position camera 1,0,0,0
Point camera 1,0,0,0
Xrotate camera 1,90
Set Camera Range 1,1,50000
`Make Lights
Make light 1
Color Light 1,RGB(250,100,50)
`Load Temple
Make object cone 5,50
Position Object 5,2000,10,500
Scale Object 5,2.5,2.5,2.5
`Enemies
dim key(256)
type enem
health as integer
startx as integer
startz as integer
endx as integer
endz as integer
move as integer
scale as integer
cast as integer
damage as integer
showdamage as integer
endtype
dim enemy(100) as enem
make object box 9,10000,5,10000
move object down 9,5
for a=10 to 100
make object sphere a,3,6,6
position object a,rnd(1000),0,rnd(1000)
color object a,rgb(0,0,200)
enemy(a).health=100
enemy(a).startx=object position x(a)
enemy(a).startz=object position z(a)
enemy(a).endx=object position x(a)+rnd(60)
enemy(a).endz=object position z(a)+rnd(60)
enemy(a).scale=100
make object sphere a+100,3,6,6
texture object a+100,3
ghost object on a+100
hide object a+100
next a
make object cube 1,1.5
Color object 1,RGB(150,200,10)
make object cube 3,1.5
Color object 3,RGB(150,200,100)
make object cube 4,1.5
Color object 4,RGB(100,200,10)
playerhealth=100
maxplayerhealth = 100
playerexperience=0
playerlevel=1
playerdamage=0
playershowdamage=0
playershowlevel=0
make object box 2,.2,.2,2.5
color object 2,rgb(20,0,0)
hide object 2
offset limb 2,0,0,0,2
`Magic Blast
Make object sphere 6,.5,.5,.5
color object 6,RGB(20,20,200)
Hide object 6
`Katars
Make object cone 7,.5
xrotate object 7,90
Fix object pivot 7
color object 7,RGB(200,20,200)
Hide object 7
Make object cone 8,.5
xrotate object 8,90
Fix object pivot 8
color object 8,RGB(200,20,200)
Hide object 8
`End Characters
set global collision on
sync on
sync rate 60
do
`Go to menu
if keystate(25)=1
gosub Menu
endif
`Ally Positions
Position object 3,object position x(1),object position y(1),object position z(1)-10
Position object 4,object position x(1),object position y(1),object position z(3)-10
`Light Settings
Position light 1,object position X(1),object position Y(1),object position z(1)
Point light 1,object position X(1),object position Y(1),object position z(1)
`Gosubs
Gosub huds
Gosub info
Gosub Controls
Gosub Stats
Gosub Slidecollision
`Enemy AI
for a=10 to 100
if object exist(a)=1
if enemy(a).cast=0 and distance(1,a)<50 and attack>0 and attack<8 then move object a,-1
if distance(1,a)>50
enemy(a).cast=0
hide object a+100
scale object a+100,100,100,100
patrol(a)
else
if enemy(a).cast=0
set object collision off a+100
point object a,object position x(1),0,object position z(1)
move object a,.5
if object collision(a,1)=1
playerhealth=playerhealth-5
playerdamage=-5
playershowdamage=50
move object a,-15
endif
testforcast=0
if distance(1,a)<50
testforcast=rnd(ChanceOfCast)
endif
if testforcast=3
enemy(a).cast=100
show object a+100
set object collision on a+100
endif
endif
if enemy(a).cast>0
enemy(a).cast=enemy(a).cast+3
scale object a+100,enemy(a).cast,enemy(a).cast,enemy(a).cast
if object collision(a+100,1)=1
playerdamage=-1
playershowdamage=50
playerhealth=playerhealth-1
endif
endif
if enemy(a).cast>500
enemy(a).cast=0
hide object a+100
endif
endif
position object a+100,object position x(a),object position y(a)-1.5,object position z(a)
endif
next a
position camera object position x(1),object position y(1)+5,object position z(1)-10
point camera object position x(1),object position y(1),object position z(1)
sync
loop
`Gosubs
Huds:
`This gosub deals with the huds and leveling up
`Paste image 1,5,360,1
ink rgb(200,0,0),0
box 146,385,146+(playerhealth*1.567),405
ink rgb(0,255,0),0
box 146,435,146+(playerexperience*1.564),455
if playerhealth<1
playerhealth=0
endif
if playerexperience>100
playerexperience=0
playerlevel=playerlevel+1
playershowlevel=50
maxplayerhealth = maxplayerhealth + (10 * Playerlevel)
playerhealth = maxplayerhealth
endif
ink rgb(0,0,0),0
text 216,365,str$(playerlevel)
`Map
Set Camera View 1,375,365,495,470
Position camera 1,object position x(1),object position y(1)+80,object position z(1)
Point camera 1,object position x(1),object position y(1),object position z(1)
Return
Info:
Ink RGB(0,0,0),0
Text 5,5,"Fps: " +STR$(Screen FPS())
Return
Controls:
up=0
down=0
right=0
left=0
if keystate(17)=1 then up=1
if keystate(31)=1 then down=1
if keystate(32)=1 then right=1
if keystate(30)=1 then left=1
if up=1 and left=0 and right=0 and down=0
OldAng=object angle y(1)
TargetAng=0
yrotate object 1,TargetAng
move object 1,1
yrotate object 1,OldAng
endif
if up=1 and left=1 and right=0 and down=0
OldAng=object angle y(1)
TargetAng=315
yrotate object 1,TargetAng
move object 1,1
yrotate object 1,OldAng
endif
if up=1 and left=0 and right=1 and down=0
OldAng=object angle y(1)
TargetAng=45
yrotate object 1,TargetAng
move object 1,1
yrotate object 1,OldAng
endif
if up=0 and left=1 and right=0 and down=0
OldAng=object angle y(1)
TargetAng=270
yrotate object 1,TargetAng
move object 1,1
yrotate object 1,OldAng
endif
if up=0 and left=0 and right=1 and down=0
OldAng=object angle y(1)
TargetAng=90
yrotate object 1,TargetAng
move object 1,1
yrotate object 1,OldAng
endif
if up=0 and left=0 and right=0 and down=1
OldAng=object angle y(1)
TargetAng=180
yrotate object 1,TargetAng
move object 1,1
yrotate object 1,OldAng
endif
if up=0 and left=0 and right=1 and down=1
OldAng=object angle y(1)
TargetAng=135
yrotate object 1,TargetAng
move object 1,1
yrotate object 1,OldAng
endif
if up=0 and left=1 and right=0 and down=1
OldAng=object angle y(1)
TargetAng=215
yrotate object 1,TargetAng
move object 1,1
yrotate object 1,OldAng
endif
yrotate object 1,curveangle(TargetAng,object angle y(1),5)
`Combat Controls
if keyready(57)=1 and attack=0
rotate object 2,object angle x(1),object angle y(1)-70,object angle z(1)
attack=16
show object 2
endif
if attack>0
attack=attack-1
position object 2,object position x(1),0,object position z(1)
yrotate object 2,object angle y(2)+10
for a=10 to 100
if object exist(a)=1
if object collision(2,a)=1
playerexperience=playerexperience+rnd(playerlevel*2.5)
enemy(a).damage=0-playerlevel*10
enemy(a).showdamage=50
enemy(a).health=enemy(a).health-playerlevel*8
move object a,-playerlevel*5
enemy(a).scale=enemy(a).scale-playerlevel*5
enemy(a).cast=0
hide object a+100
endif
if enemy(a).health<10 then delete object a : delete object a+100
endif
next a
endif
if attack=1 then hide object 2
Return
Stats:
ink rgb(255,200,0),0
if playershowlevel>0
center text object screen x(1),object screen y(1)-200+(playershowlevel*4),str$(playerlevel)
playershowlevel=playershowlevel-1
endif
ink rgb(200,0,0),0
if playershowdamage>0
center text object screen x(1),object screen y(1)-100+(playershowdamage*2),str$(playerdamage)
playershowdamage=playershowdamage-1
endif
ink rgb(255,255,255),0
for a=10 to 100
if object exist(a)=1 and enemy(a).showdamage>0
center text object screen x(a),object screen y(a)-100+(enemy(a).showdamage*2),str$(enemy(a).damage)
enemy(a).showdamage=enemy(a).showdamage-1
endif
next a
for a = 10 to 100
If Object Exist(a)
if distance(1,a) <100
Ink RGB(0,0,0),0
Box Object Screen X(a),Object screen Y(a),Object Screen X(a)+50,Object Screen Y(a)+10
Ink RGB(100,0,0),0
Box Object Screen X(a)+1,Object screen Y(a)+1,Object Screen X(a)+(enemy(a).health/2)-1,Object Screen Y(a)+9
Endif
Endif
Next a
Return
SlideCollision:
col_dist=2
for i=1 to 200
if object exist(i)=1
maxtemp#=0
for j=0 to 360 step 45
temp#=intersect object (i,tempx#,2,tempz#,newxvalue(tempx#,j,col_dist),2,newzvalue(tempz#,j,col_dist))
if temp#>maxtemp#
maxtemp#=temp#
maxangle#=j
endif
next j
if maxtemp#>0
tempx#=newxvalue(object position x(1),maxangle#,maxtemp#-col_dist)
tempz#=newzvalue(object position z(1),maxangle#,maxtemp#-col_dist)
endif
endif
next i
Return
`Functions
function patrol(object)
if threeD_distance(object position x(object),enemy(object).endx,0,0,object position z(object),enemy(object).endz)<2 then enemy(object).move=1
if threeD_distance(object position x(object),enemy(object).startx,0,0,object position z(object),enemy(object).startz)<2 then enemy(object).move=0
if enemy(object).move=0
point object object,enemy(object).endx,0,enemy(object).endz
move object object,1
endif
if enemy(object).move=1
point object object,enemy(object).startx,0,enemy(object).startz
move object object,1
endif
endfunction
function distance(obj1,obj2)
dist=sqrt(((object position x(obj1)-object position x(obj2))*(object position x(obj1)-object position x(obj2)))+((object position z(obj1)-object position z(obj2))*(object position z(obj1)-object position z(obj2))))
endfunction dist
FUNCTION threeD_distance(x1# AS float, x2# AS float, y1# AS float, y2# AS float, z1# AS float, z2# AS float)
temp = 1
null = make vector3(temp)
set vector3 temp, x1# - x2#, y1# - y2#, z1# - z2#
length_vector = abs(length vector3(temp))
null = delete vector3(temp)
ENDFUNCTION length_vector
function keyready(keyz)
vl=0
if keystate(keyz)=1 and key(keyz) = 0
key(keyz) = 1
vl=1
endif
if keystate(keyz)=0
key(keyz) = 0
vl = 0
endif
endfunction vl
Menu:
autocam off
sync on
sync rate 0
do
if keystate(25)=0
exit
endif
loop
do
rotate camera curveangle(0,camera angle x(),50),curveangle(0,camera angle y(),50),0
if wrapvalue(camera angle x())<0.5 and wrapvalue(camera angle y())<0.5
rotate camera 0,0,0
exit
endif
sync
loop
MaxObject=2
for o=1 to MaxObject
make object plain o+StartMenuObject,50,10
position object o+StartMenuObject,camera position x(),camera position y(),camera position z()+100
disable object zdepth o+StartMenuObject
for r=0 to o-1
if r>0
xrotate object o+StartMenuObject,wrapvalue(object angle x(o+StartMenuObject)+15)
move object down o+StartMenuObject,15
endif
next r
next o
Selected=1
do
if downkey()=1 and Move=0
Selected=Selected+1
if Selected>MaxObject
Selected=MaxObject
else
Move=150
endif
endif
if upkey()=1 and Move=0
Selected=Selected-1
if Selected<1
Selected=1
else
Move=-150
endif
endif
if Move>0
dec Move
for o=1 to MaxObject
xrotate object o+StartMenuObject,wrapvalue(object angle x(o+StartMenuObject)-0.1)
move object up o+StartMenuObject,0.1
next o
endif
if Move<0
inc Move
for o=1 to MaxObject
xrotate object o+StartMenuObject,wrapvalue(object angle x(o+StartMenuObject)+0.1)
move object down o+StartMenuObject,0.1
next o
endif
if returnkey()=1
exit
endif
if keystate(25)=1
exit
Selected=100
endif
sync
loop
for o=1 to MaxObject
delete object o+StartMenuObject
next o
if Selected=2
end
endif
do
if keystate(25)=0
exit
endif
loop
sync on
sync rate 60
return
There you go. On the first menu, option 1 is start and option 2 is quit. If you press 'P' then the in game menu will appear. Press 'P' again and it will close. Option 1 is continue and option 2 is quit. The integer 'StartMenuObject' is the object ID to start making the menu objects from.