commit 4e86a22776bd4c699615601afdc6ab1634c7e2f7 Author: Isabelle L Date: Wed Jul 1 19:16:55 2020 -0500 initial commit! diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/conf.lua b/conf.lua new file mode 100644 index 0000000..88c3fa6 --- /dev/null +++ b/conf.lua @@ -0,0 +1,5 @@ +function love.conf(t) + t.window.width = 640 + t.window.height = 480 + t.window.title = "unnamed" +end \ No newline at end of file diff --git a/img/tiles/dirt.png b/img/tiles/dirt.png new file mode 100644 index 0000000..4b816ee Binary files /dev/null and b/img/tiles/dirt.png differ diff --git a/img/tiles/grass.png b/img/tiles/grass.png new file mode 100644 index 0000000..97cc08e Binary files /dev/null and b/img/tiles/grass.png differ diff --git a/img/tiles/nothing.png b/img/tiles/nothing.png new file mode 100644 index 0000000..67fc5cb Binary files /dev/null and b/img/tiles/nothing.png differ diff --git a/img/tiles/select.png b/img/tiles/select.png new file mode 100644 index 0000000..8c67ce3 Binary files /dev/null and b/img/tiles/select.png differ diff --git a/img/tiles/water.png b/img/tiles/water.png new file mode 100644 index 0000000..d03f096 Binary files /dev/null and b/img/tiles/water.png differ diff --git a/main.lua b/main.lua new file mode 100644 index 0000000..8ec5f7b --- /dev/null +++ b/main.lua @@ -0,0 +1,72 @@ +-- world module +local world = require("world") + +-- love's load function +function love.load() + -- set the overall map offset + offset = { + x = 0, + y = 0 + } + + -- generate the world and load the files + world.new(10, 10) + world.loadTiles() + + -- store the mouse position + mouse = { + x = love.mouse.getX(), + y = love.mouse.getY() + } +end + +-- love's update function +function love.update(dt) + -- get the current mouse location + local mouseNow = { + x = love.mouse.getX(), + y = love.mouse.getY() + } + + -- if mouse is pressed move the offset + if love.mouse.isDown(1) then + local mouseDelta = { + x = mouse.x - mouseNow.x, + y = mouse.y - mouseNow.y, + } + + offset.x = offset.x - mouseDelta.x + offset.y = offset.y - mouseDelta.y + end + + mouse = mouseNow +end + +-- love's key press funciton +function love.keypressed(key, scanCode, isRepeat) + -- arrow keys for moving offset + if key == "left" then + offset.x = offset.x - 16 + end + + if key == "right" then + offset.x = offset.x + 16 + end + + if key == "up" then + offset.y = offset.y - 16 + end + + if key == "down" then + offset.y = offset.y + 16 + end +end + +-- love's draw function +function love.draw() + -- clear the window + love.graphics.clear() + + -- draw the map + world.render(offset) +end \ No newline at end of file diff --git a/util.lua b/util.lua new file mode 100644 index 0000000..1b21845 --- /dev/null +++ b/util.lua @@ -0,0 +1,17 @@ +local util = {} + +function util.cartToIso(cart) + local iso = {} + iso.x = cart.x - cart.y + iso.y = (cart.x + cart.y) / 2 + return iso +end + +function util.isoToCart(iso) + local cart = {} + cart.x = (2 * iso.y + iso.x) / 2 + cart.y = (2 * iso.y - iso.x) / 2 + return cart +end + +return util \ No newline at end of file diff --git a/world.lua b/world.lua new file mode 100644 index 0000000..5a5425c --- /dev/null +++ b/world.lua @@ -0,0 +1,50 @@ +-- bring in the util module +local util = require("util") + +-- world stuffs +local world = {} + -- create a new world with given height and width + function world.new(width, height) + world.width = width + world.height = height + + for x = 1, world.width do + world[x] = {} + for y = 1, world.height do + world[x][y] = "nothing" + end + end + end + + -- load the tile files + function world.loadTiles() + world.grass = love.graphics.newImage("img/tiles/grass.png") + world.dirt = love.graphics.newImage("img/tiles/dirt.png") + world.water = love.graphics.newImage("img/tiles/water.png") + world.nothing = love.graphics.newImage("img/tiles/nothing.png") + world.select = love.graphics.newImage("img/tiles/select.png") + end + + -- render the world + function world.render(offset) + for x = 1, world.width do + for y = 1, world.height do + local tile = world[x][y] + local loc = util.cartToIso({x = x, y = y}) + + if tile == "grass" then + image = world.grass + elseif tile == "dirt" then + image = world.dirt + elseif tile == "water" then + image = world.water + else + image = world.nothing + end + + love.graphics.draw(image, loc.x * 16 + offset.x, loc.y * 16 + offset.y) + end + end + end + +return world \ No newline at end of file