Advertisement
CaptainSpaceCat

Water Tanks Mini

Jun 22nd, 2015
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.58 KB | None | 0 0
  1. local Tank = {
  2. x = 0,
  3. y = 0,
  4. dir = 0,
  5. power = 50,
  6. moves = 4,
  7. color = colors.blue
  8. }
  9.  
  10. local w, h = term.getSize()
  11. local function draw(string, x, y, txtcol, bakcol)
  12.     string = string or ""
  13.     txtcol = txtcol or colors.white
  14.     bakcol = bakcol or colors.black
  15.     term.setCursorPos(x, y)
  16.     term.setBackgroundColor(bakcol)
  17.     term.setTextColor(txtcol)
  18.     term.write(string)
  19. end
  20.  
  21. local function Tank:new(x, y, dir, power, color)
  22.     local class = {x = x, y = y, dir = dir, power = 50, moves = 4, color = color}
  23.     setmetatable(class, self)
  24.     self.__index = self
  25.     return class
  26. end
  27.  
  28. local function Tank:display()
  29.     local tankimg = {{0, self.color, 0}, {self.color, self.color, self.color}}
  30.     paintutils.drawImage(tankimg, self.x, self.y)
  31.     local barrel, x, y
  32.     local back = 2^15
  33.     if self.dir == 1 then
  34.         barrel, x, y = "-", -1, 0
  35.     elseif self.dir == 2 then
  36.         barrel, x, y = "\\", -1, -1
  37.     elseif self.dir == 3 then
  38.         barrel, x, y = "|", 0, -1
  39.     elseif self.dir == 4 then
  40.         barrel, x, y = "/", 1, -1
  41.     elseif self.dir == 5 then
  42.         barrel, x, y =  "-", 1, 0
  43.     elseif self.dir == 6 then
  44.         barrel, x, y = "\\", 1, 1
  45.         back = self.color
  46.     elseif self.dir == 7 then
  47.         barrel, x, y = "|", 0, 1
  48.         back = self.color
  49.     elseif self.dir == 8 then
  50.         barrel, x, y = "/", -1, 1
  51.         back = self.color
  52.     end
  53.     draw(barrel, self.x + x, self.y + y, colors.white, back)
  54. end
  55.  
  56. local function Tank:changeAngle(events)
  57.    
  58. end
  59.  
  60. local function Tank:move(events)
  61.     self.moves = self.moves - 1
  62.     if events[2] == keys.left then
  63.         self.x = self.x + 1
  64.     elseif evebts[2] == keys.right then
  65.         self.x = self.x - 1
  66.     end
  67. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement