Code: Select all
background = Image.load("myimages/background.png")
-- ladda bakgrundsbild
player = Image.load("myimages/marioright2.png")
-- ladda spelarbild
board = Image.load("myimages/board.png")
-- ladda animation
moveright1 = Image.load("myimages/marioright1.png")
moveright2 = Image.load("myimages/marioright2.png")
moveright3 = Image.load("myimages/marioright3.png")
moveleft1 = Image.load("myimages/marioleft1.png")
moveleft2 = Image.load("myimages/marioleft2.png")
moveleft3 = Image.load("myimages/marioleft3.png")
grass = Image.load("myimages/grass.png")
sky = Image.load("myimages/sky.png")
-- marios startbild
player = moveright1
-- ladda board
playerx = 100
playery = 100
-- animeringen börja på 0
move = 0
-- var x och y kordinaterna ska vara ifrån start
speed = 1
-- bestämmer hastigheten på player
green = Color.new(0, 255, 0)
-- delkarera green till färgen grön
-- detta är för animeringen av mario
bPressOnce1 = 0
bPressOnce2 = 0
-- storleken på värden.
sizeX = 30
sizeY = 17
array = {}
for x=0,sizeX do
array[x] = {}
for y=0,sizeY do
array[x][y] = 0
end
end
while true do
pad = Controls.read() -- kontrollerna
if pad:left() then
if bPressOnce1 == 0 then
move= 0
end
bPressOnce1 = true;
playerx = playerx - speed
move = move + 1
if move == 1 then
player = moveleft1
end
if move == 6 then
player = moveleft2
end
if move == 11 then
player = moveleft3
end
if move == 16 then
move = 0
end
end
if pad:left() == 0 then
bPressOnce1 = false
end
if pad:right() then
if bPressOnce2 == 0 then
move = 0
end
bPressOnce2 = true;
playerx = playerx + speed
move = move + 1
if move == 1 then
player = moveright1
end
if move == 6 then
player = moveright2
end
if move == 11 then
player = moveright3
end
if move == 16 then
move = 0
end
end
if pad:right() == 0 then
bPressOnce2 = false
end
if pad:up() then
playery = playery - 3
end
if pad:down() then
end
if pad:cross() then
break
end
if pad:triangle() then
speed = speed + 0.5
end
if pad:square() then
speed = speed - 0.5
end
if playerx > 464 then -- blockera så att den inte kan åka utanför skärmen :)
playerx = 464
end
if playerx < 0 then
playerx = 0
end
if playery > 256 then
playery = 256
end
if playery < 0 then
playery = 0
end --här sluta blockeringen
screen:blit(0, 0, background, 0, 0, background:width(), background:height(), false)
-- blitta bakgrunden till skärmen
screen:blit(playerx, playery, player)
array[29][16] = 1
array[28][16] = 1
array[27][16] = 1
array[26][16] = 1
array[25][16] = 1
array[24][16] = 1
array[23][16] = 1
array[22][16] = 1
array[21][16] = 1
array[20][16] = 1
array[19][16] = 1
array[18][16] = 1
array[17][16] = 1
array[16][16] = 1
array[15][16] = 1
array[14][16] = 1
array[13][16] = 1
array[12][16] = 1
array[11][16] = 1
array[10][16] = 1
array[9][16] = 1
array[8][16] = 1
array[7][16] = 1
array[6][16] = 1
array[5][16] = 1
array[4][16] = 1
array[3][16] = 1
array[2][16] = 1
array[1][16] = 1
array[0][16] = 1
for x=0, sizeX do
for y=0, sizeY do
if array[x][y] == 1 then
screen:blit(x*16, y*16, grass)
end
if array[x][y] == 2 then
screen:blit(x*16, y*16, sky)
end
end
end
--blitta player till skärmen
--screen:blit(0, 0, board)
screen:print(4, 4, "Speed:", green)
screen:print(50, 4, speed, green)
screen:print(4, 14, "X pos:", green)
screen:print(50, 14, playerx, green)
screen:print(4, 24, "Y pos:", green)
screen:print(50, 24, playery, green)
-- skriver ut speed, Y och X värden i vänstra hörnet på skärmen
screen.waitVblankStart()
screen.flip()
-- vänd skärmen så att man ser allt.
tilex = playerx / 16
tiley = playery / 16
if array[tilex][tiley] == 2 then
playery = playery
end
if array[tilex][tiley] == 1 then
playery = playery + 3
end
end