View difference between Paste ID: Ut23Y86k and 9wXFt5J8
SHOW: | | - or go back to the newest paste.
1
--Dig Dug--
2
local mined = {}
3
local x,y = term.getSize()
4
local round = 1
5
local lives = 3
6
local channel = "SinglePlayer"
7
local Mult = false
8
local Players = {}
9
local noLagg = ""
10
11
local currentX = x/2
12
local currentY = 2
13
local direction = ">"
14
15
for i = 1,x do
16
	noLagg = noLagg.. "X"
17
end
18
19
local function cPrint(text)
20
   local x,y = term.getSize()
21
   x2,y2 = term.getCursorPos()
22
   term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
23
   write(text)
24
end
25
26
27
function drawCursor()
28
  term.clear() --Clears the screen
29
  if lives < 0 then
30
	term.setCursorPos(1,3)
31
	cPrint("GAME OVER")
32
	sleep(2)
33
	error()
34
  else
35
	for v = 2,y-2 do
36
			term.setCursorPos(1,v)
37
			write(noLagg)
38
	end
39
	
40
	term.setCursorPos(4,2)
41
	write("Y")
42
	
43
	for i = 1,lives do
44
		term.setCursorPos(i,y)
45
		write(">")
46
	end
47
	
48
	
49
	term.setCursorPos(x-string.len("RND: " ..round),y)
50
	write("RND: " ..round)
51
	
52
	for i = 1,#mined do
53
		if mined[i] then
54
			mined[i] = tostring(mined[i])
55
			minedX, minedY = string.match(mined[i], "(%-?%d+)/(%-?%d+)")
56
			term.setCursorPos(tonumber(minedX),tonumber(minedY))
57
			write(" ")
58
			--if currentX == minedX and currentY == minedY-1 then
59
			--    currentY = minedY
60
			--end
61
		end
62
	end
63
	term.setCursorPos(x-1,1)
64
	write("@")
65
	  if currentY == 1 then currentY = 2 end
66
	  if currentX == x then
67
		currentX = x-1
68
	  elseif currentX == 0 then
69
		currentX = 1
70
	  end
71
	  
72
	if Mult then
73
		
74
		for i,kik in pairs(Players) do
75
			v = tostring(kik)
76
			if v then
77
				minedX, minedY = string.match(v, "(%-?%d+)/(%-?%d+)")
78
				if tonumber(minedX) then
79
					term.setCursorPos(tonumber(minedX),tonumber(minedY))
80
					write("I")
81
					mined[#mined+1] = kik
82
				end
83
			end
84
		end
85
	end
86
	
87
	if Mult then
88
		term.setCursorPos(4,2)
89
		write("Y")
90
	end
91
	term.setCursorPos(currentX, currentY)
92
	write(direction)
93
  end
94
end
95
96
function begin()
97
	while true do
98
		drawCursor()
99
		local e,key,message = os.pullEvent()
100
		if e == "key" then
101
			if key == 17 or key == 200 then --up
102
				mined[#mined+1] = currentX.. "/" ..currentY
103
				currentY = currentY -1
104
				direction = "^"
105
			elseif key == 31 or key == 208 then --down
106
				if currentY < y-1 then
107
					mined[#mined+1] = currentX.. "/" ..currentY
108
					currentY = currentY +1
109
				end
110
				direction = "v"
111
			elseif key == 203 or key == 30 then --left
112
				mined[#mined+1] = currentX.. "/" ..currentY
113
				currentX = currentX -1
114
				direction = "<"
115
			elseif key == 205 or key == 32 then --right
116
				mined[#mined+1] = currentX.. "/" ..currentY
117
				currentX = currentX +1
118
				direction = ">"
119
			end
120
			
121
			if Mult then
122
				rednet.broadcast("[MM] ["..channel.."] " ..currentX.. "/" ..currentY)
123
			end
124
			
125
			if currentX == 4 and currentY == 2 then
126
				if Mult then
127
					term.setCursorPos(1,1)
128
					write("The flower ate you.")
129
					sleep(1)
130
					lives = lives-100000
131
				end
132
			end
133
		elseif Mult and e == "rednet_message" then
134
			if string.sub(message, 1, string.len("[MM] [" ..channel.."] ")) == "[MM] [" ..channel.."] " then
135
				Players[key] = string.sub(message, string.len("[MM] [" ..channel.."] *"), string.len(message))
136
			end
137
		end
138
	end
139
end