Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 3D cube/prism created by MagnusCaligo
- -- Coding style by Nitrogen Fingers
- l, h = term.getSize()
- d = 10
- running = true
- -- Allows the points to have a "refrence" point for "smooth" animation
- -- through the 3rd dimension
- local cube = {
- xpos = l/2;
- ypos = h/2;
- zpos = d/2;
- points = {};
- }
- -- Spawns a point in as a sprite in the points table above ^
- function spawnPoint(x, y, z)
- local point = {
- xpos = x;
- ypos = y;
- zpos = z;
- col = 1;
- update = function(self, p1)
- if p1 == keys.a then
- self.xpos = self.xpos - (self.zpos/d)
- elseif p1 == keys.d then
- self.xpos = self.xpos + (self.zpos/d)
- elseif p1 == keys.s then
- self.ypos = self.ypos + (self.zpos/d)
- elseif p1 == keys.w then
- self.ypos = self.ypos - (self.zpos/d)
- elseif p1 == keys.q then
- self.zpos = self.zpos - (self.zpos/d)
- self:zUpdate(1)
- elseif p1 == keys.e then
- self.zpos = self.zpos + (self.zpos/d)
- self:zUpdate(2)
- end
- end;
- zUpdate = function(self, p1)
- if p1 == 1 then
- if self.xpos > cube.xpos then
- self.xpos = self.xpos - 1
- elseif self.xpos < cube.xpos then
- self.xpos = self.xpos + 1
- end
- if self.ypos > cube.ypos then
- self.ypos = self.ypos - 1
- elseif self.ypos < cube.ypos then
- self.ypos = self.ypos + 1
- end
- elseif p1 == 2 then
- if self.xpos > cube.xpos then
- self.xpos = self.xpos + 1
- elseif self.xpos < cube.xpos then
- self.xpos = self.xpos - 1
- end
- if self.ypos > cube.ypos then
- self.ypos = self.ypos + 1
- elseif self.ypos < cube.ypos then
- self.ypos = self.ypos - 1
- end
- end
- end;
- draw = function(self)
- term.setTextColour(2^self.col)
- term.setCursorPos(self.xpos, self.ypos)
- if self.zpos/d <= .4 then
- term.setBackgroundColour(colours.black)
- term.write("*")
- elseif self.zpos/d < .5 then
- term.setBackgroundColour(colours.black)
- term.write("&")
- elseif self.zpos/d < .8 then
- term.setBackgroundColour(2^self.col)
- term.write(" ")
- elseif self.zpos/d <= 1 then
- term.setBackgroundColour(2^self.col)
- term.write(" ")
- term.setCursorPos(self.xpos, self.ypos + 1)
- term.write(" ")
- elseif self.zpos/d > 1 then
- term.setBackgroundColour(2^self.col)
- for x = 0, 2 do
- for y = 0, 1 do
- term.setCursorPos(self.xpos + x, self.ypos + y)
- term.write(" ")
- end
- end
- end
- end;
- }
- return point
- end
- -- Just inserts all the points, I never really considered a way to optimize this XD
- table.insert(cube.points, spawnPoint(l/2, h/2, d - 5))
- table.insert(cube.points, spawnPoint(l/2 + 5, h/2, d -5))
- table.insert(cube.points, spawnPoint(l/2 + 5, h/2 + 5, d - 5))
- table.insert(cube.points, spawnPoint(l/2, h/2 + 5, d - 5))
- table.insert(cube.points, spawnPoint(l/2, h/2, d))
- table.insert(cube.points, spawnPoint(l/2 + 5, h/2, d))
- table.insert(cube.points, spawnPoint(l/2 + 5, h/2 + 5, d))
- table.insert(cube.points, spawnPoint(l/2, h/2 + 5, d))
- -- The rest of the game essentials (I learned this from Nitrogen Finers)
- function drawGame()
- term.setBackgroundColour(colours.black)
- term.clear()
- for i,v in pairs(cube.points) do
- v:draw()
- end
- end
- function updateGame()
- id, p1, p2 = os.pullEvent()
- if id == "key" then
- if p1 == keys.t then
- running = false
- else
- for i,v in pairs(cube.points) do
- v:update(p1)
- end
- end
- end
- end
- function gameLoop()
- while running do
- drawGame()
- updateGame()
- end
- end
- gameLoop()
- term.setBackgroundColour(colours.black)
- shell.run("clear")
- sleep(.1)
Advertisement
Add Comment
Please, Sign In to add comment