Started using a project file to load scenes

Signed-off-by: Robear Selwans <robear.selwans@outlook.com>
This commit is contained in:
2021-06-02 08:04:44 +02:00
parent 4e37cad399
commit e6cc79f1dc
10 changed files with 190 additions and 141 deletions

25
res/project/game.proj Normal file
View File

@@ -0,0 +1,25 @@
{
"name": "dummy_game",
"engineVersion": "0.2",
"mounts": [
{
"path": "./res",
"mountpoint": "res"
},
{
"path": "./res/scripts",
"mountpoint": "scripts"
},
{
"path": "./res/scenes",
"mountpoint": "scenes"
}
],
"scenes": [
{
"id": "MainScene",
"path": "scenes://MainScene.evsc"
}
],
"activeScene": "MainScene"
}

View File

@@ -0,0 +1,104 @@
{
"id":"MainScene",
"nodes": [
{
"id": "Camera",
"components": [
{
"type": "TransformComponent",
"position": [0.0, 0.0, 0.0],
"rotation": [0.0, 0.0, 0.0],
"scale": [1.0, 1.0, 1.0]
},
{
"type": "CameraComponent",
"view": "Perspective",
"fov": 120,
"near": 0.001,
"far": 1000,
"aspectRatio": 1.3333
},
{
"type": "ScriptComponent",
"script_name": "CameraController",
"script_path": "scripts://Scene0/camera.lua"
}
]
},
{
"id": "Player",
"components": [
{
"type": "TransformComponent",
"position": [0.0, 0.0, -15.0],
"rotation": [0.0, 0.0, 0.0],
"scale": [1.0, 1.0, 1.0]
},
{
"type": "RigidbodyComponent",
"rigidbodyType": "Dynamic",
"mass": 1.0,
"restitution": 1.0,
"collisionShape": {
"type": "Sphere",
"radius": 1.0
}
},
{
"type": "ScriptComponent",
"script_name": "PlayerController",
"script_path": "scripts://Scene0/player.lua"
}
],
"children": [
{
"id": "Child",
"components": [
{
"type": "TransformComponent",
"position": [0.0, 5.0, -5.0],
"rotation": [0.0, 0.0, 0.0],
"scale": [1.0, 1.0, 1.0]
},
{
"type": "RigidbodyComponent",
"rigidbodyType": "Kinematic",
"mass": 1.0,
"restitution": 1.0,
"collisionShape": {
"type": "Sphere",
"radius": 1.0
}
},
{
"type": "ScriptComponent",
"script_name": "ChildController",
"script_path": "scripts://Scene0/child.lua"
}
]
}
]
},
{
"id": "Ground",
"components": [
{
"type": "TransformComponent",
"position": [0.0, -15.0, -15.0],
"rotation": [0.0, 0.0, 0.0],
"scale": [1.0, 1.0, 1.0]
},
{
"type": "RigidbodyComponent",
"rigidbodyType": "Static",
"mass": 0.0,
"restitution": 0.0,
"collisionShape": {
"type": "Sphere",
"radius": 10.0
}
}
]
}
]
}

View File

@@ -0,0 +1,18 @@
this.on_init = function()
this.speed = 0.1
end
this.on_fixedupdate = function()
if Input.getKeyDown(Input.KeyCode.Up) then
this.position = this.position + Vec3:new(0, 1, 0) * this.speed
end
if Input.getKeyDown(Input.KeyCode.Down) then
this.position = this.position - Vec3:new(0, 1, 0) * this.speed
end
if Input.getKeyDown(Input.KeyCode.Right) then
this.position = this.position + Vec3:new(1, 0, 0) * this.speed
end
if Input.getKeyDown(Input.KeyCode.Left) then
this.position = this.position - Vec3:new(1, 0, 0) * this.speed
end
end

View File

@@ -0,0 +1,14 @@
this.on_init = function ()
this.custom_eulerangles = Vec3:new()
this.custom_angularvelocity = Vec3:new(0, 0.01, 0)
end
this.on_fixedupdate = function ()
if Input.getKeyDown(Input.KeyCode.Left) then
this.custom_eulerangles:add(Vec3:new(0,0.01,0))
end
if Input.getKeyDown(Input.KeyCode.Right) then
this.custom_eulerangles:sub(Vec3:new(0,0.01,0))
end
this.eulerAngles = this.custom_eulerangles
end

View File

@@ -0,0 +1,22 @@
this.on_collisionenter = function(other)
-- other.position = other.position + Vec3:new(3.2, 0, 0)
end
this.on_update = function ()
rb = this:getComponent(Rigidbody)
if Input.getKeyDown(Input.KeyCode.Space) then
rb:addForce(Vec3:new(0, 100, 0))
end
if Input.getKeyDown(Input.KeyCode.D) then
rb:addForce(Vec3:new(10, 0, 0))
end
if Input.getKeyDown(Input.KeyCode.A) then
rb:addForce(Vec3:new(-10, 0, 0))
end
if Input.getKeyDown(Input.KeyCode.W) then
rb:addForce(Vec3:new(0, 0, -10))
end
if Input.getKeyDown(Input.KeyCode.S) then
rb:addForce(Vec3:new(0, 0, 10))
end
end

View File

@@ -0,0 +1,23 @@
this.on_init = function ()
this.custom_eulerangles = Vec3:new()
this.custom_angularvelocity = Vec3:new(0, 0.01, 0)
end
this.on_update = function ()
rb = this:getComponent(Rigidbody)
if Input.getKeyDown(Input.KeyCode.Enter) then
rb:addForce(Vec3:new(0, 100, 0))
end
if Input.getKeyDown(Input.KeyCode.Right) then
rb:addForce(Vec3:new(10, 0, 0))
end
if Input.getKeyDown(Input.KeyCode.Left) then
rb:addForce(Vec3:new(-10, 0, 0))
end
if Input.getKeyDown(Input.KeyCode.Up) then
rb:addForce(Vec3:new(0, 0, -10))
end
if Input.getKeyDown(Input.KeyCode.Down) then
rb:addForce(Vec3:new(0, 0, 10))
end
end

View File

@@ -0,0 +1,22 @@
this.on_collisionenter = function(other)
other.position = other.position + Vec3:new(0.2, 0, 0)
end
this.on_update = function ()
rb = this:getComponent(Rigidbody)
if Input.getKeyDown(Input.KeyCode.Space) then
rb:addForce(Vec3:new(0, 100, 0))
end
if Input.getKeyDown(Input.KeyCode.D) then
rb:addForce(Vec3:new(10, 0, 0))
end
if Input.getKeyDown(Input.KeyCode.A) then
rb:addForce(Vec3:new(-10, 0, 0))
end
if Input.getKeyDown(Input.KeyCode.W) then
rb:addForce(Vec3:new(0, 0, -10))
end
if Input.getKeyDown(Input.KeyCode.S) then
rb:addForce(Vec3:new(0, 0, 10))
end
end