-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathworld.lua
89 lines (75 loc) · 1.89 KB
/
world.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
local Gamestate = require "lib.gamestate"
local sprites = require "gfx"
local Player = require "player"
local module = Gamestate.new()
Gamestate.world = module
module.change = 16
local SIZE = 16;
local landscape = sprites.landscape
-- TODO: different levels/maps/locations
-- Yes, the map is 9x9, deal w/ it 4 now
-- Or better yet, let's get started on random generation
local map_data = {
size = 81;
{0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 1, 1, 1, 1, 1, 1, 1, 0},
{0, 1, 2, 2, 0, 2, 2, 1, 0},
{0, 1, 2, 3, 3, 3, 2, 1, 0},
{0, 1, 0, 3, 4, 3, 0, 1, 0},
{0, 1, 2, 3, 3, 3, 2, 1, 0},
{0, 1, 2, 2, 0, 2, 2, 1, 0},
{0, 1, 1, 1, 1, 1, 1, 1, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0},
}
local batch = love.graphics.newSpriteBatch(landscape.image, map_data.size)
batch:bind()
local i = 0;
for y = 1, #map_data do
for x = 1, #map_data[y] do
batch:addq(landscape[map_data[y][x]][1], (x-1)*SIZE, (y-1)*SIZE)
end
end
batch:unbind();
-- default starting stuff
-- Place selected map here
module.map = {
image = landscape.image;
raw = landscape;
batch = batch;
data = map_data;
x = 0;
y = 0;
}
module.player = Player {
speed = 4; -- walk 4 blocks per second
steps = 8; -- take 8 steps per block, more = smoother movement
}
module.player:random_position(module)
function module:enter()
-- TODO: something about picking different portions of the world such as
-- starting in different towns
end
function module:draw()
local graphics = love.graphics
graphics.push()
graphics.scale(2)
graphics.draw(self.map.batch, self.map.x, self.map.y)
self.player:draw()
graphics.pop()
end
function module:update(dt)
self.player:update(self, dt)
end
--[[
function module:keypressed(key)
if key == "left" then
self.x = self.x - self.change
elseif key == "right" then
self.x = self.x + self.change
elseif key == "up" then
self.y = self.y - self.change
elseif key == "down" then
self.y = self.y + self.change
end
end
]]