Posted: 31st Oct 2004 01:23
Here is the code [codesync : center text screen width()/2,screen height()/2,"Loading Game" : sync
sync on
sync rate 30
hide mouse
set ambient light 5
gosub gamesetup
gosub enemies:
gosub objects:
`BEGIN LOOP********************************************************************************
Do
Rem Store Object angle Y in aY#
aY# = Object angle Y(10)
Rem Control input for camera
If Downkey()=1 then Move object 10,-10
If Upkey()=1 then Move object 10,10
If Leftkey()=1 then Yrotate object 10,Wrapvalue(aY#-5)
If Rightkey()=1 then Yrotate object 10,Wrapvalue(aY#+5)
Rem Detect collision
If Object collision(10,0)>0 then position object 10,X#,26,Z#
Rem get player object position and store in X# and Z#
X# = Object position x(10)
Z# = Object position z(10)
Rem get new camera position and store in cZ# and cX#
cZ# = Newzvalue(Z#,aY#-180,100)
cX# = Newxvalue(X#,aY#-180,100)
Rem position camera
Position Camera cX#,75,cZ#
Rem point the camera at the player object
Point camera X#,70,Z#
gosub displaystats
gosub battleengine
gosub _control_gunandbullet
Sync
Loop
`END OF LOOP******************************************************************************
DisplayStats:
if controlkey()=1
if object in screen(10)
set cursor OBJECT SCREEN X(10)-30,OBJECT SCREEN Y(10)
Print "HP: ",PlrHealth
endif
endif
return
_control_gunandbullet:
rem Control gun firing
if mouseclick()=1 and bullet=-50
bullet=100
position object BulletObj,camera position x(0),camera position y(0),camera position z(0)
rotate object BulletObj,camera angle x(0),camera angle y(0),0
set bsp object collision 2,19,0.1,1
move object BulletObj,0.2
rem *ADDCODE* TUT9B
endif
rem Control life of bullet
if bullet>0
rem If bullet collides with BSP world
if object collision (BulletObj,0) or bulletimpact=1
rem End bullet on wall
bulletimpact=0
bullet=0
else
rem Move bullet
dec bullet
move object BulletObj,0.5
endif
rem Bullet dies
if bullet=0
rem *ADDCODE* TUT9D
set object collision off 2
endif
else
rem Gun recharge phase
if bullet>-50 then dec bullet
endif
return
gamesetup:
PlrHealth=100
return
enemies:
make object cube 2,50
scale object 2,300,300,300
position object 2,100,0,300
Set object collision to boxes 2
return
battleengine:
if object collision (2,10) = 1 then
if spacekey()=1 then
killenemy=1
if killenemy=1
set object collision off 2
hide object 2
killenemy=0
endif
return
objects:
Rem Make sphere
make object sphere 10,50
Position object 10,-100,26,-100
Set object collision to spheres 10
`World
BulletObj=3 : make object cube BulletObj,1
`Land
make object plain 100,10000,10000
xrotate object 100,270
`Water
make object plain 101,20000,20000
xrotate object 101,270
position object 101,0,-100,0
`Texture ground
for x=1 to 32
for y=1 to 32
dot x, y, rgb(0,100+rnd(155),0)
next y
next x
get image 1,1,1,32,32
texture object 100,1
SCALE OBJECT TEXTURE 100, 20, 20
`Texture water
for x=1 to 32
for y=1 to 32
dot x, y, rgb(0,0,100+rnd(155))
next y
next x
get image 2,1,1,32,32
texture object 101,2
SCALE OBJECT TEXTURE 101, 10, 10
return
There are a few problems with the bullet that I cant fix. The first is the bullet appears behind the character and the second is it seems to move with the camera after its stopped moving eg. when you turn it moves with the camera. If somebody can fix it i would be greatful.