Nenohum,
Here is your code freshly edited.
sync on : sync rate 0
hide mouse
autocam off
` constants/for ease of variable initializing
null = 0 : false = 0 : true = 1 : upLocked = 1 : downLocked = 2
playerUpLookMax = -75 : playerDownLookMax = 60 : mouseSpeed# = 0.50 : playerSpeed# = 8.00 : playerY# = 30.00
fowards = 0 : rightStrafe = fowards + 90 : backwards = fowards + 180 : leftStrafe = fowards + 270
playerObject = 1
`make some interacting objects
make object cube 1,50: Color object 1,RGB(000,255,000)
make object sphere 2,50: Color object 2,RGB(255,000,000)
set object collision on 2 : position object 2,130,0,0
make object box 3,100,100,5: Position object 3,0,0,150 : color object 3,RGB(000,150,150)
make object box 4,15,20,50: color object 4,RGB(000,255,255) : position object 4,-80,0,0
`set some collision stuff
set object collision to spheres 2 : set object collision to boxes 1
`make limb
make object cylinder 9999,100 : rotate object 9999,90,0,0 : scale object 9999,50,500,50
make mesh from object 1,9999 : add limb 1,1,1 : delete object 9999 : offset limb 1,1,0,0,250
delete mesh 1
`variables
enemyhp# = 5000
ammo# = 1000
maxammo# = 1000
clips# = 3
maxclips# = 3
DO
`---------------
`CAMERA MOVEMENT
`---------------
` Use mouse for 'look' - LOCKplayerAngleX flag limits player's x rotational axis
` IN FPS's IT'S BEST IF ALL ROTATIONAL MOTION IS CONTROLLED BY MOUSE
if mousemovex() <> null then inc playerAngleY#,(mousemovex() * mouseSpeed#)
if LOCKplayerAngleX = false and mousemovey() <> null then inc playerAngleX#,(mousemoveY() * mouseSpeed#)
` Limit player's X axis rotation
if playerAngleX# < playerUpLookMax
LOCKplayerAngleX = upLocked
playerAngleX# = playerUpLookMax
endif
if playerAngleX# > playerDownLookMax
LOCKplayerAngleX = downLocked
playerAngleX# = playerDownLookMax
endif
` Release axis lock
if LOCKplayerAngleX = upLocked and mousemovey() > null then LOCKplayerAngleX = false
if LOCKplayerAngleX = downLocked and mousemovey() < null then LOCKplayerAngleX = false
` walking/strafing; based on angle of movement relative to the player's point of view(POV)
` HERE WE SET RELATIONAL WALK ANGLES - rightstrafe will be at an angle pointing away from
` the player to the right and so on...
if upkey() = true then playerWalkAngle = fowards
if rightkey() = true then playerWalkAngle = rightstrafe
if downkey() = true then playerWalkAngle = backwards
if leftkey() = true then playerWalkAngle = leftstrafe
` reposition character if the assigned keys are pressed
` HERE IS HOW STRAFE WORKS - playerwalkangle is added to playeryangle so that
` movement will be relational to player's POV(playerAngleY#)
if upkey() = true or downkey() = true or rightkey() = true or leftkey() = true
playerX# = playerX# + (sin(playerAngleY# + playerWalkAngle) * playerSpeed#)
playerZ# = playerZ# + (cos(playerAngleY# + playerWalkAngle) * playerSpeed#)
endif
position camera playerX#,playerY#,playerZ#
` rotate player if there if any mouse movement detected
if mousemovex() <> null or mousemovey() <> null
xrotate camera wrapvalue(playerAngleX#)
yrotate camera wrapvalue(playerAngleY#)
endif
` HERE IS WHERE WE WILL SIMPLY REPOSITION AND ROTATE THE PLAYER COLLISION OBJECT
` BY REUSING THE ALREADY CALCULATED PLAYER VARIABLES (use collision object's properties when
` testing collision - we are simply parenting it to the camera on these lines)
position object playerObject,playerX#,playerY#,playerZ#
xrotate object playerObject,wrapvalue(playerAngleX#)
yrotate object playerObject,wrapvalue(playerAngleY#)
`-------------------
`ammo and reloading
`------------------
if mouseclick()=1 and keystate(19)=0
if ammo#>0
dec ammo#,1
endif
if object collision(1,0)
cc=object collision(1,0)
if ammo#>0
if cc=2
dec enemyhp#,1
endif
endif
endif
endif
if enemyhp#=0 and object exist(2)=1
delete object 2
endif
if object exist(4)=1 then center text object screen x(4),object screen y(4)-70, "Ammo Crate"
if object exist(2)=1
center text object screen x(2),object screen y(2)-70,"Enemy health: " + str$(enemyhp#)
endif
text 0,screen height()-50,"Ammo: " + str$(ammo#): text 0,screen height()-40, "clips :" + str$(clips#)
if mouseclick()=0 and keystate(19)=1 and clips#>0 then reload#=1
if reload#=1 then inc time#,.01
if time#>=1 then ammo# = maxammo#: dec clips#,1 : time#=0 : reload# = 0
if reload#=1 then center text screen width()/2,screen height()/2, "Reloading"
sync
LOOP
There were a few important variables I failed to mention to you about.
null = 0 : false = 0 : true = 1 : upLocked = 1 : downLocked = 2
playerUpLookMax = -75 : playerDownLookMax = 60 : mouseSpeed# = 0.50 : playerSpeed# = 8.00 : playerY# = 30.00
fowards = 0 : rightStrafe = fowards + 90 : backwards = fowards + 180 : leftStrafe = fowards + 270
playerObject = 1
These are 'easy-initialization' variables. The first two are the player's up and down look barrier values. The uplook value must be negative, or the player will be stuck looking down. The downlook must be a positive value, as shown in the image below.
mouseSpeed# might be better known as playerLookSpeed#. A larger value will make the mouse more sensitive, and will rotate the camera a greater distance when the mouse is moved.
playerObject assigns a specific object to the camera to be used as the collision object.
playerSpeed# determines how fast your character walks(in relation to the size of the scene).
playerY# is there to be able to simply adjust the player's height for now.
Any other variables are there just to make the code easier to undertand. For instance, instead of using...
...I use...
if object exist(2) = true
Just set
true to equal a value of
1 at the top of your program. I try to implement a variable in place of a number value:
1. It takes down the confusion of seeing so many numerical values within your code
2. It helps to make your code more clear and easier to understand your intentions for each line of code.
3. A single variable can be used to set several different parts of your program, or even just one, simply and without having to sort through your code to find out where 'that darn!' variable is, so that you can change it's value...hehe.
By the way, though I could be wrong, you might want to down size your objects some. I beleive that the larger an object is, the more memory and processor it takes to get it to the screen. Just make sure to readjust the playerY# variable when resizing the scene.
I wasn't quite sure which object was the player collision object. However, just set that with the 'easy-initialization' variable named
playerObject. There was a 2nd position camera command directly above the sync command. It was causing the scene to flucker from position to position. So, set playerObject, and you will be set for player collision, using that object.
I have done away with the
move object command, and have stuck with the angle variables. There is no need for the move object comomand here.
Well, that's about it. Study the code to understand it more and ask me if you have any questions.
[EDIT] Well, the weapon limb code is stil a WIP. I should be finnished soon though.