Here are the other 2 zip files I missed off and below is the code for each one.
MAP EDITOR:
// Project: Map Editor
// Created: 2016-01-11
// By SpecTre
// ************* CONTROLS *************
// Spacebar = Show platform blocks to select from.
// Arrows l, r, u, d = Move around the map
// Left mouse = Paint a block
// Right mouse = Delet a block
// 0 = Water layer
// 1 = Start position and enemy layer
// 2 = Main Platform layer and collectables
// S = Save level
// ********** Set Properties **********
#constant keyLeft = GetRawKeyState(37)
#constant keyRight = GetRawKeyState(39)
#constant keyUp = GetRawKeyState(38)
#constant keyDown = GetRawKeyState(40)
#constant keyEsc = GetRawKeyState(27)
#constant space = GetRawKeyPressed(32)
#constant pointerReleased = GetRawMouseLeftReleased()
#constant pointerPressed = GetRawMouseLeftPressed()
#constant mouseStateLeft = GetRawMouseLeftState()
#constant mouseStateRight = GetRawMouseRightState()
#constant key0 = GetRawKeyState(48)
#constant key1 = GetRawKeyState(49)
#constant key2 = GetRawKeyState(50)
#constant keyS = GetRawKeyReleased(83)
#constant keyL = GetRawKeyReleased(76)
#constant true = 1
#constant false = 0
#constant numberLvlBlocks = 64
#constant blockPickSize = 80
#constant blockSize = 40
#constant drawBlockDepth = 0
#constant drawBlockDepth2 = 1000
#constant mapPieceDepth = 1
#constant gridLayerDepth = 50
#constant layer0Depth = 100
#constant layer1Depth = 200
#constant layer2Depth = 300
#constant colorTrans = 150
#constant layerMax = 2
global layer as integer
layer = 2
Dim mapPiece[numberLvlBlocks] as integer
Dim lvlGrid[1000, 1000, 2] as integer
for l = 0 to layerMax
for y = 0 to 1000
for x = 0 to 1000
lvlGrid[ x, y, l] = 0
next x
next y
next l
global windowWidth as integer
global windowHeight as integer
global screensWide as integer
global screensHeight as integer
global lvlX as integer
global lvlY as integer
gosub loadLevelImages
windowWidth = 1280
windowHeight = 800
displayOffsetX = 0
displayOffsetY = 0
displayOffsetSpeed = 10
// ***************************************************************************************************************
screensWide = 1 // Change this for how many screens wide you want the map. 0 = Single screen
screensHeight = 1 // Change this for how many screens heigh you want the map. 0 = Single screen
lvlNum = 1 // Change this for the name on the level, eg level 1 or 2 etc
gosub readLevel // Uncomment this line if want to load in a level to re edit.
// ***************************************************************************************************************
//mapSizeX = screensWide * windowWidth
//mapSizeY = screensHeight * windowHeight
lvlX = (screensWide + 1) * 32
lvlY = (screensHeight + 1) * 20
mapSizeX = (lvlX * blockSize) - windowWidth
mapSizeY = (lvlY * blockSize) - windowHeight
mouseToggle = false
lineSizeX = 2
lineSizeY = 2
SetPrintColor(180, 180, 180)
SetPrintSize(30)
// ************************************
SetWindowTitle( "MAP EDITOR" )
SetVirtualResolution( windowWidth, windowHeight )
SetWindowSize( windowWidth, windowHeight, 0 )
SetWindowPosition( 0, 0 )
/*
displayLeft# = GetScreenBoundsLeft()
displayRight# = GetScreenBoundsRight()
displayTop# = GetScreenBoundsTop()
displayBottom# = GetScreenBoundsBottom()
SetScissor( displayLeft#, displayTop#, displayRight#, displayBottom# )
*/
SetScissor( 0, 0, 0, 0 )
i = 0
mapPiece[i] = CreateSprite(0)
SetSpriteDepth( mapPiece[i], mapPieceDepth )
SetSpriteColor( mapPiece[i], 0, 0, 200, 255 )
SetSpriteSize( mapPiece[i], blockPickSize*8+50, blockPickSize*8+50)
SetSpritePosition( mapPiece[i], -1005, -5 )
for y = 0 to 7
for x = 0 to 7
i=i+1
mapPiece[i] = CreateSprite(lvlBlock[i].iImage)
SetSpriteSize( mapPiece[i], blockPickSize, blockPickSize )
SetSpritePosition( mapPiece[i], (blockPickSize+5) * x - 1000, (blockPickSize+5) * y )
SetSpriteDepth( mapPiece[i], mapPieceDepth )
next x
next y
CreateGrid(lvlX, lineSizeX, lineSizeY)
CreateGrid(lvlY, lineSizeX, lineSizeY)
drawBlock = CreateSprite(lvlBlock[1].iImage)
SetSpriteSize( drawBlock, blockSize, blockSize )
SetSpritePosition( drawBlock, -1000, 0 )
SetSpriteOffset( drawBlock, GetSpriteWidth(drawBlock)/2, GetSpriteHeight(drawBlock)/2 )
SetSpriteDepth( drawBlock, drawBlockDepth )
do
mouseX# = ScreenToWorldX(GetPointerX())
mouseY# = ScreenToWorldY(GetPointerY())
if keyEsc
DeleteAllSprites()
DeleteAllImages()
End
endif
if keyS
gosub saveLevel
endif
if keyLeft
displayOffsetX = displayOffsetX - displayOffsetSpeed
if displayOffsetX <= 0 then displayOffsetX = 0
endif
if keyRight
displayOffsetX = displayOffsetX + displayOffsetSpeed
if displayOffsetX >= mapSizeX then displayOffsetX = mapSizeX + 2
endif
if keyUp
displayOffsetY = displayOffsetY - displayOffsetSpeed
if displayOffsetY <= 0 then displayOffsetY = 0
endif
if keyDown
displayOffsetY = displayOffsetY + displayOffsetSpeed
if displayOffsetY >= mapSizeY then displayOffsetY = mapSizeY
endif
if key0
layer = 0
for y = 0 to lvlY
for x = 0 to lvlX
if lvlGrid[ x, y, 0 ] <> 0 or lvlGrid[ x, y, 1 ] <> 0 or lvlGrid[ x, y, 2 ] <> 0
SetSpriteColorAlpha(lvlGrid[ x, y, 0], 255)
SetSpriteColorAlpha(lvlGrid[ x, y, 1], colorTrans)
SetSpriteColorAlpha(lvlGrid[ x, y, 2], colorTrans)
endif
next x
next y
elseif key1
layer = 1
for y = 0 to lvlY
for x = 0 to lvlX
if lvlGrid[ x, y, 0 ] <> 0 or lvlGrid[ x, y, 1 ] <> 0 or lvlGrid[ x, y, 2 ] <> 0
SetSpriteColorAlpha(lvlGrid[ x, y, 0], colorTrans)
SetSpriteColorAlpha(lvlGrid[ x, y, 1], 255)
SetSpriteColorAlpha(lvlGrid[ x, y, 2], colorTrans)
endif
next x
next y
elseif key2
layer = 2
for y = 0 to lvlY
for x = 0 to lvlX
if lvlGrid[ x, y, 0 ] <> 0 or lvlGrid[ x, y, 1 ] <> 0 or lvlGrid[ x, y, 2 ] <> 0
SetSpriteColorAlpha(lvlGrid[ x, y, 0], colorTrans)
SetSpriteColorAlpha(lvlGrid[ x, y, 1], colorTrans)
SetSpriteColorAlpha(lvlGrid[ x, y, 2], 255)
endif
next x
next y
endif
if space
if mouseToggle = false
gosub positionMapBlocksOn
else
gosub positionMapBlocksOff
endif
endif
if mouseToggle = true
if pointerReleased
blockClicked = GetSpriteHit(mouseX#, mouseY#)
for i = 1 to numberLvlBlocks
if blockClicked = mapPiece[i]
SetSpriteImage(drawBlock, lvlBlock[i].iImage)
endif
next i
gosub positionMapBlocksOff
endif
else
if mouseStateLeft
blockX = 0
blockY = 0
for y = 1 to lvlY
for x = 1 to lvlX
gosub checkGridPosition
gosub pasteBlock
next x
next y
elseif mouseStateRight
blockX = 0
blockY = 0
for y = 1 to lvlY
for x = 1 to lvlX
gosub checkGridPosition
gosub deleteBlock
next x
next y
endif
endif
SetSpritePositionByOffset( drawBlock, mouseX#, mouseY# )
SetViewOffset(displayOffsetX, displayOffsetY)
print ("Layer = " + Str(layer))
print ("Layer 0 = Water")
print ("Layer 1 = Enemies")
print ("Layer 2 = Platforms")
Print(GetWritePath())
Sync()
loop
checkGridPosition:
if mouseX# >= (x-1)*blockSize and mouseX# <= x*blockSize and mouseY# >= (y-1)*blockSize and mouseY# <= y*blockSize
blockX = x
blockY = y
endif
return
pasteBlock:
if lvlGrid[ blockX, blockY, layer ] <> 0
SetSpriteImage(lvlGrid[ blockX, blockY, layer ], GetSpriteImageID(drawBlock))
else
blockSprite=CreateSprite(GetSpriteImageID(drawBlock))
SetSpriteSize(blockSprite, blockSize, blockSize)
if layer = 0
SetSpriteDepth(blockSprite, layer0Depth)
elseif layer = 1
SetSpriteDepth(blockSprite, layer1Depth)
elseif layer = 2
SetSpriteDepth(blockSprite, layer2Depth)
endif
lvlGrid[ blockX, blockY, layer ]=blockSprite
SetSpritePosition( lvlGrid[ blockX, blockY, layer ], (blockX-1) * blockSize, (blockY-1) * blockSize )
endif
return
deleteBlock:
if lvlGrid[ blockX, blockY, layer ] <> 0
DeleteSprite(lvlGrid[ blockX, blockY, layer ])
lvlGrid[ blockX, blockY, layer ]=0
endif
return
positionMapBlocksOn:
i = 0
SetSpriteVisible(drawBlock, 0)
SetSpritePosition( mapPiece[i], mouseX# - (blockPickSize*4+25), mouseY# - (blockPickSize*4+25) )
for y = 0 to 7
for x = 0 to 7
i=i+1
SetSpritePosition( mapPiece[i], (blockPickSize+5) * x + (mouseX# - (blockPickSize*4+17)), (blockPickSize+5) * y + (mouseY# - (blockPickSize*4+17)))
next x
next y
mouseToggle = true
SetSpriteDepth( drawBlock, drawBlockDepth2 )
return
positionMapBlocksOff:
SetSpriteVisible(drawBlock, 1)
i = 0
SetSpritePosition( mapPiece[i], -1005, -5 )
for y = 0 to 7
for x = 0 to 7
i=i+1
SetSpritePosition( mapPiece[i], (blockPickSize+5) * x - 1000, (blockPickSize+5) * y )
next x
next y
mouseToggle = false
SetSpriteDepth( drawBlock, drawBlockDepth )
return
readLevel:
file$ = "lvl_" + Str(lvlNum) + ".txt"
OpenToRead(1, file$)
ReadLine(1)
screensWide = Val(ReadLine(1))
screensHeight = Val(ReadLine(1))
lvlX = (screensWide + 1) * 32
lvlY = (screensHeight + 1) * 20
for l = 0 to layerMax
ReadLine(1)
for y = 1 to lvlY
for x = 1 to lvlX
fileBlock$ = ReadLine(1)
if fileBlock$ <> "0"
for i = 1 to numberLvlBlocks
if fileBlock$ = lvlBlock[i].sLevelSection
blockSprite=CreateSprite(lvlBlock[i].iImage)
SetSpriteSize(blockSprite, blockSize, blockSize)
if layer = 0
SetSpriteDepth(blockSprite, layer0Depth)
elseif layer = 1
SetSpriteDepth(blockSprite, layer1Depth)
elseif layer = 2
SetSpriteDepth(blockSprite, layer2Depth)
endif
lvlGrid[ x, y, l ]=blockSprite
SetSpritePosition( lvlGrid[ x, y, l ], (x-1) * blockSize, (y-1) * blockSize )
endif
next i
else
lvlGrid[ x, y, l ] = 0
endif
next x
next y
next l
CloseFile ( 1 )
return
saveLevel:
file$ = "lvl_" + Str(lvlNum) + ".txt"
OpenToWrite(1,file$)
WriteLine(1, "Next 2 numbers are how many screens wide and heigh in X and Y")
WriteLine(1, Str(screensWide))
WriteLine(1, Str(screensHeight))
for l = 0 to layerMax
WriteLine(1, "Layer " + Str(l))
for y = 1 to lvlY
for x = 1 to lvlX
if lvlGrid[ x, y, l ] <> 0
blockSprite = GetSpriteImageID(lvlGrid[ x, y, l ])
for i = 1 to numberLvlBlocks
if blockSprite = lvlBlock[i].iImage
WriteLine(1, lvlBlock[i].sLevelSection)
endif
next i
else
WriteLine(1, "0")
endif
next x
next y
next l
CloseFile ( 1 )
return
Function CreateGrid(gridCount, lineSizeX, lineSizeY)
for grid = 0 to gridCount
gridSprite = CreateSprite(0)
SetSpriteDepth( gridSprite, gridLayerDepth )
if gridCount = lvlX
if Mod(grid,32) = 0
SetSpriteColor( gridSprite, 150, 0, 0, 255 )
else
SetSpriteColor( gridSprite, 100, 100, 100, 255 )
endif
SetSpriteSize(gridSprite, lineSizeX, (screensHeight + 1) * windowHeight)
SetSpritePosition(gridSprite, grid * blockSize, 0)
else
if Mod(grid,20) = 0
SetSpriteColor( gridSprite, 150, 0, 0, 255 )
else
SetSpriteColor( gridSprite, 100, 100, 100, 255 )
endif
SetSpriteSize(gridSprite, (screensWide + 1) * windowWidth, lineSizeY)
SetSpritePosition(gridSprite, 0, grid * blockSize -1)
endif
next grid
endfunction
loadLevelImages:
Type level_block_Type
iImage as integer
sLevelSection as string
Endtype
lvlBlock as level_block_Type[numberLvlBlocks]
level_texture_image = LoadImage("level_blocks.png")
for i = 1 to numberLvlBlocks
lvlBlock[i].iImage = LoadSubImage(level_texture_image, str(i) + ".png")
next i
lvlBlock[1].sLevelSection = "1"
lvlBlock[2].sLevelSection = "2"
lvlBlock[3].sLevelSection = "3"
lvlBlock[4].sLevelSection = "4"
lvlBlock[5].sLevelSection = "5"
lvlBlock[6].sLevelSection = "6"
lvlBlock[7].sLevelSection = "7"
lvlBlock[8].sLevelSection = "8"
lvlBlock[9].sLevelSection = "9"
lvlBlock[10].sLevelSection = "A"
lvlBlock[11].sLevelSection = "B"
lvlBlock[12].sLevelSection = "C"
lvlBlock[13].sLevelSection = "D"
lvlBlock[14].sLevelSection = "E"
lvlBlock[15].sLevelSection = "F"
lvlBlock[16].sLevelSection = "G"
lvlBlock[17].sLevelSection = "H"
lvlBlock[18].sLevelSection = "I"
lvlBlock[19].sLevelSection = "J"
lvlBlock[20].sLevelSection = "K"
lvlBlock[21].sLevelSection = "L"
lvlBlock[22].sLevelSection = "M"
lvlBlock[23].sLevelSection = "N"
lvlBlock[24].sLevelSection = "O"
lvlBlock[25].sLevelSection = "P"
lvlBlock[26].sLevelSection = "Q"
lvlBlock[27].sLevelSection = "R"
lvlBlock[28].sLevelSection = "S"
lvlBlock[29].sLevelSection = "T"
lvlBlock[30].sLevelSection = "U"
lvlBlock[31].sLevelSection = "V"
lvlBlock[32].sLevelSection = "W"
lvlBlock[33].sLevelSection = "X"
lvlBlock[34].sLevelSection = "Y"
lvlBlock[35].sLevelSection = "Z"
lvlBlock[36].sLevelSection = "a"
lvlBlock[37].sLevelSection = "b"
lvlBlock[38].sLevelSection = "c"
lvlBlock[39].sLevelSection = "d"
lvlBlock[40].sLevelSection = "e"
lvlBlock[41].sLevelSection = "f"
lvlBlock[42].sLevelSection = "g"
lvlBlock[43].sLevelSection = "h"
lvlBlock[44].sLevelSection = "i"
lvlBlock[45].sLevelSection = "j"
lvlBlock[46].sLevelSection = "k"
lvlBlock[47].sLevelSection = "l"
lvlBlock[48].sLevelSection = "m"
lvlBlock[49].sLevelSection = "n"
lvlBlock[50].sLevelSection = "o"
lvlBlock[51].sLevelSection = "p"
lvlBlock[52].sLevelSection = "q"
lvlBlock[53].sLevelSection = "r"
lvlBlock[54].sLevelSection = "s"
lvlBlock[55].sLevelSection = "t"
lvlBlock[56].sLevelSection = "u"
lvlBlock[57].sLevelSection = "v"
lvlBlock[58].sLevelSection = "w"
lvlBlock[59].sLevelSection = "x"
lvlBlock[60].sLevelSection = "y"
lvlBlock[61].sLevelSection = "z"
lvlBlock[62].sLevelSection = "$"
lvlBlock[63].sLevelSection = "%"
lvlBlock[64].sLevelSection = "&"
return
FIXED SCREEN WITH BUILT IN MAP EDITOR:
// Title: Platypus Peril
// Project: Platform Game and Level Editor
// Created: Leap (c) 2015
// Coder: Paul Harthen (SpecTre)
// ######################################## Set up the screen
SetSyncRate(60,0)
SetOrientationAllowed(0,0,1,1)
screenWidth# = GetMaxDeviceWidth()
screenHeight# = GetMaxDeviceHeight()
aspect# = screenWidth#/screenHeight#
SetDisplayAspect(-1)
displayLeft# = GetScreenBoundsLeft()
displayRight# = GetScreenBoundsRight()
displayTop# = GetScreenBoundsTop()
displayBottom# = GetScreenBoundsBottom()
displayWidth# = displayRight# - displayLeft#
displayHeight# = displayBottom# - displayTop#
displayCentreX# = displayWidth# * 0.5
displayCentreY# = displayHeight# * 0.5
SetScissor( displayLeft#, displayTop#, displayRight#, displayBottom# )
// ######################################## Set up pixel percentages
onePercentX# = screenWidth#/100.0
onePercentY# = screenHeight#/100.0
/*
To find the number for pixels then times pixels by xPixel# or yPixel#
Eg something 300 pixels wide then
300 * xPixel#
*/
xPixel# = 100.0/screenWidth#
yPixel# = 100.0/screenHeight#
// ######################################## Some game preferences
#constant lvlX = 25
#constant lvlX_MAX = 50 // Maximum width of level - 1 screen width is 10
lvlY = 20
Dim lvl_map[lvlX_MAX,lvlY]
mapPieceX = 1
mapPieceY = 1
mapPieceNUM = 1
#constant totalLevels = 2
Dim lvl$[totalLevels]
id$ = GetDeviceBaseName()
//id$ = "android" // use this to test joystick on mac
eggs = 0
mushrooms = 0
timeRemaining = 500
// ######################################## Setup Level Editor or Game
gosub media
gosub readLevels
// Use gameMode$ "editor" for level editor or "game" to play the game
gameMode$ = "game"
//gameMode$ = "editor"
if gameMode$ = "editor"
lvlNUM = 1
gosub build_lvl
mapPiece = CreateSprite(lvlBlock[mapPieceNUM].iImage)
SetSpriteDepth(mapPiece,0)
SetSpriteSize(mapPiece, blockSizeX#, blockSizeY#)
SetSpritePosition( mapPiece, (mapPieceX-1) * blockSizeX#, (mapPieceY-1) * blockSizeY# )
else
if id$ = "mac" or id$ = "windows"
else
gosub joystickSetup
endif
lvlNUM = 1
gosub build_lvl
gosub create_player
gosub game_physics
endif
// ###########################################################################################
// ######################################## Main Loop ########################################
// ###########################################################################################
SetPrintColor(255,255,255)
do
if gameMode$ = "editor"
gosub editor_controls
SetSpritePosition( mapPiece, (mapPieceX-1) * blockSizeX#, (mapPieceY-1) * blockSizeY# )
else
gosub game_controls
endif
if GetRawKeyPressed(27) // Check for Esc key
DeleteAllSprites()
DeleteAllImages()
End
endif
//Print ("Mushrooms: " + str(mushrooms))
//Print ("Eggs: " + str(eggs))
Print( ScreenFPS() )
Sync()
loop
// ###########################################################################################
// ###########################################################################################
// ###########################################################################################
// ######################################## Load player
create_player:
/*
Animation frames as follows:
1 - standing
1 - 4 walking
5 - jumping
6 - 7 climbing
*/
playerFPS = 13
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")
//playerImage = LoadImage("platypus2.png")
player = CreateSprite(playerImage)
//SetSpriteAnimation(player,128,128,16)
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
feetDistance# = playerWidth# * 0.08
PlaySprite(player, playerFPS, playerLoop, 1, 1)
//PlaySprite(player, playerFPS, playerLoop, 1, 4)
donthitLadder = 0
return
// ######################################## Physics settings for sprites in game
game_physics:
gravity# = 0.05
yvelocity# = yPlayer#
yplayerMove# = -1.25
playerSpeedLimit# = 1.25
playerMove$ = "0"
return
// ######################################## Control check for game
game_controls:
gosub player_PointCheck
playerSpeed# = 3.5
physics = 1
platformBelow = 0 // Change to 0 to only jump when on ground
ladderContact = 0
dontMoveLadder$ = "0"
ladderJump = 0
movingLadder = 0
ladderWallJump = 0
timeTest# = Timer() - time#
if timeTest# > 0.08
donthitLadder = 0
else
donthitLadder = 1
endif
// Checks for the collision detection
for y = 1 to lvlY
for x = 1 to lvlX
if lvl_map[x,y] <> 0
blockSpriteImage = GetSpriteImageID(lvl_map[x,y])
gosub check_Block_Positions
// ######################################## // Check if player touching MUSHROOM or EGG
if blockSpriteImage = lvlBlock[9].iImage or blockSpriteImage = lvlBlock[26].iImage
if xPlayer# >= bL# and xPlayer# <= bR# and yPlayer# >= bT# and yPlayer# <= bB#
DeleteSprite(lvl_map[x,y])
lvl_map[x,y] = 0
if blockSpriteImage = lvlBlock[26].iImage then mushrooms = mushrooms + 1
if blockSpriteImage = lvlBlock[9].iImage then eggs = eggs + 1
endif
endif
// ######################################## // Check if player touching main platform blocks
if blockSpriteImage = lvlBlock[1].iImage or blockSpriteImage = lvlBlock[2].iImage or blockSpriteImage = lvlBlock[3].iImage
if blockSpriteImage = lvlBlock[1].iImage then gosub collision_Feet
gosub collision_LR
gosub collision_Head
endif
// ######################################## // Check if player touching ladder
if blockSpriteImage = lvlBlock[8].iImage or blockSpriteImage = lvlBlock[7].iImage or blockSpriteImage = lvlBlock[6].iImage
if xPlayer# >= bL# and xPlayer# <= bR# and yPlayer# >= bT# and yPlayer# <= bB#
//if leftFoot_X# >= bL# and leftFoot_X# <= bR# and leftFoot_Y# >= bT# and leftFoot_Y# <= bB# or rightFoot_X# >= bL# and rightFoot_X# <= bR# and rightFoot_Y# >= bT# and rightFoot_Y# <= bB#
if donthitLadder = 0
ladderContact = 1
physics = 0
yPlayerSpeed# = 0.0
endif
if blockSpriteImage = lvlBlock[6].iImage
if yPlayer# = bB# then dontMoveLadder$ = "D"
elseif blockSpriteImage = lvlBlock[7].iImage
if yPlayer# =< bT# + (10 * xPixel#) then dontMoveLadder$ = "U"
ladderJump = 1
endif
endif
endif
endif
next x
next y
// Gravity and animation checks for jumping and L and R directions
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
//PlaySprite(player, playerFPS, playerLoop, 13, 16)
else
if movePlayer$ = "0"
PlaySprite(player, playerFPS, playerLoop, 1, 1) // Frame for standing if not moving
//PlaySprite(player, playerFPS, playerLoop, 1, 4)
elseif movePlayer$ = "L" or movePlayer$ = "R"
if GetSpritePlaying( player ) = 0 then PlaySprite(player, playerFPS, playerLoop, 1, 4) // Frames to play for walking
//if GetSpritePlaying( player ) = 0 then PlaySprite(player, playerFPS, playerLoop, 5, 8)
elseif movePlayer$ = "U" or movePlayer$ = "D"
if GetSpritePlaying( player ) = 0 then PlaySprite(player, playerFPS, playerLoop, 6, 7) // Frames to play for climbing
//if GetSpritePlaying( player ) = 0 then PlaySprite(player, playerFPS, playerLoop, 9, 12)
endif
endif
// check for left and right movement with keys
if GetRawKeyState(37) or GetVirtualJoystickX(joyStick) < 0.0 // Check for Left key (Move player L Direction)
blockPlayer$ = "L"
movePlayer$ = "L"
xPlayer# = xPlayer# - xPlayerSpeed#
SetSpriteFlip(player, 1, 0)
if ladderContact = 1
ladderJump = 1
endif
elseif GetRawKeyState(39) or GetVirtualJoystickX(joyStick) > 0.0 // Check for Right key (Move player R Direction)
blockPlayer$ = "R"
movePlayer$ = "R"
xPlayer# = xPlayer# + xPlayerSpeed#
SetSpriteFlip(player, 0, 0)
if ladderContact = 1
ladderJump = 1
endif
// check for up and down
elseif 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"
movePlayer$ = "U"
movingLadder = 1
yPlayerSpeed# = (screenHeight#/screenWidth#) * aspect#
yPlayer# = yPlayer# - (xPlayerSpeed# * yPlayerSpeed#)
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"
movePlayer$ = "D"
movingLadder = 1
yPlayerSpeed# = (screenHeight#/screenWidth#) * aspect#
yPlayer# = yPlayer# + (xPlayerSpeed# * yPlayerSpeed#)
endif
else
blockPlayer$ = "0"
movePlayer$ = "0"
endif
// check for jump
if GetRawKeyPressed(32) or GetVirtualButtonPressed(button1) = 1 // Check for Space key (Paste Block to Screen)
if platformBelow = 1 or ladderJump = 1
if ladderContact = 1 and ladderWallJump = 1
else
yPlayerSpeed# = yPlayerMove#
endif
if ladderJump = 1
time# = Timer()
endif
endif
endif
xPlayerSpeed# = xPixel# * playerSpeed#
if movingLadder = 0
yvelocity# = yvelocity# + yPlayerSpeed#
SetSpritePositionByOffset( player, xPlayer#, yvelocity# )
elseif movingLadder = 1
SetSpritePositionByOffset( player, xPlayer#, yPlayer# )
yvelocity# = yPlayer#
endif
return
player_PointCheck:
// ########## Six points of player to check for collision
// This is the bottom of the feet position in the middle
xPlayer# = GetSpriteXByOffset(player)
yPlayer# = GetSpriteYByOffset(player)
// Point for top of head in middle
headPlayer# = yPlayer# - ceilingProbeDistance#
// 2 Points for left positions, upper and lower
leftSideHigh_X# = xPlayer# - wallProbeDistance#
leftSideHigh_Y# = yPlayer# - (playerHeight# * 0.8)
leftSideLow_X# = leftSideHigh_X#
leftSideLow_Y# = yPlayer# - (playerHeight# * 0.2)
// 2 Points for right positions, upper and lower
rightSideHigh_X# = xPlayer# + wallProbeDistance#
rightSideHigh_Y# = leftSideHigh_Y#
rightSideLow_X# = rightSideHigh_X#
rightSideLow_Y# = leftSideLow_Y#
// Left and Right foot position
rightFoot_X# = xPlayer# + feetDistance#
rightFoot_Y# = yPlayer#
leftFoot_X# = xPlayer# - feetDistance#
leftFoot_Y# = yPlayer#
// ########################################
return
// ########################################
check_Block_Positions:
bL# = GetSpriteX(lvl_map[x,y])
bR# = GetSpriteX(lvl_map[x,y])+blockSizeX#
bT# = GetSpriteY(lvl_map[x,y])
bB# = GetSpriteY(lvl_map[x,y])+blockSizeY#
return
// ######################################## // Check if player touching top of grey brick blocks
collision_Feet:
if xPlayer# >= bL# and xPlayer# <= bR# and yPlayer# >= bT# and yPlayer# <= bB#
//if leftFoot_X# >= bL# and leftFoot_X# <= bR# and leftFoot_Y# >= bT# and leftFoot_Y# <= bB# or rightFoot_X# >= bL# and rightFoot_X# <= bR# and rightFoot_Y# >= bT# and rightFoot_Y# <= bB#
platformBelow = 1
physics = 0
yPlayerSpeed# = 0.0
yvelocity# = bT#
endif
return
// ######################################## check for collision with tile blocks left and right
collision_LR:
if blockPlayer$ = "L"
if leftSideHigh_X# > bL# and leftSideHigh_X# <= bR# and leftSideHigh_Y# >= bT# and leftSideHigh_Y# <= bB#
playerSpeed# = 0.0
leftSideHigh_X# = bR# + wallProbeDistance#
xPlayer# = leftSideHigh_X#
ladderWallJump = 1
elseif leftSideLow_X# > bL# and leftSideLow_X# <= bR# and leftSideLow_Y# >= bT# and leftSideLow_Y# <= bB#
playerSpeed# = 0.0
leftSideLow_X# = bR# + wallProbeDistance#
xPlayer# = leftSideLow_X#
ladderWallJump = 1
endif
elseif blockPlayer$ = "R"
if rightSideHigh_X# >= bL# and rightSideHigh_X# < bR# and rightSideHigh_Y# >= bT# and rightSideHigh_Y# <= bB#
playerSpeed# = 0.0
rightSideHigh_X# = bL# - wallProbeDistance#
xPlayer# = rightSideHigh_X#
ladderWallJump = 1
elseif rightSideLow_X# >= bL# and rightSideLow_X# < bR# and rightSideLow_Y# >= bT# and rightSideLow_Y# <= bB#
playerSpeed# = 0.0
rightSideLow_X# = bL# - wallProbeDistance#
xPlayer# = rightSideLow_X#
ladderWallJump = 1
endif
endif
return
// ######################################## check for collision with tile blocks up
collision_Head:
if xPlayer# >= bL# and xPlayer# <= bR# and headPlayer# >= bT# and headPlayer# <= bB#
physics = 1
yPlayerSpeed# = 0.0
yvelocity# = bB# + ceilingProbeDistance#
endif
return
// ######################################## Controls check for editor
editor_controls:
if GetRawKeyPressed(90) // Check for Z key (Change Map Block Left)
mapPieceNUM = mapPieceNUM - 1
if mapPieceNUM < 1 then mapPieceNUM = numberLvlBlocks
SetSpriteImage( mapPiece, lvlBlock[mapPieceNUM].iImage)
elseif GetRawKeyPressed(88) // Check for X key (Change Map Block Right)
mapPieceNUM = mapPieceNUM + 1
if mapPieceNUM > numberLvlBlocks then mapPieceNUM = 1
SetSpriteImage( mapPiece, lvlBlock[mapPieceNUM].iImage)
elseif GetRawKeyPressed(38) // Check for Up key (Move Block in Direction)
mapPieceY = mapPieceY - 1
if mapPieceY < 1 then mapPieceY = 1
elseif GetRawKeyPressed(40) // Check for Down key (Move Block in Direction)
mapPieceY = mapPieceY + 1
if mapPieceY > lvlY then mapPieceY = lvlY
elseif GetRawKeyPressed(37) // Check for Left key (Move Block in Direction)
mapPieceX = mapPieceX - 1
if mapPieceX < 1 then mapPieceX = 1
elseif GetRawKeyPressed(39) // Check for Right key (Move Block in Direction)
mapPieceX = mapPieceX + 1
if mapPieceX > lvlX then mapPieceX = lvlX
elseif GetRawKeyPressed(32) // Check for Space key (Paste Block to Screen)
gosub paste_block
elseif GetRawKeyPressed(65) // Check for A key (Delete Block from Screen)
gosub delete_block
elseif GetRawKeyPressed(83) // Check for S key (Save the Level)
gosub saveLevel
endif
return
// ######################################## Paste Block to Screen
paste_block:
if lvl_map[mapPieceX,mapPieceY] <> 0
SetSpriteImage(lvl_map[mapPieceX,mapPieceY],lvlBlock[mapPieceNUM].iImage)
else
blockSprite=CreateSprite(lvlBlock[mapPieceNUM].iImage)
SetSpriteSize(blockSprite, blockSizeX#, blockSizeY#)
lvl_map[mapPieceX,mapPieceY]=blockSprite
SetSpritePosition( lvl_map[mapPieceX,mapPieceY], (mapPieceX-1) * blockSizeX#, (mapPieceY-1) * blockSizeY# )
endif
return
// ######################################## Delete Block from Screen
delete_block:
if lvl_map[mapPieceX,mapPieceY] <> 0
DeleteSprite(lvl_map[mapPieceX,mapPieceY])
lvl_map[mapPieceX,mapPieceY]=0
endif
return
// ######################################## Build Levels
build_lvl:
textPos = 0
for y = 1 to lvlY
for x = 1 to lvlX
textPos = textPos + 1
blockNUM$ = Mid(lvl$[lvlNUM],textPos,1)
if blockNUM$ <> "0"
for i = 1 to numberLvlBlocks
if blockNUM$ = lvlBlock[i].sLevelSection
blockSprite=CreateSprite(lvlBlock[i].iImage)
endif
next i
SetSpriteSize(blockSprite, blockSizeX#, blockSizeY#)
lvl_map[x,y]=blockSprite
SetSpritePosition( lvl_map[x,y], (x-1) * blockSizeX#, (y-1) * blockSizeY# )
else
lvl_map[x,y]=0
endif
next x
next y
return
// ######################################## Load all Levels
readLevels:
for i = 0 to totalLevels
OpenToRead(1, "lvl_" + Str(i) + ".txt")
for n = 1 to lvlX * lvlY
if n = 1
l$ = ReadString(1)
else
l$ = l$ + ReadString(1)
endif
next n
lvl$[i] = l$
CloseFile ( 1 )
next i
return
// ######################################## Save Edited Level
saveLevel:
OpenToWrite(1,"lvl.txt")
for y = 1 to lvlY
for x = 1 to lvlX
if lvl_map[x,y] <> 0
blockSpriteImage = GetSpriteImageID(lvl_map[x,y])
for i = 1 to numberLvlBlocks
if blockSpriteImage = lvlBlock[i].iImage
WriteString(1, lvlBlock[i].sLevelSection)
endif
next i
else
WriteString(1, "0")
endif
next x
next y
CloseFile ( 1 )
return
// ######################################## Set up joystick and buttons
joystickSetup: // This part is for the game
joyStick = 1
joyStickSizeX# = xPixel# * 250.0
joyStickSizeY# = joyStickSizeX# * aspect#
joyStickCentreX# = joyStickSizeX# * 0.5
joyStickCentreY# = joyStickSizeY# * 0.5
AddVirtualJoystick(joyStick, 99.0 - joyStickCentreX# , 99.0 - joyStickCentreY# , joyStickSizeX#)
SetVirtualJoystickAlpha(joyStick, 60.0, 110.0)
button1 = 1
button2 = 2
buttonSizeX# = xPixel# * 150.0
buttonSizeY# = buttonSizeX# * aspect#
buttonCentreX# = buttonSizeX# * 0.5
buttonCentreY# = buttonSizeY# * 0.5
AddVirtualButton(button1, 1.0 + buttonCentreX#, 99.0 - buttonCentreY#, buttonSizeX#)
//AddVirtualButton(button2, 2.0 + buttonSizeX# + buttonCentreX#, 99.0 - buttonCentreY#, buttonSizeX#)
//SetVirtualButtonText(button1,"JUMP")
//SetVirtualButtonText(button2,"FIRE")
SetVirtualButtonAlpha(button1, 110.0)
//SetVirtualButtonAlpha(button2, 110.0)
return
// ######################################## Load media
media:
#constant numberLvlBlocks = 57
gosub loadLevelImages
percentageX = 4 // 4 to make 4% for block width
percentageY = 5 // 5 to make 5% for block height
/*
backImage = LoadImage("background1.png") // This is the background image
backSprite = CreateSprite(backImage)
SetSpriteSize(backSprite, 100.0, 100.0)
SetSpritePosition(backSprite, 0.0, 0.0)
*/
blockSizeX# = xPixel# * (onePercentX# * percentageX)
blockSizeY# = yPixel# * (onePercentY# * percentageY)
return
// ######################################## Levels
loadLevelImages:
Type level_block_Type
iImage as integer
sLevelSection as string
Endtype
lvlBlock as level_block_Type[numberLvlBlocks]
level_texture_image = LoadImage("level_blocks.png")
lvlBlock[1].iImage = LoadSubImage(level_texture_image, "brick_grey.png")
lvlBlock[2].iImage = LoadSubImage(level_texture_image, "brick_red_slime.png")
lvlBlock[3].iImage = LoadSubImage(level_texture_image, "brick_red.png")
lvlBlock[4].iImage = LoadSubImage(level_texture_image, "girder.png")
lvlBlock[5].iImage = LoadSubImage(level_texture_image, "girder_grate.png")
lvlBlock[6].iImage = LoadSubImage(level_texture_image, "ladderB.png")
lvlBlock[7].iImage = LoadSubImage(level_texture_image, "ladderT.png")
lvlBlock[8].iImage = LoadSubImage(level_texture_image, "ladder.png")
lvlBlock[9].iImage = LoadSubImage(level_texture_image, "egg.png")
lvlBlock[10].iImage = LoadSubImage(level_texture_image, "grass_tan.png")
lvlBlock[11].iImage = LoadSubImage(level_texture_image, "metal_ladder.png")
lvlBlock[12].iImage = LoadSubImage(level_texture_image, "grass1.png")
lvlBlock[13].iImage = LoadSubImage(level_texture_image, "grass2.png")
lvlBlock[14].iImage = LoadSubImage(level_texture_image, "grass3.png")
lvlBlock[15].iImage = LoadSubImage(level_texture_image, "grass4.png")
lvlBlock[16].iImage = LoadSubImage(level_texture_image, "grate.png")
lvlBlock[17].iImage = LoadSubImage(level_texture_image, "pipe1.png")
lvlBlock[18].iImage = LoadSubImage(level_texture_image, "pipe2.png")
lvlBlock[19].iImage = LoadSubImage(level_texture_image, "pipe3.png")
lvlBlock[20].iImage = LoadSubImage(level_texture_image, "pipe4.png")
lvlBlock[21].iImage = LoadSubImage(level_texture_image, "pipe5.png")
lvlBlock[22].iImage = LoadSubImage(level_texture_image, "pipe6.png")
lvlBlock[23].iImage = LoadSubImage(level_texture_image, "waterlow.png")
lvlBlock[24].iImage = LoadSubImage(level_texture_image, "watermid.png")
lvlBlock[25].iImage = LoadSubImage(level_texture_image, "mushroom_brown.png")
lvlBlock[26].iImage = LoadSubImage(level_texture_image, "mushroom_red.png")
lvlBlock[27].iImage = LoadSubImage(level_texture_image, "mushroom_tan.png")
lvlBlock[28].iImage = LoadSubImage(level_texture_image, "water3.png")
lvlBlock[29].iImage = LoadSubImage(level_texture_image, "water4.png")
lvlBlock[30].iImage = LoadSubImage(level_texture_image, "waterfull.png")
lvlBlock[31].iImage = LoadSubImage(level_texture_image, "tap1.png")
lvlBlock[32].iImage = LoadSubImage(level_texture_image, "tap2.png")
lvlBlock[33].iImage = LoadSubImage(level_texture_image, "rock_moss.png")
lvlBlock[34].iImage = LoadSubImage(level_texture_image, "rock.png")
lvlBlock[35].iImage = LoadSubImage(level_texture_image, "tap3.png")
lvlBlock[36].iImage = LoadSubImage(level_texture_image, "tap4.png")
lvlBlock[37].iImage = LoadSubImage(level_texture_image, "waterfromtap1.png")
lvlBlock[38].iImage = LoadSubImage(level_texture_image, "waterfromtap2.png")
lvlBlock[39].iImage = LoadSubImage(level_texture_image, "waterfromtap3.png")
lvlBlock[40].iImage = LoadSubImage(level_texture_image, "waterfromtap4.png")
lvlBlock[41].iImage = LoadSubImage(level_texture_image, "tap.png")
lvlBlock[42].iImage = LoadSubImage(level_texture_image, "stone_diamond.png")
lvlBlock[43].iImage = LoadSubImage(level_texture_image, "stone_dirt.png")
lvlBlock[44].iImage = LoadSubImage(level_texture_image, "stone_gold_alt.png")
lvlBlock[45].iImage = LoadSubImage(level_texture_image, "stone_gold.png")
lvlBlock[46].iImage = LoadSubImage(level_texture_image, "stone_grass.png")
lvlBlock[47].iImage = LoadSubImage(level_texture_image, "stone_iron_alt.png")
lvlBlock[48].iImage = LoadSubImage(level_texture_image, "stone_iron.png")
lvlBlock[49].iImage = LoadSubImage(level_texture_image, "stone_sand.png")
lvlBlock[50].iImage = LoadSubImage(level_texture_image, "stone_silver_alt.png")
lvlBlock[51].iImage = LoadSubImage(level_texture_image, "stone_silver.png")
lvlBlock[52].iImage = LoadSubImage(level_texture_image, "stone_snow.png")
lvlBlock[53].iImage = LoadSubImage(level_texture_image, "stone.png")
lvlBlock[54].iImage = LoadSubImage(level_texture_image, "water.png")
lvlBlock[55].iImage = LoadSubImage(level_texture_image, "wheat_stage1.png")
lvlBlock[56].iImage = LoadSubImage(level_texture_image, "wheat_stage2.png")
lvlBlock[57].iImage = LoadSubImage(level_texture_image, "wheat_stage3.png")
lvlBlock[1].sLevelSection = "1"
lvlBlock[2].sLevelSection = "2"
lvlBlock[3].sLevelSection = "3"
lvlBlock[4].sLevelSection = "4"
lvlBlock[5].sLevelSection = "5"
lvlBlock[6].sLevelSection = "6"
lvlBlock[7].sLevelSection = "7"
lvlBlock[8].sLevelSection = "8"
lvlBlock[9].sLevelSection = "9"
lvlBlock[10].sLevelSection = "A"
lvlBlock[11].sLevelSection = "B"
lvlBlock[12].sLevelSection = "C"
lvlBlock[13].sLevelSection = "D"
lvlBlock[14].sLevelSection = "E"
lvlBlock[15].sLevelSection = "F"
lvlBlock[16].sLevelSection = "G"
lvlBlock[17].sLevelSection = "H"
lvlBlock[18].sLevelSection = "I"
lvlBlock[19].sLevelSection = "J"
lvlBlock[20].sLevelSection = "K"
lvlBlock[21].sLevelSection = "L"
lvlBlock[22].sLevelSection = "M"
lvlBlock[23].sLevelSection = "N"
lvlBlock[24].sLevelSection = "O"
lvlBlock[25].sLevelSection = "P"
lvlBlock[26].sLevelSection = "Q"
lvlBlock[27].sLevelSection = "R"
lvlBlock[28].sLevelSection = "S"
lvlBlock[29].sLevelSection = "T"
lvlBlock[30].sLevelSection = "U"
lvlBlock[31].sLevelSection = "V"
lvlBlock[32].sLevelSection = "W"
lvlBlock[33].sLevelSection = "X"
lvlBlock[34].sLevelSection = "Y"
lvlBlock[35].sLevelSection = "Z"
lvlBlock[36].sLevelSection = "a"
lvlBlock[37].sLevelSection = "b"
lvlBlock[38].sLevelSection = "c"
lvlBlock[39].sLevelSection = "d"
lvlBlock[40].sLevelSection = "e"
lvlBlock[41].sLevelSection = "f"
lvlBlock[42].sLevelSection = "g"
lvlBlock[43].sLevelSection = "h"
lvlBlock[44].sLevelSection = "i"
lvlBlock[45].sLevelSection = "j"
lvlBlock[46].sLevelSection = "k"
lvlBlock[47].sLevelSection = "l"
lvlBlock[48].sLevelSection = "m"
lvlBlock[49].sLevelSection = "n"
lvlBlock[50].sLevelSection = "o"
lvlBlock[51].sLevelSection = "p"
lvlBlock[52].sLevelSection = "q"
lvlBlock[53].sLevelSection = "r"
lvlBlock[54].sLevelSection = "s"
lvlBlock[55].sLevelSection = "t"
lvlBlock[56].sLevelSection = "u"
lvlBlock[57].sLevelSection = "v"
return