From 4ec2e421bd05fb178c5bf8317606b4fadd622b54 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Tue, 5 Apr 2022 04:14:51 +0100 Subject: convert mansion to fennel --- src/mansion.fnl | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/mansion.lua | 80 ----------------------------------------------------- 2 files changed, 86 insertions(+), 80 deletions(-) create mode 100644 src/mansion.fnl delete mode 100644 src/mansion.lua diff --git a/src/mansion.fnl b/src/mansion.fnl new file mode 100644 index 0000000..067c679 --- /dev/null +++ b/src/mansion.fnl @@ -0,0 +1,86 @@ +(local bump (require :bump)) +(local player (require :player)) + +(local world (bump.newWorld)) + +(macro inpush [...] + `(do + (love.graphics.push) + (do ,...) + (love.graphics.pop))) + + + +(local draw_thing (coroutine.wrap + (fn draw_thing [] + (var t 0) + (var angry false) + + (local tri-a 100) + (local tri-h (* tri-a (/ (math.sqrt 3) 2))) + (local ell-l 20) + (local ell-r 30) + + (while true + (let [theta (/ t 10) + c (math.cos theta) + s (math.sin theta)] + (let [dist (math.sqrt (+ (^ (- 420 player.x) 2) + (^ (- 240 player.y) 2)))] + (if (and (< dist 100) (not angry)) + (set angry true) + (and (> dist 200) angry) + (set angry false))) + (inpush + (love.graphics.translate 420 240) + + (inpush + (love.graphics.setLineWidth 10) + (love.graphics.setColor (if angry [1 0 0 0.8] [0.7 0 0.5 0.8])) + (love.graphics.rotate (/ (- theta) 1.618)) + (love.graphics.polygon :line (- (/ tri-a 2)) (- (/ tri-h 3)) + (/ tri-a 2) (- (/ tri-h 3)) + 0 (* 2 (/ tri-h 3)))) + + (love.graphics.setLineWidth 7) + (love.graphics.setColor 0.8 0.8 0 0.7) + (love.graphics.ellipse :line (* ell-l c) (* ell-l s) ell-r (* 2 ell-r)) + (love.graphics.setColor 0 0.8 0.8 0.7) + (love.graphics.ellipse :line (- (* ell-l c)) (- (* ell-l s)) ell-r (* 2 ell-r))) + + (set t (+ t (if angry 1.8 1))) + (coroutine.yield)))))) + +(var font nil) +(var title nil) +(var jerma nil) +(fn theload [] + (set font (love.graphics.newFont :APL333.ttf 72)) + (set title (love.graphics.newText font :mansion)) + (set jerma (love.graphics.newImage :jerma.jpg)) + (world:add :jerma 30 400 400 50)) + +(fn draw_jerma [] + (love.graphics.setColor 1 1 1 1) + (let [sx (/ 400 (jerma:getWidth)) + sy (/ 50 (jerma:getHeight))] + (love.graphics.draw jerma 30 400 0 sx sy))) + +(fn draw [] + (love.graphics.setColor 0.8 0.8 0.8) + (love.graphics.setLineWidth 10) + (love.graphics.rectangle :line 30 80 580 370) + (love.graphics.draw title (- 610 (title:getWidth)) -10) + + (draw_thing) + (draw_jerma)) + +{ : world + : draw + :load theload } + + + + + + diff --git a/src/mansion.lua b/src/mansion.lua deleted file mode 100644 index d0114f9..0000000 --- a/src/mansion.lua +++ /dev/null @@ -1,80 +0,0 @@ -local bump = require "bump" -local player = require "player" - -local mansion = {} - -local world = bump.newWorld() -mansion.world=world - -local draw_thing = coroutine.wrap(function() - local t = 0 - local angry = false - - local tri_a = 100 - local tri_h = (math.sqrt(3)/2)*tri_a - - local ell_l = 20 - local ell_r = 30 - - while true do - local theta = t/10 - local c = math.cos(theta) - local s = math.sin(theta) - - local dist = math.sqrt((420-player.x)^2 + (240-player.y)^2) - if not angry and dist < 100 then - angry = true - elseif angry and dist > 200 then - angry = false - end - - love.graphics.push() - love.graphics.translate(420,240) - - love.graphics.push() - love.graphics.setLineWidth(10) - love.graphics.setColor(angry and {1,0,0,0.8} or {0.7,0,0.5,0.8}) - love.graphics.rotate(-theta/1.618) - love.graphics.polygon("line", -tri_a/2,-tri_h/3, tri_a/2,-tri_h/3, 0,2*tri_h/3) - love.graphics.pop() - - love.graphics.setLineWidth(7) - love.graphics.setColor(0.8,0.8,0,0.7) - love.graphics.ellipse("line", ell_l*c,ell_l*s, ell_r,2*ell_r) - love.graphics.setColor(0,0.8,0.8,0.7) - love.graphics.ellipse("line", -ell_l*c,-ell_l*s, ell_r,2*ell_r) - love.graphics.pop() - - t = t + (angry and 1.8 or 1) - - coroutine.yield() - end -end) - -local font,title,jerma -function mansion.load() - font = love.graphics.newFont("APL333.ttf",72) - title = love.graphics.newText(font,"mansion") - jerma = love.graphics.newImage("jerma.jpg") - world:add("jerma", 30,400, 400,50) -end - -local function draw_jerma() - love.graphics.setColor(1,1,1,1) - local sx = 400 / jerma:getWidth() - local sy = 50 / jerma:getHeight() - love.graphics.draw(jerma, 30,400, 0, sx,sy) -end - -function mansion.draw() - love.graphics.setColor(0.8,0.8,0.8) - love.graphics.setLineWidth(10) - love.graphics.rectangle("line",30,80,580,370) - love.graphics.draw(title,610-title:getWidth(),-10) - - draw_thing() - draw_jerma() -end - -return mansion - -- cgit v1.2.3