Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Load all the sprites here. It's long so I wont paste it 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
- sprites_player = {sprite_player_1, -- Up
- sprite_player_2, -- Down
- sprite_player_3, -- Left
- sprite_player_4} -- Right
- player = {x = 2, y = 2, facing = 2}
- map_width = 20
- map_height = 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}}
- obj_attr = {{walkable = false},
- {walkable = true},
- {walkable = true},
- {walkable = true},
- {walkable = false},
- {walkable = false},
- {walkable = false},
- {walkable = true}}
- on_title_screen = true;
- function is_valid(x, y)
- return x >= 1 and y >= 1 and x <= map_width and y <= map_height
- end
- function is_walkable(x, y)
- if map[y][x] ~= 0 then
- return obj_attr[map[y][x]].walkable
- end
- return true
- end
- function is_valid_walkable(x, y)
- return is_valid(x, y) and is_walkable(x, y)
- end
- function on.paint(gc)
- if on_title_screen then
- gc:drawImage(title_screen, 0, 0)
- else
- for i = 1, map_height do
- for j = 1, map_width do
- if map[i][j] ~= 0 then
- gc:drawImage(sprites[map[i][j]], (j - 1) * 16, (i - 1) * 16)
- end
- end
- end
- gc:drawImage(sprites_player[player.facing], (player.x - 1) * 16, (player.y - 1) * 16)
- gc:fillRect(0, 209, 318, 3)
- end
- end
- function on.enterKey()
- if on_title_screen then
- on_title_screen = false
- platform.window:invalidate()
- end
- end
- function on.arrowKey(key)
- if key == "up" then
- if player.facing == 1
- and is_valid_walkable(player.x, player.y - 1) then
- player.y = player.y - 1
- else player.facing = 1 end
- elseif key == "down" then
- if player.facing == 2
- and is_valid_walkable(player.x, player.y + 1) then
- player.y = player.y + 1
- else player.facing = 2 end
- elseif key == "left" then
- if player.facing == 3
- and is_valid_walkable(player.x - 1, player.y) then
- player.x = player.x - 1
- else player.facing = 3 end
- elseif key == "right" then
- if player.facing == 4
- and is_valid_walkable(player.x + 1, player.y) then
- player.x = player.x + 1
- else player.facing = 4 end
- 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