white = Color.new (255,255,255)
black = Color.new (0,0,0)
back1 = Image.load ("back1.png")
back2 = Image.load ("back2.png")
endback = Image.load ("endback.png")
player1 = Image.load ("player1.png")
player1s = Image.load ("player1s.png")
gameover = Image.load ("gameover.png")
winner = Image.load ("youwin.png")
winsnd = Sound.load ("win.wav")
jet = Image.load ("jet.png")
jumpsnd = Sound.load("jump.wav")
gamemsk = Sound.load("game.wav",true)
gameoversnd = Sound.load("gameover.wav")
direction = "right"
collision = "false"
over = "no"
gamepos = 0
movespeed = 2
speed = "walking"
screenwidth = 449
currentscreen = back1
block = Image.createEmpty(20,25)
block:clear(black)
player = {}
player.gravity = 230
player.y = 230
player.x = 50
player.jumpspeed = 10
player.jumpstate = "ground"
playerHeight = 41
playerWidth = 31
Block = {}
Block[1] = { x = 100, y = 250, height = block:height(), width = block:width() }
Block[2] = { x = 300, y = 250, height = block:height(), width = block:width() }
Block[3] = { x = 200, y = 250, height = block:height(), width = block:width() }
Block[4] = { x = 200, y = 250, height = block:height(), width = block:width() }
Block[5] = { x = 190, y = 250, height = block:height(), width = block:width() }
Block[6] = { x = 210, y = 250, height = block:height(), width = block:width() }
Block[7] = { x = 230, y = 225, height = block:height(), width = block:width() }
Block[8] = { x = 210, y = 250, height = block:height(), width = block:width() }
Block[9] = { x = 230, y = 250, height = block:height(), width = block:width() }
Block[10] = { x = 350, y = 250, height = block:height(), width = block:width() }
Block[11] = { x = 150, y = 250, height = block:height(), width = block:width() }
Block[12] = { x = 170, y = 250, height = block:height(), width = block:width() }
Block[13] = { x = 330, y = 250, height = block:height(), width = block:width() }
Block[14] = { x = 330, y = 225, height = block:height(), width = block:width() }
Block[15] = { x = 210, y = 250, height = block:height(), width = block:width() }
Block[16] = { x = 230, y = 250, height = block:height(), width = block:width() }
Block[17] = { x = 250, y = 250, height = block:height(), width = block:width() }
Block[18] = { x = 230, y = 225, height = block:height(), width = block:width() }
Block[19] = { x = 250, y = 225, height = block:height(), width = block:width() }
Block[20] = { x = 250, y = 200, height = block:height(), width = block:width() }
Block[21] = { x = 440, y = 235, height = block:height(), width = block:width() }
Block[22] = { x = 460, y = 235, height = block:height(), width = block:width() }
function collisionCheck(object)
if player.x + playerWidth > object.x and player.x < object.x + object.width and player.y + playerHeight > object.y and player.y < object.y + object.height then
player.x = oldx
player.y = oldy
collision = "true"
end
end
local sound = gamemsk
voice = sound:play()
Music.volume(128)
while true do
oldx = player.x
oldy = player.y
screen:clear()
screen:blit(0,0,currentscreen)
screen:blit(player.x,player.y,player1)
pad = Controls.read()
if direction == "left" then
screen:clear()
screen:blit(0,0,currentscreen)
screen:blit(player.x,player.y,player1s)
end
if direction == "right" then
screen:clear()
screen:blit(0,0,currentscreen)
screen:blit(player.x,player.y,player1)
end
if gamepos == 6 then
currentscreen = endback
for f = 21,22 do
screen:blit(Block[f].x,Block[f].y,block)
screen:blit(440,240,jet)
end
collisionCheck(Block[21])
collisionCheck(Block[22])
end
if gamepos == 5 then
currentscreen = back2
for e = 15,20 do
screen:blit(Block[e].x,Block[e].y,block)
end
collisionCheck(Block[15])
collisionCheck(Block[16])
collisionCheck(Block[17])
collisionCheck(Block[18])
collisionCheck(Block[19])
collisionCheck(Block[20])
end
if gamepos == 4 then
currentscreen = back2
for d = 11,14 do
screen:blit(Block[d].x,Block[d].y,block)
end
collisionCheck(Block[11])
collisionCheck(Block[12])
collisionCheck(Block[13])
collisionCheck(Block[14])
end
if gamepos == 3 then
currentscreen = back2
for c = 7,10 do
screen:blit(Block[c].x,Block[c].y,block)
end
collisionCheck(Block[7])
collisionCheck(Block[8])
collisionCheck(Block[9])
end
if gamepos == 2 then
currentscreen = back2
for b = 5,6 do
screen:blit(Block[b].x,Block[b].y,block)
end
collisionCheck(Block[5])
collisionCheck(Block[6])
end
if gamepos == 1 then
currentscreen = back2
for a = 1,3 do
screen:blit(Block[a].x,Block[a].y,block)
end
collisionCheck(Block[1])
collisionCheck(Block[2])
collisionCheck(Block[3])
end
if gamepos == 0 then
currentscreen = back1
screen:blit(Block[4].x,Block[4].y,block)
collisionCheck(Block[4])
end
if collision == "true" and gamepos == 6 then
over = "win"
dofile ("gameover.lua")
end
if collision == "true" then
over = "lose"
dofile ("gameover.lua")
end
if gamepos == 0 and player.x > screenwidth and currentscreen == back1 then
gamepos = 1
player.x = 10
player.y = 250
end
if gamepos == 1 and player.x > screenwidth and currentscreen == back2 then
gamepos = 2
player.x = 10
player.y = 250
end
if gamepos == 2 and player.x > screenwidth and currentscreen == back2 then
gamepos = 3
player.x = 10
player.y = 250
end
if gamepos == 3 and player.x > screenwidth and currentscreen == back2 then
gamepos = 4
player.x = 10
player.y = 250
end
if gamepos == 4 and player.x > screenwidth and currentscreen == back2 then
gamepos = 5
player.x = 10
player.y = 250
end
if gamepos == 5 and player.x > screenwidth and currentscreen == back2 then
gamepos = 6
player.x = 10
player.y = 250
end
if pad:right() and player.x < 451 then
speed = "walking"
movespeed = 2
direction = "right"
player.x = player.x + movespeed
end
if pad:left()and player.x > 0 then
speed = "walking"
movespeed = 2
direction = "left"
player.x = player.x - movespeed
end
if pad:right()and pad:square()and player.x < 451 then
speed = "running"
movespeed = 3
direction = "right"
player.x = player.x + movespeed
end
if pad:left()and pad:square()and player.x > 0 then
speed = "running"
movespeed = 3
direction = "left"
player.x = player.x - movespeed
end
if pad:cross() and player.jumpstate == "ground" then
jumpsnd:play()
player.jumpstate = "jumping"
end
if pad:cross() and player.jumpstate == "ground" then
jumpsnd:play()
player.jumpstate = "jumping"
end
if player.jumpstate == "jumping" then
player.jumpspeed = player.jumpspeed - 0.5
player.gravity = player.gravity - player.jumpspeed
end
if player.gravity < 0 then
player.jumpstate = "falling"
end
if player.gravity < 230 and player.jumpstate == "falling" then
player.gravity = player.gravity + (player.jumpspeed + 3)
end
if player.gravity == 230 then
player.jumpspeed = 10
player.jumpstate = "ground"
end
if player.gravity > 230 then player.gravity = 230 end
player.y = player.gravity
screen.flip()
screen.waitVblankStart()
end