summaryrefslogtreecommitdiffhomepage
path: root/world.lua
blob: e4301e437196bb7e05deccdc67dd3d9ae42bff04 (plain)
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
-- `World`
-- Used to manage physical world and everything inside it: clouds, platforms, nauts, background etc.

-- WHOLE CODE HAS FLAG OF "need a cleanup"

-- Metatable of `World`
-- nils initialized in constructor
World = {
	world = nil,
	nauts = nil,
	platforms = nil,
	clouds = nil,
	camera = nil -- not sure yet? menu will need scaling too
}

-- Constructor of `World` ZA WARUDO!
function World:new()
	-- Meta
	local o = {}
	setmetatable(o, self)
	self.__index = self
	-- Physical world initialization
	love.physics.setMeter(64)
	o.world = love.physics.newWorld(0, 9.81*64, true)
	o.world:setCallbacks(o.beginContact, o.endContact)
	-- Empty tables for objects
	local c = {}
	o.clouds = c
	local n = {}
	o.nauts = n
	local p = {}
	o.platforms = {}
	return o
end

-- Add new platform to the world
function World:createPlatform(x, y, polygon, sprite)
	table.insert(self.platforms, Ground:new(self.world, x, y, polygon, sprite))
end

-- Add new naut to the world
function World:createNaut(x, y, sprite)
	table.insert(self.nauts, Player:new(self.world, x, y, sprite))
end

-- Add new cloud to the world

-- Update
-- Keypressed
-- Keyreleased
-- Draw

-- beginContact
-- endContact