| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- import { coordinates } from "./coordinates.js";
- import { position } from "./position.js";
- import { moving } from "./moving.js";
- class actor extends coordinates {
- #movement;
- #rotation;
- #speed;
- constructor() {
- super();
- this.#speed = 0.25;
- this.#movement = new moving();
- this.#rotation = new moving();
- }
- 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, scale = 2) {
- 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.");
- }
- if (typeof(scale) !== "number") {
- throw new TypeError("Scale must be an number.");
- }
- const rotate = cursor.x / size.x * 360 * scale;
- const bottom_rotate = cursor.y / size.y * 180 * scale;
-
- this.rotate_bottom(bottom_rotate);
- this.rotate_clockwise(rotate);
- }
- get movement() {
- return this.#movement;
- }
- get rotation() {
- return this.#rotation;
- }
- update() {
- this.#update_position();
- this.#update_rotation();
- }
- #update_rotation() {
- this.rotate_clockwise(this.#speed * 10 * this.rotation.z);
- }
- #update_position() {
- this.move_front(this.#speed * this.movement.y);
- this.move_right(this.#speed * this.movement.x);
- }
- }
- export { actor };
|