Skip to content

Instantly share code, notes, and snippets.

@shundroid
Last active April 20, 2019 12:10
Show Gist options
  • Save shundroid/c1dc37502449b43c49f7784710bd780e to your computer and use it in GitHub Desktop.
Save shundroid/c1dc37502449b43c49f7784710bd780e to your computer and use it in GitHub Desktop.
SG四角形で登場
--track0:width,0,9999,40
--track1:height,0,9999,60
--track2:padding,-9999,9999,5
--track3:holding time(s),0,9999,1
local COLORS = { 0x000000, 0xffffff }
local DIRECTIONS = { "left", "right", "up", "down" }
local SPEED = 300
if chars == null then
chars = {}
end
debug_print(string.format("index = %d",obj.index))
if chars[obj.index] == null then
chars[obj.index] = { direction = DIRECTIONS[math.floor(obj.rand(1, #DIRECTIONS))], color = COLORS[math.floor(obj.rand(1, #COLORS))] }
end
local w, h = obj.getpixel()
local width, height, pad, holdingtime = obj.track0, obj.track1, obj.track2, obj.track3
local time = math.max(obj.time - holdingtime, 0)
local entrytime = 0.5 - obj.time
local dx = obj.ox + obj.index * (width + pad) - width / 2
local dy = obj.oy - height / 2
if entrytime < 0 then
obj.draw(obj.index * (width + pad), 0)
end
obj.load("figure", "四角形", chars[obj.index].color, 1)
local direction = chars[obj.index].direction
local left, right, top, bottom = dx, dx + width, dy, dy + height
if direction == "left" then
if entrytime > 0 then
left, right = dx - entrytime * SPEED / 4, dx + width - entrytime * SPEED
else
left, right = dx + time * SPEED, dx + width + time * SPEED / 4
end
right = math.max(left, right)
elseif direction == "right" then
if entrytime > 0 then
left, right = dx + entrytime * SPEED, dx + width + entrytime * SPEED / 4
else
left, right = dx - time * SPEED / 4, dx + width - time * SPEED
end
left = math.min(left, right)
elseif direction == "up" then
if entrytime > 0 then
top, bottom = dy + entrytime * SPEED, dy + height + entrytime * SPEED / 4
else
top, bottom = dy - time * SPEED / 4, dy + height - time * SPEED
end
bottom = math.max(top, bottom)
elseif direction == "down" then
if entrytime > 0 then
top, bottom = dy - entrytime * SPEED / 4, dy + height - entrytime * SPEED
else
top, bottom = dy + time * SPEED, dy + height + time * SPEED / 4
end
top = math.min(top, bottom)
end
obj.drawpoly(left, top, 0, right, top, 0, right, bottom, 0, left, bottom, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment