2021-12-12 00:10:52 -05:00
|
|
|
require "../src/game"
|
|
|
|
|
|
|
|
class TextGame < PF::Game
|
2022-01-02 20:41:17 -05:00
|
|
|
def initialize(*args, **kwargs)
|
2021-12-12 00:10:52 -05:00
|
|
|
super
|
|
|
|
@x = 0.0
|
|
|
|
@y = 0.0
|
|
|
|
@dx = 50.0
|
|
|
|
@dy = 50.0
|
|
|
|
@msg = "Hello, World!"
|
2022-02-04 00:09:09 -05:00
|
|
|
# @msg = "HI"
|
|
|
|
@color = PF::Pixel.random
|
2021-12-12 00:10:52 -05:00
|
|
|
end
|
|
|
|
|
2022-01-02 19:39:17 -05:00
|
|
|
def update(dt, event)
|
2021-12-12 00:10:52 -05:00
|
|
|
@x += @dx * dt
|
|
|
|
@y += @dy * dt
|
|
|
|
|
|
|
|
if @x < 0
|
|
|
|
@x = 0
|
|
|
|
@dx = -@dx
|
2022-02-04 00:09:09 -05:00
|
|
|
@color = PF::Pixel.random
|
2021-12-12 00:10:52 -05:00
|
|
|
end
|
|
|
|
|
2022-02-04 00:09:09 -05:00
|
|
|
if @x > @width - (@msg.size * PF::Sprite::CHAR_WIDTH)
|
|
|
|
@x = @width - (@msg.size * PF::Sprite::CHAR_WIDTH)
|
2021-12-12 00:10:52 -05:00
|
|
|
@dx = -@dx
|
2022-02-04 00:09:09 -05:00
|
|
|
@color = PF::Pixel.random
|
2021-12-12 00:10:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
if @y < 0
|
|
|
|
@y = 0
|
|
|
|
@dy = -@dy
|
2022-02-04 00:09:09 -05:00
|
|
|
@color = PF::Pixel.random
|
2021-12-12 00:10:52 -05:00
|
|
|
end
|
|
|
|
|
2022-02-04 00:09:09 -05:00
|
|
|
if @y > @height - (PF::Sprite::CHAR_HEIGHT)
|
|
|
|
@y = @height - (PF::Sprite::CHAR_HEIGHT)
|
2021-12-12 00:10:52 -05:00
|
|
|
@dy = -@dy
|
2022-02-04 00:09:09 -05:00
|
|
|
@color = PF::Pixel.random
|
2021-12-12 00:10:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def draw
|
|
|
|
clear(0, 0, 50)
|
2022-02-04 00:09:09 -05:00
|
|
|
draw_string(@msg, @x.to_i, @y.to_i, @color)
|
2021-12-12 00:10:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-02-04 00:09:09 -05:00
|
|
|
engine = TextGame.new(160, 100, 4).run!
|