Created
March 28, 2023 00:38
-
-
Save JoeStrout/911cf4f4f2d2268b9473d64460bde335 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Point={} | |
Point.make = function(x,y) | |
p = new Point | |
p.x = x; p.y = y | |
return p | |
end function | |
Point.zero = Point.make(0, 0) | |
current = null | |
dirInput = {} | |
dirInput.update = function | |
x = key.axis("Horizontal") | |
y = key.axis("Vertical") | |
ax = abs(x) | |
ay = abs(y) | |
if ax < 0.8 and ay < 0.8 then | |
p = null | |
else | |
p = Point.make(sign(x)*(ax>0.2), sign(y)*(ay>0.2)) | |
end if | |
outer.current = p | |
end function | |
dirInput.available = function(update=true) | |
if update then self.update | |
return current != null | |
end function | |
dirInput.get = function | |
if current == null then return Point.zero | |
result = current | |
outer.current = null | |
return result | |
end function | |
if locals == globals then | |
while true | |
if dirInput.available then | |
d = dirInput.get | |
print time + ": " + d.x + "," + d.y | |
end if | |
yield | |
end while | |
end if |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment