Okay update on where up to with this and a video will follow soon.
I have managed to implement the ladders to fully work! It is so much easier to do all this with my own collision and physics than use the native commands
[EDIT]
Forgot to mention, in order to code the ladders correctly I used 3 images one for the top, middle and bottom with the middle one being able to make ladder any length by repeating the block. As long as the top block is on the top and bottom block on the bottom of the ladder it works
Each of the 3 blocks have different rules to make the ladder work using the rules below.
Ladder rules:
- Can climb up and down!
- Can jump on ladder, e.g. jump onto it half way up
- Can jump off ladder but only when moving left or right
- Can walk off ladder and fall to ground
- Can fall off ladder and whilst falling get back on ladder
Well I am quite happy with it and the game now is fully working with 6 point collision. I might expand this later to 8 point for calculating slopes but at the moment I am happy with blocks.
Physics is fully working.
The only issue at the moment now is the animation of the sprite. I changed to an atlas image for the character and it uses 7 images to animate.
1 for standing (1 of the walking images)
4 for walking
2 for climbing
1 for jumping
Anyone able to assist? I will keep playing with the code in the mean time.
Loading in the player:
create_player:
/*
Animation frames as follows:
1 - standing
1 - 4 walking
5 - jumping
6 - 7 climbing
*/
playerFPS = 10
playerLoop = 0
xPlayer# = 2.0
yPlayer# = 12.0 // 17.0 is correct positiion on floor when falls into place
playerSpeed# = 3.5
xPlayerSpeed# = xPixel# * playerSpeed#
yPlayerSpeed# = (screenHeight#/screenWidth#) * aspect#
playerImage = LoadImage("platypus.png")
player = CreateSprite(playerImage)
SetSpriteAnimation(player,128,128,7)
SetSpriteSize(player, blockSizeX#*2, blockSizeY#*2)
SetSpritePosition( player, (xPlayer#-1) * blockSizeX#, (yPlayer#-1) * blockSizeY# )
SetSpriteOffset(player, GetSpriteWidth(player)/2, GetSpriteHeight(player))
xPlayer# = GetSpriteXByOffset(player)
yPlayer# = GetSpriteYByOffset(player)
playerWidth# = GetSpriteWidth(player)
playerHeight# = GetSpriteHeight(player)
wallProbeDistance# = playerWidth# * 0.2
ceilingProbeDistance# = playerHeight# * 0.95
PlaySprite(player, playerFPS, playerLoop, 1, 1)
return
Section to control and animate:
if physics = 1
yPlayerSpeed# = yPlayerSpeed# + gravity#
if yPlayerSpeed# >= playerSpeedLimit# then yPlayerSpeed# = playerSpeedLimit#
PlaySprite(player, playerFPS, playerLoop, 5, 5) // Frame for jumping as in the air
else
if movePlayer$ = "0"
PlaySprite(player, playerFPS, playerLoop, 1, 1) // Frame for standing if not moving
elseif movePlayer$ = "L" or movePlayer$ = "R"
PlaySprite(player, playerFPS, playerLoop, 1, 4) // Frames to play for walking
endif
endif
if GetRawKeyState(38) and ladderContact = 1 or GetVirtualJoystickY(joyStick) < 0.0 and ladderContact = 1 // Check for Up key (Move Block in Direction)
if dontMoveLadder$ = "D" or dontMoveLadder$ = "0"
movingLadder = 1
yPlayerSpeed# = (screenHeight#/screenWidth#) * aspect#
yPlayer# = yPlayer# - (xPlayerSpeed# * yPlayerSpeed#)
PlaySprite(player, playerFPS, playerLoop, 6, 7) // Frame for climbing on ladder
endif
elseif GetRawKeyState(40) and ladderContact = 1 or GetVirtualJoystickY(joyStick) > 0.0 and ladderContact = 1 // Check for Down key (Move Block in Direction)
if dontMoveLadder$ = "U" or dontMoveLadder$ = "0"
movingLadder = 1
yPlayerSpeed# = (screenHeight#/screenWidth#) * aspect#
yPlayer# = yPlayer# + (xPlayerSpeed# * yPlayerSpeed#)
PlaySprite(player, playerFPS, playerLoop, 6, 7) // Frame for climbing on ladder
endif
endif
I am thinking at the moment that the problem I am having is that when I press the key to move it is just playing the first frame in the sequence instead of the full frames as it is being called every time the key is pressed but not too sure yet?
So I am pressing key and keeping finger on key to move but in code when key is pressed then PlaySprite command.
PlaySprite(player, playerFPS, playerLoop, 6, 7)
player is the sprite
playerFPS is set to 10
playerLoop is set to 1
Cheers
[EDIT]
Just put the images on for ladders and player so you can see.
As you can see in the ladders images I put a bit of green on the top block and brown on the bottom one, the middle section stays the same. Also by doing this it helps to know which block I am using in my editor