-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
141 lines (122 loc) · 3.38 KB
/
main.lua
File metadata and controls
141 lines (122 loc) · 3.38 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
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
139
140
141
function love.conf()
t.screen.width = 1024
t.screen.height = 768
end
-- groundx : 482
-- groundy : 124
-- grundw : 62
-- groundh : 31
function love.load()
grafik = require 'grafik'
block_width = 62
-- grass:getWidth()
block_height = 32
-- grass:getHeight()
block_depth = block_height
-- block_depth = block_height/2
map_w = 20
map_h = 20
map_x = 0
map_y = 0
map_display_buffer = 10
map_display_w = 20
map_display_h = 15
grid_size = 200
grid = {}
for x = 1,grid_size do
grid[x] = {}
for y = 1,grid_size do
grid[x][y] = math.random(9)
end
end
lastmousex = 0
lastmousey = 0
end
function love.update(dt)
cameraUpdate(dt)
end
function love.draw()
draw_map()
love.graphics.setColor(255,255,255)
love.graphics.print("Isometric Map Test\ndarookee", 15, 15)
love.graphics.print("x:" .. lastmousex .. " y:" .. lastmousey, 15, 115)
love.graphics.print("x:" .. map_x .. " y:" .. map_y, 15, 125)
end
function love.keypressed(key, u)
if key == "rctrl" then
debug.debug()
end
if key == "up" then
map_y = map_y + 10
if map_y > grid_size-100 then map_y = grid_size-100; end
end
if key == "down" then
map_y = map_y - 10
if map_y < 0 then map_y = 0; end
end
if key == "left" then
map_x = math.min(map_x+10, grid_size-50)
end
if key == "right" then
map_x = math.max(map_x-10, 0)
end
end
function love.mousepressed(x,y,button)
lastmousex = x
lastmousey = y
end
function love.mousereleased(x,y,button)
lastmousex = x
lastmousey = y
end
function draw_map()
for x = 1,grid_size do
for y = 1,grid_size do
toDraw = grafik.determineGraphicToDraw(grid[x][y])
love.graphics.draw(
grafik.spriteMap,
toDraw,
map_x + ((y-x) * (block_width/2)),
map_y + ((x+y) * (block_depth/2)) - (block_depth * (grid_size/2))
)
if x == 10 and y == 12 then
love.graphics.draw(
grafik.spriteMap,
grafik.graphics.highlight.border,
map_x + ((y-x) * (block_width/2)),
map_y + ((x+y) * (block_depth/2)) - (block_depth * (grid_size/2))
)
end
end
end
end
function cameraUpdate(dt)
if love.mouse.isDown('r') then
map_x = math.floor(map_x - ((lastmousex - love.mouse.getX())) / block_width*4)
map_y = math.floor(map_y - ((lastmousey - love.mouse.getY())) / block_height*4)
end
-- Handle keyboard panning
if love.keyboard.isDown("lshift") or love.keyboard.isDown("rshift") then
if love.keyboard.isDown("left") then
map_x = map_x + 300 * dt
end
if love.keyboard.isDown("right") then
map_x = map_x - 300 * dt
end
if love.keyboard.isDown("up") then
map_y = map_y + 300 * dt
end
if love.keyboard.isDown("down") then
map_y = map_y - 300 * dt
end
end
end
function loadTransparent(imagePath, transR, transG, transB)
imageData = love.image.newImageData( imagePath )
function mapFunction(x, y, r, g, b, a)
if r == transR and g == transG and b == transB then a = 0 end
return r,g,b,a
end
imageData:mapPixel( mapFunction )
return love.graphics.newImage( imageData )
end