Third person shooters were allowed, so I'll make a third person shooter:
`*********************************
`Shooter
`*********************************
`Setup
sync on : sync rate 80
hide mouse
`Create player
gosub CreatePlayer
`Create World
gosub CreateWorld
`vars
type Plr
id as integer
health as integer
power as integer
aph as integer
`animation phase(used for getting the point of animation)
Move as float
Run as float
WeaponDrawed as integer
maxdelay as integer
delay as integer
endtype
dim Player(1) as Plr
Player(1).id = 1
Player(1).aph = 0
Player(1).Move = 0.4
Player(1).Run = 0.5
Player(1).maxdelay = 25
Player(1).WeaponDrawed = 1
angx# = 0.0
angy# = 0.0
id = 1
`Create a vector for checking distances
r = make vector3(1)
do
`Control player
angx# = wrapvalue(angx# + (mousemovey()*0.2))
if wrapvalue(angx#-180) > 260.0
angx# = 80.0
else
if wrapvalue(angx#-180) < 150 then angx# = 330
endif
angy# = wrapvalue(angy# + (mousemovex()*0.2))
if upkey() = 1 then move = 1 else move = 0
if downkey() = 1 then back = 1 else back = 0
if leftkey() = 1 then left = 1 else left = 0
if rightkey() = 1 then right = 1 else right = 0
if controlkey() = 1 and hold = 0
hold = 1
Player(1).WeaponDrawed = abs(Player(1).WeaponDrawed-1)
endif
if mouseclick() = 1 then shoot = 1 else shoot = 0
ControlPlayer(1, angx#, angy#, move, back, left, right, shoot)
`Camera
CamBehind(1, 20.0, angx#, angy#)
`control all bullets
for b = 1 to bulletQuant
if Bullet(b) > 0
move object bulletStart + b, 1
dec Bullet(b)
if Bullet(b) = 0 then hide object bulletStart + b
endif
next b
if controlkey() = 0 then hold = 0
sync
loop
`*** Create player ***
CreatePlayer:
`create player
make object box 1,2,3,1
make object sphere 2,1.5
make mesh from object 1,2
delete object 2
add limb 1,1,1
link limb 1,0,1
offset limb 1,1,0,2.5,0
delete mesh 1
`make arms
make object box 2,0.5,1.5,0.5
offset limb 2,0,0,-0.75,0
make mesh from object 1,2
`left arm
add limb 1,2,1
add limb 1,3,1
link limb 1,2,3
offset limb 1,3,0,-1.5,0
offset limb 1,2,1.25,1.5,0
`right arm
add limb 1,4,1
add limb 1,5,1
link limb 1,4,5
offset limb 1,5,0,-1.5,0
offset limb 1,4,-1.25,1.5,0
`make legs
`left leg
add limb 1,6,1
add limb 1,7,1
link limb 1,6,7
offset limb 1,7,0,-1.5,0
offset limb 1,6,-0.5,-1,0
`right leg
add limb 1,8,1
add limb 1,9,1
link limb 1,8,9
offset limb 1,9,0,-1.5,0
offset limb 1,8,0.5,-1,0
`clean up
delete object 2
delete mesh 1
return
CreateWorld:
`Create world
make matrix 1,1000,1000,50,50
randomize matrix 1,10
CreateGrassTex(1,256,256)
prepare matrix texture 1,1,1,1
update matrix 1
`make bullets
#constant bulletStart = 1000
#constant bulletQuant = 500
global currentBullet
dim Bullet(bulletQuant)
for i = 1 to bulletQuant
make object cylinder bulletStart + i, 30
xrotate object bulletStart + i, 90 : fix object pivot bulletStart + i
scale object bulletStart + i, 1, 30, 1
hide object bulletStart + i
next i
return
`************************************
`Function
`************************************
function ControlPlayer(id, angx#, angy#, move, back, left, right, shoot)
`Extract data
obj = Player(id).id
posx# = object position x(obj)
posy# = object position y(obj)
posz# = object position z(obj)
Weapon = Player(id).WeaponDrawed
`animate character
animate(obj)
`Control player
`move the player
if Weapon = 1
move# = Player(id).Move
rotate limb obj,2,wrapvalue(angx#-90),0,0
rotate limb obj,3, 0, 0, 0
else
move# = Player(id).Run
endif
if move = 1 and left+right = 0
posx# = newxvalue(posx#, angy#, move#)
posz# = newzvalue(posz#, angy#, move#)
endif
if back = 1 and left+right = 0
posx# = newxvalue(posx#, angy#, -move#)
posz# = newzvalue(posz#, angy#, -move#)
endif
if left = 1
yrotate object obj, wrapvalue(angy# - 90)
if Weapon > 0
rotate limb obj,2, wrapvalue(angx#-90), 90, 0
rotate limb obj,3, 0, 0, 0
endif
posx# = newxvalue(posx#, wrapvalue(angy# - 90), move#)
posz# = newzvalue(posz#, wrapvalue(angy# - 90), move#)
endif
if right = 1
yrotate object obj, wrapvalue(angy# + 90)
if Weapon > 0
rotate limb obj,2, -90,0,-10
rotate limb obj,3, wrapvalue(angx#), 0, -90
endif
posx# = newxvalue(posx#, wrapvalue(angy# + 90), move#)
posz# = newzvalue(posz#, wrapvalue(angy# + 90), move#)
endif
`animate
if left + right + move + back > 0
if Player(id).aph <= 2 then Player(id).aph = 3
else
if Player(id).aph > 2 then Player(id).aph = 0
endif
`Shooting
if Weapon > 0
if Player(id).delay > 0 then dec Player(id).delay
if shoot > 0 and Player(id).delay = 0
Player(id).delay = Player(id).maxdelay
inc currentBullet
if currentBullet > bulletQuant then currentBullet = 1
position object bulletStart + currentBullet, limb position x(obj,2), limb position y(obj,2), limb position z(obj,2)
rotate object bulletStart + currentBullet, angx#, angy#, 0
show object bulletStart + currentBullet
Bullet(currentBullet) = 150
endif
endif
`calculate height
posy# = get ground height(1, posx#, posz#) + 4
`update player
position object obj, posx#, posy#, posz#
if left + right = 0
yrotate object obj, angy#
endif
endfunction
function animate(id)
obj = Player(id).id
Phase = Player(id).aph
`Animate character
if Phase <= 2
select Phase
case 0
`reset body
for i = 1 to 8
rotate limb obj,i,0,0,0
next i
Player(id).aph = 1
endcase
case 1
pass = 0
if wrapvalue(limb angle x(obj,6)+180)>150
rotate limb obj,6,wrapvalue(limb angle x(obj,6)-0.1),0,0
rotate limb obj,7,wrapvalue(360-limb angle x(obj,6)),0,0
else
pass=1
endif
if wrapvalue(limb angle x(obj,8)+180)>150
rotate limb obj,8,wrapvalue(limb angle x(obj,8)-0.1),0,0
rotate limb obj,9,wrapvalue(360-limb angle x(obj,8)),0,0
else
pass=1
endif
if pass = 1 then Player(id).aph = 2
rotate limb obj,0,wrapvalue(90 - (limb angle x(obj,6)/4)),0,0
endcase
case 2
pass = 0
if wrapvalue(limb angle x(obj,6)+180)<180
rotate limb obj,6,wrapvalue(limb angle x(obj,6)+0.1),0,0
rotate limb obj,7,wrapvalue(360-limb angle x(obj,6)),0,0
else
pass=1
endif
if wrapvalue(limb angle x(obj,8)+180)<180
rotate limb obj,8,wrapvalue(limb angle x(obj,8)+0.1),0,0
rotate limb obj,9,wrapvalue(360-limb angle x(obj,8)),0,0
else
pass=1
endif
if pass = 1 then Player(id).aph = 1
rotate limb obj,0,wrapvalue(90 - (limb angle x(obj,6)/4)),0,0
endcase
endselect
rotate limb obj,2,0,0,0 : rotate limb obj,3,0,0,0
rotate limb obj,4,0,0,0 : rotate limb obj,5,0,0,0
endif
if Phase>2 and Phase<=5
select Phase
case 3
`reset body
for i = 1 to 8
rotate limb obj,i,0,0,0
next i
Player(id).aph = 4
endcase
case 4
pass = 0
if wrapvalue(limb angle x(obj, 6)-180) < 210
rotate limb obj,6,wrapvalue(limb angle x(obj,6)+2),0,0
rotate limb obj,7,wrapvalue(30 - limb angle x(obj,6)),0,0
else
pass = 1
endif
if wrapvalue(limb angle x(obj, 8)-180) > 150
rotate limb obj,8,wrapvalue(limb angle x(obj,8)-2),0,0
rotate limb obj,9,wrapvalue(30-limb angle x(obj,8)),0,0
else
pass = 1
endif
if pass = 1 then Player(id).aph = 5
endcase
case 5
pass = 0
if wrapvalue(limb angle x(obj,6)-180) > 150
rotate limb obj,6,wrapvalue(limb angle x(obj,6)-2),0,0
rotate limb obj,7,wrapvalue(30-limb angle x(obj,6)),0,0
else
pass = 1
endif
if wrapvalue(limb angle x(obj,8)-180) < 210
rotate limb obj,8,wrapvalue(limb angle x(obj,8)+2),0,0
rotate limb obj,9,wrapvalue(30-limb angle x(obj,8)),0,0
else
pass = 1
endif
if pass = 1 then Player(id).aph = 4
endcase
endselect
rotate limb obj,2, limb angle x(obj,8),0,0
rotate limb obj,4, limb angle x(obj,6),0,0
rotate limb obj,3, -100,0,0
rotate limb obj,5, -100,0,0
endif
endfunction
function CamBehind(obj, Dist#, angx#, angy#)
`get position data
posx# = object position x(obj)
posy# = object position y(obj) + 3.5
posz# = object position z(obj)
angy# = wrapvalue(angy#-180)
`work out the camera position
camx# = newxvalue(posx#, angy#, cos(angx#)*Dist#)
camz# = newzvalue(posz#, angy#, cos(angx#)*Dist#)
camy# = posy# + (sin(angx#)*Dist#)
`smoothen up
camx# = curvevalue(camx#, camera position x(), 15)
camy# = curvevalue(camy#, camera position y(), 15)
camz# = curvevalue(camz#, camera position z(), 15)
`collision with ground
if camy# < get ground height(1, camx#, camz#)+1
distance# = sqrt(Dist#^2 - (posy#-get ground height(1,posx#,posz#))^2)
camx# = newxvalue(posx#, angy#, distance#)
camz# = newzvalue(posz#, angy#, distance#)
camy# = get ground height(1, camx#, camz#)+1
endif
`update camera
position camera camx#,camy#,camz#
point camera posx#,posy#,posz#
endfunction
function CreateGrassTex(nr, Width, Height)
`create a memblock
make memblock nr, 12 + (Width*Height*4)
`write header
write memblock DWORD nr,0, Width
write memblock DWORD nr,4, Height
write memblock DWORD nr,8, 32
`write data
for i = 1 to (Width*Height)
green = 50 + rnd(55)
write memblock byte nr, 12 + ((i-1)*4), 0
write memblock byte nr, 13 + ((i-1)*4), green
write memblock byte nr, 14 + ((i-1)*4), 0
write memblock byte nr, 15 + ((i-1)*4), 255
next i
`create an image from the memblock and delete memblock
make image from memblock nr,nr
delete memblock nr
endfunction
arrow keys to move/strafe. mouse to rotate.
controlkey to draw weapon or put it away. (When you put away your weapon, you can run faster).
Enemies not added yet.
It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.