Skip to content

Commit b60a591

Browse files
committed
Stuff.
1 parent aedef76 commit b60a591

File tree

8 files changed

+105
-46
lines changed

8 files changed

+105
-46
lines changed

assets/music/0.ogg

1.08 MB
Binary file not shown.

builds/universal/atman.love

0 Bytes
Binary file not shown.

builds/win32/atman.exe

0 Bytes
Binary file not shown.

builds/win64/atman.exe

0 Bytes
Binary file not shown.

deploy.bat

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
butler push builds\universal danieldan0/atman:windows-osx-linux-love
2+
butler push builds\win32 danieldan0/atman:windows-32
3+
butler push builds\win64 danieldan0/atman:windows-64

src/input_handlers.lua

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
function handle_input(user_input)
2+
-- Movement keys
3+
if user_input.keys['up'] then
4+
return {move = {0, -1}}
5+
elseif user_input.keys['down'] then
6+
return {move = {0, 1}}
7+
elseif user_input.keys['left'] then
8+
return {move = {-1, 0}}
9+
elseif user_input.keys['right'] then
10+
return {move = {1, 0}}
11+
end
12+
13+
if user_input.keys['return'] and user_input.keys['lalt'] then
14+
-- Alt+Enter: toggle full screen
15+
return {fullscreen = true}
16+
elseif user_input.keys['escape'] then
17+
-- Exit the game
18+
return {exit = true}
19+
end
20+
21+
-- No key was pressed
22+
return {}
23+
end
24+
25+
return handle_input

src/main.lua

+52-46
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
moonshine = require 'lib/moonshine'
1+
local moonshine = require 'lib/moonshine'
2+
local utils = require 'utils'
3+
local handle_input = require 'input_handlers'
24

35
function love.load()
6+
-- Loading shaders
47
s_scanlines = moonshine(moonshine.effects.scanlines)
58
.chain(moonshine.effects.crt)
69
s_scanlines.scanlines.thickness = 0.5
@@ -12,81 +15,84 @@ function love.load()
1215
s_screen.scanlines.thickness = 0.5
1316
s_screen.crt.scaleFactor = {1.15, 1.15}
1417

18+
-- Loading font
1519
font = love.graphics.newFont("assets/fonts/Press_Start_2P/PressStart2P-Regular.ttf", 24)
20+
love.graphics.setFont(font)
21+
22+
-- Loading images
1623
frame = love.graphics.newImage("assets/images/screen-frame.png")
17-
mouseXY = {0, 0}
18-
tileXY = {0, 0}
19-
playerXY = {0, 0}
24+
25+
-- Initialiazing game state.
26+
game = {
27+
playerXY = {0, 0},
28+
user_input = {
29+
keys = {},
30+
mouseXY = {0, 0},
31+
tileXY = {0, 0},
32+
pressed_key = false
33+
}
34+
}
35+
action = {}
2036
end
2137

2238
function love.update(dt)
39+
if game.user_input.pressed_key then
40+
action = handle_input(game.user_input)
41+
move = action['move']
42+
exit = action['exit']
43+
fullscreen = action['fullscreen']
44+
45+
if move then
46+
dx, dy = unpack(move)
47+
game.playerXY = {game.playerXY[1] + dx, game.playerXY[2] + dy}
48+
end
49+
50+
if exit then
51+
love.event.quit()
52+
end
53+
54+
if fullscreen then
55+
love.window.setFullscreen(not love.window.getFullscreen(), "exclusive")
56+
end
57+
58+
game.user_input.pressed_key = false
59+
end
2360
end
2461

2562
function love.keypressed(key)
26-
if key == "z" then
27-
print(tileXY[1]..";"..tileXY[2])
28-
end
63+
game.user_input.keys[key] = true
64+
game.user_input.pressed_key = true
65+
end
2966

30-
if key == "up" then
31-
playerXY = {playerXY[1], playerXY[2] - 1}
32-
elseif key == "down" then
33-
playerXY = {playerXY[1], playerXY[2] + 1}
34-
elseif key == "left" then
35-
playerXY = {playerXY[1] - 1, playerXY[2]}
36-
elseif key == "right" then
37-
playerXY = {playerXY[1] + 1, playerXY[2]}
38-
end
67+
function love.keyreleased(key)
68+
game.user_input.keys[key] = nil
3969
end
4070

4171
function love.mousemoved(x, y, dx, dy, istouch)
4272
-- Correcting mouse coordinates.
43-
mouseXY = fisheye({x, y}, 640, 496, 1.15, 1.06, 1.065)
44-
tileXY = {math.floor(mouseXY[1] / 24), math.floor(mouseXY[2] / 24)}
73+
game.user_input.mouseXY = utils.fisheye({x, y}, 640, 496, 1.15, 1.06, 1.065)
74+
game.user_input.tileXY = {math.floor(game.user_input.mouseXY[1] / 24), math.floor(game.user_input.mouseXY[2] / 24)}
4575
end
4676

4777
function love.draw()
48-
love.graphics.setFont(font)
49-
5078
s_scanlines(function()
5179
love.graphics.setColor({5, 5, 5, 255})
5280
love.graphics.rectangle("fill", 0, 0, 640, 480)
5381
end)
5482

5583
s_screen(function()
56-
drawChar("@", playerXY[1], playerXY[2], {255, 0, 0, 255}, {0, 255, 0, 255})
57-
if tileXY[1] == playerXY[1] and tileXY[2] == playerXY[2] then
58-
drawChar("@", playerXY[1], playerXY[2], {255, 127, 127, 255}, {127, 255, 127, 255})
84+
drawChar("@", game.playerXY[1], game.playerXY[2], {255, 0, 0, 255}, {0, 255, 0, 255})
85+
if game.user_input.tileXY[1] == game.playerXY[1] and game.user_input.tileXY[2] == game.playerXY[2] then
86+
drawChar("@", game.playerXY[1], game.playerXY[2], {255, 127, 127, 255}, {127, 255, 127, 255})
5987
end
6088
-- cursors
6189
love.graphics.setColor({255, 0, 0, 255})
62-
love.graphics.rectangle("fill", mouseXY[1] - 5, mouseXY[2] - 5, 10, 10)
90+
love.graphics.rectangle("fill", game.user_input.mouseXY[1] - 5, game.user_input.mouseXY[2] - 5, 10, 10)
6391
end)
6492

6593
love.graphics.draw(frame, 0, 0)
6694
end
6795

68-
function readAll(file)
69-
local f = io.open(file, "rb")
70-
local content = f:read("*all")
71-
f:close()
72-
return content
73-
end
74-
75-
function inArea(x, y, area_x, area_y, area_w, area_h)
76-
return (((x >= area_x) and (x <= area_x + area_w)) and ((y >= area_y) and (y <= area_y + area_h)))
77-
end
78-
79-
function fisheye(vec, w, h, scale, distortX, distortY)
80-
result = {vec[1] / w, vec[2] / h}
81-
result = {result[1] * 2.0 - 1.0, result[2] * 2.0 - 1.0}
82-
result = {result[1] * scale, result[2] * scale}
83-
result = {result[1] + (result[2] * result[2] * result[1] * (distortX - 1)),
84-
result[2] + (result[1] * result[1] * result[2] * (distortY - 1))}
85-
result = {(result[1] + 1.0) / 2.0, (result[2] + 1.0) / 2.0}
86-
result = {result[1] * w, result[2] * h}
87-
return result
88-
end
89-
9096
function drawChar(char, x, y, color, bg)
9197
love.graphics.setColor(bg)
9298
love.graphics.rectangle('fill', x * 24, y * 24, 24, 24)

src/utils.lua

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
utils = {}
2+
3+
function utils.readAll(file)
4+
local f = io.open(file, "rb")
5+
local content = f:read("*all")
6+
f:close()
7+
return content
8+
end
9+
10+
function utils.inArea(x, y, area_x, area_y, area_w, area_h)
11+
return (((x >= area_x) and (x <= area_x + area_w)) and ((y >= area_y) and (y <= area_y + area_h)))
12+
end
13+
14+
function utils.fisheye(vec, w, h, scale, distortX, distortY)
15+
result = {vec[1] / w, vec[2] / h}
16+
result = {result[1] * 2.0 - 1.0, result[2] * 2.0 - 1.0}
17+
result = {result[1] * scale, result[2] * scale}
18+
result = {result[1] + (result[2] * result[2] * result[1] * (distortX - 1)),
19+
result[2] + (result[1] * result[1] * result[2] * (distortY - 1))}
20+
result = {(result[1] + 1.0) / 2.0, (result[2] + 1.0) / 2.0}
21+
result = {result[1] * w, result[2] * h}
22+
return result
23+
end
24+
25+
return utils

0 commit comments

Comments
 (0)