Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Star = {
- xPos = 0,
- yPos = 0,
- xDir = 0,
- yDir = 0
- }
- local stars = {}
- --term.redirect(peripheral.wrap("right"))
- local w, h = term.getSize()
- function Star:new(xPos, yPos, xDir, yDir)
- local class = {xPos = xPos, yPos = yPos, xDir = xDir, yDir = yDir}
- setmetatable(class, self)
- self.__index = self
- return class
- end
- function Star:move()
- self.xPos = self.xPos + self.xDir
- self.yPos = self.yPos + self.yDir
- if self.xPos == w then
- self.xDir = -1
- elseif self.xPos == 1 then
- self.xDir = 1
- end
- if self.yPos == h then
- self.yDir = -1
- elseif self.yPos == 1 then
- self.yDir = 1
- end
- end
- function Star:display()
- draw("*", self.xPos, self.yPos)
- draw(" ", self.xPos - self.xDir, self.yPos - self.yDir)
- end
- function draw(words,x,y)
- term.setCursorPos(x,y)
- write(words)
- end
- function eventHandler(events)
- if events[1] == "mouse_click" and events[2] == 1 then
- stars[#stars + 1] = Star:new(events[3], events[4], -1, 0)
- stars[#stars + 1] = Star:new(events[3], events[4], -1, -1)
- stars[#stars + 1] = Star:new(events[3], events[4], -1, 1)
- stars[#stars + 1] = Star:new(events[3], events[4], 0, 1)
- stars[#stars + 1] = Star:new(events[3], events[4], 0, -1)
- stars[#stars + 1] = Star:new(events[3], events[4], 1, 1)
- stars[#stars + 1] = Star:new(events[3], events[4], 1, 0)
- stars[#stars + 1] = Star:new(events[3], events[4], 1, -1)
- end
- end
- local gameTimer = os.startTimer(.05)
- while true do
- local events = {os.pullEvent()}
- term.clear()
- if events[1] == "timer" and events[2] == gameTimer then
- for i, v in pairs(stars) do
- v:move()
- v:display()
- end
- gameTimer = os.startTimer(.05)
- else
- eventHandler(events)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement