ComputerCraft Archive

RunnerX game - after sprite update:new update: 3.3

computer game unknown forum

Description

RunnerX agme

Installation

Copy one of these commands into your ComputerCraft terminal:

Pastebin:pastebin get HBGrdSfA runnerx_game_-_after_sprite_update:new_update:_3.3
wget:wget https://pastebin.com/raw/HBGrdSfA runnerx_game_-_after_sprite_update:new_update:_3.3
Archive:wget https://cc.shobie.xyz/cc/get/pb-HBGrdSfA runnerx_game_-_after_sprite_update:new_update:_3.3
Quick Install: wget https://cc.shobie.xyz/cc/get/pb-HBGrdSfA RunnerX game - after sprite update:new update: 3.3

Usage

Run the program after downloading

Tags

gameforumpocket-programs

Source

View Original Source

Code Preview

--RunnerX agme
--by Konlab
--variables:
ver = "3.3"
anFrame = 1
page = 1
--is ground? 13c is
c1 = true
c2 = true
c3 = true
c4 = true
c5 = true
c6 = true
c7 = true
c8 = true
c9 = true
c10 = true
c11 = true
c12 = true
c13 = true
next = true
bigH = 1
curH = 0
bigL = 5
curL = 0
isL = true
csprite = "Default"
--height
mHeight = 0 -- 0 = on ground
--config paths:
AppDataPath = ".Konlab/RunnerX/"
AP1 = ".Konlab/"
--strange sprite function:
function stranges()
  spritelist = {"q";"w";"e";"r";"t";"y";"u";"i";"o";"p";"a";"s";"d";"f";"g";"h";"j";"k";"l";"z";"x";"c";"v";"b";"n";"m";";";'"';"'";":";"/";"-";"=";"_";"+";"*";"1";"2";"3";"4";"5";"6";"7";"8";"9";"0";"!";"@";"#";"{{code}}quot;;"%";"^";"&";"(";")";"[";"]";"{";"}";"?";">";"<";",";".";"|";"~"}
  hmany = 0
  for k,v in pairs(spritelist) do
    hmany = k
  end
  rnumb = math.random(1,hmany)
  return spritelist[rnumb]
end
--config functions:
function setSprite()
  sfile = fs.open(AppDataPath.."Sprite.cfg","w")
  sfile.write(csprite)
  sfile.close()
end
function getSprite()
  sfile = fs.open(AppDataPath.."Sprite.cfg","r")
  csprite = sfile.readLine()
  sfile.close()
end
function check()
  if not fs.exists(AP1) then
    fs.makeDir(AP1)
  end
  if not fs.exists(AppDataPath) then
    fs.makeDir(AppDataPath)
  end
  if not fs.exists(AppDataPath.."Sprite.cfg") then
    setSprite("Default")
  end
end
--main code:
function genNext()
  if isL then
    yy = bigL - curL
    if yy == 0 then
      isL = false
      bigH = math.random(1,2)
      curH = 0
    else
      curL = curL+1
      next = true
    end
    
  else
  xx = bigH - curH
  if xx == 0 then
    isL = true 
    bigL = math.random(2,10)
    curL = 0
  else
  curH = curH+1
  next = false
  end
  end
end
function custo()
  while true do
  
  term.setBackgroundColor(colors.gray)
  term.clear()
  term.setCursorPos(1,1)
  print("Customize sprite")
  print()
  --term.setBackgroundColor(colors.black)
  print("Current:"..csprite)
  print()
  term.setBackgroundColor(colors.black)
  if page == 1 then
  print("Default                    ")
  print()
  print("Old sprite 2.0 >           ")
  print()
  print("Dollar                     ")
  print()
  print("Wheel                      ")
  print()
  print("Next page -->              ")
  print()
  print("<-- Go back                ")
  elseif page == 2 then
    print("Strange                   ")
    print()
    print("Rocket 1                  ")
    print()
    print("Rocket 2                  ")
    print()
    print("Pacman                    ")
    print()
    print("Previous page <--         ")
    print()
    print("<-- Go back               ")
  end
    ev15,bu15,x16,y16 = os.pullEvent("mouse_click")
    if y16 == 5 then
      --default
      if page == 1 then
      csprite = "Default"
      elseif page == 2 then
      csprite = "Strange"
      end 
    elseif y16 == 7 then
      if page == 1 then
      csprite = "Old"
      elseif page == 2 then
      csprite = "Rocket 1"
      end
    elseif y16 == 9 then
      if page == 1 then
      csprite = "Dollar"
      elseif page == 2 then
      csprite = "Rocket 2"
      end
    elseif y16 == 11 then
      if page == 1 then
      csprite = "Wheel"
      elseif page == 2 then
       csprite = "Pacman"
      end
    elseif y16 == 13 then
    if page == 1 then
      page = 2
    elseif page == 2 then
      page = 1
    end
    elseif y16 == 15 then
      break
    end
    term.setBackgroundColor(colors.gray)
    term.setCursorPos(9,3)
    term.write("             ")
    term.setCursorPos(9,3)
    term.write(csprite)    
              
  end
  --save sprite settings
  setSprite(csprite)
end
function animate()
--  if anFrame == 1 then
  term.setBackgroundColor(colors.black)
  for l=10,2,-1 do
  term.setCursorPos(13,l)
  term.write(" ")
  end
    term.setCursorPos(13,10-mHeight)
    term.setBackgroundColor(colors.black)
  if anFrame == 1 then
    if csprite == "Old" then
    term.write("%")
    elseif csprite == "Dollar" then
    term.setTextColor(colors.green)
    term.write("{{code}}quot;)
    term.setTextColor(colors.white)
    elseif csprite == "Wheel" then
    term.setTextColor(colors.red)
    term.write("+")
    term.setTextColor(colors.white)
    elseif csprite == "Default" then
    term.setTextColor(colors.yellow)
    term.write("&")
    term.setTextColor(colors.white)
    elseif csprite == "Pacman" then
    term.setTextColor(colors.yellow)
    term.write("@")
    term.setTextColor(colors.white)
    elseif csprite == "Rocket 1" then
    term.setTextColor(colors.brown)
    term.write(">")
    term.setTextColor(colors.white)
    elseif csprite == "Rocket 2" then
    term.setTextColor(colors.blue)
    term.write("-")
    term.setTextColor(colors.white)
    elseif csprite == "Strange" then
    schar = stranges()
    rcol = math.random(0,14)
    term.setTextColor(2^rcol)
    term.write(schar)
    term.setTextColor(colors.white)
    else
    term.write("E")    
    end
    
    anFrame = 2
  elseif anFrame == 2 then
    if csprite == "Dollar" then
    term.setTextColor(colors.yellow)
    term.write("{{code}}quot;)
    term.setTextColor(colors.white)
    elseif csprite == "Wheel" then
    term.setTextColor(colors.orange)
    term.write("x")
    term.setTextColor(colors.white)
    elseif csprite == "Default" then
    term.setTextColor(colors.yellow)
    term.write("#")
    term.setTextColor(colors.white)
    elseif csprite == "Pacman" then
    term.setTextColor(colors.yellow)
    term.write("O")
    term.setTextColor(colors.white)
    elseif csprite == "Rocket 1" then
    term.setTextColor(colors.red)
    term.write(">")
    term.setTextColor(colors.white)
    elseif csprite == "Rocket 2" then
    term.setTextColor(colors.blue)
    term.write("=")
    term.setTextColor(colors.white)
    elseif csprite == "Strange" then
    schar = stranges()
    rcol = math.random(0,14)
    term.setTextColor(2^rcol)
    term.write(schar)
    term.setTextColor(colors.white)
    elseif csprite == "Old" then
    term.write("#")
    else
    term.write("e")
    end
    anFrame = 1
  end
  
  
  
end
function drawPillar(pNum,col)
  curx = pNum * 2 - 1
  for j=0,1 do
  for i=20,11,-1 do
--draw a pillar at c-cell  
  term.setBackgroundColor(col)
  term.setCursorPos(curx+j,i)
  term.write(" ")
  end
  end
end
function goForward()
  c1 = c2
  c2 = c3
  c3 = c4
  c4 = c5
  c5 = c6
  c6 = c7
  c7 = c8
  c8 = c9
  c9 = c10
  c10 = c11
  c11 = c12
  c12 = c13
  c13 = next
  
end
function drawGround()
  if c1 then
    drawPillar(1,colors.gray)
  else
    drawPillar(1,colors.black)
  end
  if c2 then
    drawPillar(2,colors.gray)
  else
    drawPillar(2,colors.black)
  end
  if c3 then
    drawPillar(3,colors.gray)
  else
    drawPillar(3,colors.black)  
  end
  if c4 then
    drawPillar(4,colors.gray)
  else
    drawPillar(4,colors.black)  
  end
  if c5 then
    drawPillar(5,colors.gray)
  else
    drawPillar(5,colors.black)
  end
  if c6 then
    drawPillar(6,colors.gray)
  else
    drawPillar(6,colors.black)
  end
  if c7 then
    drawPillar(7,colors.gray)
  else
    drawPillar(7,colors.black)
  end
  if c8 then
    drawPillar(8,colors.gray)
  else
    drawPillar(8,colors.black)
  end
  if c9 then
    drawPillar(9,colors.gray)
  else
    drawPillar(9,colors.black)
  end
  if c10 then
    drawPillar(10,colors.gray)
  else
    drawPillar(10,colors.black)  
  end
  if c11 then
    drawPillar(11,colors.gray)
  else
    drawPillar(11,colors.black)
  end
  if c12 then
    drawPillar(12,colors.gray)
  else
    drawPillar(12,colors.black)
  end
  if c13 then
    drawPillar(13,colors.gray)
  else
    drawPillar(13,colors.black)
  end
  
    
end
tSpeed = 1
function game(bSpeed)
  getSprite()
  if bSpeed == nil then
    tSpeed = 1
  else
    tSpeed = bSpeed
  end
  c1 = true
  c2 = true
  c3 = true
  c4 = true
  c5 = true
  c6 = true
  c7 = true
  c8 = true
  c9 = true
  c10 = true
  c11 = true
  c12 = true
  c13 = true
  next = true
  lose = false
  spUp = 0
  curSpeed = tSpeed
  score = 0
  mHeight = 0
  term.clear()
  term.setCursorPos(1,1)
  term.setBackgroundColor(colors.black)
  term.clear()
  term.setBackgroundColor(colors.brown)
  parallel.waitForAny(sim,keyy)
  end
  function sim()
  while true do
    animate()
    sleep(curSpeed)
    score = score + 1
    spUp = spUp + 1
    term.setCursorPos(1,1)
    print("Current speed:"..curSpeed)
    if spUp == 12 then
      spUp = 0
      if curSpeed > 0.1 then
        oldCS = curSpeed
--        print("Gen.:OldCS:"..oldCS)
        curSpeed = curSpeed / 2
        addSpeed = oldCS / 3
        curSpeed = curSpeed + addSpeed
      else
        curSpeed = curSpeed * 0.95
      end
    end
    drawGround(1)
    genNext()  
    if not c8 and mHeight == 1 then
      lose = true
    end
    if lose then
      if not c7 and mHeight == 0 then
      term.clear()
      term.setCursorPos(1,1)
      term.write("GAME OVER!")
      term.setCursorPos(1,2)
      sleep(0.5)
      term.write("Your score: "..tostring(score))
      
      term.setCursorPos(1,4)
      sleep(2)
      term.write("(Click to continue)")
      os.pullEvent("mouse_click")
      return
      end
    end
  --  end
    goForward()
    if mHeight == 0 then
      if not c8 then
        lose = true
      end
      
      --  term.clear()
--        term.setCursorPos(1,1)
--        term.write("You lose!")
--        sleep(1)
--        print("Click to continue")
--        os.pullEvent("mouse_click")
--        return
  --    end        
    else
      mHeight = mHeight - 1    
    end
  end
mHeight = 0
end
function adv()
  term.setBackgroundColor(colors.gray)
  term.clear()
  term.setCursorPos(1,1)
  print("Fast begin mode")
  print()
  print()
  print("Choose your begin speed:")
  print()
  term.setBackgroundColor(colors.black)
  print("           [0.10]                     ")
  print()
  print("           [0.20]                     ")
  print()
  print("           [0.33]                     ")
  print()
  print("           [0.50]                     ")
  print()
  print("           [0.75]                     ")
  print()
  print("<-- Go back               ")
  
  --0.10 y6
  --0.50 y8
  --0.75 y10
  while true do
    eevvvve,buttttu,x11,y11 = os.pullEvent("mouse_click")
    if y11 == 6 then
      game(0.1)
      return
    elseif y11 == 8 then
      game(0.2)
      return
    elseif y11 == 10 then
      game(0.33333)
      return
    elseif y11 == 12 then
      game(0.5)
      return
    elseif y11 == 14 then
      game(0.75)
      return
    elseif y11 == 16 then
      return
    end
  end
end
function keyy()
isJ = false

  while true do
    
--    if mHeight > 0 and cJ < 4 then
--    sleep(0.01)
--    else
    if isJ == false then
    ee,cc = os.pullEvent("char")
    if cc == "w" then
      isJ = true
    end
    end
    if isJ then
    --  cJ = 2
      mHeight = mHeight+2
      sleep(curSpeed)
      
    
    --  cJ = 3
      mHeight = mHeight+2
      sleep(curSpeed)
    
    --  cJ = 4
      --mHeight = mHeight
      mHeight = mHeight+1
      sleep(curSpeed)
      sleep(curSpeed * 3)
      isJ = false      
    end  
--  end
  end
end
--end

function drawMenu()
  term.setCursorPos(1,1)
  term.setBackgroundColor(colors.red)
  term.clear()
  term.setBackgroundColor(colors.orange)
  print("RunnerX  game by Konlab     ")
  print("                          ")
  term.setBackgroundColor(colors.black)
  print()
  print("Normal mode               ")
  print()
  print("Fast begin mode             ") 
  print()
  print("Controls                  ")
  print()
  print("Customize sprite          ")
  print()
  print("Exit game                 ")
  term.setBackgroundColor(colors.red)
  return  
end
function credits()
  term.clear()
  term.setCursorPos(1,1)
  print("RunnerX - Controls")
  print()
  print("Normal mode - begin speed is 1")
  print("Fast begin mode - choose begin speed")
  print("W - jump")
  --print("Your speed is 2 pos/sec!!!")
  print()
  print("Current version: "..ver)
  print()
  print("Click to continue")
  os.pullEvent("mouse_click")
  return
  
  
  
end

function main()
  term.setTextColor(colors.white)
  check()  
  while true do
    drawMenu()
    event,button,x,y = os.pullEvent("mouse_click")
    if y == 4 then
      game()
    elseif y == 6 then
      adv()
    elseif y == 8 then
      credits()
    elseif y == 10 then
      custo()
    elseif y == 12 then
      return
    end
  end
end
err = "no"
ok,err = pcall(main)
--if not err == "Terminated" then
if err == "Terminated" then
  print("Terminated")
  return
end
if ok then
  term.setBackgroundColor(colors.black)
  term.clear()
  term.setCursorPos(1,1)
  print("Thanks for using RunnerX game!")
end

if not ok then
  term.setBackgroundColor(colors.gray)
  term.setTextColor(colors.yellow) 
  term.clear()
  term.setCursorPos(1,1)
  print("Crash report")
  print()
  print("RunnerX has crashed")
  print("Error is:")
  print()
  print(err)
  print()
  print("Please report on forums!")
  print()
  print("Click to continue")
  os.pullEvent("mouse_click")
  return

end

--else
--print("Terminated")
--end