From 203f111b8a67dd0e44f9fc07f8a6d8d6caa1bf2c Mon Sep 17 00:00:00 2001 From: Sebastian Hugentobler Date: Wed, 21 May 2014 11:36:02 +0200 Subject: [PATCH] the story beginns --- src/engine/init.lua | 21 +++++++++++++++++---- src/engine/ui.lua | 13 ++++++++----- src/{assets/map.lua => levels/01.lua} | 0 src/{assets => levels}/tiles/atlas00.png | Bin src/{assets => levels}/tiles/atlas01.png | Bin src/{assets => levels}/tiles/atlas03.png | Bin src/{assets => levels}/tiles/atlas04.png | Bin src/story.lua | 8 ++++++++ 8 files changed, 33 insertions(+), 9 deletions(-) rename src/{assets/map.lua => levels/01.lua} (100%) rename src/{assets => levels}/tiles/atlas00.png (100%) rename src/{assets => levels}/tiles/atlas01.png (100%) rename src/{assets => levels}/tiles/atlas03.png (100%) rename src/{assets => levels}/tiles/atlas04.png (100%) create mode 100644 src/story.lua diff --git a/src/engine/init.lua b/src/engine/init.lua index c09a8df..5e3b33d 100644 --- a/src/engine/init.lua +++ b/src/engine/init.lua @@ -7,6 +7,7 @@ collider = HC(100) local sti = require "engine/libs/sti" local object = require "engine/object" local ui = require "engine/ui" +local story = require 'story' Engine = class() @@ -16,10 +17,7 @@ function Engine:__init() self.windowWidth = love.graphics.getWidth() self.windowHeight = love.graphics.getHeight() - self.map = sti.new("assets/map") - self.collision = self.map:getCollisionMap("collision") - - self:initObjects() + story:start(self) end function Engine:checkObjectAnimation(key) @@ -76,6 +74,8 @@ function Engine:draw() end function Engine:initObjects() + self.objects = {} + self.map:addCustomLayer("object layer", 4) local objectLayer = self.map.layers["object layer"] @@ -120,3 +120,16 @@ function Engine:debugDrawing() -- Draw Collision Map (useful for debugging) self.map:drawCollisionMap(collision) end + +function Engine:loadLevel(name) + local mapName = 'levels/' .. name + + self.map = sti.new(mapName) + self.collision = self.map:getCollisionMap("collision") + + self:initObjects() +end + +function Engine:showMessage(message) + ui:showMessage(message) +end diff --git a/src/engine/ui.lua b/src/engine/ui.lua index 604c16a..4b55586 100644 --- a/src/engine/ui.lua +++ b/src/engine/ui.lua @@ -15,11 +15,14 @@ ui.endLine = 1 local font = love.graphics.newFont("assets/ui/font.ttf", 24) love.graphics.setFont(font) +ui.windowWidth = love.graphics.getWidth() +ui.windowHeight = love.graphics.getHeight() + function ui:showMessage(message) ui.active = true local maxLines = math.floor((ui.height - ui.border) / font:getHeight()) - local fullLines = font:getWrap(ui.fullMessage, windowWidth - ui.border) + local fullLines = font:getWrap(ui.fullMessage, ui.windowWidth - ui.border) ui.textLines = {} @@ -57,9 +60,9 @@ function ui:getMaxString(stringTail) local index = string.len(stringTail) local width = font:getWidth(string.sub(stringTail, 1, index)) - local needsCutting = width > windowWidth - ui.border + local needsCutting = width > ui.windowWidth - ui.border - while width > windowWidth - ui.border do + while width > ui.windowWidth - ui.border do width = font:getWidth(string.sub(stringTail, 1, index)) index = index - 1 end @@ -79,10 +82,10 @@ end function ui:draw() if ui.active then love.graphics.setColor(255, 255, 255, 150) - love.graphics.rectangle("fill", 0, windowHeight - ui.height, windowWidth, ui.height) + love.graphics.rectangle("fill", 0, ui.windowHeight - ui.height, ui.windowWidth, ui.height) love.graphics.setColor(55, 60, 60, 255) - love.graphics.printf(ui.fullMessage, ui.border, windowHeight - ui.height + ui.border, windowWidth - ui.border) + love.graphics.printf(ui.fullMessage, ui.border, ui.windowHeight - ui.height + ui.border, ui.windowWidth - ui.border) end end diff --git a/src/assets/map.lua b/src/levels/01.lua similarity index 100% rename from src/assets/map.lua rename to src/levels/01.lua diff --git a/src/assets/tiles/atlas00.png b/src/levels/tiles/atlas00.png similarity index 100% rename from src/assets/tiles/atlas00.png rename to src/levels/tiles/atlas00.png diff --git a/src/assets/tiles/atlas01.png b/src/levels/tiles/atlas01.png similarity index 100% rename from src/assets/tiles/atlas01.png rename to src/levels/tiles/atlas01.png diff --git a/src/assets/tiles/atlas03.png b/src/levels/tiles/atlas03.png similarity index 100% rename from src/assets/tiles/atlas03.png rename to src/levels/tiles/atlas03.png diff --git a/src/assets/tiles/atlas04.png b/src/levels/tiles/atlas04.png similarity index 100% rename from src/assets/tiles/atlas04.png rename to src/levels/tiles/atlas04.png diff --git a/src/story.lua b/src/story.lua new file mode 100644 index 0000000..65def9c --- /dev/null +++ b/src/story.lua @@ -0,0 +1,8 @@ +local story = {} + +function story:start(engine) + engine:loadLevel('01') + engine:showMessage('Du befindest dich auf einer sturmgebeutelten Insel. Wo ist denn nur die Milch?') +end + +return story \ No newline at end of file