`======================================================== ;; <
`=================\//TSA VIDEO GAME DESIGN PROJECT//\==== '| |' ;;; <<
`===============================07/08==================== | | ;;;; <<<
`======================================================== |_| ;;;;;; <<<<
`====-Cullin Moran, Christian Persico, Andriy Rusyn,===== ;;;;;;; <<<
`=====Lucas Neffa-=======================================\\-////;;;;;;;; <<
`========================================================\\--///;;;;;; <
`=========================Special Thanks: Kai Lieth======\\---//;;;;
sync on
sync rate 60
backdrop off
hide mouse
autocam off
phy start
phy set auto fixed timing
phy set gravity 0,-17.0,0
global NextIDNumber = 0
global newy = 0
`=====Create player object=====
PlayerObject = NextIDNumber()
make object cube PlayerObject,2
scale object PlayerObject,2,5,2
position object PlayerObject,10,2.5,0
move object PlayerObject,-25
sc_setupobject PlayerObject,0,2
hide object PlayerObject
`=====Create player object=====
pbpx#=object position x(PlayerObject)
pbpy#=object position y(PlayerObject)
pbpz#=object position z(PlayerObject)
`======== Make Dummy Object representing Player for Physics ==============
PlayerDummyObject = NextIDNumber()
make object cube PlayerDummyObject,5
scale object PlayerDummyObject,100,250,100
position object PlayerDummyObject,pbpx#,pbpy#-3,pbpz#
hide object PlayerDummyObject
phy make rigid body dynamic box PlayerDummyObject,PlayerDummyObject
phy set rigid body mass PlayerDummyObject,25.0
phy set rigid body kinematic PlayerDummyObject,1
`=========================================================================
`=====Add Level Light 1=====
make light 1
set spot light 1,100,200
position light 1,200,350,100
point light 1,0,0,0
set light range 1,600
color light 1,rgb(255, 0, 0)
`=====Add Level Light 1=====
color light 0,255,255,255
`=====Add Level Light 2=====
make light 2
set spot light 2,100,250
point light 2,0,0,0
set light range 2,600
color light 2,rgb(0, 0, 255)
`=====Add Level Light 2=====
set normalization on
`=====Level Fog=====
`-(Only works if GFX card supports it)
fog on
fog color rgb(000,040,000)
fog distance 350
set ambient light 75.0
color ambient light rgb(255, 0, 0)
`=====Level Fog=====
`=====Load Level=====
LevelObject = NextIDNumber()
load object "level.x", LevelObject
position object LevelObject ,0,0,0
scale object LevelObject,400,400,400
SC_setupTerrainCollision LevelObject,0,999
phy make rigid body static mesh LevelObject
`=====Load Level=====
leveltex=NextIDNumber()
load image "wall_m_35.jpg",leveltex
texture object LevelObject,0,leveltex
`=====TRANSPARENT IMAGE=====
nicebigtransparentimage=NextIDNumber()
planefortransparentimage=NextIDNumber()
load image "transparentimage.png",nicebigtransparentimage,1
make object plain planefortransparentimage,40,40
position object planefortransparentimage,0,30,63.9
scale object planefortransparentimage,100,100,100
texture object planefortransparentimage,nicebigtransparentimage
set object transparency planefortransparentimage,5
`=====TRANSPARENT IMAGE=====
`BUMPMAPPING WITH SPECULAR - Only for supported cards,
`textures are killed if unsupported.
remstart
bumpmaptest=NextIDNumber()
bumpmapshader=NextIDNumber()
load image "wall_m_35_bumpmap.jpg",bumpmaptest
texture object LevelObject,1,bumpmaptest
load effect "Bumpmapping-specular.fx",bumpmapshader,0
set object effect LevelObject,bumpmapshader
remend
`=====Load and position crosshair=====
screen_height=screen height()
screen_width=screen width()
screen_center_x=screen_width / 2
screen_center_y=screen_height / 2
CrossHairImage = NextIDNumber()
load image "crosshair.bmp",CrossHairImage,1
CrossHairSprite = NextIDNumber()
`=====Load and position crosshair=====
masscubetex = NextIDNumber()
load image "masscubetex.bmp",masscubetex
`=====STACK OF BRICKS=====
brickspawnid = 4738400
xbrickspawnstart# = -2
ybrickspawnstart# = 2.5
for x = 0 to 10
for y = 0 to 10
make object cube brickspawnid,5
`color object brickspawnid, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
texture object brickspawnid,masscubetex
set object specular brickspawnid, rgb (255, 255, 255)
set object specular power brickspawnid, 255
set object ambient brickspawnid, 0
position object brickspawnid, xbrickspawnstart#, ybrickspawnstart#, 0
phy make rigid body dynamic box brickspawnid
phy set rigid body mass brickspawnid,50.0
xbrickspawnstart# = xbrickspawnstart# + 5.0
inc brickspawnid
next y
xbrickspawnstart# = -2
ybrickspawnstart# = ybrickspawnstart# + 5.0
next x
`=====STACK OF BRICKS=====
sparkdeltimer# = 1
cyclecount#=1
MovementSpeed# = 35.0
`JUMP/CROUCH VARS
`==============
`=======
`===
jumpa#=0
jumpon#=0
jumpmaxheight#=4.0
jumpmaxheightcrouched#=2.0
`===
`=======
`==============
`=======
`===
crouching#=0
crouchamount#=2.0
movementspeedcrouched#=17.0
`===
`=======
`==============
cutscene=NextIDNumber()
load animation "pkdnb.avi",cutscene
cutsceneplayed#=0
phy update 0
sprite CrossHairSprite,screen_center_x - 50,screen_center_y - 50,CrossHairImage
physics_gravity#=-17.0
physicsberunnin=1
`Begin main loop:
do
PreviousCycleTime = CycleTime
CycleTime = timer()
ElapsedTime = CycleTime - PreviousCycleTime
CyclesPerSecond# = 1000.0 / ElapsedTime
inc sparkdeltimer#
oldx#=object position x(PlayerObject)
oldy#=object position y(PlayerObject)
oldz#=object position z(PlayerObject)
`=====WASD Controls=====
`NOT Crouching
if crouching#=0
if keystate(17)=1 then move object PlayerObject, MovementSpeed# / CyclesPerSecond#
if keystate(30)=1 then move object left PlayerObject, MovementSpeed# / CyclesPerSecond#
if keystate(31)=1 then move object PlayerObject, 0.0 - (MovementSpeed# / CyclesPerSecond#)
if keystate(32)=1 then move object right PlayerObject, MovementSpeed# / CyclesPerSecond#
endif
`Crouching
if crouching#=1
if keystate(17)=1 then move object PlayerObject, movementspeedcrouched# / CyclesPerSecond#
if keystate(30)=1 then move object left PlayerObject, movementspeedcrouched# / CyclesPerSecond#
if keystate(31)=1 then move object PlayerObject, 0.0 - (movementspeedcrouched# / CyclesPerSecond#)
if keystate(32)=1 then move object right PlayerObject, movementspeedcrouched# / CyclesPerSecond#
endif
`=====WASD Controls=====
`=====JUMPING=====
if spacekey()=1 then text 100,60,"Spacebar Down." else text 100,60,"Spacebar Up."
popx#=object position x(PlayerObject)
popy#=object position y(PlayerObject)
popz#=object position z(PlayerObject)
if spacekey()=1 and jumpon#=0
jumpon#=1
prepopy#=object position y(PlayerObject)
endif
if jumpon#=1
gosub jumping
popy#=prepopy#+popynew#
else
popy#=10
endif
gosub jumpposition
text 860,290,"Player Cube Height:"
text 900,300,str$(popy#)
`=====JUMPING=====
`=====CROUCHING=====
if keystate(29)=1
crouching#=1
else
crouching#=0
endif
gosub crouching
text 860,310,"Crouching:"
if crouching#=1
text 900,320,"Yes"
else
text 900,320,"No"
endif
`=====CROUCHING=====
x#=object position x(PlayerObject)
y#=object position y(PlayerObject)
z#=object position z(PlayerObject)
`=====Camera/Player Obj Lock=====
position camera object position x(PlayerObject),object position y(PlayerObject)+2.5,object position z(PlayerObject)
rotate camera camera angle x(),object angle y(PlayerObject),camera angle z()
`=====Camera/Player Obj Lock=====
`=====Camera equal Flashlight=====
cpx#=camera position x()
cpy#=camera position y()
cpz#=camera position z()
position light 2,cpx#,cpy#,cpz#
point light 2,xvec#,yvec#,zvec#
`=====
`=====Camera Controls=====
speed#=0.2
damper#=10.0
camy#=wrapvalue(camy#+mousemovex()*speed#):camx#=wrapvalue(camx#+mousemovey()*speed#)
if camx#<=290 and camx#>180 then camx#=290
if camx#>=70 and camx#<180 then camx#=70
tx#=curvevalue(-camx#,tx#,damper#)
ty#=curvevalue(-camy#,ty#,damper#)
rotate camera camx#,object angle y(PlayerObject),0
yrotate object 1,camy#
`=====Camera Controls=====
if mouseclick()=1
gosub firemahlazer
endif
text 900,700,str$(lazerhitid)
`SPARKY'S SLIDING COLLISION FUNCTION CALL
slidingcollision(oldx#,oldy#,oldz#,x#,y#,z#,3,PlayerObject,LevelObject)
if cutsceneplayed#=0 and keystate(46)=1
cutsceneplayed#=1
goto cutscenemode
endif
text 500,500,"Hit C to go to the cutscene. :D"
`=====GRAVITY CONTROLS=====
text 0,480,"N = Ub3rstrong Gravity"
text 0,500,"M = Upward Gravity"
text 0,520,", = Strong Gravity"
text 0,540,". = Weak Gravity"
text 0,560,"/ = No Gravity"
if keystate(49)=1 then physics_gravity#=-75.0
if keystate(50)=1 then physics_gravity#=17.0
if keystate(51)=1 then physics_gravity#=-17.0
if keystate(52)=1 then physics_gravity#=-9.8
if keystate(53)=1 then physics_gravity#=0.0
phy set gravity 0,physics_gravity#,0
`=====GRAVITY CONTROLS=====
`=====PLAYER PHY OBJ=====
phy set rigid body kinematic position PlayerDummyObject,object position x(PlayerObject), object position y(PlayerObject)-6,object position z(PlayerObject)
phy set rigid body kinematic rotation PlayerDummyObject,object angle x(PlayerObject), object angle y(PlayerObject),object angle z(PlayerObject)
`=====PLAYER PHY OBJ=====
`=====PHYSICS TOGGLE=====
gosub physicstoggle
`=====PHYSICS TOGGLE=====
text 0,750,"FPS: "
text 50,750,str$(screen fps())
sync
loop
`End main loop
`--------------------------------------------------------------------------------------------------
firemahlazer:
camx_lazer#=camera position x()
camy_lazer#=camera position y()
camz_lazer#=camera position z()
move camera 1
xvec# = camera position x() - camx_lazer#
yvec# = camera position y() - camy_lazer#
zvec# = camera position z() - camz_lazer#
move camera -1
lazerhit=phy ray cast closest shape(camera position x(),camera position y(),camera position z(),xvec#,yvec#,zvec#)
if lazerhit=1
lazerhitid=phy get ray cast object()
if lazerhitid=LevelObject
return
else
phy set rigid body position lazerhitid,999,-999,999
phy sleep rigid body lazerhitid
exclude object on lazerhitid
endif
endif
return
`---------------------------------------------------------------------------------------------------
jumping:
`PlayerObject and orig height 10
`NOT Crouching
if crouching#=0
if jumpa#>=0 and jumpa#<=180
popynew#=sin(jumpa#*4)*jumpmaxheight#
inc jumpa#
endif
if jumpa#=45
jumpon#=0
jumpa#=0
endif
if jumpon#=1
text 100,70,"Jumping subroutine running."
endif
endif
`Crouching
if crouching#=1
if jumpa#>=0 and jumpa#<=180
popynew#=sin(jumpa#*4)*jumpmaxheightcrouched#
inc jumpa#
endif
if jumpa#=45
jumpon#=0
jumpa#=0
endif
if jumpon#=1
text 100,70,"Jumping subroutine running. (Crouched)"
endif
endif
return
`---------------------------------------------------------------------------------------
jumpposition:
position object PlayerObject,popx#,popy#,popz#
return
`---------------------------------------------------------------------------------------
crouching:
if crouching#=1
position object PlayerObject,object position x(PlayerObject),object position y(PlayerObject)-crouchamount#,object position z(PlayerObject)
endif
return
`---------------------------------------------------------------------------------------
`Spark Deletion Timer Stuff
sparks:
if sparkdeltimer#>50
if sparkexist#>0
`phy delete emitter particleemitter
endif
sparkdeltimer#=1
endif
return
` --------------------------------------------------------------------------------------------------
`Sparky's Function
function slidingcollision(x1#,y1#,z1#,x2#,y2#,z2#,Radius#,Dyn,Obj)
C = sc_SphereSlide(Obj,x1#,y1#,z1#,x2#,y2#,z2#,Radius#,0)
if C > 0
cx# = sc_getCollisionSlideX()
cy# = sc_getCollisionSlideY()
cz# = sc_getCollisionSlideZ()
position object Dyn, cx#, cy#, cz#
endif
endfunction
delete memblock 1
` --------------------------------------------------------------------------------------------------
function ThreeDimensionDistance#(FromX#, FromY#, FromZ#, ToX#, ToY#, ToZ#)
` calculate the distance between two points in three dimensions
TempX# = abs(FromX# - ToX#)
TempY# = abs(FromY# - ToY#)
TempZ# = abs(FromZ# - ToZ#)
ReturnValue# = sqrt((TempX# * TempX#) + (TempY# * TempY#) + (TempZ# * TempZ#))
endfunction ReturnValue#
` --------------------------------------------------------------------------------------------------
function NextIDNumber()
` determine ID numbers
inc NextIDNumber
endfunction NextIDNumber
function newy()
inc newy
endfunction newy
`------------------------------------------------------------------------------------------
cutscenemode:
sync on
sync rate 60
flush video memory
phy clear
color backdrop black
delete sprite CrossHairSprite
play animation cutscene,0,0,1024,768
do
text 0,0,"Terrible quality = ripped from youtube but w/e."
text 0,20,"Cutscenes are used as transitions because the previous level CANNOT be loaded again correctly,"
text 0,30,"so just hit ESC when you're done."
sync
loop
end
`------------------------------------------------------------------------------------------
physicstoggle:
text 0,600,"[ = Physics Off"
text 0,620,"] = Physics On"
if keystate(26)=1 and physicsberunnin=1
physicsberunnin=0
endif
if keystate(27)=1 and physicsberunnin=0
physicsberunnin=1
endif
if physicsberunnin=1
phy start
phy update 1
phy update 0
endif
if physicsberunnin=0
endif
return
`------------------------------------------------------------------------------------------
There's my code. Here's a link to my entire project folder, including media:
http://www.megaupload.com/?d=FYKAY68B
Anyway, I need to be able to change the player height and angle. My future levels are going to require that the character can change height and angle in accordance with the terrain beneath him. If anyone could help me out with this, I'd be really grateful, as my deadline is drawing nearer and nearer.
Thanks in advance.