Jump to content




Game: LaserBlast


  • You cannot reply to this topic
32 replies to this topic

#1 nitrogenfingers

    Lua Professor

  • Members
  • 551 posts
  • LocationAustralia

Posted 04 March 2012 - 03:59 PM

I recently made a game in Lua, with ComputerCraft. It's called LaserBlast:



It took about 5 hours to write, I have no idea where I got the idea from- I think I might have played something similar on my dad's Powerbook when I was 10 or something.
It's actually pretty good fun to play.

I've recently update this for colour as well, but is still compatible on B&W monitors.

Controls:
Arrow Keys- move left and right
Space Bar- fire laser
Enter- quit game

Instructions:
Collect the powerup P's while shooting down asteroid O's and fragment *'s.

Download: http://pastebin.com/uBfD8SAe

#2 Espen

    Curious Explorer

  • Members
  • 708 posts

Posted 04 March 2012 - 04:35 PM

Very nice, looks pretty solid. *thumbs up*

All of your computer's programs can be found here:
.minecraftsavesYOURWORLDcomputer
Within this folder there will be numbered directories.
Each number represents the ID of a computer and within each will be your programs for that computer.
Hope that helps. :unsure:/>

#3 nitrogenfingers

    Lua Professor

  • Members
  • 551 posts
  • LocationAustralia

Posted 04 March 2012 - 04:53 PM

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>

#4 Mega1mpact

  • New Members
  • 15 posts

Posted 04 March 2012 - 05:29 PM

sweet game! but it is so hard ;.;

#5 Espen

    Curious Explorer

  • Members
  • 708 posts

Posted 04 March 2012 - 05:31 PM

Lua Pro is just a title/group name. The actual username is above that on the blue line, in my case: Espen
But no biggie, thanks for sharing! :unsure:/>

#6 nitrogenfingers

    Lua Professor

  • Members
  • 551 posts
  • LocationAustralia

Posted 05 March 2012 - 09:55 AM

So sorry Espen! Very late night last night, clearly wasn't thinking very clearly.

I agree the game is too hard, I've modified it so level progression is 50% slower and I cap at level 10 rather than that fiendish level 6.
That one seemed to do alright, and it was a lot of fun to make. I might do another one at some stage- probably keep it in the one post so as not to bloat the forums.

Thanks for playing!

#7 Baldfrost

  • New Members
  • 5 posts

Posted 05 March 2012 - 04:18 PM

ok so i tried just writing off all the code into my computer in smp but i get this message.

bios:206: [string "LaserBlast"]:38 '=' expected

what whould i do to fix it?

#8 Espen

    Curious Explorer

  • Members
  • 708 posts

Posted 05 March 2012 - 08:21 PM

View PostBaldfrost, on 05 March 2012 - 04:18 PM, said:

ok so i tried just writing off all the code into my computer in smp but i get this message. bios:206: [string "LaserBlast"]:38 '=' expected what whould i do to fix it?
Works perfectly for me. You must've mistyped somewhere.
Go to the line it tells you and see if it's different to what you've copied by hand.
Sometimes it's not exacty on the given line, but 1 above or below.
It's just some missing brackets or something similar, I'm sure.

#9 Baldfrost

  • New Members
  • 5 posts

Posted 05 March 2012 - 10:29 PM

is the line then 206 or 38?

found it.

now just to fix some other mistypes.

thx for the help.

There was one problem i couldn't find any mistakes anywhere.

It says
LaserBlast:34: attempt to index ? (a nil value)

couldn't find any mistakes in the code i copied.

#10 nitrogenfingers

    Lua Professor

  • Members
  • 551 posts
  • LocationAustralia

Posted 05 March 2012 - 11:58 PM

That sounds like a bug on my end- I'll see if I can replicate it.

Line 34 on my version calls term.clear() so I have no idea how that error has occurred.
I've added a download to mediafire at the top of the page so might be worth trying that one.

Edited by nitrogenfingers, 06 March 2012 - 12:05 AM.


#11 FuzzyPurp

    Part-Time Ninja

  • Members
  • 510 posts
  • LocationHarlem, NY

Posted 06 March 2012 - 09:10 AM

Dude...this is nice!

#12 Baldfrost

  • New Members
  • 5 posts

Posted 06 March 2012 - 09:39 AM

View Postnitrogenfingers, on 05 March 2012 - 11:58 PM, said:

That sounds like a bug on my end- I'll see if I can replicate it.

Line 34 on my version calls term.clear() so I have no idea how that error has occurred.
I've added a download to mediafire at the top of the page so might be worth trying that one.

it works for me in singleplayer where i put it in the save game folder, the bug is on multiplayer.

#13 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

Posted 06 March 2012 - 12:02 PM

View PostBaldfrost, on 06 March 2012 - 09:39 AM, said:

View Postnitrogenfingers, on 05 March 2012 - 11:58 PM, said:

That sounds like a bug on my end- I'll see if I can replicate it.

Line 34 on my version calls term.clear() so I have no idea how that error has occurred.
I've added a download to mediafire at the top of the page so might be worth trying that one.

it works for me in singleplayer where i put it in the save game folder, the bug is on multiplayer.

The code should be executing exactly the same - it is probably an issue with typing it out, or the person who put it on the server.

#14 Baldfrost

  • New Members
  • 5 posts

Posted 06 March 2012 - 02:57 PM

View PostCloudy, on 06 March 2012 - 12:02 PM, said:

View PostBaldfrost, on 06 March 2012 - 09:39 AM, said:

View Postnitrogenfingers, on 05 March 2012 - 11:58 PM, said:

That sounds like a bug on my end- I'll see if I can replicate it.

Line 34 on my version calls term.clear() so I have no idea how that error has occurred.
I've added a download to mediafire at the top of the page so might be worth trying that one.

it works for me in singleplayer where i put it in the save game folder, the bug is on multiplayer.

The code should be executing exactly the same - it is probably an issue with typing it out, or the person who put it on the server.

it was me who put in on the server (typing it on the computer) and fixed all the mistypes, think the last mistype was on line 186 or something and then there was a mistake on line 34 yesterday which aren't there today or maybe because i deleted some code and re typed it exacly like it was before.

#15 Baldfrost

  • New Members
  • 5 posts

Posted 07 March 2012 - 04:54 PM

View Postnitrogenfingers, on 05 March 2012 - 11:58 PM, said:

That sounds like a bug on my end- I'll see if I can replicate it.

Line 34 on my version calls term.clear() so I have no idea how that error has occurred.
I've added a download to mediafire at the top of the page so might be worth trying that one.

i no longer have that bug. now it just give me a number, so far i it have said 13 12 and 16.

#16 BrettSmith21

  • New Members
  • 20 posts

Posted 13 May 2012 - 01:13 PM

Nice can i add it in ...os its my os i will link this post

#17 nitrogenfingers

    Lua Professor

  • Members
  • 551 posts
  • LocationAustralia

Posted 14 May 2012 - 01:08 AM

Sure, you're free to it! If you do end up using it, let me know; I'd love to see where it ends up.

#18 libraryaddict

  • New Members
  • 195 posts

Posted 14 May 2012 - 09:14 AM

Kind of amazed a nice game like this sank into oblivion for a while..

#19 djm1999

  • Members
  • 12 posts

Posted 02 November 2012 - 09:23 AM

how do u play it? im having trouble with the vid

#20 Skullblade

  • Members
  • 470 posts
  • LocationThe Big Apple, NY

Posted 02 November 2012 - 09:36 AM

this is a really cool game and if you are not updating it it the pretty colors of computercraft 1.45 can you give me permission to? thx





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users