Checkpoint 2: integrate native Editor, MCP, gameplay builds and standalone export
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
#include "Gameplay.hpp"
|
||||
#include <iostream>
|
||||
|
||||
namespace faset::gameplay {
|
||||
void registerGameplay(runtime::Runtime& world) {
|
||||
runtime::Behavior character;
|
||||
character.fixedUpdate = [](runtime::Runtime& game, runtime::EntityHandle self, double) {
|
||||
const auto settings = game.fields(self, "tutorial.character");
|
||||
const auto input = game.input();
|
||||
auto velocity = game.velocity(self); // Metres per second; preserve the Y component.
|
||||
velocity[0] = input.horizontal * settings.value("speed", 4.0f);
|
||||
if (input.jumpPressed && game.grounded(self))
|
||||
velocity[1] = settings.value("jump_speed", 5.0f);
|
||||
// Do not multiply velocity by delta. The physics solver integrates it.
|
||||
game.setVelocity(self, velocity);
|
||||
};
|
||||
character.onCollision = [](runtime::Runtime&, runtime::EntityHandle,
|
||||
const runtime::CollisionEvent& event) {
|
||||
if (event.began)
|
||||
std::cout << "Character contact began\n";
|
||||
};
|
||||
world.registerBehavior("tutorial.character", std::move(character));
|
||||
}
|
||||
|
||||
nlohmann::json schema() {
|
||||
return nlohmann::json::array({{{"id", "tutorial.character"},
|
||||
{"version", 1},
|
||||
{"name", "Physics character"},
|
||||
{"fields",
|
||||
{{"speed",
|
||||
{{"id", "speed"},
|
||||
{"type", "number"},
|
||||
{"default", 4.0},
|
||||
{"min", 0.0},
|
||||
{"units", "m/s"}}},
|
||||
{"jump_speed",
|
||||
{{"id", "jump_speed"},
|
||||
{"type", "number"},
|
||||
{"default", 5.0},
|
||||
{"min", 0.0},
|
||||
{"units", "m/s"}}}}}}});
|
||||
}
|
||||
} // namespace faset::gameplay
|
||||
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
#include <faset/runtime/Runtime.hpp>
|
||||
|
||||
namespace faset::gameplay {
|
||||
void registerGameplay(runtime::Runtime& world);
|
||||
nlohmann::json schema();
|
||||
} // namespace faset::gameplay
|
||||
@@ -0,0 +1,148 @@
|
||||
{
|
||||
"format": "faset.scene",
|
||||
"version": 1,
|
||||
"id": "tutorial-physics",
|
||||
"name": "Physics tutorial",
|
||||
"dimension": 2,
|
||||
"simulation": {
|
||||
"fixed_delta": 0.016666666666666666,
|
||||
"max_catch_up_ticks": 4,
|
||||
"physics_substeps": 4,
|
||||
"gravity": [
|
||||
0,
|
||||
-9.81,
|
||||
0
|
||||
]
|
||||
},
|
||||
"entities": [
|
||||
{
|
||||
"id": "floor",
|
||||
"name": "floor",
|
||||
"parent": null,
|
||||
"components": [
|
||||
{
|
||||
"id": "floor-faset.transform",
|
||||
"type": "faset.transform",
|
||||
"version": 1,
|
||||
"fields": {
|
||||
"position": [
|
||||
0,
|
||||
-0.5,
|
||||
0
|
||||
],
|
||||
"rotation": [
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"scale": [
|
||||
1,
|
||||
1,
|
||||
1
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "floor-faset.sprite",
|
||||
"type": "faset.sprite",
|
||||
"version": 1,
|
||||
"fields": {
|
||||
"color": [
|
||||
0.4,
|
||||
0.5,
|
||||
0.6,
|
||||
1
|
||||
],
|
||||
"size": [
|
||||
12,
|
||||
1
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "floor-faset.rigid_body_2d",
|
||||
"type": "faset.rigid_body_2d",
|
||||
"version": 1,
|
||||
"fields": {
|
||||
"body_type": "static",
|
||||
"half_extents": [
|
||||
6,
|
||||
0.5
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "actor",
|
||||
"name": "actor",
|
||||
"parent": null,
|
||||
"components": [
|
||||
{
|
||||
"id": "actor-faset.transform",
|
||||
"type": "faset.transform",
|
||||
"version": 1,
|
||||
"fields": {
|
||||
"position": [
|
||||
0,
|
||||
0.5,
|
||||
0
|
||||
],
|
||||
"rotation": [
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"scale": [
|
||||
1,
|
||||
1,
|
||||
1
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "actor-faset.sprite",
|
||||
"type": "faset.sprite",
|
||||
"version": 1,
|
||||
"fields": {
|
||||
"color": [
|
||||
0.2,
|
||||
0.7,
|
||||
0.9,
|
||||
1
|
||||
],
|
||||
"size": [
|
||||
1,
|
||||
1
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "actor-faset.rigid_body_2d",
|
||||
"type": "faset.rigid_body_2d",
|
||||
"version": 1,
|
||||
"fields": {
|
||||
"body_type": "dynamic",
|
||||
"half_extents": [
|
||||
0.5,
|
||||
0.5
|
||||
],
|
||||
"density": 1,
|
||||
"friction": 0.3,
|
||||
"gravity_scale": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "actor-tutorial.character",
|
||||
"type": "tutorial.character",
|
||||
"version": 1,
|
||||
"fields": {
|
||||
"speed": 4,
|
||||
"jump_speed": 5
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"instances": []
|
||||
}
|
||||
Reference in New Issue
Block a user