Skip to content

Commit

Permalink
Final update
Browse files Browse the repository at this point in the history
  • Loading branch information
rackover committed Jun 24, 2018
1 parent 7363a84 commit 0348284
Show file tree
Hide file tree
Showing 2 changed files with 194 additions and 20 deletions.
163 changes: 145 additions & 18 deletions main.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
io.stdout:setvbuf("no")

local utf8 = require("utf8")

local celltypes = require('celltypes')
local cellinfo = require('cellinfo')
local world = require("world")
Expand All @@ -17,16 +19,18 @@ local view = {}
local theseWords = {}
local screens = 5 -- the world will be screens² sized

local chooseWord = true -- The player is still choosing the word, and not actually ingame
local typedWord = ''
local authorizedChars = "azertyuiopqsdfghjklmwxcvbn"
local displayLabel = true

-- debug elements
local debugText,debugFont

-- On start
function love.load(arg)
--if arg and arg[#arg] == "-debug" then require("mobdebug").start() end

-- Words
theseWords = words:new("home")

-- View
view.size = {w=15, h=15}
view.unit = 16 -- Width/Height of a square unit (sprite) in pixels
Expand All @@ -39,20 +43,38 @@ function love.load(arg)
-- Window setup
love.window.setMode(view.size.w*view.unit, view.size.h*view.unit, {fullscreen=false})

-- Game setup
initializeGame()

-- Debug
debugFont = love.graphics.newFont("res/font/tahoma.ttf", view.unit/2)
debugText = love.graphics.newText(debugFont, "bonjour")

-- Init
view:refreshView(thisWorld, explorer)

end

function love.textinput( text )
if (chooseWord) then
text = string.lower(text)
if (string.len(typedWord) < 9 and
string.find(authorizedChars, text) ~= nil and
string.find(authorizedChars, text) <= string.len(authorizedChars)
) then
typedWord = typedWord..text
end
end
end

function love.keypressed(key)
-- in v0.9.2 and earlier space is represented by the actual space character ' ', so check for both

if (chooseWord) then
if (key == "backspace") then
typedWord = string.sub(typedWord, 1, string.len(tostring(typedWord))-1)
elseif (key == "return") then
chooseWord = false
theseWords = words:new(typedWord)
initializeGame()
view:refreshView(thisWorld, explorer)
end
return
end
if (key == "right") then
explorer:move({x=1,y=0})

Expand Down Expand Up @@ -125,14 +147,28 @@ function explorer:move(vec2_direction)
return
end
local nextCell = thisWorld.map[nextPosition.x][nextPosition.y]
if (cellinfo[nextCell].solid) then
local nextCellIsOccupied = false
for l,w in pairs(entities) do
if (w.position.x == nextPosition.x and
w.position.y == nextPosition.y and
w.solid and
(
ent.entityType ~= ent.types.key or
w.entityType ~= ent.types.door
)) then
ent.position.x = explorer.position.x
ent.position.y = explorer.position.y
explorer.position.x = futurePosition.x
explorer.position.y = futurePosition.y
return
end
end

if (cellinfo[nextCell].solid or nextCellIsOccupied) then
if (nextCell == celltypes.water) then
-- the player pushed it in the water!
for l,w in pairs(entities) do
if (w == ent) then
entities[l] = nil
end
end
entities[k] = nil

explorer.position.x = futurePosition.x
explorer.position.y = futurePosition.y
dialog:start("Oh!It's underwater now...")
Expand All @@ -157,6 +193,7 @@ function explorer:move(vec2_direction)
thisWorld:affect(self.position)
self.position = futurePosition
dialog:terminate()
displayLabel = false

updateEntities(thisWorld, entities)
end
Expand Down Expand Up @@ -233,9 +270,7 @@ function initializeGame()
table.insert(entities, entity:new(entity.types.door, {x=explorer.position.x, y=explorer.position.y-1}))

-- ((here for debugging only, creating a portal))
table.insert(entities, entity:newVillager({x=explorer.position.x, y=explorer.position.y+1}, dialog:getSentence(theseWords)))
--table.insert(entities, entity:new(entity.types.portal, {x=explorer.position.x, y=explorer.position.y+1}))


-- Put keys in the world
for i=1,3 do
local pos = {x=math.random(thisWorld.size.w), y=math.random(thisWorld.size.h)}
Expand All @@ -244,6 +279,17 @@ function initializeGame()
end
table.insert(entities, entity:new(entity.types.key, pos))
end

-- Put npcs in the world
for i=1,1+math.random(4) do
local pos = {x=math.random(thisWorld.size.w), y=math.random(thisWorld.size.h)}
while (cellinfo[thisWorld.map[pos.x][pos.y]].solid) do
pos = {x=math.random(thisWorld.size.w), y=math.random(thisWorld.size.h)}
end
table.insert(entities, entity:newVillager(pos, dialog:getSentence(theseWords)))
end

displayLabel = true
end

-------
Expand All @@ -259,6 +305,39 @@ function love.draw()
love.graphics.setColor(0,0,0,255)
love.graphics.rectangle("fill", 0, 0, w, h)


if (chooseWord) then
local str = "Where do you want to go ?"
local breaks = 0

love.graphics.setColor(255,255,255)
for i=1,#str do

if (i*view.unit - (view.size.w)*view.unit*breaks > (view.size.w-2)*view.unit) then
breaks = breaks+1
end

if (string.sub(str,i,i) ~= " ") then
worldCellText:set(string.sub(str, i, i))
love.graphics.draw(worldCellText, i*view.unit - (view.size.w-2)*view.unit*breaks, view.unit + breaks*view.unit)
else
worldCellText:clear()
end
end

local str = ("=> "..tostring(typedWord))
for i=1,#str do
if (string.sub(str,i,i) ~= " ") then
worldCellText:set(string.sub(str, i, i))
love.graphics.draw(worldCellText, i*view.unit, view.unit*3 + breaks*view.unit)
else
worldCellText:clear()
end
end

return
end

-- Draw gridcells on view
for x=view.position.x*view.size.w+1, (view.position.x+1)*view.size.w do
for y=view.position.y*view.size.h+1, (view.position.y+1)*view.size.h do
Expand All @@ -274,10 +353,16 @@ function love.draw()
-- Draw player, always in last
drawExplorer(explorer, view, worldCellText)

-- Label
if (displayLabel) then
drawLabel(theseWords.currentWord)
end

-- Hud elements
if (dialog.ongoing) then
dialog:draw(view, worldCellText)
end

end


Expand All @@ -289,6 +374,48 @@ function view:refreshView(thisWorld, explorer)
}
end

function drawLabel(str)

local str = "One day,on your trip to "..str.."..."

if (math.floor(screens/2) == view.position.x and
math.floor(screens/2) == view.position.y) then

-- Drawing label if player is not at the bottom of the screen
local y=(explorer.position.y-view.position.y*view.size.h-1)

if (y < view.size.h-3) then

love.graphics.setColor(0,0,0)
love.graphics.rectangle("fill", 0, (view.size.w-3)*view.unit, view.unit*view.size.w, 3*view.unit)
love.graphics.setColor(255,255,255)

local skips = 0

for i=1,#str do

local breaks = 0
local pos = i

while (pos > view.size.h) do
breaks = breaks +1
pos = pos - view.size.h
end

if (string.sub(str,i,i) ~= " ") then
worldCellText:set(string.sub(str, i, i))
love.graphics.draw(worldCellText, (pos-skips-1)*view.unit, view.unit*(view.size.h-3) + breaks*view.unit)
else
if (pos == 1 and breaks < 2) then
skips = skips +1
end
worldCellText:clear()
end
end
end
end
end

function drawEntity(entity, view, worldCellText)
local x = entity.position.x
local y = entity.position.y
Expand Down
51 changes: 49 additions & 2 deletions res/txt/sentences.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,56 @@
Why don't you stay here ?
I like #.
It's like nothing matters.
I hope things work out.
Would you have taken me ?
I can't be your guide.
It's alright. Cheer up!
You look happy.
Hold on for a minute.
Roses aren't that red.
Roses aren't that red.
Others wld hve run away.
I want to leave.
I will never live here.
I live here.
# is nt for vryone.
I like your name.
I hope things work out.
Take me with you :(
<The creature looks sad>
...
...#...#...
# drives me mad
Could you inhabit here ?
I've left regret behind.
I regret every decision.
Never say goodbye.
Did you ever see truth ?
I'm having troubles.
I cannot breathe.
<The kid looks worried>
I may be lost.
Hope you'll find your way
Where's the way out ?
It's been hours already.
Those hours flt lke days.
I'm startng to feel hngry
Run while you can!
Explore, explore!
This place is mysterious
There's something hidden
I'm feeling observed...
Where did I bury it ?
Where's my happiness ?
I'm looking for love.
I like your enthusiasm.
Keep going!
Enjoy it while it lasts.
You look tired...
Everything's all right ?
Do you hate trees ?!
You're hurting Nature!
I feel wrecked.
Day 4, still no sleep.
Help me. I need help.
Any food yet ?
Anythng interstng yet ?
I won't look back.

0 comments on commit 0348284

Please sign in to comment.