摄像机系统,和子对象绑定
This commit is contained in:
@@ -8,10 +8,10 @@
|
||||
"input": [
|
||||
{ "action": "quit", "keys": ["Escape"] },
|
||||
{ "action": "switch_scene", "keys": ["Tab"] },
|
||||
{ "action": "move_left", "keys": ["Left"] },
|
||||
{ "action": "move_right", "keys": ["Right"] },
|
||||
{ "action": "move_up", "keys": ["Up"] },
|
||||
{ "action": "move_down", "keys": ["Down"] }
|
||||
{ "action": "move_left", "keys": ["a"] },
|
||||
{ "action": "move_right", "keys": ["d"] },
|
||||
{ "action": "move_up", "keys": ["w"] },
|
||||
{ "action": "move_down", "keys": ["s"] }
|
||||
],
|
||||
|
||||
"start_scene": "square",
|
||||
|
||||
@@ -19,10 +19,6 @@ void register_square_behaviors() {
|
||||
"square_tick",
|
||||
[](boundard::Actor& actor, float dt, const boundard::render::InputMap& input) {
|
||||
const float t = actor.age();
|
||||
actor.set_facing({
|
||||
std::cos(t * 1.5F),
|
||||
std::sin(t * 1.5F),
|
||||
});
|
||||
|
||||
if (actor.mesh() != nullptr) {
|
||||
actor.mesh()->set_color({
|
||||
@@ -34,7 +30,7 @@ void register_square_behaviors() {
|
||||
}
|
||||
|
||||
auto position = actor.position();
|
||||
const float move_speed = 0.7F;
|
||||
constexpr float move_speed = 0.7F;
|
||||
position[0] += input.get_axis("move_left", "move_right") * move_speed * dt;
|
||||
position[1] += input.get_axis("move_up", "move_down") * move_speed * dt;
|
||||
actor.set_position(position);
|
||||
@@ -54,12 +50,8 @@ void register_square_behaviors() {
|
||||
|
||||
behaviors.register_tick(
|
||||
"square_alt_tick",
|
||||
[](boundard::Actor& actor, float dt, const boundard::render::InputMap& input) {
|
||||
[](boundard::Actor& actor, const float dt, const boundard::render::InputMap& input) {
|
||||
const float t = actor.age();
|
||||
actor.set_facing({
|
||||
std::sin(t * 1.3F),
|
||||
std::cos(t * 1.3F),
|
||||
});
|
||||
|
||||
if (actor.mesh() != nullptr) {
|
||||
actor.mesh()->set_color({
|
||||
@@ -71,7 +63,7 @@ void register_square_behaviors() {
|
||||
}
|
||||
|
||||
auto position = actor.position();
|
||||
const float move_speed = 0.7F;
|
||||
constexpr float move_speed = 0.7F;
|
||||
position[0] += input.get_axis("move_left", "move_right") * move_speed * dt;
|
||||
position[1] += input.get_axis("move_up", "move_down") * move_speed * dt;
|
||||
actor.set_position(position);
|
||||
|
||||
@@ -1,21 +1,31 @@
|
||||
{
|
||||
"actors": [
|
||||
{
|
||||
"name": "square",
|
||||
"init": "square_init",
|
||||
"tick": "square_tick",
|
||||
"position": {
|
||||
"x": 0,
|
||||
"y": 0
|
||||
},
|
||||
"facing": {
|
||||
"x": 1,
|
||||
"y": 0
|
||||
},
|
||||
"mesh": {
|
||||
"shape": "quad",
|
||||
"texture": "Dank.png"
|
||||
}
|
||||
}
|
||||
]
|
||||
"default_camera": "square_camera",
|
||||
"grid_background": true,
|
||||
"actors": [
|
||||
{
|
||||
"name": "square",
|
||||
"init": "square_init",
|
||||
"tick": "square_tick",
|
||||
"position": {
|
||||
"x": 0,
|
||||
"y": 0
|
||||
},
|
||||
"facing": {
|
||||
"x": 1,
|
||||
"y": 0
|
||||
},
|
||||
"mesh": {
|
||||
"shape": "quad",
|
||||
"texture": "Dank.png"
|
||||
},
|
||||
"children": [
|
||||
{
|
||||
"name": "square_camera",
|
||||
"type": "camera",
|
||||
"position": { "x": 0, "y": 0 },
|
||||
"zoom": 0.2
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
{
|
||||
"default_camera": "square_alt_camera",
|
||||
"grid_background": true,
|
||||
"actors": [
|
||||
{
|
||||
"name": "square_alt",
|
||||
@@ -9,7 +11,15 @@
|
||||
"mesh": {
|
||||
"shape": "quad",
|
||||
"color": { "r": 0.9, "g": 0.3, "b": 0.2, "a": 1.0 }
|
||||
}
|
||||
},
|
||||
"children": [
|
||||
{
|
||||
"name": "square_alt_camera",
|
||||
"type": "camera",
|
||||
"position": { "x": 0, "y": 0 },
|
||||
"zoom": 1.0
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user