Skip to content

Instantly share code, notes, and snippets.

@MattRoelle
Last active December 14, 2021 19:17
Show Gist options
  • Save MattRoelle/f678a7d5787cea1eba84a2291fb333d2 to your computer and use it in GitHub Desktop.
Save MattRoelle/f678a7d5787cea1eba84a2291fb333d2 to your computer and use it in GitHub Desktop.
(require-macros :golly)
(local golly (require :golly))
(defentity test-entity [self props]
{:x 300 :y 200 :width 200 :height 200}
(mixins (golly.mixins.mouse-interaction))
(field :state
(statemachine :red
(transitions
(turn-red {:to :red})
(turn-blue {:to :blue})
(turn-green {:to :green}))
(state :red
(field :color [1 0 0 1])
(on-enter [] (print :entered-red)))
(state :blue
(field :color [0 0 1 1])
(on-enter [] (print :entered-blue)))
(state :green
(field :color [0 1 0 1]))))
(on :mouseover [] (self.state:turn-red))
(on :mouseout [] (self.state:turn-blue))
(on :mousepress [] (self.state:turn-green))
(on :draw []
(love.graphics.setColor (unpack self.state.color))
(love.graphics.rectangle :fill 0 0 self.width self.height)))
(fn main-scene [scene]
(golly.scene.draw-game-frame scene)
(scene:add-entity (test-entity)))
(golly.setgame {:scenes {:main main-scene} :initial-scene :main
:stage-width (/ 1280 2) :stage-height (/ 720 2)
:assets (require :src.aseprite)})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment