It does indeed, thanks Lua Pro!
Sleep is not coming tonight so I may as well upload the source. It's just below.
That was a lot of fun to make, hope someone has fun playing it.
w,h = term.getSize()
plpos = w/2
--music stuff
minterval = 1
mtimer = 1
left = false
level = 1
score = 0
gameover=false
killc = 0
--x,y,dir
projlist = {}
--x,y,intvspeed,dtimer
baddylist = {}
btimer = 0
bintv = 1
utime = 0.05
bsmp = 6
powerup = 0
function drawHeader()
term.setCursorPos(5, 1)
term.write("Score: "..score)
if score~=0 then term.write("00") end
local lstr = "Level: "..level
term.setCursorPos(w-#lstr-5,1)
term.write(lstr)
end
function drawWorld()
term.clear()
drawHeader()
drawLandscape()
term.setCursorPos(plpos-1, h-1)
term.write("@@@")
for i=1,#projlist do
local proj = projlist[i]
term.setCursorPos(proj.x, proj.y)
term.write("|")
end
for i=1,#baddylist do
local baddy = baddylist[i]
term.setCursorPos(baddy.x, baddy.y)
if baddy.dtimer==0 then
if baddy.pup then term.write("P")
elseif baddy.frag then term.write("*")
else term.write("O") end
else
term.write("#")
end
end
end
function drawLandscape()
term.setCursorPos(1,h)
local land = string.rep("-", w)
term.write(land)
local m6=" _____________ "
local m5=" _______ / ____ "
local m4=" / ___/___ ________"
local m3=" / "
local m2=" / ________ "
local m1="______/ ______________"
term.setCursorPos(1, h-8)
term.write(m6)
term.setCursorPos(1, h-7)
term.write(m5)
term.setCursorPos(1, h-6)
term.write(m4)
term.setCursorPos(1, h-5)
term.write(m3)
term.setCursorPos(1, h-4)
term.write(m2)
term.setCursorPos(1, h-3)
term.write(m1)
end
function updateWorld()
--The music stuff
redstone.setOutput("back", false)
mtimer=mtimer-utime
if mtimer<=0 then
mtimer = minterval
if left then
redstone.setOutput("left", true)
redstone.setOutput("right", false)
else
redstone.setOutput("left", false)
redstone.setOutput("right", true)
end
left = not left
end
local i=1
while i<=#projlist do
projlist[i].y = projlist[i].y+projlist[i].dir
if projlist[i].y < 0 or projlist[i].y > h-1 then
table.remove(projlist,i)
i=i-1
end
i=i+1
end
i=1
while i<=#baddylist do
local baddy = baddylist[i]
baddy.timer=baddy.timer+utime
if baddy.y==h-1 and math.abs(baddy.x-plpos)<2 then
if baddy.pup then powerup = 10
else
gameover = true
redstone.setOutput("back", true)
end
end
j=1
while j<=#projlist do
local proj = projlist[j]
if baddy.x==proj.x and math.abs(baddy.y-proj.y)<2
and baddy.dtimer==0 then
baddy.dtimer = 0.5
table.remove(projlist,j)
j=j-1
score=score+5
redstone.setOutput("back", true)
killc=killc+1
if killc>5+(level*5) and level<10 then levelUp() end
--Adds fragments
if math.random(1, 5) == 2 and not baddy.frag then
table.insert(baddylist, {
x = baddy.x-1,
y = baddy.y,
pup = false,
frag = true,
timer = 0,
dtimer = 0,
speed = baddy.speed/2
})
table.insert(baddylist, {
x = baddy.x+1,
y = baddy.y,
pup = false,
frag = true,
timer = 0,
dtimer = 0,
speed = baddy.speed/2
})
end
end
j=j+1
end
if baddy.timer>baddy.speed and baddy.dtimer==0 then
baddy.y=baddy.y+1
baddy.timer = 0
if baddy.y==h then
table.remove(baddylist,i)
i=i-1
score=score-1
end
elseif baddy.dtimer>0 then
baddy.dtimer=baddy.dtimer-utime
if baddy.dtimer<=0 then
table.remove(baddylist,i)
i=i-1
end
end
i=i+1
end
btimer=btimer+utime
if btimer > bintv then
table.insert(baddylist, {
x = math.random(w/4, 3*(w/4)),
y = 1,
speed = utime*bsmp,
timer = 0,
dtimer = 0,
pup = math.random(1,20)==5,
frag = false
})
btimer=0
end
end
function levelUp()
level=level+1
bintv=bintv-0.10
bsmp=bsmp-0.5
killc=0
minterval=minterval-0.10
end
function updatePlayer(key)
if powerup>0 then
powerup = powerup-utime
end
if key==203 and plpos>1 then
plpos=plpos-1
elseif key==205 and plpos<w then
plpos=plpos+1
elseif key==57 then
if powerup>0 then
table.insert(projlist, {
dir = -1,
x = plpos+1,
y = h-2
})
table.insert(projlist, {
dir = -1,
x = plpos-1,
y = h-2
})
else
table.insert(projlist, {
dir = -1,
x = plpos,
y = h-2
})
end
end
end
local wtimer os.startTimer(utime)
while not gameover do
local e, v = os.pullEvent()
if e=="timer" then
updateWorld()
wtimer = os.startTimer(utime)
elseif e=="key" then
if v==28 then break end
updatePlayer(v)
end
drawWorld()
end
term.setCursorPos(plpos-1, h-1)
term.write("###")
local go = "Game Over!"
term.setCursorPos(w/2 - #go/2, 10)
term.write(go)
term.setCursorPos(1,h)
sleep(5)
redstone.setOutput("back", false)
term.clear()
</w>