Functionnal place and delete

master
KikooDX 3 years ago
parent a469153f3a
commit b8e5a0699c
  1. BIN
      JetBrainsMono-Regular.ttf
  2. 4
      conf.lua
  3. 24
      draw.lua
  4. 4
      keyboard.lua
  5. 5
      load.lua
  6. 26
      mouse.lua
  7. 7
      tiles.lua
  8. 1
      update.lua

Binary file not shown.

@ -1,7 +1,7 @@
function love.conf(t)
package.path = package.path..";./?.lua"
GAME_WIDTH = 512
GAME_HEIGHT = 288
GAME_WIDTH = 416
GAME_HEIGHT = 240
scale = 2 --scale multiplier
t.version = "11.3"
t.window.width = GAME_WIDTH * scale

@ -1,7 +1,25 @@
function love.draw()
if tiles [selected_tile].texture then
love.graphics.draw(tiles[selected_tile].texture, 0, 0)
end
love.graphics.push()
love.graphics.scale(scale)
x = 0
y = 0
for i = 1, SCREEN_LEN, 1 do
current_tile = selected_screen:sub(i, i)
tile_id = 0
for i, v in ipairs(tiles_char) do
if v == current_tile then tile_id = i break end
end
if tiles[tile_id] then
love.graphics.draw(tiles[tile_id], x, y)
end
x = x + 16
if x > 16 * 25 then
x = 0
y = y + 16
end
end
--gui
love.graphics.pop()
love.graphics.setColor(0.8, 0.8, 0.8, 1)
love.graphics.print(tiles_char[selected_tile], 2, 0)
end

@ -2,10 +2,6 @@ function update_keyboard()
--get keys inputs
--debug key
if love.keyboard.isDown("d") then debug.debug() end
--mute
local buffer = k_m
k_m = love.keyboard.isDown("m")
if k_m and not buffer then sfx = not sfx end
--swap selected object
local buffer = k_tab
k_tab = love.keyboard.isScancodeDown("tab")

@ -4,3 +4,8 @@ love.graphics.setDefaultFilter("nearest", "nearest")
selected_screen = "000000000000000000000000000000000000000000000000000000......................0000......................0000......................0000......................0000......................0000......................0000......................0000......................0000......................0000......................0000......................000000000000000000000000000000000000000000000000000000"
SCREEN_LEN = 390
path = "../platformer/"
--font
love.graphics.setNewFont("JetBrainsMono-Regular.ttf", 24)
mouse_mode = 0

@ -2,30 +2,32 @@ function update_mouse()
mouse_x, mouse_y = love.mouse.getX(), love.mouse.getY() --mouse position
mouse_x = math.floor(mouse_x / scale)
mouse_y = math.floor(mouse_y / scale)
clip_mouse_x = mouse_x - mouse_x % grid_spacing
clip_mouse_y = mouse_y - mouse_y % grid_spacing
clip_mouse_x = mouse_x - mouse_x % 16
clip_mouse_y = mouse_y - mouse_y % 16
--edition mode
mouse_mode = 0
if (clip_mouse_x >= bounds.min_x) and (clip_mouse_x <= bounds.max_x) and
(clip_mouse_y >= bounds.min_y) and (clip_mouse_y <= bounds.max_y) then
if love.mouse.isDown(1) then
mouse_mode = 1
elseif love.mouse.isDown(2) then
mouse_mode = -1
end
if love.mouse.isDown(1) then
mouse_mode = 1
elseif love.mouse.isDown(2) then
mouse_mode = -1
end
if mouse_mode == 0 then buffer_x, buffer_y = 0, 0 end
--add to layer if
if mouse_mode == 1 and (clip_mouse_x ~= buffer_x or clip_mouse_y ~= buffer_y) then
add_to_layer(layer_selected)
if sfx then s_place:stop() s_place:play() end
set_tile(tiles_char[selected_tile])
buffer_x = clip_mouse_x
buffer_y = clip_mouse_y
end
--delete of layer if
if mouse_mode == -1 and (clip_mouse_x ~= buffer_x or clip_mouse_y ~= buffer_y) then
rem_of_layer(layer_selected)
set_tile('.')
buffer_x = clip_mouse_x
buffer_y = clip_mouse_y
end
end
function set_tile(char)
pos = clip_mouse_x / 16 + 1 + clip_mouse_y / 16 * 26
selected_screen = selected_screen:sub(1, pos - 1)..char..
selected_screen:sub(pos + 1, -1)
end

@ -1,9 +1,10 @@
local img_path = "img/"
tiles = {
{id = '0', texture = love.graphics.newImage(img_path.."ground.png")},
{id = '^', texture = love.graphics.newImage(img_path.."elevator1.png")},
{id = '.', texture = nil},
love.graphics.newImage(img_path.."ground.png"),
love.graphics.newImage(img_path.."elevator1.png"),
false,
}
tiles_char = { '0', '^', '.' }
selected_tile = 1

@ -1,3 +1,4 @@
function love.update(dt)
update_keyboard()
update_mouse()
end

Loading…
Cancel
Save