Im still a newb at this so sorry in advance. I searched the forums but I still can't figure out what is wrong with this.
My problem is I am drawing (currently) 5 objects on the screen. When I move around they overlap each other and never appear correctly.
So my question is what am I doing wrong and why do the objects keep overlapping each other? And also why is it when I have objects over matrixes when I look at the objects they tend to have odd artifacting on the objects (see my signature for sys specs, its not that)
NOTE: The code has images in it that you obviously won't have so you will need to edit those out if you try it. Thanks very much for any help! Also some of the code (such as collision detection) isn't even used yet, so just ignore it... Sorry... Controls are WASD and the spacebar acts as a jumppack (kinda) Dont worry about that I will fix it I just wanted to know why the boxes look funny.
Rem Sets up the programs basics
Rem Project: Core Engine 1.0
Rem Created: 7/23/2006
Rem ***** Main Source File *****
Gosub Startup
Gosub LevelSetup
Do
GoSub CameraMove
GoSub CameraGravity
GoSub FinalCameraMove
Sync
Loop
Rem - SUBROUTINES USED BY PROGRAM
Startup:
Sync On
Sync Rate 60
Draw to front
Backdrop on
Autocam off
Hide mouse
SET DISPLAY MODE 1024,768,32
Set Camera Range 0,(6000)
Rem - Turn fog on if fog is wanted
Fog off
Fog distance 4000
Fog color RGB(128,128,128)
Color Backdrop RGB(17,118,193)
MoveSpeed# = 10
PHeight# = 200
CeilingCap# = 5000
JumpPackRate# = 20
PHeightAllowance# = 5
GravAdjustSpeed# = 30
Start=2
Return
LevelSetup:
Rem - Variables for level
MatrixXSize = 740
MatrixZSize = 1000
MatrixSQSize = 20
Make matrix 1,MatrixXSize,MatrixZSize,MatrixSQSize,MatrixSQSize
Load Image "Media\Textures\8001tile.jpg",8001
Prepare Matrix Texture 1,8001,1,1
Fill MAtrix 1,0,1
Position Matrix 1,0,0,0
Rem - Boxes
Load Image "Media\Textures\8000door.jpg",8000
Box1PositionZ# = 80
Box1PositionX# =5
Box1PositionY# =220
Box1Width# =160
Box1Length# =10
Box1Height# =440
Make Object Box 1,Box1Length#,Box1Height#,Box1Width#
Position Object 1,Box1PositionX#,Box1PositionY#,Box1PositionZ#
Texture Object 1,8000
Load Image "Media\Textures\8005drywall.jpg",8005
Box2PositionZ# =585
Box2PositionX# =5
Box2PositionY# =220
Box2Width# =850
Box2Length# =10
Box2Height# =440
Make Object Box 2,Box2Length#,Box2Height#,Box2Width#
Position Object 2,Box2PositionX#,Box2PositionY#,Box2PositionZ#
Texture Object 2,8005
SCALE OBJECT TEXTURE 2, 20, 20
Box3PositionZ# =1005
Box3PositionX# =445
Box3PositionY# =220
Box3Width# =10
Box3Length# =570
Box3Height# =440
Make Object Box 3,Box3Length#,Box3Height#,Box3Width#
Position Object 3,Box3PositionX#,Box3PositionY#,Box3PositionZ#
Texture Object 3,8005
SCALE OBJECT TEXTURE 3, 20, 20
Box4PositionZ# =620
Box4PositionX# =725
Box4PositionY# =220
Box4Width# =760
Box4Length# =10
Box4Height# =440
Make Object Box 4,Box4Length#,Box4Height#,Box4Width#
Position Object 4,Box4PositionX#,Box4PositionY#,Box4PositionZ#
Texture Object 4,8005
SCALE OBJECT TEXTURE 4, 20, 20
Box5PositionZ# =5
Box5PositionX# =365
Box5PositionY# =220
Box5Width# =10
Box5Length# =730
Box5Height# =440
Make Object Box 5,Box5Length#,Box5Height#,Box5Width#
Position Object 5,Box5PositionX#,Box5PositionY#,Box5PositionZ#
Texture Object 5,8005
SCALE OBJECT TEXTURE 5, 20, 20
Load Image "Media\Textures\12.jpg",12
Box6PositionZ# =240
Box6PositionX# =150
Box6PositionY# =70
Box6Width# =220
Box6Length# =10
Box6Height# =140
Make Object Box 6,Box6Length#,Box6Height#,Box6Width#
Position Object 6,Box6PositionX#,Box6PositionY#,Box6PositionZ#
Texture Object 6,12
Return
CameraMove:
Rem ||||START OF CORE PROGRAM CONTROLS FOR KEYBOARD MOVEMENT||||
Rem - Values used for camera movement with keyboard (resets values)
oldcAY# = cAY#
oldcAX# = cAX#
oldX#=X#
oldZ#=Z#
Rem - The following control the keyboard input for camera
Rem - W controls (W key moves player forward)
If KEYSTATE(17)=1
X# = Newxvalue(X#,cAY#,MoveSpeed#)
Z# = Newzvalue(Z#,cAY#,MoveSpeed#)
Endif
Rem - A Controls (A key strafes to the left)
If KEYSTATE(31)=1
X# = Newxvalue(X#,Wrapvalue(cAY#-180),MoveSpeed#)
Z# = Newzvalue(Z#,Wrapvalue(cAY#-180),MoveSpeed#)
Endif
Rem - S Controls (S key makes player walk backwards)
If KEYSTATE(30)=1
X# = Newxvalue(X#,Wrapvalue(cAY#-90),MoveSpeed#)
Z# = Newzvalue(Z#,Wrapvalue(cAY#-90),MoveSpeed#)
Endif
Rem - D Controls (D key strafes to the left)
If KEYSTATE(32)=1
X# = Newxvalue(X#,Wrapvalue(cAY#+90),MoveSpeed#)
Z# = Newzvalue(Z#,Wrapvalue(cAY#+90),MoveSpeed#)
Endif
Rem - Additional Controls
Rem - Basically a piece of code for a jump pack
Rem ||||START OF CORE PROGRAM CONTROLS FOR MOUSE MOVEMENT||||
Rem - Values used for camera movement with mouse (resets values)
Rem - Detects mouse movement
cAY# = WrapValue(cAY#+MousemoveX()*0.2)
cAX# = WrapValue(cAX#+MousemoveY()*0.2)
caZ# = Camera angle Z()
Rem - Code to rotate the camera and to keep the camera from going to extreme degrees
cTestX#=WrapValue(cAX#-180)
if cTestX# > 240 then cAX#=60
if cTestX# < 95 then cAX#=275
YRotate camera CurveAngle(cAY#,oldcAY#,24)
XRotate camera CurveAngle(cAX#,oldcAX#,24)
Rem ||||End OF CORE PROGRAM CONTROLS FOR KEYBOARD MOVEMENT||||
Return
CameraGravity:
OldPCameraHeight# = PCameraHeight#
If KEYSTATE(57)=1
PCameraHeight# = Newyvalue(PCameraHeight#,90*(-1),JumpPackRate#)
PlayerVRate# = 0
PAirTime# = 0
Endif
Rem - Activates Players gravity
If PCameraHeight# > PHeight# and KEYSTATE(57)=0 and OnTop#=0
StartTimer = TIMER(): INC PAirTime#
AirTime# = PAirTime#
gosub Gravity:
PlayerVRate# = ObjectVRate#
Endif
PCameraHeight# = Newyvalue(PCameraHeight#,90,PlayerVRate#)
Return
CollisionDetection:
Rem - Universal Collision Detection Code for Camera
If X# >=MatrixXSize then X#=OldX#
If Z# >=MatrixZSize then Z#=OldZ#
If X# <=MatrixXSize-MatrixXSize then X#=OldX#
If Z# <=MatrixZSize-MatrixZSize then Z#=OldZ#
If PCameraHeight# >=CeilingCap# then PCameraHeight#=oldPCameraHeight#
TestObjectCollisionX1# = int(CollisionTestPositionX#) - (int(CollisionTestWidth#) / 2)
TestObjectCollisionX2# = int(CollisionTestPositionX#) + (int(CollisionTestWidth#) / 2)
TestObjectCollisionZ1# = int(CollisionTestPositionZ#) - (int(CollisionTestLength#) / 2)
TestObjectCollisionZ2# = int(CollisionTestPositionZ#) + (int(CollisionTestLength#) / 2)
TestObjectCollisionY1# = int(CollisionTestPositionY#) - (int(CollisionTestHeight#) / 2)
TestObjectCollisionY2# = int(CollisionTestPositionY#) + (int(CollisionTestHeight#) / 2)
If X# >=TestObjectCollisionX1# and Z# >=TestObjectCollisionZ1# and X#<=TestObjectCollisionX2# and Z#<=TestObjectCollisionZ2# and PCameraHeight#<= TestObjectCollisionY2# and PCameraHeight#>= TestObjectCollisionY1#
X#=oldx#
Z#=oldZ#
Endif
If X# >=TestObjectCollisionX1# and Z# >=TestObjectCollisionZ1# and X#<=TestObjectCollisionX2# and Z#<=TestObjectCollisionZ2# and PCameraHeight#-60<= TestObjectCollisionY2# and PCameraHeight#>= TestObjectCollisionY1#
PCameraHeight#=OldPCameraHeight#
OnTop#=1
else
OnTop#=0
endif
Return
FinalCameraMove:
Rem - The following codes ensure that the player doesn't go out of bounds and test to actually move the player
If PCameraHeight# <PHeight# then PCameraHeight# = PHeight#
If Keystate (57)=1 or PCameraHeight# <=PHeight# or PCameraHeight# - PHeightAllowance# -PHeight# - FinalPHeightToObject# <=0 then PlayerVRate# = 0 and PAirTime#=0
If PCameraHeight#+PHeightAllowance# <=PHeight# then PlayerVRate# = 0 and PAirTime#=0
Position Camera X#,PCameraHeight#,Z#
If Start#<20
Start#=Start#+2
X#=30
PCameraHeight#=200
Z#=30
endif
Return
BoxCollisionSetup1:
CollisionTestHeight# = Box1Height#
CollisionTestWidth# = Box1Length#
CollisionTestLength# = Box1Width#
CollisionTestPositionX# = Box1PositionX#
CollisionTestPositionY# = Box1PositionY#
CollisionTestPositionZ# = Box1PositionZ#
Return
Gravity:
Rem - Simple Universal gravity code that will simulate gravity and return an objects new rate of decent
Rem - Code for start of gravity test goes here
Rem - StartTimer = TIMER(): INC (*name for amount of time the specific object has been in the air*)
Rem - AirTime# = (*name for amount of time the specific object has been in the air*)
Rem - gosub Gravity:
Rem - (*accel rate name of object goes here*) = ObjectVRate#
If AirTime# >0 then ObjectVRate# = .2*GravAdjustSpeed#
If AirTime# >10 then ObjectVRate# = .3*GravAdjustSpeed#
If AirTime# >20 then ObjectVRate# = .4*GravAdjustSpeed#
If AirTime# >30 then ObjectVRate# = .5*GravAdjustSpeed#
If AirTime# >40 then ObjectVRate# = .6*GravAdjustSpeed#
If AirTime# >50 then ObjectVRate# = .8*GravAdjustSpeed#
If AirTime# >60 then ObjectVRate# = 1*GravAdjustSpeed#
If AirTime# >70 then ObjectVRate# = 1.2*GravAdjustSpeed#
If AirTime# >80 then ObjectVRate# = 1.3*GravAdjustSpeed#
If AirTime# >90 then ObjectVRate# = 1.4*GravAdjustSpeed#
If AirTime# >100 then ObjectVRate# = 1.6*GravAdjustSpeed#
If AirTime# >110 then ObjectVRate# = 1.7*GravAdjustSpeed#
If AirTime# >130 then ObjectVRate# = 1.9*GravAdjustSpeed#
Return
P.s. For reference I am basically making a virtual showroom for my cabinet shop using real cabinet pictures for the boxes. Its probably not the best way of doing it but oh well...
Thanks in advance for any help!
System Specs: Hypersonic Aviator CX7 Duo
Intel 2.0 GHZ Core Duo, Nvidia Go 7900 GTX 512mb, 100gig 7200 RPM Hard Drive, 1920x1200 LCD