summaryrefslogtreecommitdiff
path: root/character.lua
diff options
context:
space:
mode:
Diffstat (limited to 'character.lua')
-rw-r--r--character.lua97
1 files changed, 97 insertions, 0 deletions
diff --git a/character.lua b/character.lua
new file mode 100644
index 0000000..431e473
--- /dev/null
+++ b/character.lua
@@ -0,0 +1,97 @@
+require 'honey.std'
+
+return function(db)
+ local capsule = db:createEntityWithComponents{
+ node = {
+ matrix = Mat4()
+ :identity()
+ :translate(Vec3{0,10,0})
+ :rotateX(0.5*math.pi)
+ },
+ collision = {
+ class = "capsule",
+ radius = 1,
+ length = 2,
+ category = 2,
+ collide = bit.bxor(0xffffffff, 2)
+ },
+ physics = {
+ mass = {
+ class = "capsule",
+ mass = 10,
+ direction = 3,
+ radius = 1,
+ length = 2,
+ },
+ surface = true,
+ maxAngularSpeed = 0,
+ },
+ renderMesh = {
+ mesh = { filename="assets/capsule.obj", index=1 },
+ shader = { vertex="vertex.glsl", fragment="fragment.glsl" },
+ textures = {
+ ourTexture = { filename = "assets/green-grass.jpg" },
+ },
+ },
+ script = { script = "scripts.capsuleMove" },
+ }
+
+
+ local spring = db:createEntityWithComponents{
+ node = {
+ name = "spring",
+ parent = capsule,
+ matrix = Mat4():identity()
+ :translate(Vec3{0,-1,0})
+ },
+ collision = {
+ class = "ray",
+ length = 4,
+ category = 2,
+ collide = bit.bxor(0xffffffff, 2)
+ },
+ onCollision = {
+ script = "scripts.character.spring",
+ },
+ spring = {
+ F = 0,
+ }
+ }
+
+
+ local pivotPivot = db:createEntityWithComponents{
+ node = {
+ name = "p",
+ parent = capsule,
+ matrix = Mat4():identity():rotateX(-0.5*math.pi),
+ },
+ }
+
+
+ local capcamPivot = db:createEntityWithComponents{
+ node = {
+ name = "pivot",
+ parent = pivotPivot,
+ matrix = Mat4():identity(),
+ },
+ pitchyaw = {
+ pitch = 0,
+ yaw = 0,
+ },
+ onCursorPos = { script = "scripts.cameraPivot" },
+ }
+
+
+ local capcam = db:createEntityWithComponents{
+ camera = {
+ projection = Mat4():perspective(math.rad(45), 640/480, 0.1, 1000),
+ render="screen",
+ },
+ node = {
+ parent = capcamPivot,
+ matrix = Mat4():identity():translate(Vec3{0,0,20}),
+ },
+ onScroll = { script = "scripts.character.cameraDistance" },
+ onFramebufferSize = { script = "scripts.cameraHandleResize" },
+ }
+end