| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import { coordinates } from "./coordinates.js";
- import { position } from "./position.js";
- import { moving } from "./moving.js";
- import { rotating } from "./rotating.js";
- class actor extends coordinates {
- #movement;
- #rotation;
- #speed;
- constructor() {
- super();
- this.#speed = 0.25;
- this.#movement = new moving();
- this.#rotation = new rotating();
- }
- set speed(target) {
- if (typeof(target) !== "number") {
- throw new TypeError("Speed must be an number.");
- }
- this.#speed = target;
- }
- get speed() {
- return this.#speed;
- }
- rotate_cursor(cursor, size) {
- if (!(cursor instanceof position)) {
- throw new TypeError("Cursor compare must be an position object.");
- }
- if (!(size instanceof position)) {
- throw new TypeError("Size must be an position object.");
- }
- const rotate = cursor.x / size.x * 360;
- this.rotate_clockwise(rotate);
- }
- get movement() {
- return this.#movement;
- }
- get rotation() {
- return this.#rotation;
- }
- update() {
- this.#update_position();
- this.#update_rotation();
- }
- #update_rotation() {
- if (this.rotation.is_right) {
- this.rotate_clockwise(this.#speed * 10);
- }
- if (this.rotation.is_left) {
- this.rotate_counterclockwise(this.#speed * 10);
- }
- }
- #update_position() {
- if (this.movement.is_front) this.move_front(this.#speed);
- if (this.movement.is_back) this.move_back(this.#speed);
- if (this.movement.is_left) this.move_left(this.#speed);
- if (this.movement.is_right) this.move_right(this.#speed);
- }
- }
- export { actor };
|