`Tank Project ```````````````````````````````````````````````````````````````` `setup ```````````````````````````````````````````````````````````````` `basic settings appSetup() `UDT setup and world creation GOSUB _tankSetup GOSUB _worldSetup GOSUB _netSetup ```````````````````````````````````````````````````````````````` `main loop ```````````````````````````````````````````````````````````````` DO `user controls tankUpdate(0) tankMove(tank.obj,0.5,0.5,17,31,30,32) tankUpdate(1) tankCollision(tank.obj,world.obj,tank.radius#,tank.ox#,tank.oz#,tank.x#,tank.z#) tankUpdate(1) tankCam(0,tank.x#,tank.z#,tank.ya#,100,30) tankShoot() tankUpdate(1) `if the user is a host, recieve the data, otherwise, send the data IF tank.obj = 1 netRecieve() tankColCheck() ELSE netSend() ENDIF `if the user is a host, send the data, otherwise, receive the data IF tank.obj = 1 netSend() ELSE netRecieve() ENDIF `gui guiText() guiStats() `refresh screen SYNC `repeat LOOP ```````````````````````````````````````````````````````````````` `functions ``````````````````````````````````````````````````````````````` FUNCTION tankMove(obj,moveSpeed#,turnSpeed#,keyUp,keyDown,keyLeft,keyRight) MOVE OBJECT obj, (KEYSTATE(keyUp)-KEYSTATE(keyDown)) * moveSpeed# YROTATE OBJECT obj, WRAPVALUE(OBJECT ANGLE Y(obj) + ((KEYSTATE(keyRight)-KEYSTATE(keyLeft)) * turnSpeed#)) ENDFUNCTION FUNCTION tankUpdate(state) `tank update will update any important variables for the user. `give state a 1 to update the tank's current x and z `position, or 0 to update it's old position. IF state tank.x# = OBJECT POSITION X(tank.obj) tank.z# = OBJECT POSITION Z(tank.obj) ELSE tank.ox# = OBJECT POSITION X(tank.obj) tank.oz# = OBJECT POSITION Z(tank.obj) ENDIF tank.ya# = OBJECT ANGLE Y(tank.obj) ENDFUNCTION FUNCTION tankCam(cam,x#,z#,ya#,dist#,height#) POSITION CAMERA cam,x#,height#,z# ROTATE CAMERA cam,0,ya#,0 MOVE CAMERA cam,-dist# ENDFUNCTION FUNCTION tankShoot() `Check if the elapsed time since the last shot is `>= to the tank's reload delay# variable. IF (TIMER()-tank.shootTime#)/1000 >= tank.shootDelay# `If spacekey is pressed, reset the tank's shoot time `and record it's shooting. IF SPACEKEY() tank.shooting = 1 tank.shootTime# = TIMER() ENDIF ELSE `If the time hasnt elapsed, display some reloading junk CENTER TEXT SCREEN WIDTH()/2,(SCREEN HEIGHT()/2)+100,"< reloading >" ENDIF ENDFUNCTION FUNCTION tankColCheck() `Loop through every player in the game FOR i = 1 TO net.maxPlayers `If theyre shooting IF clients(i).shooting `Calculate a point infront of the player bx# = NEWXVALUE(tank.x#,tank.ya#,tank.range#) bz# = NEWZVALUE(tank.z#,tank.ya#,tank.range#) `cycle through all other players checking for intersection FOR x = 1 TO net.maxPlayers `if the current player isnt the player shooting IF NOT x = i `perform intersection check hit = sc_rayCast(x,clients(x).x#,0,clients(x).z#,bx#,0,bz#,tank.obj) `damage the hit tank IF hit THEN DEC clients(x).health, tank.damage ENDIF NEXT x `reset the tank's shooting variable clients(i).shooting = 0 ENDIF NEXT i ENDFUNCTION FUNCTION worldSetup() `test matrix MAKE MATRIX 1,1000,1000,10,10 POSITION MATRIX 1,-500,0,-500 `test world MAKE OBJECT BOX world.obj, 200,50,40 POSITION OBJECT world.obj, 30,0,200 sc_setupObject world.obj,0,0 `test enemy MAKE OBJECT CUBE 2,10 POSITION OBJECT 2,100,0,20 COLOR OBJECT 2,RGB(255,000,000) sc_setupObject 2,1,0 ENDFUNCTION FUNCTION appSetup() SYNC ON:SYNC RATE 0:AUTOCAM OFF:HIDE MOUSE ENDFUNCTION FUNCTION guiText() TEXT 0,0,"FPS: "+STR$(SCREEN FPS()) ENDFUNCTION FUNCTION guiStats() FOR x = 1 TO net.maxPlayers TEXT OBJECT SCREEN X(x),OBJECT SCREEN Y(x)-100,clients(x).name$ TEXT OBJECT SCREEN X(x),OBJECT SCREEN Y(x)-85,STR$(clients(x).health) NEXT x ENDFUNCTION FUNCTION tankCollision(obj1,obj2,radius#,x1#,z1#,x2#,z2#) C = sc_SphereSlide(obj2,x1#,0,z1#,x2#,0,z2#,radius#,0) IF C > 0 cx# = sc_getCollisionSlideX() cy# = sc_getCollisionSlideY() cz# = sc_getCollisionSlideZ() POSITION OBJECT obj1,cx#,cy#,cz# ENDIF ENDFUNCTION FUNCTION netRecieve() FOR x = 1 TO net.maxPlayers `recieve data NEXT x ENDFUNCTION FUNCTION netSend() IF tank.obj = 1 `send data ENDIF ENDFUNCTION _tankSetup: TYPE tankStat ox#,oz# x#,z# ya# range# obj radius# shootTime#,shootDelay# shooting health,damage name$ ENDTYPE GLOBAL tank AS tankStat tank.range# = 1000 tank.obj = 1 tank.shootDelay# = 2 tank.shootTime# = tank.shootDelay# MAKE OBJECT CUBE tank.obj,10 tank.radius# = OBJECT SIZE Z(tank.obj)/2 RETURN _worldSetup: TYPE worldStat obj ENDTYPE GLOBAL world AS worldStat world.obj = 1000 worldSetup() RETURN _netSetup: TYPE netStat maxPlayers, players IP$ clientColGroup ENDTYPE GLOBAL net AS netStat net.maxPlayers = 2 net.clientColGroup = 1 TYPE clientStat x#,z# ya# hit health shooting name$ ENDTYPE DIM clients(net.maxPlayers) AS clientStat clients(1).name$ = "boon" clients(1).health = 100 clients(2).name$ = "nooby" clients(2).health = 100 RETURN DELETE MEMBLOCK 1