View difference between Paste ID: XSNBXL95 and 3ayBDWJw
SHOW: | | - or go back to the newest paste.
1
-- Variables --
2
debug = "Debug"
3
w, h = term.getSize()
4
5
-- Values --
6
7
limeName = "Lime gem: "
8
limeSell = 10
9
lblueName = "Light blue gem: "
10
lblueSell = 15
11
yellowName = "Yellow gem: "
12
yellowSell = 50
13
orangeName = "Orange gem: "
14
orangeSell = 100
15
16
-- Stats --
17
money = 0
18
playerName = "nil"
19-
limeGems = 10
19+
limeGems = 0
20-
lblueGems = 10
20+
lblueGems = 0
21-
yellowGems = 10
21+
yellowGems = 0
22-
orangeGems = 10
22+
orangeGems = 0
23
multi = 1
24
multiCost = 1000
25
-- End Stats --
26
27
-- End Variables --
28
-- Game --
29
30
function playGame()
31
    slc = 1
32
    -- Variables --
33
    minX = 13
34
    maxX = w-1
35
    minY = 2
36
    maxY = h-1
37
    maxGem = 20
38
    spawnedGems = 0
39
    bgColor = colors.black
40
        local gems = { }
41
    
42
  function spawnGem()
43
        if spawnedGems >= maxGem then
44
            gemClick()
45
        else
46
            sleep(0.05)
47
            paintutils.drawPixel(newX, newY, color)
48
            spawnedGems = spawnedGems + 1
49
            sleep(0.05)
50
            local Gem = {newX, newY, color}
51
            table.insert(gems, Gem) 
52
            gem()
53
        end
54
    end   
55
56
    function gem()
57
        while true do
58
            newX = math.random(minX, maxX)
59
            newY = math.random(minY, maxY)
60
            colorNum = math.random(1,4)
61
            if colorNum == 1 then
62
                color = colors.orange
63
                sleep(0.1)
64
                spawnGem()
65
            elseif colorNum == 2 then
66
                color = colors.yellow
67
                sleep(0.1)
68
                spawnGem()
69
            elseif colorNum == 3 then
70
                color = colors.lime
71
                sleep(0.1)
72
                spawnGem()
73
            elseif colorNum == 4 then
74
                color = colors.lightBlue
75
                sleep(0.1)
76
                spawnGem()
77
            end
78
        end
79
    end
80
81
    function gemClick()
82
    slc = 1
83
    while true do
84
    local e, p1, p2, p3 = os.pullEvent("mouse_click")
85
    if slc == 1 then
86
    for i, v in ipairs(gems) do
87
        if p1 == 1 and v[1] == p2 and v[2] == p3 then -- A gem was LEFT clicked
88
        -- Remove the gem
89
            term.setBackgroundColor(bgColor)
90
            term.setCursorPos(v[1], v[2])
91
            write(" ")
92
            table.remove(gems, i)
93
            spawnedGems = spawnedGems - 1
94
            if v[3] == colors.orange then
95
                orangeGems = orangeGems + (1*multi)
96
            elseif v[3] == colors.yellow then
97
                yellowGems = yellowGems + (1*multi)
98
            elseif v[3] == colors.lime then
99
                limeGems = limeGems + (1*multi)
100
            elseif v[3] == colors.lightBlue then
101
                lblueGems = lblueGems +(1*multi)
102
            end    
103
104
 
105
            -- Spawn a new gem
106
            gem()
107
 
108
        elseif p1 == 1 and p2 >= 5 and p2 <= 10 and p3 == h-4 then
109
            frame2()
110
                        end
111
112
    end
113
    sleep(0.05)
114
end
115
end
116
end
117
118
119
    local function frame()
120
        term.clear()
121
        term.setBackgroundColor(colors.black)
122
        term.clear()
123
        paintutils.drawLine(12, 1, 12, h, colors.red)
124
        paintutils.drawLine(12, 1, w, 1, colors.red)
125
        paintutils.drawLine(12, h, w, h, colors.red)
126
        paintutils.drawLine(w, 1, w, h, colors.red)
127
        paintutils.drawLine(1, 1, 1, h, colors.red)
128
        paintutils.drawLine(1, 1, 1, h, colors.red)
129
        paintutils.drawLine(2, 1, 2, h, colors.red)
130
        paintutils.drawLine(3, 1, 3, h, colors.red)
131
        paintutils.drawLine(4, 1, 4, h, colors.red)
132
        paintutils.drawLine(5, 1, 5, h, colors.red)
133
        paintutils.drawLine(6, 1, 6, h, colors.red)
134
        paintutils.drawLine(7, 1, 7, h, colors.red)
135
        paintutils.drawLine(8, 1, 8, h, colors.red)
136
        paintutils.drawLine(9, 1, 9, h, colors.red)
137
        paintutils.drawLine(10, 1, 10, h, colors.red)
138
        paintutils.drawLine(11, 1, 11, h, colors.red)
139
        term.setBackgroundColor(colors.lime)
140
        term.setTextColor(colors.black)
141
        term.setCursorPos(1, 2)
142
        print("Multiplier:")
143
        term.setCursorPos(1,4)
144
        print(multi)
145
        term.setCursorPos(5, h-4)
146
        print(" Exit ")
147
    end
148
149
150
151
152
    frame()
153
    gem()
154
155
end
156
157
function sellGems()
158
    term.setBackgroundColor(1)
159
    term.clear()
160
paintutils.drawPixel(1, 4, 32)
161
    paintutils.drawPixel(1, 6, 8)
162
    paintutils.drawPixel(1, 8, 16)
163
    paintutils.drawPixel(1, 10, 2)
164
    term.setBackgroundColor(1)
165
    term.setCursorPos(1, 2)
166
    print("Money: "..money)
167
    term.setCursorPos(3, 4)
168
    print(limeName ..limeGems)
169
    term.setCursorPos(3, 6)
170
    print(lblueName ..lblueGems)
171
    term.setCursorPos(3, 8)
172
    print(yellowName ..yellowGems)
173
    term.setCursorPos(3, 10)
174
    print(orangeName ..orangeGems)
175
    term.setCursorPos(3, 12)
176
    print("Back")
177
    term.setCursorPos(w-25, 5)
178
    print("Upgrades       Cost")
179
    term.setCursorPos(w-25, 7)
180
    print("+1 Multiplier "..multiCost)
181
    while true do
182
        event, but, x, y = os.pullEvent("mouse_click")
183
        if event == "mouse_click" then
184
            if but == 1 and x >= 3 and x <= 13 and y == 4 then
185
                money = limeGems*limeSell + money
186
                limeGems = 0
187
                sellGems()
188
            elseif but == 1 and x >= 3 and x <= 18 and y == 6 then
189
                money = lblueGems*lblueSell+money
190
                lblueGems = 0
191
                sellGems()
192
            elseif but == 1 and x >= 3 and x <= 14 and y == 8 then
193
                money = yellowGems*yellowSell+money
194
                yellowGems = 0
195
                sellGems()    
196
            elseif but == 1 and x >= 3 and x <= 14 and y == 10 then
197
                money = orangeGems*orangeSell+money
198
                orangeGems = 0
199
                sellGems()
200
            elseif but == 1 and x >= 3 and x <= (w-25)+14 and y == 7 then
201
                if money >= multiCost then
202
                    money = money-multiCost
203
                    multi = multi+1
204
                    multiCost = multiCost*2
205
                    sellGems()
206
                end
207
            elseif but == 1 and x >= 3 and x <= 7 and y == 12 then
208
                frame2()
209
            end
210
        end
211
    end
212
end
213
214
215
216
function frame2()
217
    slc = 0
218
    term.setBackgroundColor(colors.white)
219
    term.clear()
220
    term.setCursorPos(math.floor(w-string.len("Logged in as: "..playerName))/2, 2)
221
    print("Logged in as: "..playerName )
222
    paintutils.drawPixel(1, 4, 32)
223
    paintutils.drawPixel(1, 6, 8)
224
    paintutils.drawPixel(1, 8, 16)
225
    paintutils.drawPixel(1, 10, 2)
226
    term.setBackgroundColor(1)
227
    term.setCursorPos(3, 4)
228
    print(limeName ..limeGems)
229
    term.setCursorPos(3, 6)
230
    print(lblueName ..lblueGems)
231
    term.setCursorPos(3, 8)
232
    print(yellowName ..yellowGems)
233
    term.setCursorPos(3, 10)
234
    print(orangeName ..orangeGems)
235
    term.setBackgroundColor(32)
236
    term.setCursorPos(10, 15)
237
    print("Play")
238
    term.setCursorPos(20, 15)
239
    print("Sell Gems")
240
    while true do
241
    event, button, x, y = os.pullEvent("mouse_click")
242
    if event == "mouse_click" then
243
        if slc == 0 then
244
            if x >= 10 and x <= 15 and y == 15 and button == 1 then
245
                term.clear()
246
                playGame()
247
                break
248
            elseif x >= 20 and x <= 30 and y == 15 and button == 1 then
249
                sellGems()
250
            end
251
        elseif slc == 1 then
252
                if x >= 5 and x <= 10 and y == h-4 and button == 1 then
253
                    slc = 0
254
                    frame2()
255
                end
256
            end
257
        end
258
    end
259
end
260
261
function game()
262
    term.clear()
263
    term.setBackgroundColor(1)
264
    term.setTextColor(32768)
265
    term.clear()
266
    term.setCursorPos(math.floor(w-string.len("Name: "))/2, 2)
267
    write("Name: ")
268
    playerName = read()
269
    if playerName == "" then
270
        game()
271
    else
272
        frame2()
273
    end
274
end
275
276
-- End Functions --
277
278
game()