-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworldThread.lua
More file actions
92 lines (86 loc) · 2.75 KB
/
worldThread.lua
File metadata and controls
92 lines (86 loc) · 2.75 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
require'threadMgr'
require 'love.audio'
require 'love.event'
require 'love.graphics'
require 'love.image'
require 'love.joystick'
require 'love.keyboard'
require 'love.math'
require 'love.mouse'
require 'love.physics'
require 'love.sound'
require 'love.system'
require 'love.timer'
require 'love.touch'
require 'love.video'
require 'love.window'
require 'love.thread'
binser = require'binser-master/binser'
require'mainCamera'
require'objects'
--init
local v = channel.mTw:demand()
tileAngle,tileSize = v[1],v[2]
chunkHandler = {currentChunkX = 0, currentChunkY = 0, lastChunkX =0, lastChunkY = 0}
chunkHandler.width = 5 --might change varname later as it is misleading. Ammount of chunks in the X axis
chunkHandler.height = 5 -- ammount of chunks in the y axis
chunkHandler.chunkSize = 16 -- square root of the ammount of tiles on one layer of a chunk
local w,h,size = chunkHandler.width,chunkHandler.height,chunkHandler.chunkSize
--generating an empty world map with 5 by 5 (w and h) chunks, each made out of a 16 by 16 grid
sin = math.abs(math.sin(tileAngle) *tileSize*math.cos(tileAngle*2))
cos = math.abs(math.cos(tileAngle) *tileSize*math.cos(tileAngle*2))
--objSurface:new({dim = {z = z,x = -2*cos +( cos*l) +k*cos, y = -sin + (sin*l) -k*sin , w = tileSize, h=tileSize,pos= {x=k,y=l,z=z}} })
map = {}
loadedMap = {}
--create map first, change here to load from file/files
for xx=1,w do
map[xx]={}
for yy=1,h do
map[xx][yy] = {}
for x=1,size do
map[xx][yy][x] = {}
for y=1,size do
map[xx][yy][x][y] = {active = 'active'}
for z=1,1 do
map[xx][yy][x][y][z] = {}
local length = #map[xx][yy][x][y][z]
local k,l,z = x,y,z
map[xx][yy][x][y][z][length +1] = {type = 1, tbl ={dim = {pos= {x=k,y=l,z=z,xx=xx,yy=yy}} } }
end
end
end
end
end
--load the map
for xx,v in ipairs(map) do
for yy,v in ipairs(map[xx]) do
for x,v in ipairs(map[xx][yy]) do
for y,v in ipairs(map[xx][yy][x]) do
for z,v in ipairs(map[xx][yy][x][y]) do
for k,v in ipairs(map[xx][yy][x][y][z]) do
if v.type == 1 then
loadedMap[#loadedMap +1] = objSurface:new(v.tbl)
end
end
end
end
end
end
end
--
function updateWorld()
local dt = love.timer.getDelta()
player:update()
for k,v in ipairs(loadedMap) do
v:update(dt)
end
end
function drawWorld()
channel.wTm:push(map)
player:draw()
end
--main loop
while true do
updateWorld()
drawWorld()
end