diff --git a/data/images/tongue.png b/data/images/tongue.png new file mode 100644 index 0000000..2c51ce9 Binary files /dev/null and b/data/images/tongue.png differ diff --git a/data/scripts/classes/feed.lua b/data/scripts/classes/feed.lua new file mode 100644 index 0000000..859c284 --- /dev/null +++ b/data/scripts/classes/feed.lua @@ -0,0 +1,41 @@ +local Vector3 = require "types.vector3" +local util = require "util" + +local TEXTURE = "images/tongue.png" + +local Feed = { + position = {}, + direction = {}, + velocity = {}, + landed = false, + + speed = 0.15, +} + +Feed.__index = Feed + +function Feed.new(p_position, p_direction) + local f = util.shallow_copy(Feed) + f.position = p_position:copy() + f.direction = p_direction:copy() + 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 \ No newline at end of file diff --git a/data/scripts/game.lua b/data/scripts/game.lua index 4af6dec..d6b3f83 100644 --- a/data/scripts/game.lua +++ b/data/scripts/game.lua @@ -1,6 +1,13 @@ local player = require "classes.player" local util = require "util" local Vector3 = require "types.vector3" +local Feed = require "classes.feed" + +local feed = {} + +local function create_feed(position, direction) + table.insert(feed, Feed.new(position, direction)) +end -- called every frame, with constant delta time function game_tick() @@ -8,13 +15,9 @@ function game_tick() if ctx.initialization_needed then -- ctx.udata persists on reload ctx.udata = { - capture = false + capture = false, } - player.ThrowPressed:connect( - function (position, direction) - print(position, " ", direction) - end - ) + player.ThrowPressed:connect(create_feed) end ctx.mouse_capture = ctx.udata.capture @@ -24,10 +27,14 @@ function game_tick() ctx.udata.capture = not ctx.udata.capture end + for _, v in pairs(feed) do + v:tick(ctx) + end + player:tick(ctx) -- draw_camera{position = Vector3(0, 1, 0), direction = Vector3.FORWARD} -- draw ground - local q = util.create_plane_quad(Vector3(0, 0, 0), Vector3.UP, 10) + local q = util.create_plane_quad(Vector3(0, 0, 0), Vector3.UP, 20) local params = { texture = "images/measure001a.png", texture_region = { x = 0, y = 0, w = 512, h = 512 }, diff --git a/data/scripts/types/vector3.lua b/data/scripts/types/vector3.lua index 62e712a..893313a 100644 --- a/data/scripts/types/vector3.lua +++ b/data/scripts/types/vector3.lua @@ -2,7 +2,7 @@ --- @field x number --- @field y number --- @field z number ---- @alias vectorlike table | Vector3 +--- @alias vectorlike number[] | Vector3 local Vector3 = { x = 0, y = 0,