behdadsoft, here is an example which uses Raycasts to stop the sticky walls. This small example, should illustrate everything you need to get you started with a simple physics platform game (without ladders
). I haven't provided any comments, as its not Christmas anymore, but I'd be more than happy to answer any questions you have, if you are unable to get the answers from the online documentation...
This was done in AppGameKit 1 for you... Just copy and paste this into AppGameKit, you do not need any media.
SetVirtualResolution(1138, 640)
SetPhysicsScale(0.05)
SetPhysicsGravity(0, 1000)
SetPhysicsWallBottom(0)
SetPhysicsWallTop(0)
SetPhysicsWallRight(0)
SetPhysicsWallLeft(0)
global Ground_Spr
global dim Platform_Spr[3]
global LeftEdge_Spr
global RightEdge_Spr
global Charater_Spr
global RaycastBottom
global dim RaycastRight[2]
global dim RaycastLeft[2]
// Create Ground
Ground_Spr = CreateSprite(0)
SetSpriteSize(Ground_Spr, 1138, 32)
SetSpritePosition(Ground_Spr, 0, 608)
SetSpritePhysicsOn(Ground_Spr, 1)
SetSpritePhysicsRestitution(Ground_Spr, 0)
SetSpriteGroup(Ground_Spr, 1)
// Create Left Edge
LeftEdge_Spr = CreateSprite(0)
SetSpriteSize(LeftEdge_Spr, 32, 640)
SetSpritePosition(LeftEdge_Spr, -32, 0)
SetSpritePhysicsOn(LeftEdge_Spr, 1)
SetSpritePhysicsRestitution(LeftEdge_Spr, 0)
SetSpriteGroup(LeftEdge_Spr, 1)
// Create Right Edge
RightEdge_Spr = CreateSprite(0)
SetSpriteSize(RightEdge_Spr, 32, 640)
SetSpritePosition(RightEdge_Spr, 1138, 0)
SetSpritePhysicsOn(RightEdge_Spr, 1)
SetSpritePhysicsRestitution(RightEdge_Spr, 0)
SetSpriteGroup(RightEdge_Spr, 1)
// Create Platforms
for i=1 TO 3
Platform_Spr[i] = CreateSprite(0)
SetSpriteSize(Platform_Spr[i], 128, 32)
SetSpritePhysicsOn(Platform_Spr[i], 1)
SetSpritePhysicsRestitution(Platform_Spr[i], 0)
SetSpriteGroup(Platform_Spr[i], 1)
next i
SetSpritePositionByOffset(Platform_Spr[1], 300, 450)
SetSpritePositionByOffset(Platform_Spr[2], 569, 350)
SetSpritePositionByOffset(Platform_Spr[3], 838, 450)
// Create Character
Character_Spr = CreateSprite(0)
SetSpriteSize(Character_Spr, 32, 32)
SetSpriteColor(Character_Spr, 255, 0, 0, 255)
SetSpritePosition(Character_Spr, 32, 576)
SetSpritePhysicsOn(Character_Spr, 2)
SetSpritePhysicsCanRotate(Character_Spr, 0)
SetSpritePhysicsRestitution(Character_Spr, 0)
do
// Raycast Bottom
RaycastBottom = PhysicsRayCastGroup(1, GetSpriteXByOffset(Character_Spr), GetSpriteYByOffset(Character_Spr), GetSpriteXByOffset(Character_Spr), GetSpriteYByOffset(Character_Spr) + 18)
// Raycast Right
RaycastRight[1] = PhysicsRayCastGroup(1, GetSpriteXByOffset(Character_Spr), GetSpriteY(Character_Spr), GetSpriteXByOffset(Character_Spr) + 18, GetSpriteY(Character_Spr))
RaycastRight[2] = PhysicsRayCastGroup(1, GetSpriteXByOffset(Character_Spr), GetSpriteY(Character_Spr) + 32, GetSpriteXByOffset(Character_Spr) + 18, GetSpriteY(Character_Spr) + 32)
// Raycast Left
RaycastLeft[1] = PhysicsRayCastGroup(1, GetSpriteXByOffset(Character_Spr), GetSpriteY(Character_Spr), GetSpriteXByOffset(Character_Spr) - 18, GetSpriteY(Character_Spr))
RaycastLeft[2] = PhysicsRayCastGroup(1, GetSpriteXByOffset(Character_Spr), GetSpriteY(Character_Spr) + 32, GetSpriteXByOffset(Character_Spr) - 18, GetSpriteY(Character_Spr) + 32)
// Character Movement
if GetRawKeyState(37) = 1 AND RaycastLeft[1] = 0 AND RaycastLeft[2] = 0
SetSpritePhysicsVelocity(Character_Spr, -200, GetSpritePhysicsVelocityY(Character_Spr))
elseif GetRawKeyState(39) = 1 AND RaycastRight[1] = 0 AND RaycastRight[2] = 0
SetSpritePhysicsVelocity(Character_Spr, 200, GetSpritePhysicsVelocityY(Character_Spr))
else
SetSpritePhysicsVelocity(Character_Spr, 0, GetSpritePhysicsVelocityY(Character_Spr))
endif
if GetRawKeyPressed(32) = 1 AND RaycastBottom = 1
SetSpritePhysicsVelocity(Character_Spr, GetSpritePhysicsVelocityX(Character_Spr), -700)
endif
Sync()
loop