Very basic Platform game code here. It still is in early dev, but, getting there.
// Project: PlatTest
// Created: 2018-03-04
// Amon - Imagination Engineer
// show all errors
SetErrorMode(2)
Global DeviceWidth
Global DeviceHeight
DeviceWidth = GetDeviceWidth()
DeviceHeight = GetDeviceHeight()
SetFolder( "/media" )
// set window properties
SetWindowTitle( "PlatTest" )
SetWindowSize( DeviceWidth, DeviceHeight, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 512, 960 ) // doesn't have to match the window
SetOrientationAllowed( 1, 0, 0, 0 ) // 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 ) // since version 2.0.22 we can use nicer default fonts
#include "Constants.agc"
Global GreyPlat
Global imgDude
GreyPlat = LoadImage("grey.png")
imgDude = LoadImage("dude.png")
Type Dude
id as integer
x as float
y as float
speed as float
jumpHeight as float
gravity as float
isJumping as integer
canJump as integer
isFalling as integer
EndType
Global DudeList as Dude[]
type Plat
id as integer
x as float
y as float
EndType
Global PlatList as Plat[]
Global GameArray as integer [8,12]
file = OpenToRead("level1.txt")
level$ = ReadLine(file)
CloseFile(file)
local X = 0
local y = 0
For iter=1 to Len(level$)
if x = 8
x = 0
y = y + 1
endif
GameArray[x,y] = val((Mid(level$, iter, 1)))
x = x + 1
next
for xi = 0 to 8
for yi = 0 to 12
if GameArray[xi,yi] = 1
local p as Plat
p.x = xi * 64
p.y = yi * 64
GreyPlatSprite = CreateSprite(GreyPlat)
SetSpritePosition(GreyPlatSprite, p.x, p.y)
PlatList.insert(p)
endif
if GameArray[xi,yi] = 2
local d as Dude
d.x = xi * 64
d.y = yi * 64
d.canJump = 1
d.isFalling = 0
d.isJumping = 0
d.jumpHeight = 8.0
d.gravity = 0.25
DudeSprite = CreateSprite(imgDude)
SetSpritePosition(DudeSprite, d.x, d.y)
DudeList.insert(d)
endif
next
next
do
if GetRawKeyState(KEY_RIGHT) = 1
d.x = d.x + 6.1
endif
if GetRawKeyState(KEY_LEFT) = 1
d.x = d.x- 6.1
endif
if GetRawKeyState(KEY_SPACE) = 1 and d.canJump = 1
d.isJumping = 1
d.canJump = 0
endif
If d.isJumping = 1
d.y = d.y - d.jumpHeight
d.jumpHeight = d.jumpHeight - d.gravity
If d.jumpHeight <0
d.isFalling = 1
d.isJumping = 0
d.jumpHeight = 8.0
Endif
Endif
if d.isFalling = 1
d.canJump = 0
d.y = d.y + d.jumpHeight
d.jumpHeight = d.jumpHeight + d.gravity
If GameArray[ floor(d.x) / 64 , floor(d.y) / 64 + 1] = 1
If mod(d.y, 64) < d.jumpHeight * 2.0
d.y = d.y - Mod(d.y,64)
d.isFalling = 0
d.canJump = 1
d.jumpHeight = 8.0
Endif
Endif
Endif
If d.isFalling = 0 And d.isJumping = 0
If GameArray[floor(d.x) / 64, floor(d.y) / 64 + 1 ] = 0
d.isFalling = 1
d.canJump = 0
Endif
Endif
SetSpritePosition(DudeSprite, d.x, d.y)
Print( ScreenFPS() )
Sync()
loop
Imaginations' greatest gift is the knowledge you supply it.