Posted 01 June 2013 - 02:45 PM
So I decided to practice my skills with making the game Tetris… and so just to get a little bit of practice and understand of what I will need to do I wrote a simple code to rotate blocks
(first off, if you think there could be something improved here please tell me!!)
Alright, so the object is 4 blocks tall and they go vertially, and what i'm trying to do is make them go horizontaly by switching the xpos and ypos when the left key is clicked… but I'm not sure If I did this right… I don't get any errors but It doesn't rotate…. please help!!
running = true
refreshRate = 0.15
gtID = os.startTimer(refreshRate)
l, h = term.getSize()
function draw()
term.setBackgroundColour(colours.white)
term.write(" ")
end
xposO = math.floor(l/2)
yposO = math.floor(h/2)
blocks = {
update = {
xpos = xposO;
ypos = yposO;
};
draw = function(self)
for i = 1,4 do
term.setCursorPos(self.update.xpos,
self.update.ypos + i)
term.setBackgroundColour(colours.white)
term.write(" ")
end
end;
}
function update()
id, p1 = os.pullEvent()
if id == "timer" and p1 == gtID then
blocks:draw()
gtID = os.startTimer(refreshRate)
elseif id == "key" and p1 == keys.left then
blocks.update.xpos = yposO
blocks.update.ypos = xposO
blocks:draw()
elseif id == "key" and p1 == keys.q then
running = false
end
end
while running do
update()
end
term.setBackgroundColour(colours.black)
shell.run("clear")
sleep(0.01)
(first off, if you think there could be something improved here please tell me!!)
Alright, so the object is 4 blocks tall and they go vertially, and what i'm trying to do is make them go horizontaly by switching the xpos and ypos when the left key is clicked… but I'm not sure If I did this right… I don't get any errors but It doesn't rotate…. please help!!