mirror of
https://github.com/SleepingInsomniac/pixelfaucet
synced 2025-01-31 19:57:53 +01:00
Update examples to use Vector instead of Point
This commit is contained in:
parent
e5237337ed
commit
f4409b4496
6 changed files with 34 additions and 34 deletions
|
@ -2,8 +2,8 @@ require "../src/game"
|
|||
require "../src/controller"
|
||||
require "../src/sprite"
|
||||
require "../src/pixel"
|
||||
require "../src/point"
|
||||
require "../src/pixel_text"
|
||||
require "../src/vector"
|
||||
|
||||
require "../src/3d/*"
|
||||
|
||||
|
@ -101,16 +101,16 @@ class ThreeDee < PF::Game
|
|||
tris.each do |tri|
|
||||
# Rasterize all triangles
|
||||
fill_triangle(
|
||||
PF::Point.new(tri.p1.x.to_i, tri.p1.y.to_i),
|
||||
PF::Point.new(tri.p2.x.to_i, tri.p2.y.to_i),
|
||||
PF::Point.new(tri.p3.x.to_i, tri.p3.y.to_i),
|
||||
PF::Vector[tri.p1.x.to_i, tri.p1.y.to_i],
|
||||
PF::Vector[tri.p2.x.to_i, tri.p2.y.to_i],
|
||||
PF::Vector[tri.p3.x.to_i, tri.p3.y.to_i],
|
||||
pixel: tri.color
|
||||
)
|
||||
|
||||
# draw_triangle(
|
||||
# PF::Point.new(tri.p1.x.to_i, tri.p1.y.to_i),
|
||||
# PF::Point.new(tri.p2.x.to_i, tri.p2.y.to_i),
|
||||
# PF::Point.new(tri.p3.x.to_i, tri.p3.y.to_i),
|
||||
# PF::Vector[tri.p1.x.to_i, tri.p1.y.to_i],
|
||||
# PF::Vector[tri.p2.x.to_i, tri.p2.y.to_i],
|
||||
# PF::Vector[tri.p3.x.to_i, tri.p3.y.to_i],
|
||||
# pixel: PF::Pixel.blue
|
||||
# )
|
||||
end
|
||||
|
|
|
@ -7,7 +7,7 @@ module PF
|
|||
class Ball < Entity
|
||||
include CircleCollision
|
||||
|
||||
getter frame : Array(Point(Float64))
|
||||
getter frame : Array(Vector(Float64, 2))
|
||||
|
||||
def initialize(size : Float64)
|
||||
@frame = Shape.circle(size.to_i32, size.to_i32)
|
||||
|
@ -23,10 +23,10 @@ module PF
|
|||
super
|
||||
|
||||
15.times do
|
||||
position = Point(Float64).new(rand(0.0_f64..@width.to_f64), rand(0.0_f64..@height.to_f64))
|
||||
position = Vector(Float64, 2).new(rand(0.0_f64..@width.to_f64), rand(0.0_f64..@height.to_f64))
|
||||
ball = Ball.new(rand(10.0..30.0))
|
||||
ball.position = position
|
||||
ball.velocity = Point(Float64).new(rand(-50.0..50.0), rand(-50.0..50.0))
|
||||
ball.velocity = Vector(Float64, 2).new(rand(-50.0..50.0), rand(-50.0..50.0))
|
||||
|
||||
@balls << ball
|
||||
end
|
||||
|
|
|
@ -11,18 +11,18 @@ class FillShape < PF::Game
|
|||
|
||||
def draw
|
||||
clear(0, 0, 100)
|
||||
fill_shape(PF::Point.new(15, 15), PF::Point.new(50, 10), PF::Point.new(60, 55), PF::Point.new(10, 60))
|
||||
fill_shape(PF::Point.new(100, 10), PF::Point.new(150, 10), PF::Point.new(150, 60), PF::Point.new(100, 60))
|
||||
fill_shape(PF::Vector[15, 15], PF::Vector[50, 10], PF::Vector[60, 55], PF::Vector[10, 60])
|
||||
fill_shape(PF::Vector[100, 10], PF::Vector[150, 10], PF::Vector[150, 60], PF::Vector[100, 60])
|
||||
fill_shape(
|
||||
PF::Point.new(10, 100),
|
||||
PF::Point.new(20, 110),
|
||||
PF::Point.new(30, 100),
|
||||
PF::Point.new(40, 110),
|
||||
PF::Point.new(50, 100),
|
||||
PF::Point.new(50, 150),
|
||||
PF::Point.new(10, 150),
|
||||
PF::Vector[10, 100],
|
||||
PF::Vector[20, 110],
|
||||
PF::Vector[30, 100],
|
||||
PF::Vector[40, 110],
|
||||
PF::Vector[50, 100],
|
||||
PF::Vector[50, 150],
|
||||
PF::Vector[10, 150],
|
||||
)
|
||||
fill_shape(PF::Point.new(115, 115), PF::Point.new(150, 120), PF::Point.new(160, 155), PF::Point.new(110, 160))
|
||||
fill_shape(PF::Vector[115, 115], PF::Vector[150, 120], PF::Vector[160, 155], PF::Vector[110, 160])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ module PF
|
|||
super
|
||||
|
||||
@emitter = Emitter.new
|
||||
@emitter.position = Point.new(@width / 2, @height / 2)
|
||||
@emitter.position = viewport / 2
|
||||
end
|
||||
|
||||
def update(dt, event)
|
||||
|
|
|
@ -2,7 +2,7 @@ require "../src/game"
|
|||
require "../src/controller"
|
||||
require "../src/sprite"
|
||||
require "../src/pixel"
|
||||
require "../src/point"
|
||||
require "../src/vector"
|
||||
require "../src/pixel_text"
|
||||
|
||||
class Wind
|
||||
|
@ -13,8 +13,8 @@ class Wind
|
|||
@step : Float64?
|
||||
|
||||
struct Gust
|
||||
property position : PF::Point(Float64)
|
||||
property strength : PF::Point(Float64)
|
||||
property position : PF::Vector(Float64, 2)
|
||||
property strength : PF::Vector(Float64, 2)
|
||||
|
||||
def initialize(@position, @strength)
|
||||
end
|
||||
|
@ -34,7 +34,7 @@ class Wind
|
|||
while y < @height
|
||||
x = step / 2
|
||||
while x < @width
|
||||
@gusts << Gust.new(PF::Point(Float64).new(x, y), PF::Point(Float64).new(rand(-1.0..1.0), rand(-1.0..1.0)))
|
||||
@gusts << Gust.new(PF::Vector(Float64, 2).new(x, y), PF::Vector(Float64, 2).new(rand(-1.0..1.0), rand(-1.0..1.0)))
|
||||
x += step
|
||||
end
|
||||
y += step
|
||||
|
@ -44,12 +44,12 @@ end
|
|||
|
||||
class Flake
|
||||
property shape : UInt8
|
||||
property position : PF::Point(Float64)
|
||||
property position : PF::Vector(Float64, 2)
|
||||
property z_pos : Float64
|
||||
property velocity : PF::Point(Float64)
|
||||
property velocity : PF::Vector(Float64, 2)
|
||||
|
||||
def initialize(@position, @shape = rand(0_u8..2_u8), @z_pos = rand(0.0..1.0), velocity : PF::Point(Float64)? = nil)
|
||||
@velocity = velocity || PF::Point(Float64).new(rand(-2.0..2.0), rand(0.0..20.0))
|
||||
def initialize(@position, @shape = rand(0_u8..2_u8), @z_pos = rand(0.0..1.0), velocity : PF::Vector(Float64, 2)? = nil)
|
||||
@velocity = velocity || PF::Vector(Float64, 2).new(rand(-2.0..2.0), rand(0.0..20.0))
|
||||
end
|
||||
|
||||
def update(dt)
|
||||
|
@ -77,7 +77,7 @@ class Snow < PF::Game
|
|||
|
||||
if @last_flake >= 0.025
|
||||
@last_flake = 0.0
|
||||
@flakes << Flake.new(position: PF::Point.new(rand(0.0..@width.to_f64), 0))
|
||||
@flakes << Flake.new(position: PF::Vector[rand(0.0..@width.to_f64), 0.0])
|
||||
end
|
||||
|
||||
@flakes.reject! do |flake|
|
||||
|
|
|
@ -3,13 +3,13 @@ require "../src/controller"
|
|||
require "../src/entity"
|
||||
require "../src/pixel"
|
||||
require "../src/shape"
|
||||
require "../src/point"
|
||||
require "../src/vector"
|
||||
|
||||
class Triangle < PF::Entity
|
||||
property frame : Array(PF::Point(Float64))
|
||||
property frame : Array(PF::Vector(Float64, 2))
|
||||
|
||||
def initialize(*args, **kwargs)
|
||||
@frame = [] of PF::Point(Float64)
|
||||
@frame = [] of PF::Vector(Float64, 2)
|
||||
end
|
||||
|
||||
def update(dt)
|
||||
|
@ -31,7 +31,7 @@ class TriangleThing < PF::Game
|
|||
super(@width, @height, @scale)
|
||||
|
||||
@tri = Triangle.new
|
||||
@tri.position = PF::Point.new(@width / 2, @height / 2)
|
||||
@tri.position = viewport / 2
|
||||
@tri.frame = PF::Shape.circle(3, size = @width / 3)
|
||||
|
||||
@controller = PF::Controller(LibSDL::Scancode).new({
|
||||
|
|
Loading…
Add table
Reference in a new issue