quack2/data/scripts/classes/feed.lua

39 lines
818 B
Lua
Raw Normal View History

2025-02-14 17:04:45 +00:00
local Vector3 = require "types.vector3"
local TEXTURE = "images/tongue.png"
local Feed = {}
2025-02-14 17:04:45 +00:00
Feed.__index = Feed
function Feed.new(position, direction)
local f = {
position = position:copy(),
direction = direction:copy(),
velocity = Vector3(),
landed = false,
occupied = false,
speed = 0.15,
}
2025-02-14 17:04:45 +00:00
f.velocity = f.direction * f.speed
f.velocity.y = 0.1
return setmetatable(f, Feed)
end
function Feed:tick(ctx)
if not self.landed then
-- gravity
self.velocity.y = math.max(self.velocity.y - 0.02, -0.2)
self.position = self.position + self.velocity
end
if self.position.y <= 0.2 and not self.landed then
self.position.y = 0.2
self.landed = true
end
draw_billboard{position = self.position, texture = TEXTURE, size = Vector3(0.2, 0.2)}
end
return Feed