-
Notifications
You must be signed in to change notification settings - Fork 0
/
stationclickable.lua
72 lines (61 loc) · 2.48 KB
/
stationclickable.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
require "button"
StationClickable = {}
StationClickable.__index = StationClickable
function StationClickable:create(station, listPosition, cost)
local stationClickable = {}
setmetatable(stationClickable, StationClickable)
stationClickable.linkedStation = station
stationClickable.clickable = Clickable:create(1400, 400 + 50 * listPosition, 450, 50)
stationClickable.clickable.fixed = true
stationClickable.listPosition = listPosition
stationClickable.stationAvailable = true
stationClickable.cost = cost
function stationClickable.clickable:clicked()
stationClickable:buyStation()
end
return stationClickable
end
function StationClickable:buyStation()
if money >= self.cost and self.stationAvailable then
money = money - self.cost
stations[self.linkedStation] = Station:create(self.linkedStation, g_shimbashi, 1)
self.stationAvailable = false
elseif not self.stationAvailable then
current_station = self.linkedStation
gui:switchStation(current_station)
end
end
function StationClickable:draw(tab)
if tab ~= 2 then
return
end
if self.linkedStation == current_station then
love.graphics.setColor(0,0.8,0)
else
love.graphics.setColor(255,255,255)
end
love.graphics.rectangle("fill", self.clickable.x +pos, self.clickable.y, self.clickable.width, self.clickable.height)
love.graphics.setColor(0,0,0)
love.graphics.rectangle("line", self.clickable.x+pos, self.clickable.y, self.clickable.width, self.clickable.height)
love.graphics.setFont(fonts["20"])
if self.stationAvailable then
love.graphics.printf(self.linkedStation, 1400+pos, self.clickable.y, self.clickable.width)
love.graphics.printf("Cost: " .. self.cost, 1400+pos, self.clickable.y +25, self.clickable.width)
else
love.graphics.printf(self.linkedStation .. " bought. Click here to visit station.", 1400+pos, self.clickable.y, self.clickable.width)
end
--love.graphics.printf("Cost: " .. (self.linkedStation.cost), 1400+pos, self.clickable.y+100, self.clickable.width, "right")
love.graphics.setFont(fonts["46"])
end
function StationClickable:mousemoved(x, y, dx, dy, istouch, tab)
if tab ~= 2 then
return
end
self.clickable:mousemoved(x,y,dx,dy,istouch)
end
function StationClickable:mousepressed(x, y, button, istouch, presses, tab)
if tab ~= 2 then
return
end
self.clickable:mousepressed(x,y,button,istouch, presses)
end