-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworld.lua
More file actions
93 lines (87 loc) · 2.51 KB
/
Copy pathworld.lua
File metadata and controls
93 lines (87 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
---@class World
---@field levelFile string
---@field size {x: number, y: number}
---@field tileSize {width: number, height: number}
---@field tileMap Tile[][]
-- world = {
-- levelFile = love.filesystem.read("assets/level0.txt"),
-- size = {x = 32, y = 32},
-- tileSize = {
-- -- width = 37.5, height = 37.5 --height/size
-- width = 18.75, height = 18.75
-- },
-- tileMap = {},
-- startPos = {x = 0, y = 0},
-- keyBind = {
-- up = 'w',
-- down = 's',
-- left = 'j',
-- right = 'l'
-- }
-- }
local Object = require "classic"
local World = Object:extend()
-- require "tile"
require "floorTile"
require "wallTile"
require "startTile"
require "endTile"
require "util"
require "hazardTile"
local bg
function World:new(levelfile)
bg = love.graphics.newImage("assets/WallMenu.png")
local FloorTile = require "floorTile"
local WallTile = require "wallTile"
print(levelfile)
local levFi = love.filesystem.read("assets/" .. levelfile)
self.levelFile = love.filesystem.read("assets/" .. levelfile)
self.size = {x=32, y=32}
self.tileSize = {
width = 18.75, height=18.75
}
self.tileMap = {}
self.startPos = {x = 0, y = 0}
self.keyBind = {
up = 'w',
down = 's',
left = 'j',
right = 'l'
}
local yCounter = 0
for line in levFi:gmatch '%S+' do
yCounter = yCounter + 1
local xCounter = 0
for ch in line:gmatch '.' do --I hate this sm
xCounter = xCounter + 1
local tile = nil
if ch == "W" then
tile = WallTile(xCounter, yCounter)
elseif ch == "F" then
tile = FloorTile(xCounter, yCounter)
elseif ch == "H" then
tile = HazardTile(xCounter, yCounter)
elseif ch == "E" then
tile = EndTile(xCounter, yCounter)
elseif ch == "S" then
tile = StartTile(xCounter, yCounter)
self.startPos = {
x = tile.topLeft.x,
y = tile.topLeft.y
}
end
table.insert(self.tileMap, tile)
end
end
end
function World:draw()
local Tile = require "tile"
local index = 0
love.graphics.draw(bg)
while index < #self.tileMap do
index = index+1
local myTile = self.tileMap[index]
love.graphics.draw(myTile.image, myTile.topLeft.x, myTile.topLeft.y, 0, Tile.scaleFactor, Tile.scaleFactor)
end
end
return World