Mostly working junk camera that can do turnbased lerp smooth motion.
This commit is contained in:
parent
cbf0955786
commit
976822ceb6
3 changed files with 119 additions and 67 deletions
|
@ -345,33 +345,9 @@ bool Raycaster::empty_space(int new_x, int new_y) {
|
|||
return $map[new_y][new_x] == 0;
|
||||
}
|
||||
|
||||
|
||||
void Raycaster::run(double speed, int dir) {
|
||||
double speed_and_dir = speed * dir;
|
||||
if(empty_space(int($posX + $dirX * speed_and_dir), int($posY))) {
|
||||
$posX += $dirX * speed_and_dir;
|
||||
}
|
||||
|
||||
if(empty_space(int($posX), int($posY + $dirY * speed_and_dir))) {
|
||||
$posY += $dirY * speed_and_dir;
|
||||
}
|
||||
}
|
||||
|
||||
void Raycaster::rotate(double speed, int dir) {
|
||||
double speed_and_dir = speed * dir;
|
||||
double oldDirX = $dirX;
|
||||
$dirX = $dirX * cos(speed_and_dir) - $dirY * sin(speed_and_dir);
|
||||
$dirY = oldDirX * sin(speed_and_dir) + $dirY * cos(speed_and_dir);
|
||||
|
||||
double oldPlaneX = $planeX;
|
||||
$planeX = $planeX * cos(speed_and_dir) - $planeY * sin(speed_and_dir);
|
||||
$planeY = oldPlaneX * sin(speed_and_dir) + $planeY * cos(speed_and_dir);
|
||||
}
|
||||
|
||||
|
||||
DinkyECS::Entity Raycaster::position_sprite(Point pos, string name) {
|
||||
auto sprite_txt = $textures.sprite_textures[name];
|
||||
$sprites.emplace_back(pos.x, pos.y, sprite_txt);
|
||||
$sprites.emplace_back(pos.x + 0.5, pos.y + 0.5, sprite_txt);
|
||||
DinkyECS::Entity ent = $sprites.size() - 1;
|
||||
$collision.insert({pos.x, pos.y}, ent);
|
||||
return ent;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue