Hey all,
I was wondering if you guys could help me out with jumping and crouching as I've never done it before. I'm on a tight project deadline and need this asap if possible. Here's my code:
`========================================================
`====================TSA VIDEO GAME DESIGN PROJECT=======
`===============================07/08====================
`========================================================
`=====Cullin Moran, Christian Persico, Andriy Rusyn,=====
`=====Lucas Neffa========================================
sync on
sync rate 60
backdrop off
hide mouse
autocam off
phy start
global NextIDNumber = 0
global newy = 0
`=====Create player object=====
PlayerObject = NextIDNumber()
make object cube PlayerObject,2
scale object PlayerObject,2,20,2
position object PlayerObject,10,10,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)
remstart
`=====Character Controller=====
phy make box character controller PlayerObject,pbpx#,pbpy#,pbpz#,2,20,2,1,1,50
`=====Character Controller=====
remend
`=====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,255,255)
`=====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(255,255,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 52.0
color ambient light rgb(000,040,000)
`=====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
`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()
sprite CrossHairSprite,screen_center_x - 50,screen_center_y - 50,CrossHairImage
`=====Load and position crosshair=====
masscubetex = NextIDNumber()
load image "masscubetex.bmp",masscubetex
`=====STACK OF BRICKS=====
brickspawnid = 4738432
xbrickspawnstart# = -25
ybrickspawnstart# = 5
for x = 0 to 20
for y = 0 to 20
make object cube brickspawnid,2
`color object brickspawnid, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
texture object brickspawnid,masscubetex
set object specular brickspawnid, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 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
xbrickspawnstart# = xbrickspawnstart# + 2
inc brickspawnid
next y
xbrickspawnstart# = -2
ybrickspawnstart# = ybrickspawnstart# + 1
next x
`=====STACK OF BRICKS=====
remstart
`===Banner===
titleimg=NextIDNumber()
load image "title.bmp",titleimg,1
titlesprite=NextIDNumber()
sprite titlesprite,790,680,titleimg
`===Banner===
remend
type BulletType
ObjectNumber as integer
Distance as float
endtype
dim Bullets(10) as BulletType
for b=0 to 10
NewBullet = NextIDNumber()
make object sphere NewBullet,0.2
color object NewBullet,rgb(255,255,0)
` This is the object number.
Bullets(b).ObjectNumber = NewBullet
Bullets(b).Distance = -1.0
hide object NewBullet
position object NewBullet,0,-999,0
next b
sparktex = NextIDNumber()
load image "sparktexture.bmp",sparktex,0
BulletsInFlight = 0
BulletRange# = 150.0
BulletVelocity# = 150.0
MovementSpeed# = 35.0
`Bullethole
BulletHoleImage = NextIDNumber()
load image "bullet hole.bmp", BulletHoleImage,1
OriginalBulletHole = NextIDNumber()
make object plain OriginalBulletHole, 1, 1
texture object OriginalBulletHole, BulletHoleImage
set object transparency OriginalBulletHole, 5
hide object OriginalBulletHole
sparkdeltimer# = 1
cyclecount#=1
phy update 0
`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=====
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#
`=====WASD Controls=====
`=====JUMPING=====
if spacekey()=1 then text 100,60,"Spacebar Down." else text 100,60,"Spacebar Up."
if spacekey()=1 then gosub jumping
`=====JUMPING=====
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),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,mousex(),mousey(),0
`=====
`=====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=====
`SPARKY'S SLIDING COLLISION FUNCTION CALL
slidingcollision(oldx#,oldy#,oldz#,x#,y#,z#,3,PlayerObject,LevelObject)
if mouseclick() = 1 and FireTime < timer() - 200
gosub FireBullet
FireTime = timer()
endif
` Process the bullets that are in flight.
if BulletsInFlight > 0 then gosub bullets
sparkexist# = phy get emitter exist(particleemitter)
gosub sparks
text 500,20,"Spark Deletion Timer: "+str$(sparkdeltimer#)
inc cyclecount#
text 500,40,"Cycle Count: "+str$(cyclecount#)
text 500,60,"Frames Per Second: "+str$(screen fps())
`))$#@#!BULLET ARRAY!#@#$((
LineY = 10
for b = 0 to 10
inc LineY, 20
text 10, LineY, str$(bullets(b).ObjectNumber) + " / " + str$(bullets(b).Distance)
next b
inc LineY, 20
text 10, LineY,"Bullets in flight: "+str$(BulletsInFlight)
phy update 1
phy update 0
sync
loop
`End main loop
` --------------------------------------------------------------------------------------------------
`========<=-=Bullets=-=>========
`---------->-=-Are-=-<----------
`========<=-=Annoying=-=>=======
FireBullet:
` Find the first unused bullet.
for b = 0 to 10
` If the bullet isn't in flight, position it at the point of origin.
if Bullets(b).Distance = -1.0
BulletObject = Bullets(b).ObjectNumber
show object BulletObject
position object BulletObject, camera position x(), camera position y(), camera position z()
rotate object BulletObject, camera angle x(), camera angle y(), camera angle z()
` Annotate this bullet as being in flight.
Bullets(b).Distance = 0.0
inc BulletsInFlight
` We have our bullet, so exit.
exit
endif
next b
return
` --------------------------------------------------------------------------------------------------
bullets:
for b = 0 to 10
` If the bullet is in flight, see if it's going to hit something this program cycle.
if Bullets(b).Distance > -1.0
BulletObject = Bullets(b).ObjectNumber
` Note the bullet's position.
PositionX# = object position x(BulletObject)
PositionY# = object position y(BulletObject)
PositionZ# = object position z(BulletObject)
` Move the bullet to where it's going to be if it doesn't hit anything.
move object BulletObject, BulletVelocity# / CyclesPerSecond#
ImpactObject = SC_RayCast(0, PositionX#, PositionY#, PositionZ#, object position x(BulletObject), object position y(BulletObject), object position z(BulletObject), 0)
` An impact has occured.
if ImpactObject <> 0
newx# = SC_getStaticCollisionX()
newy# = SC_getStaticCollisionY()
newz# = SC_getStaticCollisionZ()
normx# = SC_getCollisionNormalX()
normy# = SC_getCollisionNormalY()
normz# = SC_getCollisionNormalZ()
NewBulletHole = NextIDNumber()
instance object NewBulletHole, OriginalBulletHole
position object NewBulletHole, newx# + normx# / 10.0, newy# + normy# / 10.0, newz# + normz# / 10.0
point object NewBulletHole, newx# + normx#, newy# + normy#, newz# + normz#
` Reset the distance of flight for next use of bullet.
Bullets(b).Distance = -1.0
dec BulletsInFlight
hide object BulletObject
` An impact has not occured - the bullet will keep flying.
else
DistanceOfFlight# = Bullets(b).Distance + ThreeDimensionDistance#(PositionX#, PositionY#, PositionZ#, object position x(BulletObject), object position y(BulletObject), object position z(BulletObject))
` control bullet flight distance
if DistanceOfFlight# >= BulletRange#
` Reset the distance of flight for the next use of this bullet.
Bullets(b).Distance = -1.0
dec BulletsInFlight
hide object BulletObject
` The bullet's still flying, increase the distance of flight for next time.
else
Bullets(b).Distance = DistanceOfFlight#
endif
endif
endif
next b
return
`---------------------------------------------------------------------------------------
jumping:
text 100,70,"Jumping subroutine running."
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
`------------------------------------------------------------------------------------------
Sorry if you don't have DP. As you can see though, there is a clock time thing and a jumping subroutine. If anyone could help me out with jumping and crouching I'd be forever grateful, as would my group.
Jumping: I really just need to:
-check if the player is at the lowest point possible (spawn point)
-If space is down, start a jump
-If jump is in progress, do not jump again
-Jump should go up, gradually stop, then return to the spawn Y level.
-Allow jumps again.
Later on I'll need to see if the player is touching the ground object but for now just this is fine.
Crouching: Instant camera-Y lowering is fine, but I can probably do that myself. I just need help with this:
-If player is crouching and jumps, jump height should be lower than normal jump.
I know it's kinda a lot to ask, but I really need this or my group will fall behind and maybe fail completely. Any and all help is appreciated.
Thanks in advance