2025-02-14 19:01:50 +00:00
|
|
|
util = require "util"
|
2025-02-13 21:44:00 +00:00
|
|
|
local player = require "classes.player"
|
|
|
|
local Vector3 = require "types.vector3"
|
2025-02-15 11:58:27 +00:00
|
|
|
local List = require "types.list"
|
2025-02-14 17:04:45 +00:00
|
|
|
|
2025-02-14 19:01:50 +00:00
|
|
|
local Feed = require "classes.feed"
|
2025-02-15 11:58:27 +00:00
|
|
|
local feed = List()
|
|
|
|
|
|
|
|
local Duck = require "classes.duck"
|
2025-02-15 14:25:27 +00:00
|
|
|
local ducks = List()
|
2025-02-14 17:04:45 +00:00
|
|
|
|
|
|
|
local function create_feed(position, direction)
|
2025-02-15 14:25:27 +00:00
|
|
|
print("?")
|
2025-02-15 11:58:27 +00:00
|
|
|
local f = Feed.new(position, direction)
|
|
|
|
feed:push(f)
|
|
|
|
local eligible_ducks = ducks:filter(
|
|
|
|
function (duck)
|
2025-02-15 14:25:27 +00:00
|
|
|
return duck.state ~= duck.STATES.CHASE
|
2025-02-15 11:58:27 +00:00
|
|
|
end
|
|
|
|
)
|
2025-02-15 14:25:27 +00:00
|
|
|
if eligible_ducks:is_empty() then return end
|
2025-02-15 11:58:27 +00:00
|
|
|
eligible_ducks[1]:start_chase(f)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function delete_feed(f)
|
2025-02-15 14:25:27 +00:00
|
|
|
feed:remove_value(f)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function duck_seek_feed(duck)
|
|
|
|
local eligible_feeds = feed:filter(
|
|
|
|
function (f)
|
|
|
|
return feed.occupied == false
|
|
|
|
end
|
|
|
|
)
|
|
|
|
if eligible_feeds:is_empty() then return end
|
|
|
|
duck:start_chase(eligible_feeds[1])
|
2025-02-14 17:04:45 +00:00
|
|
|
end
|
2025-02-13 21:44:00 +00:00
|
|
|
|
2025-02-13 19:19:52 +00:00
|
|
|
-- called every frame, with constant delta time
|
|
|
|
function game_tick()
|
|
|
|
-- ctx.initialization_needed is true first frame and every time dynamic reload is performed
|
|
|
|
if ctx.initialization_needed then
|
|
|
|
-- ctx.udata persists on reload
|
2025-02-13 21:44:00 +00:00
|
|
|
ctx.udata = {
|
2025-02-14 17:04:45 +00:00
|
|
|
capture = false,
|
2025-02-13 21:44:00 +00:00
|
|
|
}
|
2025-02-14 17:04:45 +00:00
|
|
|
player.ThrowPressed:connect(create_feed)
|
2025-02-15 14:25:27 +00:00
|
|
|
|
|
|
|
-- spawn some ducks
|
|
|
|
for i = 1, 5 do
|
|
|
|
local duck = Duck.new(Vector3(0, 0, -math.random() * 10.0):rotated(Vector3.UP, util.random_float(-math.pi, math.pi)))
|
|
|
|
ducks:push(duck)
|
|
|
|
duck.AteFeed:connect(delete_feed)
|
|
|
|
duck.SeekFeed:connect(duck_seek_feed)
|
|
|
|
duck.index = i
|
2025-02-15 11:58:27 +00:00
|
|
|
end
|
2025-02-15 14:25:27 +00:00
|
|
|
print(ducks[1].AteFeed._connections)
|
|
|
|
print(ducks[2].AteFeed._connections)
|
|
|
|
|
2025-02-13 19:19:52 +00:00
|
|
|
end
|
2025-02-13 21:44:00 +00:00
|
|
|
|
|
|
|
ctx.mouse_capture = ctx.udata.capture
|
|
|
|
input_action{name = "toggle_mouse", control = "ESCAPE"}
|
2025-02-15 11:58:27 +00:00
|
|
|
|
2025-02-13 21:44:00 +00:00
|
|
|
if input_action_just_pressed{name = "toggle_mouse"} then
|
|
|
|
ctx.udata.capture = not ctx.udata.capture
|
|
|
|
end
|
|
|
|
|
2025-02-15 11:58:27 +00:00
|
|
|
for _, v in ipairs(feed) do
|
|
|
|
v:tick(ctx)
|
|
|
|
end
|
|
|
|
|
|
|
|
for _, v in ipairs(ducks) do
|
2025-02-14 17:04:45 +00:00
|
|
|
v:tick(ctx)
|
|
|
|
end
|
|
|
|
|
2025-02-13 21:44:00 +00:00
|
|
|
player:tick(ctx)
|
2025-02-14 17:04:45 +00:00
|
|
|
local q = util.create_plane_quad(Vector3(0, 0, 0), Vector3.UP, 20)
|
2025-02-13 21:44:00 +00:00
|
|
|
local params = {
|
|
|
|
texture = "images/measure001a.png",
|
|
|
|
texture_region = { x = 0, y = 0, w = 512, h = 512 },
|
|
|
|
}
|
|
|
|
draw_quad(util.merge(q, params))
|
2025-02-13 19:19:52 +00:00
|
|
|
end
|