Skip to content

Commit

Permalink
Add Compass, shows only direction like N or SE
Browse files Browse the repository at this point in the history
  • Loading branch information
TomK32 committed Nov 16, 2012
1 parent b37ce7d commit 554442b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
1 change: 1 addition & 0 deletions game_state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ GameState:include({
end

local last_waypoint = Entities.Waypoint({x = self.player.position.x, y = self.player.position.y}, 'Start')
self.next_waypoint = last_waypoint
self.map:place(last_waypoint)
dt_x = self.map.width / 10
dt_y = self.map.height / 10
Expand Down
26 changes: 26 additions & 0 deletions views/compass_view.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

CompassView = class("CompassView", View)

CompassView.display = {x = 0, y = 0, height = 128, width = 128}

function CompassView:drawContent(player, waypoint)
love.graphics.setColor(255, 240, 200, 255)
love.graphics.rectangle('fill', 10, 10, self.display.width, self.display.height)
if player and waypoint then
local text = ''
if player.position.y > waypoint.position.y then
text = text .. 'N'
elseif player.position.y == waypoint.position.y then
else
text = text .. 'S'
end
if player.position.x > waypoint.position.x then
text = text .. 'W'
elseif player.position.x == waypoint.position.x then
else
text = text .. 'E'
end
love.graphics.setColor(0,0,0,255)
love.graphics.print(text, self.display.width / 2, self.display.height / 2)
end
end
9 changes: 8 additions & 1 deletion views/gui_main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ require('views/jobs_view')
require('views/map_view')
require('views/menu_view')
require('views/inspector_view')
require('views/compass_view')

GUIMain = class("GUIMain")
GUIMain:include({

initialize = function(self, game_state)
self.game_state = game_state

self.display = {x = love.graphics.getWidth() - ListView.display.width, y = 0}
self.display = {x = love.graphics.getWidth() - ListView.display.width, y = 148}

-- compass on top, any other info view below that
self.compass_view = CompassView()
self.compass_view.display.x = self.display.x

self.menu_view = MenuView()
self.jobs_view = JobsView(game_state.jobs)
self.job_status_view = JobStatusView(game_state.jobs)
Expand Down Expand Up @@ -65,6 +71,7 @@ GUIMain:include({

draw = function(self)
love.graphics.push()
self.compass_view:draw(self.game_state.player, self.game_state.next_waypoint)
love.graphics.push()
love.graphics.translate(self.display.x, self.display.y)
self.map_view.draw_cursor = false
Expand Down
2 changes: 1 addition & 1 deletion views/list_view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ListView:include({
navigatable = true,
list_entries = nil,
current_line = 1,
display = { x = 0, y = 0, width = 220, height = 300 },
display = { x = 0, y = 0, width = 148, height = 300 },

initialize = function(self)
self.display = {x = 0, y = 0}
Expand Down
4 changes: 2 additions & 2 deletions views/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ View:include({
display = {x = 0, y = 0, width = 200, height = 100},
focus = nil,

draw = function(self)
draw = function(self, ...)
love.graphics.push()
love.graphics.translate(self.display.x, self.display.y)
self:drawContent()
self:drawContent(...)
love.graphics.pop()
end
})

0 comments on commit 554442b

Please sign in to comment.