I've almost nailed it but my logic is failing me somewhere and I need some help.
[edit] Added the elevel file to the post attatchments.
// Project: OneWayJump
// Created: 19-04-03
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle("OneWayJump")
SetWindowSize(1024, 768, 0)
SetWindowAllowResize(1) // allow the user to resize the window
// set display properties
SetVirtualResolution(1024, 768) // doesn't have to match the window
SetOrientationAllowed(1, 1, 1, 1) // allow both portrait and landscape on mobile devices
SetSyncRate(60, 0) // 30fps instead of 60 to save battery
SetScissor(0, 0, 0, 0) // use the maximum available screen space, no black borders
UseNewDefaultFonts(1)
img_GreyCube = LoadImage( "GreyCube.png" )
img_RedCube = LoadImage( "RedCube.png" )
type GTile
id as integer
x as integer
y as integer
endtype
Global GList as GTile[]
global Level as integer
global levelD as string
global TileArray as integer[16,12]
global Player as integer
global PlayerX as float
global PlayerY as float
global JumpHeight as float = 15
global CanJump as Integer = 1
global IsJumping as integer = 0
global IsFalling as integer = 1
global Gravity as float = 0.8
Player = CreateSprite(img_RedCube)
Level = OpenToRead( "leveldata.txt" )
levelD = ReadLine(Level)
tempX as integer = 0
tempY as integer = 0
for x = 1 to len(levelD)
if tempX > 15
tempX = 0
tempY = tempY + 1
endif
TileArray[ tempX,tempY ] = val(mid(levelD, x, 1) )
if TileArray[ tempX,tempY ] = 1
local gt as GTile
gt.id = CreateSprite(img_GreyCube)
SetSpriteOffset(gt.id,1,1)
gt.x = tempX * 64
gt.y = tempY * 64
GList.insert(gt)
endif
if TileArray[ tempX,tempY ] = 2
SetSpritePosition( Player, tempX * 64, tempY * 64 )
endif
tempX = tempX + 1
next
for x = GList.length to 0 step -1
SetSpritePositionByOffset(GList[x].id, GList[x].x, GList[x].y)
next
PlayerX = GetSpriteX(Player)
PlayerY = GetSpriteY(Player)
do
if GetRawKeyPressed(259) and CanJump = 1 // left control key
CanJump = 0
IsJumping = 1
endif
if IsJumping = 1
PlayerY = PlayerY - JumpHeight
JumpHeight = JumpHeight - Gravity
if JumpHeight < 0
IsFalling = 1
IsJumping = 0
JumpHeight = 15
endif
endif
if IsFalling = 1
//CanJump = 0
PlayerY = PlayerY + 6
for x = GList.length to 0 step -1
if RectsOverlap(PlayerX, PlayerY, 64, 64, GList[x].x, GList[x].y, 64, 64) = 1
if mod(PlayerY, 64) < JumpHeight * 2
PlayerY = PlayerY - mod(PlayerY, 64)
JumpHeight = 15
IsFalling = 0
CanJump = 1
endif
else
endif
next
endif
if GetRawKeyState(37) = 1
PlayerX = PlayerX - 4
elseif GetRawKeyState(39) = 1
PlayerX = PlayerX + 4
endif
SetSpritePosition(Player, PlayerX, PlayerY)
Print(JumpHeight)
Sync()
loop
function RectsOverlap(x1, y1, w1, h1, x2, y2, w2, h2)
value = 1
If x1 >= (x2 + w2) Or (x1 + w1) <= x2 Then value = 0
If y1 >= (y2 + h2) Or (y1 + h1) <= y2 Then value = 0
endfunction value
Imaginations' greatest gift is the knowledge you supply it.