ComputerCraft Archive

Rocket game concept

computer game unknown forum

Description

Rotation by shearing:Real rotation:Interactive demo:pastebin get 0eXYRn3m rocketControl the rocket with the arrow keys

Installation

Copy one of these commands into your ComputerCraft terminal:

Pastebin:pastebin get 0eXYRn3m rocket_game_concept
wget:wget https://pastebin.com/raw/0eXYRn3m rocket_game_concept
Archive:wget https://cc.shobie.xyz/cc/get/pb-0eXYRn3m rocket_game_concept
Quick Install: wget https://cc.shobie.xyz/cc/get/pb-0eXYRn3m Rocket game concept

Usage

Run the program after downloading

Tags

gameforumgames

Source

View Original Source

Code Preview

local image = {
  {
    0,
    0,
    0,
    128,
  },
  {
    0,
    0,
    128,
    128,
    128,
  },
  {
    0,
    0,
    128,
    128,
    128,
  },
  {
    0,
    256,
    128,
    128,
    128,
    256,
  },
  {
    256,
    256,
    128,
    128,
    128,
    256,
    256,
  },
  {
    0,
    0,
    0,
    16384,
  },
  {
    0,
    0,
    0,
    2,
    16384,
  },
  {
    0,
    0,
    16384,
    2,
    16,
    16384,
  },
  {
    0,
    0,
    0,
    16384,
    2,
  },
  {
    0,
    0,
    0,
    2,
    16384,
  },
}
if fs.exists("rocket.nfp") then
   image = paintutils.loadImage("rocket.nfp")
end
local w, h = term.getSize()
local buffer = window.create(term.current(), 1, 1, w, h)
local oldTerm = term.redirect(buffer)
local rotation = 0
local rocketX, rocketY = 10, 10
local imageH, imageW = #image, 0
for y = 1, #image do
  if #image[y] > imageW then
    imageW = #image[y]
  end
end
local keyboard = {}
local particles = {}

function newParticle()
  table.insert(particles, {
    x = rocketX, y = rocketY, mx = math.sin(rotation+math.random(-10, 10)/10), my = math.cos(rotation+math.random(-10, 10)/10), age = 0, color = colors.orange
  })
end
function drawParticles()
  local toRemoveParticles = {}
  for i = 1, #particles do
    local particle = particles[i]
    paintutils.drawPixel(particle.x, particle.y, particle.color)
    if particle.color == colors.yellow then
      particle.color = colors.orange
    else
      particle.color = colors.yellow
    end

    particle.x = particle.x+particle.mx
    particle.y = particle.y+particle.my

    particle.age = particle.age + 1
    if particle.age > 10 then
      table.insert(toRemoveParticles, i)
    end
  end
  for i = 1, #toRemoveParticles do
    table.remove(particles, toRemoveParticles[i])
  end
end

function drawRocket()
  for y = 1, #image do
    for x = 1, #image[y] do
      if image[y][x] ~= 0 then
        local drawx = (x-imageW/2)*math.cos(rotation)+(y-imageH/2)*math.sin(rotation)
        local drawy = -(x-imageW/2)*math.sin(rotation)+(y-imageH/2)*math.cos(rotation)
        paintutils.drawPixel(drawx+rocketX, drawy+rocketY, image[y][x])
      end
    end
  end
end

while true do
  buffer.setVisible(false)

  term.setBackgroundColor(colors.black)
  term.clear()

  drawRocket()
  drawParticles()

  buffer.setVisible(true)
  buffer.redraw()

  local timer = os.startTimer(0.01)
  local event, key = os.pullEventRaw()
  if event == "terminate" then break end
  os.cancelTimer(timer)

  if event == "key_up" then
    keyboard[keys.getName(key)] = false
  elseif event == "key" then
    keyboard[keys.getName(key)] = true
  end

  if keyboard.right then
    rotation = rotation - 0.1
  elseif keyboard.left then
    rotation = rotation + 0.1
  end
  if keyboard.up then
    rocketX = rocketX-math.sin(rotation)/2
    rocketY = rocketY-math.cos(rotation)/2
    newParticle()
  end

  if rocketX > w then rocketX = 1 end
  if rocketY > h then rocketY = 1 end
  if rocketX < 1 then rocketX = w end
  if rocketY < 1 then rocketY = h end
end

term.redirect(oldTerm)
term.setBackgroundColor(colors.black)
term.clear()
term.setCursorPos(1, h)