Created
January 10, 2019 23:21
-
-
Save radgeRayden/8fc97e734b163b408382ec01878e5fbf to your computer and use it in GitHub Desktop.
output of fennel --compile pong.fnl
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
local speed, ball_speed = 10, 200 | |
local state = {dx = 2, dy = 1, left = 10, right = 10, x = 100, y = 100} | |
local w, h = love.window.getMode() | |
local keys = {a = {"left", -1}, down = {"right", 1}, up = {"right", -1}, z = {"left", 1}} | |
local function on_paddle_3f() | |
return (((state.x < 20) and (state.left < state.y) and (state.y < (state.left + 100))) or (((w - 20) < state.x) and (state.right < state.y) and (state.y < (state.right + 100)))) | |
end | |
love.update = function(dt) | |
state.x = (state.x + (state.dx * dt * ball_speed)) | |
state.y = (state.y + (state.dy * dt * ball_speed)) | |
for key, action in pairs(keys) do | |
local _0_ = action | |
local player = _0_[1] | |
local dir = _0_[2] | |
local function _1_() | |
if love.keyboard.isDown(key) then | |
state[player] = (state[player] + (dir * speed)) | |
return nil | |
end | |
end | |
_1_() | |
end | |
local function _0_() | |
if ((state.y < 0) or (state.y > h)) then | |
state.dy = (0 - state.dy) | |
return nil | |
end | |
end | |
_0_() | |
local function _1_() | |
if on_paddle_3f() then | |
state.dx = (0 - state.dx) | |
return nil | |
end | |
end | |
_1_() | |
local function _2_() | |
if (state.x < 0) then | |
print("Right player wins") | |
return love.event.quit() | |
end | |
end | |
_2_() | |
if (state.x > w) then | |
print("Left player wins") | |
return love.event.quit() | |
end | |
end | |
love.keypressed = function(key) | |
if ("escape" == key) then | |
return love.event.quit() | |
end | |
end | |
love.draw = function() | |
love.graphics.rectangle("fill", 10, state.left, 10, 100) | |
love.graphics.rectangle("fill", (w - 10), state.right, 10, 100) | |
return love.graphics.circle("fill", state.x, state.y, 10) | |
end | |
return love.draw |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment