initial commit
This commit is contained in:
commit
c9ac220089
12
.gitignore
vendored
Normal file
12
.gitignore
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
# ignore executables
|
||||
*
|
||||
!*.*
|
||||
!*/
|
||||
|
||||
*.so
|
||||
*.dll
|
||||
*.exe
|
||||
*.trace
|
||||
|
||||
data/scripts/twnapi.lua
|
||||
build/
|
8
data/scripts/game.lua
Normal file
8
data/scripts/game.lua
Normal file
@ -0,0 +1,8 @@
|
||||
-- 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
|
||||
ctx.udata = {}
|
||||
end
|
||||
end
|
177
data/scripts/types/vector3.lua
Normal file
177
data/scripts/types/vector3.lua
Normal file
@ -0,0 +1,177 @@
|
||||
local Vector3 = {
|
||||
x = 0,
|
||||
y = 0,
|
||||
z = 0,
|
||||
|
||||
_CLASS_ = "Vector3"
|
||||
}
|
||||
|
||||
setmetatable(Vector3, Vector3)
|
||||
|
||||
local function is_weak_vector3(t)
|
||||
if type(t) ~= "table" then return false end
|
||||
|
||||
local haskeys = t.x ~= nil and t.y ~= nil and t.z ~= nil
|
||||
if not haskeys then
|
||||
return type(t[1]) == "number" and type(t[2]) == "number" and type(t[3]) == "number"
|
||||
else
|
||||
return type(t.x) == "number" and type(t.y) == "number" and type(t.z) == "number"
|
||||
end
|
||||
end
|
||||
|
||||
function Vector3:__mul(b)
|
||||
if type(b) == "number" then
|
||||
return Vector3{
|
||||
x = self.x * b,
|
||||
y = self.y * b,
|
||||
z = self.z * b,
|
||||
}
|
||||
elseif type(b) == "table" and is_weak_vector3(b) then
|
||||
local other = Vector3(b)
|
||||
return Vector3{
|
||||
self.x * other.x,
|
||||
self.y * other.y,
|
||||
self.z * other.z,
|
||||
}
|
||||
end
|
||||
|
||||
error("Vector3: other must be either a number or a Vector3-like table.")
|
||||
return Vector3()
|
||||
end
|
||||
|
||||
function Vector3:__div(b)
|
||||
if type(b) == "number" then
|
||||
return Vector3{
|
||||
x = self.x / b,
|
||||
y = self.y / b,
|
||||
z = self.z / b,
|
||||
}
|
||||
elseif type(b) == "table" and is_weak_vector3(b) then
|
||||
local other = Vector3(b)
|
||||
return Vector3{
|
||||
self.x / other.x,
|
||||
self.y / other.y,
|
||||
self.z / other.z,
|
||||
}
|
||||
end
|
||||
|
||||
error("Vector3: other must be either a number or a Vector3-like table.")
|
||||
return Vector3()
|
||||
end
|
||||
|
||||
function Vector3:__add(b)
|
||||
if not is_weak_vector3(b) then
|
||||
error("Vector3: other must be a Vector3-like table.")
|
||||
return self
|
||||
end
|
||||
local other = Vector3(b)
|
||||
return Vector3{
|
||||
self.x + other.x,
|
||||
self.y + other.y,
|
||||
self.z + other.z,
|
||||
}
|
||||
end
|
||||
|
||||
function Vector3:__sub(b)
|
||||
if not is_weak_vector3(b) then
|
||||
error("Vector3: other must be a Vector3-like table.")
|
||||
return self
|
||||
end
|
||||
local other = Vector3(b)
|
||||
return Vector3{
|
||||
self.x - other.x,
|
||||
self.y - other.y,
|
||||
self.z - other.z,
|
||||
}
|
||||
end
|
||||
|
||||
function Vector3:__unm()
|
||||
return Vector3{
|
||||
-self.x,
|
||||
-self.y,
|
||||
-self.z,
|
||||
}
|
||||
end
|
||||
|
||||
function Vector3:__call(...)
|
||||
local args = {...}
|
||||
local nv = {x = 0, y = 0, z = 0}
|
||||
setmetatable(nv, Vector3)
|
||||
if type(args[1]) == "number" then
|
||||
if #args == 1 then
|
||||
nv.x, nv.y, nv.z = args[1], args[1], args[1]
|
||||
else
|
||||
nv.x, nv.y, nv.z = args[1], args[2], args[3]
|
||||
end
|
||||
elseif type(args[1]) == "table" then
|
||||
if args[1].x ~= nil then
|
||||
nv.x, nv.y, nv.z = args[1].x, args[1].y, args[1].z
|
||||
else
|
||||
nv.x, nv.y, nv.z = args[1][1], args[1][2], args[1][3]
|
||||
end
|
||||
end
|
||||
return nv
|
||||
end
|
||||
|
||||
function Vector3:__tostring()
|
||||
return "Vector3(" .. tostring(self.x) .. ", " .. tostring(self.y) .. ", " .. tostring(self.z) .. ")"
|
||||
end
|
||||
|
||||
Vector3.__index = Vector3
|
||||
|
||||
|
||||
--------API--------
|
||||
function Vector3:length_squared()
|
||||
local x2 = self.x * self.x
|
||||
local y2 = self.y * self.y
|
||||
local z2 = self.z * self.z
|
||||
|
||||
return x2 + y2 + z2
|
||||
end
|
||||
|
||||
function Vector3:length()
|
||||
return math.sqrt(self:length_squared())
|
||||
end
|
||||
|
||||
function Vector3:normalized()
|
||||
local length = math.sqrt(self:length_squared())
|
||||
if length == 0 then
|
||||
return Vector3()
|
||||
end
|
||||
return Vector3(self.x / length, self.y / length, self.z / length)
|
||||
end
|
||||
|
||||
function Vector3:dot(with)
|
||||
if not is_weak_vector3(with) then
|
||||
error("Vector3: with must be a Vector3-like table. Returning 0")
|
||||
return 0
|
||||
end
|
||||
|
||||
local v2 = Vector3(with)
|
||||
return self.x * v2.x + self.y * v2.y + self.z * v2.z
|
||||
end
|
||||
|
||||
function Vector3:cross(with)
|
||||
if not is_weak_vector3(with) then
|
||||
error("Vector3: with must be a Vector3-like table. Returning Vector3()")
|
||||
return Vector3()
|
||||
end
|
||||
local v2 = Vector3(with)
|
||||
return Vector3 {
|
||||
self.y * v2.z - self.z * v2.y,
|
||||
self.z * v2.x - self.x * v2.z,
|
||||
self.x * v2.y - self.y * v2.x,
|
||||
}
|
||||
end
|
||||
|
||||
---- CONSTANTS
|
||||
|
||||
Vector3.UP = Vector3(0, 1, 0)
|
||||
Vector3.DOWN = -Vector3.UP
|
||||
Vector3.FORWARD = Vector3(0, 0, -1)
|
||||
Vector3.BACK = -Vector3.FORWARD
|
||||
Vector3.RIGHT = Vector3(1, 0, 0)
|
||||
Vector3.LEFT = -Vector3.RIGHT
|
||||
|
||||
-------------------
|
||||
return Vector3
|
28
data/twn.toml
Normal file
28
data/twn.toml
Normal file
@ -0,0 +1,28 @@
|
||||
# This file contains everything about the engine and your game that can be
|
||||
# configured before it runs.
|
||||
#
|
||||
# Optional settings are commented out, with their default values shown.
|
||||
# Invalid values in these settings will be ignored.
|
||||
|
||||
# Data about your game as an application
|
||||
[about]
|
||||
title = "quack2"
|
||||
developer = "yag"
|
||||
app_id = "quack2"
|
||||
dev_id = "yag"
|
||||
|
||||
# Game runtime details
|
||||
[game]
|
||||
resolution = [ 640, 480 ]
|
||||
interpreter = "$TWNROOT/apps/twnlua"
|
||||
background_color = [0, 0, 0, 1]
|
||||
#debug = true
|
||||
|
||||
# Engine tweaks. You probably don't need to change these
|
||||
[engine]
|
||||
#ticks_per_second = 60 # minimum of 8
|
||||
#keybind_slots = 3 # minimum of 1
|
||||
#texture_atlas_size = 2048 # minimum of 32
|
||||
#font_texture_size = 2048 # minimum of 1024
|
||||
#font_oversampling = 4 # minimum of 0
|
||||
#font_filtering = "linear" # possible values: "nearest", "linear"
|
Loading…
Reference in New Issue
Block a user