-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.lua
More file actions
107 lines (90 loc) · 3.78 KB
/
main.lua
File metadata and controls
107 lines (90 loc) · 3.78 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
if arg[2] == "debug" then
require("lldebugger").start()
end
local maid64 = require "maid64"
local utf8 = require("utf8")
local textInput = ""
local text = ""
local oldText = ""
-- recommended screen sizes
---+--------------+-------------+------+-----+-----+-----+-----+-----+-----+-----+
-- | scale factor | desktop res | 1 | 2 | 3 | 4 | 5 | 6 | 8 | 10 |
-- +--------------+-------------+------+-----+-----+-----+-----+-----+-----+-----+
-- | width | 1920 | 1920 | 960 | 640 | 480 | 384 | 320 | 240 | 192 |
-- | height | 1080 | 1080 | 540 | 360 | 270 | 216 | 180 | 135 | 108 |
-- +--------------+-------------+------+-----+-----+-----+-----+-----+-----+-----+
local settings = {
fullscreen = false,
scaleMuliplier = 3,
sceenWidth = 320,
screenHeight = 180
}
function love.load()
love.window.setTitle( 'inLove2D' )
--optional settings for window
love.window.setMode(settings.sceenWidth*settings.scaleMuliplier, settings.screenHeight*settings.scaleMuliplier, {resizable=true, vsync=false, minwidth=200, minheight=200})
love.graphics.setDefaultFilter("nearest", "nearest")
--initilizing maid64 for use and set to 64x64 mode
--can take 2 parameters x and y if needed for example maid64.setup(64,32)
maid64.setup(settings.sceenWidth, settings.screenHeight)
--font = love.graphics.newFont('fonts/pico-8-mono.ttf', 12)
font = love.graphics.newFont('fonts/PressStart2P-Regular.ttf', 8)
--font:setFilter('nearest', 'nearest')
love.graphics.setFont(font)
-- create test sprite
--maid = maid64.newImage("maid64.png")
spr_inLove2d = maid64.newImage("inLove2d_64x64.png")
rotate = 0
-- enable key repeat so backspace can be held down to trigger love.keypressed multiple times.
love.keyboard.setKeyRepeat(true)
end
function love.update(dt)
rotate = rotate + dt
end
function love.draw()
maid64.start()--starts the maid64 process
--draw images here
--can also draw shapes and get mouse position
love.graphics.circle("fill", maid64.mouse.getX(), maid64.mouse.getY(), 2)
love.graphics.print('> ' .. textInput, 0, 226)
love.graphics.setFont(font)
love.graphics.print('' .. oldText, 0, 226-14-14)
love.graphics.print('' .. text, 0, 226-14)
--love.graphics.draw(spr_inLove2d,sceenWidth/2,screenHeight/2,rotate,3,3,32,32)
love.graphics.draw(spr_inLove2d, settings.sceenWidth/2, settings.screenHeight/2, rotate, 3, 3, spr_inLove2d:getWidth()/2, spr_inLove2d:getHeight()/2)
maid64.finish()--finishes the maid64 process
end
function love.resize(w, h)
-- this is used to resize the screen correctly
maid64.resize(w, h)
end
function love.textinput(t)
textInput = textInput .. t
end
function love.keypressed(key)
if key == "backspace" then
-- get the byte offset to the last UTF-8 character in the string.
local byteoffset = utf8.offset(textInput, -1)
if byteoffset then
-- remove the last UTF-8 character.
-- string.sub operates on bytes rather than UTF-8 characters, so we couldn't do string.sub(text, 1, -2).
textInput = string.sub(textInput, 1, byteoffset - 1)
end
end
if key == "return" then
oldText = text
text = textInput
textInput = ""
end
-- toggle fullscreen
if key == 'f11' then
if settings.fullscreen == false then
love.window.setFullscreen(true, "desktop")
settings.fullscreen = true
else
love.window.setMode(settings.sceenWidth*settings.scaleMuliplier, settings.screenHeight*settings.scaleMuliplier, {resizable=true, vsync=false, minwidth=200, minheight=200})
maid64.setup(settings.sceenWidth, settings.screenHeight)
settings.fullscreen = false
end
end
end