[update] Implemented clamping an actor's position.

This commit is contained in:
falsycat 2019-10-09 00:00:00 +00:00
parent 5e2623adf1
commit 5a7e710a1a
2 changed files with 23 additions and 1 deletions

View File

@ -12,6 +12,9 @@ class Actor {
speed = vec2(0, 0);
color = vec4(0, 0, 0, 0);
clip_lefttop = vec2(0, 0);
clip_rightbottom = vec2(0, 0);
program_ = program;
}
@ -20,10 +23,18 @@ class Actor {
program_.Draw(pos, speed, color);
}
///
vec2 pos;
///
vec2 speed;
///
vec4 color;
///
vec2 clip_lefttop;
///
vec2 clip_rightbottom;
private:
ActorProgram program_;
}

View File

@ -50,7 +50,13 @@ class ActorController : ActorScheduledController, ActorControllerInterface {
}
actor_.pos += actor_.speed;
// TODO: clamping the actor position
const left_edge = -1 + actor_.clip_lefttop.x;
const right_edge = 1 - actor_.clip_rightbottom.x;
const top_edge = 1 - actor_.clip_lefttop.y;
const bottom_edge = -1 + actor_.clip_rightbottom.y;
actor_.pos.x = actor_.pos.x.clamp(left_edge, right_edge);
actor_.pos.y = actor_.pos.y.clamp(bottom_edge, top_edge);
actor_.speed *= 1-SpeedAttenuation;
}
@ -72,6 +78,11 @@ private alias ActorScheduledController = ScheduledController!(
"color_g": "color.g",
"color_b": "color.b",
"color_a": "color.a",
"clip_left": "clip_lefttop.x",
"clip_top": "clip_lefttop.y",
"clip_right": "clip_rightbottom.x",
"clip_bottom": "clip_rightbottom.y",
]
);