On working on earlier versions of this game in devolpment, I have found that useing object collision is way to laggy for my game, so i decided to compare object positioning as an alternative which just takes the objects current area and compares it to opposing objects. Alhough my bullet area comparision works without failure, when I try to use it for monster detection (instead of deleting object it just moves object 20 because its alreay pointing in proper place), All the objects come wether there in the right place or not or none come at all regardless of there positioning. Any helpful hints or creative solutions?
Bullet Area Comparision
if BulletLife>0
if object position x(502)-200=<object position x(c)
if object position x(502)+200=>object position x(c)
if object position z(502)-200=<object position z(c)
if object position z(502)+200=>object position z(c)
BulletExplode=3
delete object c
return
endif
endif
endif
endif
endif
Whole Code
REMSTART
CREDITS TO
TDK_MAN(MatEdit Program)
Lee Bamber for code examples
Ali M(MatEdit refernce and explaination)
REMEND
Rem Set screen size
set display mode 800,600,16
Rem Load map
#include "LoadMatrix.dba"
Dim BigMatrix(600,600,1)
Dim StartLoc_X(1): Dim StartLoc_Z(1):Dim Info(2)
Dim TArrayX(1): Dim TArrayZ(1): Dim FKey(10,1)
Dim ColData(100): Dim ZoneData(100): Dim Tiles(500,500)
Dim OverTexture$(100): Dim OverName$(20): Dim ReplaceTex(100)
Dim MOffsetX(25): Dim MOffsetY(25)
Dim MWire(20): Dim MGhost(20): Dim Lock(20)
Dim MatX#(20): Dim MatY#(20): Dim MatZ#(20)
Dim MatWidth#(20): Dim MatHeight#(20)
Dim TilesX(20): Dim TilesZ(20)
Dim MatHi#(20): Dim MatLo#(20)
Rem The following line loads the matrix
Success=LoadMatrix("CHRISTMAS HILLS",1)
If Success=1
autocam off
Set Camera Range 1.0, 900000.0
load image "sky.bmp",100
load image "..\Images\Fire.BMP",2
Rem Load the objects onto the matrix
open to read 1,"pform.ara"
nextplant:
s$=""
filepath$=""
read string 1, s$: objnum=val(s$)
read string 1, s$: filepath$=s$
read string 1, s$: xval=val(s$)
read string 1, s$: zval=val(s$)
read string 1, s$: orot=val(s$)
load object filepath$,objnum
scale object objnum,100000,100000,100000
position object objnum,xval,get ground height(1,xval,zval),zval
yrotate object objnum,orot
read string 1, s$
if s$ = "~" then goto nextplant
close file 1
Rem Load & Record Monsters onto map
dim monsterstat(48,4)
open to read 1,"mform.ara"
nextmonster:
s$=""
filepath$=""
read string 1, s$: objnum=val(s$)
read string 1, s$: filepath$=s$
read string 1, s$: xval=val(s$)
read string 1, s$: zval=val(s$)
read string 1, s$: orot=val(s$)
mn=mn+1
monsterstat(mn,1)=objnum
monsterstat(mn,2)=xval
monsterstat(mn,1)=zval
load object filepath$,objnum
scale object objnum,10000,10000,10000
position object objnum,xval,get ground height(1,xval,zval),zval
yrotate object objnum,orot
read string 1, s$
if s$ = "~" then goto nextmonster
rem Set basics
Sync On
Sync Rate 30
hide mouse
rem Make Gun
load object "..\Props\weapons\AK47.3DS",501
`XRotate Object 501,90
Fix object pivot 501
Scale object 501,3000,3000,3000
position object 501,0,-7,15
Lock object on 501
Rem Make bullet
Make Object Sphere 502,2
Hide Object 502
Rem Main loop
Do
OldCamAngleY# = CameraAngleY#
OldCamAngleX# = CameraAngleX#
CameraAngleY# = WrapValue(CameraAngleY#+MousemoveX()*0.2)
CameraAngleX# = WrapValue(CameraAngleX#+MousemoveY()*0.2)
Rem Create sky
Texture Backdrop 100
Rem Control input for camera
If Controlkey()=1
XTest# = Newxvalue(X#,CameraAngleY#,100)
ZTest# = Newzvalue(Z#,CameraAngleY#,100)
If XTest#>0 and XTest#<100000 and ZTest#>0 and ZTest#<100000
X#=XTest#
Z#=ZTest#
Endif
Endif
If Upkey()=1
XTest# = Newxvalue(X#,CameraAngleY#,50)
ZTest# = Newzvalue(Z#,CameraAngleY#,50)
If XTest#>0 and XTest#<100000 and ZTest#>0 and ZTest#<100000
X#=XTest#
Z#=ZTest#
Endif
Endif
If Downkey()=1
XTest# = Newxvalue(X#,Wrapvalue(CameraAngleY#-180),50)
ZTest# = Newzvalue(Z#,Wrapvalue(CameraAngleY#-180),50)
If XTest#>0 and XTest#<100000 and ZTest#>0 and ZTest#<100000
X#=XTest#
Z#=ZTest#
Endif
Endif
If Leftkey()=1
XTest# = Newxvalue(X#,Wrapvalue(CameraAngleY#-90),50)
ZTest# = Newzvalue(Z#,Wrapvalue(CameraAngleY#-90),50)
If XTest#>0 and XTest#<100000 and ZTest#>0 and ZTest#<100000
X#=XTest#
Z#=ZTest#
Endif
Endif
If Rightkey()=1
XTest# = Newxvalue(X#,Wrapvalue(CameraAngleY#+90),50)
ZTest# = Newzvalue(Z#,Wrapvalue(CameraAngleY#+90),50)
If XTest#>0 and XTest#<100000 and ZTest#>0 and ZTest#<100000
X#=XTest#
Z#=ZTest#
Endif
Endif
if Mouseclick()=1 and BulletLife=0
Position object 502,X#,Y#+43,Z#
Set object to camera orientation 502
BulletLife = 25
show object 502
Endif
If BulletLife > 0
Dec BulletLife
if BulletLife=5 then BulletExplode=1
Move object 502,500
if BulletLife = 0 then Hide object 502
Endif
If BulletExplode>0
color object 502,rgb(255,0,0)
scale object 502,50000,50000,50000
If bulletlife = 0
scale object 502,1,1,1
ghost object on 502
texture object 502,2
BulletExplode=0
Endif
Endif
Yrotate camera CurveAngle(CameraAngleY#,OldCamAngleY#,24)
Xrotate camera CurveAngle(CameraAngleX#,OldCamAngleX#,24)
Y# = Get ground height(1,X#,Z#)
Position Camera X#,Y#+100,Z#
Rem add a way to exit
if escapekey()=1 then end
Rem Handle monsters
gosub controlmonsters
Rem Refresh Screen
Sync
Loop
Endif
Rem *** Start of Subs ***
Rem Control Monsters
controlmonsters:
Rem Search through and check if exist
for c = 201 to 300
if object exist(c)>0
Rem Make objects face player
point object c,x#,y#,z#
Rem Check to see if bullet hitting them
if BulletLife>0
if object position x(502)-200=<object position x(c)
if object position x(502)+200=>object position x(c)
if object position z(502)-200=<object position z(c)
if object position z(502)+200=>object position z(c)
BulletExplode=3
delete object c
return
endif
endif
endif
endif
endif
Rem End Offs
endif
next c
return