-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.lua
138 lines (135 loc) · 3.72 KB
/
main.lua
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
function love.load()
require "gamedata" --for the sake of abstraction
loadFont()
timer = 0
size=16 --tile height and width, no use for separate variables
mapheight = 10 -- screenheight would probably be a better name - in tiles
mapwidth = 15
windowheight = 160
windowwidth = 240
drawOverride = true --for switching between engine and specialized methods
cT = {} -- Current Terrain
cD = {} -- Current Data (solid, nonsolid blocks)
nT = {} -- Next Terrain (from load tiles)
nD = {} -- Next Data
love.graphics.setMode(windowwidth,windowheight,false,false,0)
--[[
load save
look at save
start from save
load tileset
render world
render NPCs
--]]
getSaveData()
getMapData()
loadTileSetImage()
loadQuads()
gameLoad() --from require "gamedata"
end
---------------------------------------
function love.update()
getKeyBoardInput()
end
---------------------------------------
function love.draw()
if not drawOverride then
local c = 0
for a = saveData[2], saveData[2] + 9 do -- draw the ground
local d = 0
for b = saveData[3], saveData[3] + 14 do
love.graphics.drawq(tileset, quads[cT[a][b]], (d)*size,(c)*size)
if d < 14 then d = d + 1 else d = 0 end
end
if c < 9 then c = c + 1 else c = 0 end
end
--[[
get quads of character animations
draw character
draw at (screenheight/2, screenwidth/2) offset (-spriteheight/2, -spritewidth/2)
if an animation occurs, display the frames (quads) in sequence
--]]
end
end
---------------------------------------
function getKeyBoardInput()
if love.keyboard.isDown("w") then
if love.timer.getTime() - timer > .25 then
saveData[2] = saveData[2] - 1
timer = love.timer.getTime()
end
end
if love.keyboard.isDown("a") then
if love.timer.getTime() - timer > .25 then
saveData[3] = saveData[3] - 1
timer = love.timer.getTime()
end
end
if love.keyboard.isDown("s") then
if love.timer.getTime() - timer > .25 then
saveData[2] = saveData[2] + 1
timer = love.timer.getTime()
end
end
if love.keyboard.isDown("d") then
if love.timer.getTime() - timer > .25 then
saveData[3] = saveData[3] + 1
timer = love.timer.getTime()
end
end
end
---------------------------------------
function getMapData() --relies on getSaveData()
-- this needs to be updated to orient maps in the main table (mT)
map = require(saveData[1])
cT = terrain --terrain is a table in the map file
drawOverride = false
end
---------------------------------------
function getSaveData() --called first
saveData = {}
for lines in love.filesystem.lines("save.save") do
table.insert(saveData, lines)
end
end
---------------------------------------
function loadTileSetImage() --relies on getMapData()
tileset = love.graphics.newImage(image) --image is variable in the data in the map file
end
---------------------------------------
function loadQuads() --relies on loadTileSetImage()
--this assumes there is one tileset image and does not allow for more
--each map needs a loadQuads() then
--I'll leave this in for the engine, because other games might find it useful
quads = {}
local datah = tileset:getHeight()
local dataw = tileset:getWidth()
local tilesx = dataw / 16
local tilesy = datah / 16
local count = 0
local quada = {}
for _ = 1, tilesy do
quads[_] = {}
for a = 1, tilesx do
count = count + 1
local x = (a - 1) * 16
local y = (_ - 1) * 16
quada[count] = {count, x ,y}
end
end
for _ = 1, #quada do
quads[_] = love.graphics.newQuad(quada[_][2],quada[_][3],size,size,dataw,datah)
end
end
----------------------------------------
function initializeMainTable(xsize, ysize)
--http://love2d.org/forums/memberlist.php?mode=viewprofile&u=79341
-- Idea from adekto
mT = {}
for y = 1, ysize do
mT[y] = {}
for x = 1, xsize do
mT[y][x] = 0
end
end
end