2021-11-29 08:26:51 +01:00
|
|
|
# require "crystaledge"
|
|
|
|
|
|
|
|
require "../src/game"
|
|
|
|
require "../src/controller"
|
|
|
|
require "../src/sprite"
|
|
|
|
require "../src/sprite/vector_sprite"
|
2021-11-30 04:04:31 +01:00
|
|
|
require "../src/pixel"
|
2021-11-29 08:26:51 +01:00
|
|
|
|
|
|
|
# include CrystalEdge
|
|
|
|
|
|
|
|
class Triangle < PF::Sprite
|
|
|
|
include PF::VectorSprite
|
|
|
|
|
|
|
|
def update(dt)
|
|
|
|
end
|
|
|
|
|
|
|
|
def draw(engine)
|
|
|
|
frame = project_points(@frame)
|
|
|
|
engine.fill_triangle(frame[0], frame[1], frame[2], PF::Pixel.new(255, 255, 0))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TriangleThing < PF::Game
|
|
|
|
@tri : Triangle
|
|
|
|
@paused = false
|
|
|
|
|
|
|
|
def initialize(@width, @height, @scale)
|
|
|
|
super(@width, @height, @scale)
|
|
|
|
|
|
|
|
@tri = Triangle.build do |t|
|
|
|
|
t.position = Vector2.new(@width / 2, @height / 2)
|
2021-11-30 04:04:31 +01:00
|
|
|
t.frame = PF::VectorSprite.generate_circle(3, size = @width / 3)
|
2021-11-29 08:26:51 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
@controller = PF::Controller(LibSDL::Keycode).new({
|
|
|
|
LibSDL::Keycode::RIGHT => "Rotate Right",
|
|
|
|
LibSDL::Keycode::LEFT => "Rotate Left",
|
|
|
|
LibSDL::Keycode::SPACE => "Pause",
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
def update(dt)
|
|
|
|
@paused = !@paused if @controller.pressed?("Pause")
|
|
|
|
|
2021-12-01 02:02:59 +01:00
|
|
|
@tri.rotation += 0.5 * dt if @controller.action?("Rotate Right")
|
|
|
|
@tri.rotation -= 0.5 * dt if @controller.action?("Rotate Left")
|
2021-11-29 08:26:51 +01:00
|
|
|
|
|
|
|
unless @paused
|
|
|
|
@tri.rotation += 1.0 * dt
|
|
|
|
end
|
|
|
|
|
|
|
|
@tri.update(dt)
|
|
|
|
end
|
|
|
|
|
|
|
|
def draw
|
2021-12-01 02:02:59 +01:00
|
|
|
clear(0, 0, 100)
|
2021-11-29 08:26:51 +01:00
|
|
|
@tri.draw(self)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
engine = TriangleThing.new(100, 100, 5)
|
|
|
|
engine.run!
|