Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Load all the sprites here
- -- sprite_1 = image.new("...")
- -- [...]
- sprites = {sprite_1, -- Tree
- sprite_2, -- Ground
- sprite_3, -- Short grass
- sprite_4, -- Long grass
- sprite_5, -- Fence
- sprite_6, -- Wood fence
- sprite_7, -- Sign
- sprite_8} -- Ground 2
- spritesPlayer = {spritePlayer_1, -- Up
- spritePlayer_2, -- Down
- spritePlayer_3, -- Left
- spritePlayer_4} -- Right
- player = {x = 2, y = 2, facing = 2}
- mapWidth = 20
- mapHeight = 13
- map = {{5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5},
- {5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 5},
- {5, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 1, 4, 4, 4, 4, 5},
- {5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 4, 4, 4, 4, 5},
- {5, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 1, 4, 4, 4, 4, 5},
- {5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 5},
- {5, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 5},
- {5, 0, 0, 6, 6, 7, 6, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 5},
- {5, 0, 0, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5},
- {5, 0, 0, 3, 3, 3, 3, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5},
- {5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 5},
- {5, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5},
- {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}}
- objAttr = {{walkable = false},
- {walkable = true},
- {walkable = true},
- {walkable = true},
- {walkable = false},
- {walkable = false},
- {walkable = false},
- {walkable = true}}
- onTitleScreen = true;
- function isValid(x, y)
- return x >= 1 and y >= 1 and x <= mapWidth and y <= mapHeight
- end
- function isWalkable(x, y)
- if map[y][x] ~= 0 then
- return objAttr[map[y][x]].walkable
- end
- return true
- end
- function on.paint(gc)
- if onTitleScreen then
- gc:drawImage(titleScreen, 0, 0)
- else
- for y = 1, mapHeight do
- for x = 1, mapWidth do
- if map[y][x] ~= 0 then
- gc:drawImage(sprites[map[y][x]], (x - 1) * 16, (y - 1) * 16)
- end
- end
- end
- gc:drawImage(spritesPlayer[player.facing], (player.x - 1) * 16, (player.y - 1) * 16)
- gc:fillRect(0, 209, 318, 3)
- end
- end
- function on.enterKey()
- if onTitleScreen then
- onTitleScreen = false
- platform.window:invalidate()
- end
- end
- function on.arrowKey(key)
- local x = player.x
- local y = player.y
- if key == "up" then
- if player.facing == 1 then y = y - 1 end
- player.facing = 1
- elseif key == "down" then
- if player.facing == 2 then y = y + 1 end
- player.facing = 2
- elseif key == "left" then
- if player.facing == 3 then x = x - 1 end
- player.facing = 3
- elseif key == "right" then
- if player.facing == 4 then x = x + 1 end
- player.facing = 4
- end
- if isValid(x, y) and isWalkable(x, y) then
- player.x = x
- player.y = y
- end
- platform.window:invalidate((player.x - 2) * 16, (player.y - 2) * 16, 48, 48)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement