Universal 1st/3rd pers. AGK Framework( - physics) WIP

Started by Rick Nasher, September 24, 2017, 19:26:37

Previous topic - Next topic

Rick Nasher

Decided to give this little fellow his's own thread..



ORIGINAL POST
(Initial release and comments in this thread, left in for reference )


Hmm, 'fixed' the bug were player can climb straight high walls by moving forward and continuously pushing forward, not enirely happy with all the results yet, but.. it works.


// Project: Universal 1st/3rd person framework.
// Created: 2017-09-17
// Objective:  flexible controller for 3d games without physics.
// Features:
// -switch between 1st / 3rd person cam
// -player to obstacles collisions
// -plater to ground(either plane, other objects or terrain)
// -jumping

//  Thanks to:
//  -Janbo for initial ObstacleAvoidingCam routine.
// -Sphinx  for fixing cam turnbug using A and D keys.
//
// History/To do:
// Bug: Jumping +forward made player sliding upwards to the obstacle as if climing.
// idea: if too close to a wall then unable to jump(use raycast distance)
// conclusion: no need, was fixed by placing jumping routine above movement
// Next:
// ladder.
// terrain.
// jumping pods (if collided with then jumpheight =2x)
// moving platforms (if going up/down and player on top then incr/decr y of player too)
// shooting
// NPC
// Peer2Peer

// Setup..
WindowAndDisplaySetup()


// Initialization..
AssignKeys()

#constant version#=4.4
#constant MaxCameraDistance#= 7.0
Global NewCameraDistance
NewCameraDistance#=MaxCameraDistance#
Global UserCameraDistance#
UserCameraDistance#=MaxCameraDistance#
Global CameraDistance#

Global CameraAngleX#,CameraAngleY#
Global GetPointerMoveX#, GetPointerMoveY#
Global adjustfactor#=0
Global FrameTime#
Global PointerX#, PointerZ#

Global mouselocked=0
Global cammode=0
Global endgame=0
Global infodisplay=1
Global helpdisplay=0

Global playerheight#=2
Global playerwidth#=1

Global hspeed#= 2
Global vspeed#=.5
Global speed#=2
Global gravity#=0.4
Global jump=0
Global upy#=0
Global maxjump#=5
Global falling=0
Global climbing=0
Global hitobjectatx, hitobjectaty, hitobjectatz

Global PlayerObjectID, gunID, unaBrow, nose, tail

Global PlayerX#,PlayerY#,PlayerZ#
Global oldPlayerX#,oldPlayerY#,oldPlayerZ#
Global newPlayerX#,newPlayerY#,newPlayerZ#
Global newestPlayerX#, newestPlayerY#, newestPlayerZ#


CreateWorld()

CreatePlayer()


// main loop..
do

FrameTime#=GetFrameTime()

UpdatePlayer()

CheckAdditiionalKeys()
DisplayInfo()
DisplayHelp()
If  endgame=1 then exit
sync()

loop
end // exit  game..

//  Functions..
function CurveValue(Destination#,Current#,Steps#)
Current#=Current#+((Destination#-Current#)/Steps#)
endfunction Current#


Function CreateWorld()

// create a plane, turn its collision off, rotate it and position it under the middle box to act as a ground
// this is purely cosmetic
Global planeID
planeID=CreateObjectPlane(1000,1000)
SetObjectCollisionMode(planeID,0) // this is to stop it interfering with the collision with the map
// ensure everything is at correct starting point an orientation at creation.
SetObjectPosition(planeID,0,0,0) : SetObjectRotation(planeID,0,0,0)
// put where we want it..
SetObjectRotation(planeID,90,0,0) // put it flat
SetObjectPosition(planeID,0,0,0) //realign with origin
SetObjectColor(planeID,50,200,100,255) // color it lawn style

Global centerpoleID // mark center of our world..
centerpoleID=CreateObjectCylinder(6,.2,12)
SetObjectPosition(centerpoleID,0,3,0) :  SetObjectRotation(centerpoleID,0,0,0) // ensure is at correct starting point.
SetObjectColor( centerpoleID ,0,0,0,255)
SetObjectCastShadow(centerpoleID,1)

// Create some random static scenery objects to test with..
Global Dim obstacle[20]
For i=2 To 20
r=Random(1,4)
if r=1
obstacle[i]=CreateObjectBox( random(1,20), random(1,20) , random(1,20) )
SetObjectPosition(obstacle[i],0,0,0) :  SetObjectRotation(obstacle[i],0,0,0) // ensure is at correct starting point.
SetObjectPosition(  obstacle[i], Random(-50,50),0,Random(-50,50))
SetObjectRotation (obstacle[i],0.0,Random(0,360),0.0)
elseif r=2
obstacle[i]=CreateObjectCone(random(1,20),random(25,50),random(1,30))
SetObjectPosition(obstacle[i],0,0,0) :  SetObjectRotation(obstacle[i],0,0,0) // ensure is at correct starting point.
SetObjectPosition(  obstacle[i], Random(-50,50),0,Random(-50,50))
SetObjectRotation (obstacle[i],0.0,Random(0,360),0.0)
elseif r=3
obstacle[i]=CreateObjectCylinder(random(1,7),random(1,15),random(1,30))
SetObjectPosition(obstacle[i],0,0,0) :  SetObjectRotation(obstacle[i],0,0,0) // ensure is at correct starting point.
SetObjectPosition( obstacle[i], Random(-50,50),0,Random(-50,50))
SetObjectRotation (obstacle[i],Random(0,360),Random(0,360),0.0)
//SetObjectScale (obstacle[i],-Random(.2,1),-Random(.2,1),-Random(.2,1))

else
//( diameter, rows, columns )
diameter#= random(.5,25)
rows#=random(.1,25)
colums#=random(5,32)
obstacle[i]=CreateObjectsphere(diameter#,rows# ,colums# )
SetObjectPosition(obstacle[i],0,0,0) :  SetObjectRotation(obstacle[i],0,0,0) // ensure is at correct starting point.
SetObjectPosition(  obstacle[i], Random(-50,50),-diameter#/5+random(0,1),Random(-50,50))
// SetObjectScale (obstacle[i],Random(.2,1),Random(.2,1),Random(.2,1))
SetObjectRotation (obstacle[i],0.0,Random(0,360),0.0)
endif

//SetObjectScale (obstacle[i],Random(.2,2),Random(.2,2),Random(.2,2))
SetObjectRotation (obstacle[i],0.0,Random(0,360),0.0)
SetObjectColor (obstacle[i],Random(0,255),Random(0,255),Random(0,255),Random(0,255))
SetObjectCollisionMode(obstacle[i],1)
SetObjectCastShadow(obstacle[i],1)

Next


// create building with ladder..
building=CreateObjectBox( 20,1 ,10 )
SetObjectPosition(building,0,0,0) :  SetObjectRotation(building,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  building, -10,5,-10+70)
SetObjectColor (building,200,200,200,255)
SetObjectCastShadow(building,1)

bx#=GetObjectX(building)
by#=GetObjectY(building)-15
bz#=GetObjectZ(building)

leftwall=CreateObjectBox( 1, 5 ,10 )
SetObjectPosition(leftwall,0,0,0) :  SetObjectRotation(leftwall,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  leftwall, -19.5,2.5,-10+70)
SetObjectColor (leftwall,200,200,200,255)
SetObjectCastShadow(leftwall,1)

leftwall1=CreateObjectBox( 1, 19,10 )
SetObjectPosition(leftwall1,0,0,0) :  SetObjectRotation(leftwall1,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  leftwall1, -19.5,15,-10+70)
SetObjectColor (leftwall1,200,200,200,255)
SetObjectCastShadow(leftwall1,1)

floor1=CreateObjectBox( 20,1 ,10 )
SetObjectPosition(floor1,0,0,0) :  SetObjectRotation(floor1,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  floor1, -10,11,-10+70)
SetObjectColor (floor1,200,200,200,255)
SetObjectCastShadow(floor1,1)

floor2=CreateObjectBox( 20,1 ,10 )
SetObjectPosition(floor2,0,0,0) :  SetObjectRotation(floor2,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  floor2, -10,17,-10+70)
SetObjectColor (floor2,200,200,200,255)
SetObjectCastShadow(floor2,1)

floor3=CreateObjectBox( 20,1 ,10 )
SetObjectPosition(floor3,0,0,0) :  SetObjectRotation(floor3,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  floor3, -10,24,-10+70)
SetObjectColor (floor3,200,200,200,255)
SetObjectCastShadow(floor3,1)

rightwall=CreateObjectBox( 1, 20 ,10 )
SetObjectPosition(rightwall,0,0,0) :  SetObjectRotation(rightwall,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  rightwall, -.5,10,-10+70)
SetObjectColor (rightwall,200,200,200,255)
SetObjectCastShadow(rightwall,1)

midwall=CreateObjectBox( 1, 5 ,10 )
SetObjectPosition(midwall,0,0,0) :  SetObjectRotation(midwall,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  midwall, -10,2.5,-10+70)
SetObjectColor (midwall,200,200,200,255)
SetObjectCastShadow(midwall,1)

midwall2=CreateObjectBox( 1, 5 ,10 )
SetObjectPosition(midwall2,0,0,0) :  SetObjectRotation(midwall,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  midwall2, -10,14,-10+70)
SetObjectColor (midwall2,200,200,200,255)
SetObjectCastShadow(midwall2,1)

midwall3=CreateObjectBox( 1, 5 ,10 )
SetObjectPosition(midwall3,0,0,0) :  SetObjectRotation(midwall3,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  midwall3, -7,20,-10+70)
SetObjectColor (midwall3,200,200,200,255)
SetObjectCastShadow(midwall3,1)

window=CreateObjectBox( 8.5, 5 ,.5 )
SetObjectPosition(window,0,0,0) :  SetObjectRotation(window,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  window, -5.25,2.5,-14.5+70)
SetObjectColor (window,50,50,255,100)
SetObjectCastShadow(window,1)
SetObjectTransparency(window,1)

window2=CreateObjectBox( 8.5, 5 ,.5 )
SetObjectPosition(window2,0,0,0) :  SetObjectRotation(window2,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  window2, -14.75,14,-14.5+70)
SetObjectColor (window2,50,50,255,100)
SetObjectCastShadow(window2,1)
SetObjectTransparency(window2,1)


//ladder..
Global Dim spurt[19]
For i=0 To 17

spurt[i]=CreateObjectBox( .4,0.1, 1.5)
SetObjectPosition(spurt[i],0,0,0) :  SetObjectRotation(spurt[i],0,0,0) // ensure is at correct starting point.
SetObjectPosition(  spurt[i],bx#-10.5,(by#+10.5)+i*1.4, bz#)

SetObjectColor (spurt[i],255,255,150,255)
SetObjectCollisionMode(spurt[i],1)
SetObjectCastShadow(spurt[i],1)

next i

//bars..
leftbar=CreateObjectBox( .6, 51 ,.2 )
SetObjectPosition(leftbar,0,0,0) :  SetObjectRotation(leftbar,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  leftbar, -20.4,0,-10.8+70)
SetObjectColor (leftbar,255,255,150,255)
SetObjectCollisionMode(leftbar,1)
SetObjectCastShadow(leftbar,1)

rightbar=CreateObjectBox( .6, 51 ,.2 )
SetObjectPosition(rightbar,0,0,0) :  SetObjectRotation(rightbar,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  rightbar, -20.4,0,-9.2+70)
SetObjectColor (rightbar,255,255,150,255)
SetObjectCollisionMode(rightbar,1)
SetObjectCastShadow(rightbar,1)
       



EndFunction

Function CreatePlayer()

//Global PlayerObjectID
PlayerObjectID=CreateObjectCapsule(playerwidth#,playerheight#,1) // ( diameter, height, axis )
SetObjectPosition(PlayerObjectID,0,1,-10)
SetObjectCastShadow(PlayerObjectID,1)
SetObjectCollisionMode(PlayerObjectID,0)  //prevent self hiting

// add some detail so orientation of player is more clear..
gunID= CreateObjectCylinder(1.2,.2,10)
SetObjectPosition(gunID,0,0,0) :  SetObjectRotation(gunID,0,0,0) // ensure is at correct starting point.
SetObjectPosition(gunID,.5,0,.4)
SetObjectRotation(gunID,0,90,90)
FixObjectToObject(gunID,PlayerObjectID)
SetObjectColor(gunID,0,0,0,255) //
SetObjectCollisionMode(gunID,0)  //prevent self hiting
SetObjectCastShadow(gunID,1)

unaBrow = CreateObjectCone(.4,.8,12):SetObjectColor( unaBrow ,0,0,0,255)
SetObjectPosition(unaBrow,0,0,0) :  SetObjectRotation(unaBrow,0,0,0) // ensure is at correct starting point.
SetObjectPosition( unaBrow ,0,.4,.3)
SetObjectRotation( unaBrow ,-180,0,0)
SetObjectCastShadow(unaBrow,1)
SetObjectCollisionMode(unaBrow,0)  //prevent self hiting
FixObjectToObject(unaBrow,PlayerObjectID)

nose = CreateObjectSphere(.2,1.2,12):SetObjectColor( nose,255,0,0,255)
SetObjectPosition(nose,0,0,0) :  SetObjectRotation(nose,0,0,0) // ensure is at correct starting point.
SetObjectPosition( nose,0,.2,.5)
SetObjectCastShadow(nose,1)
SetObjectCollisionMode(nose,0)  //prevent self hiting
FixObjectToObject(nose,PlayerObjectID)

tail = CreateObjectcone(.2,.3,12):SetObjectColor( tail,255,255,255,255)
SetObjectPosition(tail,0,0,0) :  SetObjectRotation(tail,0,0,0) // ensure is at correct starting point.
SetObjectPosition( tail,0,-.9,-.4)
SetObjectRotation(tail,-130,0,0)
SetObjectCastShadow(tail,1)
SetObjectCollisionMode(tail,0)  //prevent self hiting
FixObjectToObject(tail,PlayerObjectID)

EndFunction


Function UpdatePlayer()

//store players x,y,z and angles before any movement..
oldPlayerX#=GetObjectX(PlayerObjectID)
oldPlayerY#=GetObjectY(PlayerObjectID)
oldPlayerZ#=GetObjectZ(PlayerObjectID)

If  GetRawKeyState(KEY_SHIFT)  // Shift = speedup
speed#=2
else
speed#=1
Endif

//object_hit_infront=ObjectRayCast(0,oldPlayerX#,oldPlayerY#,oldPlayerZ#,oldPlayerX#,oldPlayerY#,oldPlayerZ#+5)
//If object_hit_infront<> 0 // we've hit something then adjust the x,y,z's ..
//zdist#=GetObjectRayCastDistance( 0 )
//endif

If  GetRawKeyState(KEY_SPACE)  and falling=0  // Space = jump
If  jump=0  //  inair=0 // if not juming/inair  already..
jump=1  // intitiate new jump
Endif
Endif
if jump=1 //and climbing=0 // if jump has been initiated ..
upy#=upy#+1 // increase y
if  upy#>=maxjump# // if maxheight reached then  reset y to 0 and no end jump..
upy#=0
jump=0
else
MoveObjectLocalY(PlayerObjectID,1)
endif
endif

// get input from mouse pointer..
PointerX#=GetPointerX()
PointerY#=GetPointerY()

If mouseLocked=0
setrawmouseposition(GetVirtualWidth()*0.5,GetVirtualHeight()*0.5) // recenter mouseon screen
EndIf

GetPointerMoveX#=(PointerX#-GetPointerX()) // calculate distance moved
GetPointerMoveY#=(PointerY#-GetPointerY())

// for turning left/right..
If  GetRawKeyState(KEY_LEFT)  OR GetRawKeyState(KEY_A) // Left/A = turn player left
GetPointerMoveX# = 40 * -hspeed#
Endif
If GetRawKeyState(KEY_RIGHT) OR GetRawKeyState(KEY_D) // Right/D = turn player right
GetPointerMoveX# = 40 * hspeed#
Endif

CameraAngleX#=CameraAngleX#+GetPointerMoveY#*FrameTime#
CameraAngleY#=CameraAngleY#+GetPointerMoveX#*FrameTime# // calc camera angle
UserCameraDistance#=UserCameraDistance#-GetRawMouseWheelDelta()*0.1  // zoom in/out when used mousewheel
if UserCameraDistance#>MaxCameraDistance# then UserCameraDistance#=MaxCameraDistance# //limit max dist from cam
if UserCameraDistance#<MaxCameraDistance#*0.5 then UserCameraDistance#=MaxCameraDistance#*0.5 // limit minimum dist from cam


// get player virtual joystick input..
joystick_x# = GetJoyStickX()*hspeed#
joystick_y# = GetJoyStickY()*-vspeed#

// get keybpard input (PC only)..
// for moving forward/backward..
If GetRawKeyState(KEY_UP) = 1  or GetRawMouseRightState() // Up/W/RBM = move player forward
joystick_y#=1*vspeed#  *speed# //addjust z
endif
If   GetRawKeyState(KEY_DOWN) = 1 // Down/S = move player backward
joystick_y#=1*-vspeed# *speed#
Endif

// move player based on the input  of  joystick and  mouse..
RotateObjectLocalY(PlayerObjectID,joystick_x#) // seems redundant,but somehow makes cam movement more fluid?
MoveObjectLocalZ(PlayerObjectID,joystick_y#)
SetObjectRotation(PlayerObjectID,0,CameraAngleY#,0) // set player at  Y angle calculated according to mousemovement, don't move X angle for player will then tilt up/down


// for strafe.. ( if not put here then doesn''t work )
If GetRawKeyState(KEY_Q) // Q = move (strafe) player left
joystick_y# = .1*-hspeed#
MoveObjectLocalX(PlayerObjectID,joystick_y#)
Endif
If GetRawKeyState(KEY_E) // E = move (strafe) player right
joystick_y# = .1*hspeed#
MoveObjectLocalX(PlayerObjectID,joystick_y#)
Endif


// apply gravity..
MoveObjectLocalY(PlayerObjectID,-gravity#) // gravity ""always on''..
falling=1


// ################### manage collision checking for the player  #######################
// get players new x,y,z's for usage with collisions..
newPlayerX#=GetObjectX(PlayerObjectID)
newPlayerY#=GetObjectY(PlayerObjectID)
newPlayerZ#=GetObjectZ(PlayerObjectID)

// sphere cast between the old and new positions of the player to see if we hit something while moving to new location..
object_hit = ObjectSphereSlide(0,oldPlayerX#,oldPlayerY#,oldPlayerZ#,newPlayerX#,newPlayerY#,newPlayerZ#,playerwidth#)
// if the sphere has collided with an object then calculate sphere new position to give sliding collision
If object_hit <> 0 // we've hit something then adjust the x,y,z's ..
newestPlayerX#=GetObjectRayCastSlideX(0)
if newestPlayerX#<>newPlayerX#
hitobjectatx=1
endif
newestPlayerY#=GetObjectRayCastSlideY(0)
if newestPlayerY#<>newPlayerY#
hitobjectaty=1
falling=0
endif
newestPlayerZ#=GetObjectRayCastSlideZ(0)
if newestPlayerZ#<>newPlayerZ#
hitobjectatz=1
endif
climbing=0
if (newestPlayerZ#<>newPlayerZ#  or newestPlayerX#<>newPlayerX#) and newestPlayerY#>newPlayerY# then climbing=1

else
climbing=0
newestPlayerX#=newPlayerX#
newestPlayerY#=newPlayerY#
newestPlayerZ#=newPlayerZ#
EndIf

// prevent falling through floor due to gravity update..
If newestPlayerY# <=playerheight#/2 //1 // so if gravity aplied but now ending up below the btm floor..
newestPlayerY#=playerheight#/2 //1  // limit/reset y to minimm y so don't fall through floor
falling=0
endif

// posiition onto new location
SetObjectPosition(PlayerObjectID, newestPlayerX#, newestPlayerY#, newestPlayerZ# ) //process all modifications made above.






// #################### manage camera avoiding geometry inbetween player and cam #########
// get players new x,y,z's for usage with cam..
PlayerX#=GetObjectX(PlayerObjectID)
PlayerY#=GetObjectY(PlayerObjectID)
PlayerZ#=GetObjectZ(PlayerObjectID)

If cammode=0 //  3rd person mode(default)..
SetCameraPosition(1,PlayerX#,PlayerY#,PlayerZ#)   // place camera at player position
//SetCameraRotation(1,GetObjectAngleX(PlayerObjectID), GetObjectAngleY(PlayerObjectID) ,GetObjectAngleZ(PlayerObjectID)   ) //

// limit cam x angle otherwise may tiltl too far..
If CameraAngleX#<0
adjustfactor#=CameraAngleX#/5+.3
//CameraAngleX#=0
if CameraAngleX#<= -20
CameraAngleX#=-20
endif
//adjustfactor#=CameraAngleX#/4

else
adjustfactor#=0
endif
If CameraAngleX#>90 then CameraAngleX#=90

SetCameraRotation(1,CameraAngleX#,CameraAngleY#,0) // set camera at angle calculated according to mousemovent
MoveCameraLocalZ(1,-MaxCameraDistance#) // move cam behind player

// obstacle avoiding cam..
RayObjectID=ObjectRayCast(0,PlayerX#,PlayerY#,PlayerZ#,GetCameraX(1),GetCameraY(1),GetCameraZ(1)) // sent a ray from players pos to cam behind player.
if RayObjectID<>0 // if an object was hit, this means there's an object between player and cam, obstructing the view'
NewCameraDistance#=GetObjectRayCastDistance(0) // set distance to where has been hit.
else
NewCameraDistance#=UserCameraDistance# // nothing's wrong's so set to user defined zoom distance.
endif
CameraDistance#=CurveValue(NewCameraDistance#,CameraDistance#,10) // calc new camdistance
SetCameraPosition(1,PlayerX#,PlayerY#,PlayerZ#) // redundant?
MoveCameraLocalZ(1,-CameraDistance#) // move cam to new position behind the player.
MoveCameraLocaly(1,-adjustfactor#) // move cam to new position behind the player.

ElseIf cammode =1 // 1st person mode..
SetCameraPosition(1,PlayerX#,PlayerY#,PlayerZ#-1)   // place camera at player position
SetCameraRotation(1,CameraAngleX#,CameraAngleY#,0) // set camera at angle calculated according to mousemovent

///SetObjectVisible(PlayerObjectID,0)
Elseif cammode =2

Endif
EndFunction

Function WindowAndDisplaySetup()

// ------------not really needed for this example -------
// set window properties
SetWindowTitle("Universal 1st/3rd Person Framework V"+str(version#,1) )


// set display properties
//SetWindowSize(1920,1080,0)
SetWindowSize(1024,600,0)
SetWindowAllowResize(1) // allow the user to resize the window

//SetVirtualResolution(1920,1080) // doesn't have to match the window
setvirtualresolution(1024,600)
SetOrientationAllowed(1,1,1,1) // allow both portrait and landscape on mobile devices
SetSyncRate(30,0) // 30fps instead of 60 to save battery
SetScissor(0,0,0,0) // use the maximum available screen space, no black borders
UseNewDefaultFonts(1) // since version 2.0.22 we can use nicer default fonts
SetPrintSize( 20 )
SetPrintColor( 00, 00, 00,255 )

SetClearColor(1,128,198)
SetGlobal3DDepth(10000) // Sets the position of all 3D objects relative to 2D objects.

SetResolutionMode(1)
SetAntialiasMode(1)
SetImmersiveMode(1)
SetRawMouseVisible(0)
SetCameraRange(1,1,1000)
SetAmbientColor(128,128,128)

SetGenerateMipmaps(1)
// -----------------------------------------------------------

fog=1
// add some atmospheric fog
SetFogMode( fog )
SetFogColor( 161,183,209 )
SetFogRange( 50, 700 )
//SetFogRange( 60,95 )
SetFogSunColor( 255,230,179 )

// -----------------------------------------------------------
SetShadowMappingMode(3)
SetShadowSmoothing(1)
SetShadowMapSize(2048,2024)

EndFunction

Function CheckAdditiionalKeys()

// check additional keys..

remstart
if  GetRawKeyState(KEY_SPACE) = 1 //Space(jump)
initJump(grav decrease for while, jump_time)
endif

if GetRawKeyState(KEY_Alt = 1 //C(crouch)
crouchPlayer = 1
endif

if GetRawKeyState(KEY_CONTROL) = 1 //Ctrl/LMB
if item=weapon
launchProjectile
else
useCurrentItem
endif
endif
remend


If GetRawKeyState(KEY_F) = 1 // F= toggle focus (lock mouse to screen).
mouseLocked=1-mouseLocked
SetRawMouseVisible (mouseLocked)
period#=Timer()+1000000
For delay#=0 to period#
Next delay# // make sure doesn't  get  pressed right after again.

Endif

If  GetRawKeyState(KEY_F1) = 1
helpdisplay=1-helpdisplay // F1= help
period#=Timer()+1000000
For delay#=0 to period#
Next delay# // make sure doesn't  get  pressed right after again.

EndIf
If  GetRawKeyState(KEY_F2) = 1
infodisplay=1-infodisplay // F2= info
period#=Timer()+1000000
For delay#=0 to period#
Next delay# // make sure doesn't  get  pressed right after again.

EndIf

If  GetRawKeyState(KEY_F3) = 1
cammode=cammode+1
if cammode=2 then MoveCameraLocalZ(1,-10) // move cam to new position behind the player.
if cammode=2 then MoveCameraLocalY(1,3) // move cam to new position behind the player.

if cammode=3 then cammode=0 // F3= toggle (1st/3rd person)
period#=Timer()+1000000
For delay#=0 to period#
Next delay# // make sure doesn't  get  pressed right after again.

EndIf

If  GetRawKeyState(KEY_F4) = 1
cammode=1-cammode // F3= toggle (1st/3rd person)
period#=Timer()+1000000
For delay#=0 to period#
Next delay# // make sure doesn't  get  pressed right after again.

EndIf




remstart
If GetRawKeyState(KEY_I) = 1 then inventoryMode=1-inventoryMode //toggle inventory/zoom
If Tab/MMBwheel and inventoryMode=True then select weapon/item+ or - 
If Tab/MMBwheel and inventoryMode=False then zoom+ or -

If Enter/MMB and mulitPlayer then chat=1-chat
If M(map) then mapDisplay=1-mapDisplay
If L(light) then torchOn=-torchOn

If P/Pause then pauseGame=1-pauseGame
If F1(help) then helpDisplay=1-helpDisplay

If F4(fog)
If F5
If F5 then audioOn=1-audioOn

If F6
gfxMode=gfxMode+1
if gfxMode=gfxMax
gfxMode=gfxModeMin(PC only)
endif
endif
endif
remend

If GetRawKeyPressed(KEY_ESC) then endgame=1 // Esc = exit(windows only)

EndFunction

Function DisplayInfo()
If infodisplay
// print info on screen..

Print ("FPS: " + str(  ScreenFPS() ))
Print ("FrameTime: " + str(  GetFrameTime() ))
Print ("Seconds: " + str( GetSeconds() ))
Print ("Polygons: " + str(   GetPolygonsDrawn ()  ))
Print("CameraAngleX: "+ str(CameraAngleX#))
if cammode=0 then camdis$="3rd person(default)"
if cammode=1 then camdis$="1st person"
if cammode=2 then camdis$="detached"
Print("Cammode: "+ camdis$)
Print("")
Print ("F1 = Help")

EndIf


EndFunction

Function DisplayHelp()
If helpdisplay
// print info on screen..
Print ("F2 = toggle tech info")
Print ("F3 = toggle 1st/3rd person mode")
Print ("F4 = toggle fly/walk mode")
Print ("F5 = toggle audio on/off")
Print ("F6 = toggle fog on/off")
Print ("F7 = toggle gfxmode")
Print ("F8 = toggle sun on/off")
Print("")
Print ("W, A, S, D, RMB = move")
Print ("Q, E =  strafe")
Print ("Mouse to look round")
Print ("Mousewheel = zoom in/out")
Print ("Shift  + move = run")
Print ("Space =  jump, Alt = crouch")
Print ("-Not implemented yet-")
Print ("Ctrl / LMB = fire/use item")
Print ("Tab / i = cycle inventory items")
Print ("T =  torch, M = map, C = compass ")
Print ("")
Print ("F = toggle Mouse lock")
Print ("Esc = exit, P = pause" )

EndIf


EndFunction

Function AssignKeys()
   
#constant KEY_BACK    8
#constant KEY_TAB    9

#constant KEY_ENTER 13
#constant KEY_SHIFT 16
#constant KEY_CONTROL 17
#constant KEY_ALT 18 // added
#constant KEY_ESC 27

#constant KEY_SPACE 32
#constant KEY_PAGEUP 33
#constant KEY_PAGEDOWN 34
#constant KEY_END 35
#constant KEY_HOME 36
#constant KEY_LEFT 37
#constant KEY_UP 38
#constant KEY_RIGHT 39
#constant KEY_DOWN 40

#constant KEY_INSERT 45
#constant KEY_DELETE 46

#constant KEY_0 48
#constant KEY_1 49
#constant KEY_2 50
#constant KEY_3 51
#constant KEY_4 52
#constant KEY_5 53
#constant KEY_6 54
#constant KEY_7 55
#constant KEY_8 56
#constant KEY_9 57

#constant KEY_A 65
#constant KEY_B 66
#constant KEY_C 67
#constant KEY_D 68
#constant KEY_E 69
#constant KEY_F 70
#constant KEY_G 71
#constant KEY_H 72
#constant KEY_I 73
#constant KEY_J 74
#constant KEY_K 75
#constant KEY_L 76
#constant KEY_M 77
#constant KEY_N 78
#constant KEY_O 79
#constant KEY_P 80
#constant KEY_Q 81
#constant KEY_R 82
#constant KEY_S 83
#constant KEY_T 84
#constant KEY_U 85
#constant KEY_V 86
#constant KEY_W 87
#constant KEY_X 88
#constant KEY_Y 89
#constant KEY_Z 90

#constant KEY_F1 112
#constant KEY_F2 113
#constant KEY_F3 114
#constant KEY_F4 115
#constant KEY_F5 116
#constant KEY_F6 117
#constant KEY_F7 118
#constant KEY_F8 119


#constant KEY_SEMICOL 186   
#constant KEY_EQUALS 187
#constant KEY_COMMA 188
#constant KEY_MINUS 189
#constant KEY_POINT 190
#constant KEY_SLASH 191
#constant KEY_SINGLQUOTE 192

#constant KEY_SQRBRLEFT 219
#constant KEY_BACKSLASH 220
#constant KEY_SQRBRRIGHT 221
#constant KEY_HASH 222
#constant KEY_ACCENT 223 // ' << is called ?

EndFunction







**********************************************
******************* UPDATES *******************
**********************************************



* GENERAL INFO *




Objective:  flexible controller for 3d games without physics.
Features:
-switch between 1st / 3rd person cam
-player to obstacles collisions
-player to ground(either plane, other objects or terrain)
-jumping
-networking
-etc, etc ..


Thanks to:
-TGC for proving AGK
-Janbo for initial basics of the ObstacleAvoidingCam routine.
-Sphinx  for fixing cam turnbug using A and D keys.
-blendman  for moving platforms example and bonus pickup(not currently included for keeping oversight while  doing code restructuring for multiplayer - will put back later when all working as desired) and double collider suggestion(still needs implementing).
-puzzler2018  for the procedural  texture function(currently removed- might put back in later if he likes).
-The guys at SyntaxBomb(nearly forgot  :-[ )
-And  many others  of course..

ROADMAP (not necessarily in this order):
Fase1 - Cam/Player handling.
- Add Android buttons for turning round (currently only forward/backwards and  left/right strafe)
- CarCam mode ?
- Put back other routines I took out previously.

Fase2 -  Collectables/ Fire mechanisms.
- Create  bullets collision detection.
- Scorch marks for bullet impact.
- Create item mngr a la jeppe's
- Ammo boxes/ bullet system/inventory/scorches/bullet holes, grenades righthand?
- Target image? /zoom mode?
- Labels /energy levels above players. (decreasing health by movements, jumping costing more..

Fase3 - Environments.
- Terrain.
- Teleports/spawn points, moving platforms(removed for overhaul)
- Clouds, sun, rain, snow?
- Foliage?

Fase4 - Enemies/bots.
- NPC(follower/clingers) A*, AI
- Circeling birds?

Fase5 - Networking.
x Universal Networking Front End interface/framework (separate from this release, still in alpha stage- looks nice though ;-) )
- Peer2Peer (networking stack, msgs)
- Hosting/matchmaking Server?

*Not currently included in the download, still in progress.

Ideas:
- Level name : "The Green, the  Red and the Bluie"



* Latest release version will always appear here *


Current version: V6.9
http://www.mediafire.com/file/3ubdvphexdvkyx4/U3D13P_FW_V6.9.rar/file

NOTES:
1) Do not use IE for download for it can't handle the nasty popups of MediaFire - I use Chrome to avoid.
2) Release is in RAR format as is too large and consists of too many separate files now to update in codebox(es) every time. Will do in the final release.
3) For changes, see history in begin of main.agc.
4) Currently not all geometry and functions included in the download to keep focus on the multiplayer part and basic functionality.

Download an earlier version including exe+source and blendman's mods here to try if you like.
http://www.mediafire.com/file/h7ka0n9nr2u2nd5/Univ_Mod.rar


_______________________________________
B3D + physics + shaders + X-platform = AGK!
:D ..ALIENBREED *LIVES* (thanks to Qube).. :D
_______________________________________

Steve Elliott

Well done, but I don't know why you set the frame-rate to 30FPS.

50FPS is low enough.  You're only going to drain laptop batteries if you're running at thousands of frames per second.   :)
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

sphinx

Kind regards,
Maher F. Farag
www.ancientsoft.com
www.osakit.com

Rick Nasher

Thanks guys.

@Steve Elliott:
Good point. Is what I'd seen on the AGK default setups. Their explanation was that it would drain batteries on mobile phones, but didn't have any way to verify this to be true.

@sphinx:
I will, I will. :-)
_______________________________________
B3D + physics + shaders + X-platform = AGK!
:D ..ALIENBREED *LIVES* (thanks to Qube).. :D
_______________________________________

Qube

Coming along really well, Rick.

But but but your mouse look code does not work on Mac :o - Works on Windows fine though so that's a bit bizarre.
Mac Studio M1 Max ( 10 core CPU - 24 core GPU ), 32GB LPDDR5, 512GB SSD,
Beelink SER7 Mini Gaming PC, Ryzen 7 7840HS 8-Core 16-Thread 5.1GHz Processor, 32G DDR5 RAM 1T PCIe 4.0 SSD
MSI MEG 342C 34" QD-OLED Monitor

Until the next time.

RonTek

Looking good Rick. One thing I noticed is it walks instead when you hold shift.




Rick Nasher

#6
Thanks for testing guys.

@Qube:
QuoteBut but but your mouse look code does not work on Mac :o - Works on Windows fine though so that's a bit bizarre.
That's rather odd. Perhaps cause I didn't use all standard virtual controls? I also noticed on Android I need to add some buttons for full control.

@RonTek:
QuoteLooking good Rick. One thing I noticed is it walks instead when you hold shift.
I just checked: indeed doesn't work when using key controls. I personally use RMB + shift and that does work, so I didn't notice before. Guess I'll need to add a separate check such as if key_up and key_shift then..
_______________________________________
B3D + physics + shaders + X-platform = AGK!
:D ..ALIENBREED *LIVES* (thanks to Qube).. :D
_______________________________________

RonTek

Quote from: Rick Nasher on September 25, 2017, 22:45:03
@RonTek:
QuoteLooking good Rick. One thing I noticed is it walks instead when you hold shift.
I just checked: indeed doesn't work when using key controls. I personally use RMB + shift and that does work, so I didn't notice before. Guess I'll need to add a separate check such as if key_up and key_shift then..

keep it up, you are doing great. :)

peteswansen

Very useful!!!!!  Glad I decided to look into AGK, now that BRL is well.......   thanks Rick!

Rick Nasher

Quote from: peteswansen on November 21, 2017, 19:37:35
Very useful!!!!!  Glad I decided to look into AGK, now that BRL is well.......   thanks Rick!

Your welcome. Still working on it.
I'm upscaling the sizes to be compatible with physics scale, so easier to switch when needed and checked out lights.

Will upload when done.
_______________________________________
B3D + physics + shaders + X-platform = AGK!
:D ..ALIENBREED *LIVES* (thanks to Qube).. :D
_______________________________________

blendman

Hi Rick

Great Example ! Thanks a lot.


I have added :
- platform
- Bonus (to get)

The code :
/* INFOS

Project: Universal 1st/3rd person framework.
Created: 2017-09-17
Objective:  flexible controller for 3d games without physics.


Features:
- switch between 1st / 3rd person cam
- player to obstacles collisions
- plater to ground(either plane, other objects or terrain)
- jumping
- platform
- Get Bonus


Thanks to:
- Janbo for initial ObstacleAvoidingCam routine.
- Sphinx  for fixing cam turnbug using A and D keys.
- Blendman (platform, bonus additions)

*/


/* To do:

Bug:
- Jumping + forward made player sliding upwards to the obstacle as if climing.

idea: if too close to a wall then unable to jump(use raycast distance)
- conclusion: no need, was fixed by placing jumping routine above movement

TODO :
- ladder.
- terrain.
- jumping pods (if collided with then jumpheight = 2x)
ok 4.5 - moving platforms (if going up/down and player on top then incr/decr y of player too)
ok 4.5 - Bonus
- shooting
- NPC
- Enemy
- Peer2Peer
*/

/* CHANGES
[29/01/2018] v4.5
// New
- Add moving platform (X move)
- Add bonus to get
- F6 : toggle fog on/off
// Changes
- Change fog colors
- MaxCameraDistance#= 7 -> 10.0
- jump : increase y by 0.5 (was 1) : we can jump higher

*/



// Setup..
#constant version# = 4.5

WindowAndDisplaySetup()

FoldStart // Type (platform, ennemies...)


type tPlayer

Bonus as integer
Life as integer

endtype

Type tPlatform

ObjId as integer
x as float
y as float
z as float
W as integer
H as integer
L as integer

// platform parameter
StuckPLayer as integer // to know if the player is stucked on platform

// to animate platform (moving)
posX as float
posY as float
posZ as float

Endtype

Type tEnemy

ObjId as integer
x as float
y as float
z as float
W as integer
H as integer
L as integer

Endtype

Type tBonus

ObjId as integer
x as float
y as float
z as float
W as integer
H as integer
L as integer

Endtype


Foldend


// Initialization..
InitGame()



// main loop..
do

FrameTime# = GetFrameTime()

UpdatePlayer()
UpdateEntities()

CheckAdditiionalKeys()

DisplayInfo()
DisplayHelp()
If  endgame=1 then exit

sync()

loop

end // exit  game..





FoldStart //  Functions..


Function InitGame()

// To init the game

AssignKeys()


FoldStart // constants & globals


// Camera

#constant MaxCameraDistance# = 10.0

Global NewCameraDistance
NewCameraDistance# = MaxCameraDistance#
Global UserCameraDistance#
UserCameraDistance# = MaxCameraDistance#
Global CameraDistance#

Global CameraAngleX#,CameraAngleY#
Global GetPointerMoveX#, GetPointerMoveY#
Global adjustfactor# = 0
Global FrameTime#
Global PointerX#, PointerZ#

// Display, help...
Global mouselocked = 0
Global cammode = 0
Global endgame = 0
Global infodisplay = 1
Global helpdisplay = 0


// player parameters
Global playerheight# = 2
Global playerwidth# = 1

Global hspeed# = 2
Global vspeed# =.5
Global speed# = 2
Global gravity#=0.4
Global jump = 0
Global upy# = 0
Global maxjump# = 5
Global falling = 0
Global climbing = 0
Global hitobjectatx, hitobjectaty, hitobjectatz

// PLayer object
Global PlayerObjectID, gunID, unaBrow, nose, tail

Global Player as tplayer
player.bonus = 0
player.Life = 100


// player Position
Global PlayerX#, PlayerY#, PlayerZ#
Global oldPlayerX#, oldPlayerY#, oldPlayerZ#
Global oldPlayerX2#, oldPlayerY2#, oldPlayerZ2# // for collision (platform..)
Global newPlayerX#, newPlayerY#, newPlayerZ#
Global newestPlayerX#, newestPlayerY#, newestPlayerZ#

// Fx
Global fog

Foldend

CreateWorld()

CreatePlayer()

CreatePlatform()




Endfunction



function CurveValue(Destination#,Current#,Steps#)
Current#=Current#+((Destination#-Current#)/Steps#)
endfunction Current#

FoldStart // create

Function CreateWorld()

// create a plane, turn its collision off, rotate it and position it under the middle box to act as a ground
// this is purely cosmetic
Global planeID
planeID = CreateObjectPlane(1000,1000)
SetObjectCollisionMode(planeID,0) // this is to stop it interfering with the collision with the map
// ensure everything is at correct starting point an orientation at creation.
SetObjectPosition(planeID,0,0,0) : SetObjectRotation(planeID,0,0,0)
// put where we want it..
SetObjectRotation(planeID,90,0,0) // put it flat
SetObjectPosition(planeID,0,0,0) //realign with origin
SetObjectColor(planeID,50,200,100,255) // color it lawn style


Global centerpoleID // mark center of our world..
centerpoleID=CreateObjectCylinder(6,.2,12)
SetObjectPosition(centerpoleID,0,3,0) :  SetObjectRotation(centerpoleID,0,0,0) // ensure is at correct starting point.
SetObjectColor( centerpoleID ,0,0,0,255)
SetObjectCastShadow(centerpoleID,1)

// Create some random static scenery objects to test with..
Global Dim obstacle[20]
For i=2 To 20
r=Random(1,4)
if r=1
obstacle[i]=CreateObjectBox( random(1,20), random(1,20) , random(1,20) )
SetObjectPosition(obstacle[i],0,0,0) :  SetObjectRotation(obstacle[i],0,0,0) // ensure is at correct starting point.
SetObjectPosition(  obstacle[i], Random(-50,50),0,Random(-50,50))
SetObjectRotation (obstacle[i],0.0,Random(0,360),0.0)
elseif r=2
obstacle[i]=CreateObjectCone(random(1,20),random(25,50),random(1,30))
SetObjectPosition(obstacle[i],0,0,0) :  SetObjectRotation(obstacle[i],0,0,0) // ensure is at correct starting point.
SetObjectPosition(  obstacle[i], Random(-50,50),0,Random(-50,50))
SetObjectRotation (obstacle[i],0.0,Random(0,360),0.0)
elseif r=3
obstacle[i]=CreateObjectCylinder(random(1,7),random(1,15),random(1,30))
SetObjectPosition(obstacle[i],0,0,0) :  SetObjectRotation(obstacle[i],0,0,0) // ensure is at correct starting point.
SetObjectPosition( obstacle[i], Random(-50,50),0,Random(-50,50))
SetObjectRotation (obstacle[i],Random(0,360),Random(0,360),0.0)
//SetObjectScale (obstacle[i],-Random(.2,1),-Random(.2,1),-Random(.2,1))

else
//( diameter, rows, columns )
diameter#= random(.5,25)
rows#=random(.1,25)
colums#=random(5,32)
obstacle[i]=CreateObjectsphere(diameter#,rows# ,colums# )
SetObjectPosition(obstacle[i],0,0,0) :  SetObjectRotation(obstacle[i],0,0,0) // ensure is at correct starting point.
SetObjectPosition(  obstacle[i], Random(-50,50),-diameter#/5+random(0,1),Random(-50,50))
// SetObjectScale (obstacle[i],Random(.2,1),Random(.2,1),Random(.2,1))
SetObjectRotation (obstacle[i],0.0,Random(0,360),0.0)
endif

//SetObjectScale (obstacle[i],Random(.2,2),Random(.2,2),Random(.2,2))
SetObjectRotation (obstacle[i],0.0,Random(0,360),0.0)
SetObjectColor (obstacle[i],Random(0,255),Random(0,255),Random(0,255),Random(0,255))
SetObjectCollisionMode(obstacle[i],1)
SetObjectCastShadow(obstacle[i],1)

Next


// create building with ladder..
building=CreateObjectBox( 20,1 ,10 )
SetObjectPosition(building,0,0,0) :  SetObjectRotation(building,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  building, -10,5,-10+70)
SetObjectColor (building,200,200,200,255)
SetObjectCastShadow(building,1)

bx#=GetObjectX(building)
by#=GetObjectY(building)-15
bz#=GetObjectZ(building)

leftwall=CreateObjectBox( 1, 5 ,10 )
SetObjectPosition(leftwall,0,0,0) :  SetObjectRotation(leftwall,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  leftwall, -19.5,2.5,-10+70)
SetObjectColor (leftwall,200,200,200,255)
SetObjectCastShadow(leftwall,1)

leftwall1=CreateObjectBox( 1, 19,10 )
SetObjectPosition(leftwall1,0,0,0) :  SetObjectRotation(leftwall1,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  leftwall1, -19.5,15,-10+70)
SetObjectColor (leftwall1,200,200,200,255)
SetObjectCastShadow(leftwall1,1)

floor1=CreateObjectBox( 20,1 ,10 )
SetObjectPosition(floor1,0,0,0) :  SetObjectRotation(floor1,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  floor1, -10,11,-10+70)
SetObjectColor (floor1,200,200,200,255)
SetObjectCastShadow(floor1,1)

floor2=CreateObjectBox( 20,1 ,10 )
SetObjectPosition(floor2,0,0,0) :  SetObjectRotation(floor2,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  floor2, -10,17,-10+70)
SetObjectColor (floor2,200,200,200,255)
SetObjectCastShadow(floor2,1)

floor3=CreateObjectBox( 20,1 ,10 )
SetObjectPosition(floor3,0,0,0) :  SetObjectRotation(floor3,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  floor3, -10,24,-10+70)
SetObjectColor (floor3,200,200,200,255)
SetObjectCastShadow(floor3,1)

rightwall=CreateObjectBox( 1, 20 ,10 )
SetObjectPosition(rightwall,0,0,0) :  SetObjectRotation(rightwall,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  rightwall, -.5,10,-10+70)
SetObjectColor (rightwall,200,200,200,255)
SetObjectCastShadow(rightwall,1)

midwall=CreateObjectBox( 1, 5 ,10 )
SetObjectPosition(midwall,0,0,0) :  SetObjectRotation(midwall,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  midwall, -10,2.5,-10+70)
SetObjectColor (midwall,200,200,200,255)
SetObjectCastShadow(midwall,1)

midwall2=CreateObjectBox( 1, 5 ,10 )
SetObjectPosition(midwall2,0,0,0) :  SetObjectRotation(midwall,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  midwall2, -10,14,-10+70)
SetObjectColor (midwall2,200,200,200,255)
SetObjectCastShadow(midwall2,1)

midwall3=CreateObjectBox( 1, 5 ,10 )
SetObjectPosition(midwall3,0,0,0) :  SetObjectRotation(midwall3,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  midwall3, -7,20,-10+70)
SetObjectColor (midwall3,200,200,200,255)
SetObjectCastShadow(midwall3,1)

window=CreateObjectBox( 8.5, 5 ,.5 )
SetObjectPosition(window,0,0,0) :  SetObjectRotation(window,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  window, -5.25,2.5,-14.5+70)
SetObjectColor (window,50,50,255,100)
SetObjectCastShadow(window,1)
SetObjectTransparency(window,1)

window2=CreateObjectBox( 8.5, 5 ,.5 )
SetObjectPosition(window2,0,0,0) :  SetObjectRotation(window2,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  window2, -14.75,14,-14.5+70)
SetObjectColor (window2,50,50,255,100)
SetObjectCastShadow(window2,1)
SetObjectTransparency(window2,1)


//ladder..
Global Dim spurt[19]
For i=0 To 17

spurt[i]=CreateObjectBox( .4,0.1, 1.5)
SetObjectPosition(spurt[i],0,0,0) :  SetObjectRotation(spurt[i],0,0,0) // ensure is at correct starting point.
SetObjectPosition(  spurt[i],bx#-10.5,(by#+10.5)+i*1.4, bz#)

SetObjectColor (spurt[i],255,255,150,255)
SetObjectCollisionMode(spurt[i],1)
SetObjectCastShadow(spurt[i],1)

next i

//bars..
leftbar=CreateObjectBox( .6, 51 ,.2 )
SetObjectPosition(leftbar,0,0,0) :  SetObjectRotation(leftbar,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  leftbar, -20.4,0,-10.8+70)
SetObjectColor (leftbar,255,255,150,255)
SetObjectCollisionMode(leftbar,1)
SetObjectCastShadow(leftbar,1)

rightbar=CreateObjectBox( .6, 51 ,.2 )
SetObjectPosition(rightbar,0,0,0) :  SetObjectRotation(rightbar,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  rightbar, -20.4,0,-9.2+70)
SetObjectColor (rightbar,255,255,150,255)
SetObjectCollisionMode(rightbar,1)
SetObjectCastShadow(rightbar,1)
   



EndFunction

Function CreatePlayer()

//Global PlayerObjectID
PlayerObjectID=CreateObjectCapsule(playerwidth#,playerheight#,1) // ( diameter, height, axis )
SetObjectPosition(PlayerObjectID,0,1,-10)
SetObjectCastShadow(PlayerObjectID,1)
SetObjectCollisionMode(PlayerObjectID,0)  //prevent self hiting

// add some detail so orientation of player is more clear..
gunID= CreateObjectCylinder(1.2,.2,10)
SetObjectPosition(gunID,0,0,0) :  SetObjectRotation(gunID,0,0,0) // ensure is at correct starting point.
SetObjectPosition(gunID,.5,0,.4)
SetObjectRotation(gunID,0,90,90)
FixObjectToObject(gunID,PlayerObjectID)
SetObjectColor(gunID,0,0,0,255) //
SetObjectCollisionMode(gunID,0)  //prevent self hiting
SetObjectCastShadow(gunID,1)

unaBrow = CreateObjectCone(.4,.8,12):SetObjectColor( unaBrow ,0,0,0,255)
SetObjectPosition(unaBrow,0,0,0) :  SetObjectRotation(unaBrow,0,0,0) // ensure is at correct starting point.
SetObjectPosition( unaBrow ,0,.4,.3)
SetObjectRotation( unaBrow ,-180,0,0)
SetObjectCastShadow(unaBrow,1)
SetObjectCollisionMode(unaBrow,0)  //prevent self hiting
FixObjectToObject(unaBrow,PlayerObjectID)

nose = CreateObjectSphere(.2,1.2,12):SetObjectColor( nose,255,0,0,255)
SetObjectPosition(nose,0,0,0) :  SetObjectRotation(nose,0,0,0) // ensure is at correct starting point.
SetObjectPosition( nose,0,.2,.5)
SetObjectCastShadow(nose,1)
SetObjectCollisionMode(nose,0)  //prevent self hiting
FixObjectToObject(nose,PlayerObjectID)

tail = CreateObjectcone(.2,.3,12):SetObjectColor( tail,255,255,255,255)
SetObjectPosition(tail,0,0,0) :  SetObjectRotation(tail,0,0,0) // ensure is at correct starting point.
SetObjectPosition( tail,0,-.9,-.4)
SetObjectRotation(tail,-130,0,0)
SetObjectCastShadow(tail,1)
SetObjectCollisionMode(tail,0)  //prevent self hiting
FixObjectToObject(tail,PlayerObjectID)

EndFunction

Function CreatePlatform()


// Bonus

Global dim  Bonus[10] as tBonus
for i=0 to Bonus.length

n = CreateObjectBox(w,h,l)

// size
w = 2
h = 2
l = 2
SetObjectCollisionMode(n,1)

// position
x = random(0,50)-random(0,50)
y = 2
z = random(0,50)-random(0,50)
SetObjectPosition(n,x,y,z)
SetObjectCastShadow(n,1)
SetObjectColor(n,255,255,100,255)
Bonus[i].ObjId = n
Bonus[i].x = x
Bonus[i].y = y
Bonus[i].z = y
Bonus[i].w = w
Bonus[i].h = h
Bonus[i].l = l

next


// platforms
Global dim  Platform[3] as tPlatform
for i=0 to platform.length

// size
w = 5
h = 1
l = 5

n = CreateObjectBox(w,h,l)
SetObjectCollisionMode(n,1)

// position
x = random(0,50)-random(0,50)
y = 2
z = random(0,50)-random(0,50)
SetObjectPosition(n,x,y,z)
SetObjectCastShadow(n,1)
SetObjectColor(n,100,100,255,255)
platform[i].ObjId = n
platform[i].x = x
platform[i].y = y
platform[i].z = z
platform[i].w = w
platform[i].h = h
platform[i].l = l
platform[i].StuckPLayer = 1

next



endfunction


Foldend


FoldStart // update

Function UpdatePlayer()

//store players x,y,z and angles before any movement..
oldPlayerX# = GetObjectX(PlayerObjectID)
oldPlayerY# = GetObjectY(PlayerObjectID)
oldPlayerZ# = GetObjectZ(PlayerObjectID)

If GetRawKeyState(KEY_SHIFT)  // Shift = speedup
speed#=2
else
speed#=1
Endif

//object_hit_infront=ObjectRayCast(0,oldPlayerX#,oldPlayerY#,oldPlayerZ#,oldPlayerX#,oldPlayerY#,oldPlayerZ#+5)
//If object_hit_infront<> 0 // we've hit something then adjust the x,y,z's ..
//zdist#=GetObjectRayCastDistance( 0 )
//endif

// for platform contact
keyOn = 0


If GetRawKeyState(KEY_SPACE)  and falling=0  // Space = jump
keyOn = 1
If  jump=0  //  inair=0 // if not juming/inair  already..
jump=1  // intitiate new jump
Endif
Endif

if jump=1 //and climbing=0 // if jump has been initiated ..
upy#=upy#+0.5 // increase y
if  upy#>=maxjump# // if maxheight reached then  reset y to 0 and no end jump..
upy#=0
jump=0
else
MoveObjectLocalY(PlayerObjectID,1)
endif
endif

// get input from mouse pointer..
PointerX# = GetPointerX()
PointerY# = GetPointerY()

If mouseLocked=0
SetRawMousePosition(GetVirtualWidth()*0.5,GetVirtualHeight()*0.5) // recenter mouseon screen
EndIf

GetPointerMoveX# = (PointerX#-GetPointerX()) // calculate distance moved
GetPointerMoveY# = (PointerY#-GetPointerY())




// for turning left/right..
If  GetRawKeyState(KEY_LEFT)  OR GetRawKeyState(KEY_A) // Left/A = turn player left
keyOn = 1
GetPointerMoveX# = 40 * -hspeed#
Endif
If GetRawKeyState(KEY_RIGHT) OR GetRawKeyState(KEY_D) // Right/D = turn player right
keyOn = 1
GetPointerMoveX# = 40 * hspeed#
Endif

CameraAngleX#=CameraAngleX#+GetPointerMoveY#*FrameTime#
CameraAngleY#=CameraAngleY#+GetPointerMoveX#*FrameTime# // calc camera angle
UserCameraDistance#=UserCameraDistance#-GetRawMouseWheelDelta()*0.1  // zoom in/out when used mousewheel
if UserCameraDistance#>MaxCameraDistance# then UserCameraDistance#=MaxCameraDistance# //limit max dist from cam
if UserCameraDistance#<MaxCameraDistance#*0.5 then UserCameraDistance#=MaxCameraDistance#*0.5 // limit minimum dist from cam


// get player virtual joystick input..
joystick_x# = GetJoyStickX()* hspeed#
joystick_y# = GetJoyStickY()*-vspeed#

// get keybpard input (PC only)..
// for moving forward/backward..
If GetRawKeyState(KEY_UP) = 1  or GetRawMouseRightState() // Up/W/RBM = move player forward
keyOn = 1
joystick_y#=1*vspeed#  *speed# //addjust z
endif
If  GetRawKeyState(KEY_DOWN) = 1 // Down/S = move player backward
keyOn = 1
joystick_y#=1*-vspeed# *speed#
Endif

// move player based on the input  of  joystick and  mouse..
RotateObjectLocalY(PlayerObjectID,joystick_x#) // seems redundant,but somehow makes cam movement more fluid?
MoveObjectLocalZ(PlayerObjectID,joystick_y#)
SetObjectRotation(PlayerObjectID,0,CameraAngleY#,0) // set player at  Y angle calculated according to mousemovement, don't move X angle for player will then tilt up/down


// for strafe.. ( if not put here then doesn''t work )
If GetRawKeyState(KEY_Q) // Q = move (strafe) player left
joystick_y# = .1*-hspeed#
MoveObjectLocalX(PlayerObjectID,joystick_y#)
Endif
If GetRawKeyState(KEY_E) // E = move (strafe) player right
joystick_y# = .1*hspeed#
MoveObjectLocalX(PlayerObjectID,joystick_y#)
Endif


// apply gravity..
MoveObjectLocalY(PlayerObjectID,-gravity#) // gravity ""always on''..
falling=1


// ################### manage collision checking for the player  #######################
// get players new x,y,z's for usage with collisions..
newPlayerX# = GetObjectX(PlayerObjectID)
newPlayerY# = GetObjectY(PlayerObjectID)
newPlayerZ# = GetObjectZ(PlayerObjectID)

// sphere cast between the old and new positions of the player to see if we hit something while moving to new location..
object_hit = ObjectSphereSlide(0,oldPlayerX#,oldPlayerY#,oldPlayerZ#,newPlayerX#,newPlayerY#,newPlayerZ#,playerwidth#)
// if the sphere has collided with an object then calculate sphere new position to give sliding collision
If object_hit <> 0 // we've hit something then adjust the x,y,z's ..

newestPlayerX# = GetObjectRayCastSlideX(0)
if newestPlayerX# <> newPlayerX#
hitobjectatx=1
endif
newestPlayerY# = GetObjectRayCastSlideY(0)
if newestPlayerY# <> newPlayerY#
hitobjectaty=1
falling=0
endif
newestPlayerZ# = GetObjectRayCastSlideZ(0)
if newestPlayerZ# <> newPlayerZ#
hitobjectatz=1
endif

climbing=0
if (newestPlayerZ#<>newPlayerZ#  or newestPlayerX#<>newPlayerX#) and newestPlayerY#>newPlayerY# then climbing=1


for i=0 to Bonus.length
n = Bonus[i].ObjId
if object_hit = n
DeleteObject(n)
inc Player.Bonus
exit
endif
next


// check platform colision
for i=0 to platform.length
n = Platform[i].ObjId
if object_hit = n
// print("Hit platform !!!!!!!!!")
if keyOn = 0
newestPlayerX# = GetObjectX(n) + oldPlayerX2#
newestPlayerZ# = GetObjectZ(n) + oldPlayerZ2#
else
oldPlayerX2# =  GetObjectX(PlayerObjectID) - GetObjectX(n)
oldPlayerZ2# =  GetObjectZ(PlayerObjectID) - GetObjectZ(n)
endif
exit
endif
Next





else
climbing=0
newestPlayerX# = newPlayerX#
newestPlayerY# = newPlayerY#
newestPlayerZ# = newPlayerZ#
EndIf

// prevent falling through floor due to gravity update..
If newestPlayerY# <= playerheight#/2 //1 // so if gravity aplied but now ending up below the btm floor..
newestPlayerY# = playerheight#/2 //1  // limit/reset y to minimm y so don't fall through floor
falling = 0
endif

// posiition onto new location
SetObjectPosition(PlayerObjectID, newestPlayerX#, newestPlayerY#, newestPlayerZ# ) //process all modifications made above.






// #################### manage camera avoiding geometry inbetween player and cam #########
// get players new x,y,z's for usage with cam..
PlayerX# = GetObjectX(PlayerObjectID)
PlayerY# = GetObjectY(PlayerObjectID)
PlayerZ# = GetObjectZ(PlayerObjectID)

If cammode=0 //  3rd person mode(default)..
SetCameraPosition(1,PlayerX#,PlayerY#,PlayerZ#)   // place camera at player position
//SetCameraRotation(1,GetObjectAngleX(PlayerObjectID), GetObjectAngleY(PlayerObjectID) ,GetObjectAngleZ(PlayerObjectID)   ) //

// limit cam x angle otherwise may tiltl too far..
If CameraAngleX#<0
adjustfactor#=CameraAngleX#/5+.3
//CameraAngleX#=0
if CameraAngleX#<= -20
CameraAngleX#=-20
endif
//adjustfactor#=CameraAngleX#/4

else
adjustfactor#=0
endif
If CameraAngleX#>90 then CameraAngleX#=90

SetCameraRotation(1,CameraAngleX#,CameraAngleY#,0) // set camera at angle calculated according to mousemovent
MoveCameraLocalZ(1,-MaxCameraDistance#) // move cam behind player

// obstacle avoiding cam..
RayObjectID = ObjectRayCast(0,PlayerX#,PlayerY#,PlayerZ#,GetCameraX(1),GetCameraY(1),GetCameraZ(1)) // sent a ray from players pos to cam behind player.
if RayObjectID<>0 // if an object was hit, this means there's an object between player and cam, obstructing the view'
NewCameraDistance# = GetObjectRayCastDistance(0) // set distance to where has been hit.
else
NewCameraDistance# = UserCameraDistance# // nothing's wrong's so set to user defined zoom distance.
endif
CameraDistance# = CurveValue(NewCameraDistance#,CameraDistance#,10) // calc new camdistance
SetCameraPosition(1,PlayerX#,PlayerY#,PlayerZ#) // redundant?
MoveCameraLocalZ(1,-CameraDistance#) // move cam to new position behind the player.
MoveCameraLocaly(1,-adjustfactor#) // move cam to new position behind the player.

ElseIf cammode =1 // 1st person mode..
SetCameraPosition(1,PlayerX#,PlayerY#,PlayerZ#-1)   // place camera at player position
SetCameraRotation(1,CameraAngleX#,CameraAngleY#,0) // set camera at angle calculated according to mousemovent

///SetObjectVisible(PlayerObjectID,0)
Elseif cammode =2

Endif

EndFunction


Function UpdateEntities()


// moving platform
for i=0 to platform.length

// move platform
inc platform[i].posX
if platform[i].posX> 180
platform[i].posX =0
endif
n = Platform[i].ObjId
SetObjectPosition(n, Platform[i].x + sin(platform[i].posX)*2,Platform[i].y, Platform[i].z)

next


endFunction


Function WindowAndDisplaySetup()

// ------------not really needed for this example -------
// set window properties
SetWindowTitle("Universal 1st/3rd Person Framework V"+str(version#,1) )


// set display properties
//SetWindowSize(1920,1080,0)
SetWindowSize(1024,600,0)
SetWindowAllowResize(1) // allow the user to resize the window

//SetVirtualResolution(1920,1080) // doesn't have to match the window
setvirtualresolution(1024,600)
SetOrientationAllowed(1,1,1,1) // allow both portrait and landscape on mobile devices
SetSyncRate(30,0) // 30fps instead of 60 to save battery
SetScissor(0,0,0,0) // use the maximum available screen space, no black borders
UseNewDefaultFonts(1) // since version 2.0.22 we can use nicer default fonts
SetPrintSize( 20 )
SetPrintColor( 00, 00, 00,255 )

SetClearColor(1,128,198)
SetGlobal3DDepth(10000) // Sets the position of all 3D objects relative to 2D objects.

SetResolutionMode(1)
SetAntialiasMode(1)
SetImmersiveMode(1)
SetRawMouseVisible(0)
SetCameraRange(1,1,1000)
SetAmbientColor(128,128,128)

SetGenerateMipmaps(1)
// -----------------------------------------------------------

fog=1
// add some atmospheric fog
SetFogMode( fog )
// SetFogColor( 161,183,209 )
SetFogColor( 51,178,248 )
SetFogRange( 20, 200 )
//SetFogRange( 60,95 )
SetFogSunColor( 255,230,179 )

// -----------------------------------------------------------
SetShadowMappingMode(3)
SetShadowSmoothing(1)
SetShadowMapSize(2048,2048)

EndFunction


Foldend


// display, keys
Function CheckAdditiionalKeys()

// check additional keys..

remstart
if  GetRawKeyState(KEY_SPACE) = 1 //Space(jump)
initJump(grav decrease for while, jump_time)
endif

if GetRawKeyState(KEY_Alt = 1 //C(crouch)
crouchPlayer = 1
endif

if GetRawKeyState(KEY_CONTROL) = 1 //Ctrl/LMB
if item=weapon
launchProjectile
else
useCurrentItem
endif
endif
remend


If GetRawKeyPressed(KEY_F) = 1 // F= toggle focus (lock mouse to screen).
mouseLocked=1-mouseLocked
SetRawMouseVisible (mouseLocked)
period#=Timer()+1000000
For delay#=0 to period#
Next delay# // make sure doesn't  get  pressed right after again.

Endif

If  GetRawKeyPressed(KEY_F1) = 1
helpdisplay=1-helpdisplay // F1= help
period#=Timer()+1000000
For delay#=0 to period#
Next delay# // make sure doesn't  get  pressed right after again.

EndIf
If  GetRawKeyPressed(KEY_F2) = 1
infodisplay=1-infodisplay // F2= info
period#=Timer()+1000000
For delay#=0 to period#
Next delay# // make sure doesn't  get  pressed right after again.

EndIf

If  GetRawKeyPressed(KEY_F3) = 1 // F3= toggle (1st/3rd person)
cammode = cammode + 1
if cammode = 2 then MoveCameraLocalZ(1,-10) // move cam to new position behind the player.
if cammode = 2 then MoveCameraLocalY(1,3) // move cam to new position behind the player.

if cammode = 3 then cammode=0 // F3= toggle (1st/3rd person)
period#=Timer()+1000000
For delay#=0 to period#
Next delay# // make sure doesn't  get  pressed right after again.

EndIf


If  GetRawKeyPressed(KEY_F4) = 1
cammode = 1 - cammode // F3= toggle (1st/3rd person)
period# = Timer()+1000000
For delay#=0 to period#
Next delay# // make sure doesn't  get  pressed right after again.

EndIf

If  GetRawKeyState(KEY_F5) = 1
endif

If  GetRawKeyPressed(KEY_F6) = 1
Fog = 1 - fog
SetFogMode( fog )
endif

remstart

If GetRawKeyState(KEY_I) = 1 then inventoryMode=1-inventoryMode //toggle inventory/zoom
If Tab/MMBwheel and inventoryMode=True then select weapon/item+ or -
If Tab/MMBwheel and inventoryMode=False then zoom+ or -

If Enter/MMB and mulitPlayer then chat=1-chat
If M(map) then mapDisplay=1-mapDisplay
If L(light) then torchOn=-torchOn

If P/Pause then pauseGame=1-pauseGame
If F1(help) then helpDisplay=1-helpDisplay

If F4
If F5 (fog)
If F5 then audioOn=1-audioOn

If F6
gfxMode=gfxMode+1
if gfxMode=gfxMax
gfxMode=gfxModeMin(PC only)
endif
endif
endif

remend

If GetRawKeyPressed(KEY_ESC) then endgame=1 // Esc = exit(windows only)

EndFunction

Function DisplayInfo()

If infodisplay
// print info on screen..

Print ("Player Life " + str(player.Life)+" | Bonus : "+Str(player.Bonus))

Print ("--------------------------")
Print ("FPS: " + str(  ScreenFPS() ))
Print ("FrameTime: " + str(  GetFrameTime() ))
Print ("Seconds: " + str( GetSeconds() ))
Print ("Polygons: " + str(   GetPolygonsDrawn ()  ))
Print("CameraAngleX: "+ str(CameraAngleX#))
if cammode=0 then camdis$="3rd person(default)"
if cammode=1 then camdis$="1st person"
if cammode=2 then camdis$="detached"
Print("Cammode: "+ camdis$)
Print("")
Print ("F1 = Help")

EndIf


EndFunction

Function DisplayHelp()

If helpdisplay
// print info on screen..
Print ("F2 = toggle tech info")
Print ("F3 = toggle 1st/3rd person mode")
Print ("F4 = toggle fly/walk mode")
Print ("F5 = toggle audio on/off")
Print ("F6 = toggle fog on/off")
Print ("F7 = toggle gfxmode")
Print ("F8 = toggle sun on/off")
Print("")
Print ("W, A, S, D, RMB = move")
Print ("Q, E =  strafe")
Print ("Mouse to look round")
Print ("Mousewheel = zoom in/out")
Print ("Shift  + move = run")
Print ("Space =  jump, Alt = crouch")
Print ("-Not implemented yet-")
Print ("Ctrl / LMB = fire/use item")
Print ("Tab / i = cycle inventory items")
Print ("T =  torch, M = map, C = compass ")
Print ("")
Print ("F = toggle Mouse lock")
Print ("Esc = exit, P = pause" )

EndIf


EndFunction

Function AssignKeys()
   
#constant KEY_BACK 8
#constant KEY_TAB 9

#constant KEY_ENTER 13
#constant KEY_SHIFT 16
#constant KEY_CONTROL 17
#constant KEY_ALT 18 // added
#constant KEY_ESC 27

#constant KEY_SPACE 32
#constant KEY_PAGEUP 33
#constant KEY_PAGEDOWN 34
#constant KEY_END 35
#constant KEY_HOME 36
#constant KEY_LEFT 37
#constant KEY_UP 38
#constant KEY_RIGHT 39
#constant KEY_DOWN 40

#constant KEY_INSERT 45
#constant KEY_DELETE 46

#constant KEY_0 48
#constant KEY_1 49
#constant KEY_2 50
#constant KEY_3 51
#constant KEY_4 52
#constant KEY_5 53
#constant KEY_6 54
#constant KEY_7 55
#constant KEY_8 56
#constant KEY_9 57

#constant KEY_A 65
#constant KEY_B 66
#constant KEY_C 67
#constant KEY_D 68
#constant KEY_E 69
#constant KEY_F 70
#constant KEY_G 71
#constant KEY_H 72
#constant KEY_I 73
#constant KEY_J 74
#constant KEY_K 75
#constant KEY_L 76
#constant KEY_M 77
#constant KEY_N 78
#constant KEY_O 79
#constant KEY_P 80
#constant KEY_Q 81
#constant KEY_R 82
#constant KEY_S 83
#constant KEY_T 84
#constant KEY_U 85
#constant KEY_V 86
#constant KEY_W 87
#constant KEY_X 88
#constant KEY_Y 89
#constant KEY_Z 90

#constant KEY_F1 112
#constant KEY_F2 113
#constant KEY_F3 114
#constant KEY_F4 115
#constant KEY_F5 116
#constant KEY_F6 117
#constant KEY_F7 118
#constant KEY_F8 119


#constant KEY_SEMICOL 186   
#constant KEY_EQUALS 187
#constant KEY_COMMA 188
#constant KEY_MINUS 189
#constant KEY_POINT 190
#constant KEY_SLASH 191
#constant KEY_SINGLQUOTE 192

#constant KEY_SQRBRLEFT 219
#constant KEY_BACKSLASH 220
#constant KEY_SQRBRRIGHT 221
#constant KEY_HASH 222
#constant KEY_ACCENT 223 // ' << is called ?

EndFunction

FoldEnd



RemiD

@Rick>>can you post a link to a playable demo (an executable for Windows OS) so that i can try ?
I am curious...
Thanks

Rick Nasher

#12
@Blendman
Hehehe, that's pretty cool: moving platforms demo here we come..  8)
Like those collectable cubes too.

I'm still working on it, of and on. Added stuff to try out..
So far added: an elevator, stairs, ladders, jumping pad, glass, lights + day/night switch, procedural textures, shooting, player type array preparation for multiple player objects and converted the scale to match the bullet physics scale so that it's easier to convert code later on when desired.

Not fit for publishing though, need to tidy up first, but still busy for wasn't completely satisfied with the camera handling(original works fine, but not flexible enough for it to be perfect) so decided to introduce a cam pivot, which is currently giving me bit of a headache.  ::)





@RemiD
Sorry, didn't respond to your message sooner. They literally took off half my roof here to have an "upgraded" version installed, which has given me and my gf lot's of hassle and work. While we were just finished with fixing up the place last year- thank the landlord..  >:(

I like your submission to the coding competition and should really be 'easy' to implement in AGK. Easy of course as in that it will take a little time(which I do not have, way too busy sorry to say). But AGK has a lot of similar commands as Blitz3d only named differently and not always working exactly the same of course. Lot's are almost exact copies though. E.g.  EntityInView in AGK is GetObjectInScreen.
Bare in mind that 'entities' are called 'objects'.  :P

Anyway, sure I can generate an exe for you. I myself do not usually feel confident in running other peoples exe's no matter who (bit paranoid, but better safe than sorry..  :-[) . I'd recommend any time just to download and install the AGK demo version, which is only 300MB's. But I've posted an exe+source with blendman's mods for you down here to try if you like:

http://www.mediafire.com/file/h7ka0n9nr2u2nd5/Univ_Mod.rar


_______________________________________
B3D + physics + shaders + X-platform = AGK!
:D ..ALIENBREED *LIVES* (thanks to Qube).. :D
_______________________________________

RemiD

@Rick>>Thanks for the demo

It is a good start.

I have noticed something :
The gravity seems to not be and "increasing force". (it seems a "fixed force")
Even if you are not looking to use realistic physics, it is easy to add a gravity which increases (pull the player towards the ground faster and faster)
example :
gravity = gravity + 0.01 (if you want to have realistic force you need to increment/decrement it depending on the FPS)
translateentity(Player,0,-gravity,0)

Anyway, good luck for the next steps (nice shadows)

Rick Nasher

@RemiD
True, gravity is very, very basic.
Wasn't ready for that, was saving it for the physics version, but will indeed modify this.
Good point- easy to implement.

Shadows are very easy to implement in AGK on any object: SetObjectCastShadow(objectname,1)
So I cannot take any coding achievement claim for that at all, hehehe.

_______________________________________
B3D + physics + shaders + X-platform = AGK!
:D ..ALIENBREED *LIVES* (thanks to Qube).. :D
_______________________________________