Skip to content

Commit 7d4a10f

Browse files
committed
Add module:Celestial, refactor
1 parent 6b88b0e commit 7d4a10f

File tree

8 files changed

+66
-14
lines changed

8 files changed

+66
-14
lines changed

js/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import DOMRenderer from "./modules/DOMRenderer.js";
1010
import Physics from "./modules/Physics.js";
1111
import GameData from "./modules/GameData.js";
1212

13+
/*----- Initialize -----------------------------------------------------------*/
1314
const model = new GameData(),
1415
view = new DOMRenderer(model),
1516
physics = new Physics(model),

js/modules/Celestial.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* @file Celestial game objects.
3+
* @author Una Ada <una@anarchy.website>
4+
* @version 2021.06.02
5+
*/
6+
7+
/*----- Imports --------------------------------------------------------------*/
8+
import { Point, Vector } from "./Utils.js";
9+
10+
/*----- Classes --------------------------------------------------------------*/
11+
/** @module Celestial - Celestial game objects. */
12+
export default class Celestial {
13+
/**
14+
* Create a new celestial game object.
15+
* @arg {Object} options Optional parameters.
16+
* @arg {string} [options.name="Unnamed Celestial"] Display name.
17+
* @arg {Point} [options.position] Position coordinates in meters.
18+
* @arg {Vector} [options.velocity] Velocity vector in meters/second.
19+
* @arg {Vector} [options.acceleration] Acceleration vector in meters/second^2
20+
* @arg {number} [options.mass=0] Mass in kilograms.
21+
* @arg {number} [options.size=0] Width or diameter in meters.
22+
* @arg {ImageData} [options.texture] The texture for rendering.
23+
*/
24+
constructor(options) {
25+
/*----- Metadata ---------------------------------------------------------*/
26+
this.name = options.name || "Unnamed Celestial";
27+
/** @var {number} birth Creation timestamp. */
28+
this.birth = +new Date();
29+
30+
/*----- Physics ----------------------------------------------------------*/
31+
this.position = options.positions || new Point(0, 0);
32+
this.velocity = options.velocity || new Vector(0, 0);
33+
this.mass = options.mass || 0;
34+
/** @TODO Add HitBox class */
35+
this.hitBox = null;
36+
37+
/*----- Rendering --------------------------------------------------------*/
38+
this.size = options.size || 0;
39+
this.texture = options.texture || null;
40+
41+
}
42+
}

js/modules/DOMRenderer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
import GameData from "./GameData.js";
99
import Renderer from "./Renderer.js";
1010

11+
/*----- Classes --------------------------------------------------------------*/
1112
/** @module DOMRenderer - Manages the game view (DOM). */
1213
export default class extends Renderer {
1314
/**
1415
* Initialize a DOM-based renderer.
15-
* @param {GameData} model - A game model instance.
16+
* @arg {GameData} model - A game model instance.
1617
*/
1718
constructor(model) {
1819
super(model);

js/modules/Game.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,25 @@
55
*/
66

77
/*----- Imports --------------------------------------------------------------*/
8+
import Celestial from "./Celestial.js";
89
import GameData from "./GameData.js";
910
import Renderer from "./Renderer.js";
1011

12+
/*----- Classes --------------------------------------------------------------*/
1113
/** @module Game - Manages the game controller. */
1214
export default class Game {
1315
/**
1416
* Initialize a game controller.
15-
* @param {GameData} model - A game model instance.
16-
* @param {Renderer} view - A game view instance.
17+
* @arg {GameData} model - A game model instance.
18+
* @arg {Renderer} view - A game view instance.
1719
*/
1820
constructor(model, view) {
1921
/** @var {GameData} model - Reference to the game's model */
2022
this.model = model;
2123
/** @var {Renderer} view - Reference to the game's view */
2224
this.view = view;
25+
26+
let test = new Celestial({name: "Fuck"});
2327
}
2428

2529
/*----- Constants ----------------------------------------------------------*/
@@ -34,7 +38,7 @@ export default class Game {
3438
/*----- Event Handlers -----------------------------------------------------*/
3539
/**
3640
* Handle mouse down events
37-
* @param {MouseEvent} e - Mouse down event
41+
* @arg {MouseEvent} e - Mouse down event
3842
*/
3943
handleMouseDown(e) {
4044
let mouse = this.model.mouse;
@@ -44,7 +48,7 @@ export default class Game {
4448
}
4549
/**
4650
* Handle mouse up events
47-
* @param {MouseEvent} e - Mouse up event
51+
* @arg {MouseEvent} e - Mouse up event
4852
*/
4953
handleMouseUp(e) {
5054
let mouse = this.model.mouse;
@@ -53,7 +57,7 @@ export default class Game {
5357
}
5458
/**
5559
* Handle mouse move events
56-
* @param {MouseEvent} e - Mouse move event
60+
* @arg {MouseEvent} e - Mouse move event
5761
*/
5862
handleMouseMove(e) {
5963
this.model.mouse.position.update(e.pageX, e.pageY);

js/modules/GameData.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/*----- Imports --------------------------------------------------------------*/
88
import { Point, Vector } from "./Utils.js";
99

10+
/*----- Classes --------------------------------------------------------------*/
1011
/** @module GameData - Manages the game model. */
1112
export default class {
1213
/** Initialize a game model. */

js/modules/Physics.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* @version 2021.06.01
55
*/
66

7+
/*----- Classes --------------------------------------------------------------*/
78
/** @module Physics - Manages the physics simulation. */
89
export default class {
910
/** Initialize physics engine. */

js/modules/Renderer.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@
77
/*----- Imports --------------------------------------------------------------*/
88
import GameData from "./GameData.js";
99

10+
/*----- Classes --------------------------------------------------------------*/
1011
/** @module Renderer - Superclass for managing game view. */
1112
export default class {
1213
/**
1314
* Initialize base rendering functions.
14-
* @param {GameData} model - A game model instance.
15+
* @arg {GameData} model - A game model instance.
1516
*/
1617
constructor(model) {
1718
/** @var {GameData} model - Reference to the game's model. */
1819
this.model = model;
1920
}
2021
/**
2122
* Sets the view container
22-
* @param {HTMLElement} el - Element to set as view container.
23+
* @arg {HTMLElement} el - Element to set as view container.
2324
*/
2425
setContainer(el) {
2526
el.id = `gravity-${this.model.id}`;

js/modules/Utils.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
* @version 2021.06.02
55
*/
66

7+
/*----- Classes --------------------------------------------------------------*/
78
/** A single point in cartesian coordinated. */
89
export class Point {
910
/**
1011
* Create a single point.
11-
* @param {number} x - The point's x coordinate.
12-
* @param {number} y - The point's y coordinate.
12+
* @arg {number} x - The point's x coordinate.
13+
* @arg {number} y - The point's y coordinate.
1314
*/
1415
constructor(x, y) {
1516
/** @var {number} Point#x - The point's x coordinate. */
@@ -19,8 +20,8 @@ export class Point {
1920
}
2021
/**
2122
* Update coordinates.
22-
* @param {number} x - New x coordinate.
23-
* @param {number} y - New y coordinate.
23+
* @arg {number} x - New x coordinate.
24+
* @arg {number} y - New y coordinate.
2425
*/
2526
update(x, y) {
2627
this.x = x;
@@ -31,8 +32,8 @@ export class Point {
3132
export class Vector extends Point {
3233
/**
3334
* Create a 2-dimensional vector.
34-
* @param {number} x - The vector's x length.
35-
* @param {number} y - The vector's y length.
35+
* @arg {number} x - The vector's x length.
36+
* @arg {number} y - The vector's y length.
3637
*/
3738
constructor(x, y) {
3839
super(x, y);

0 commit comments

Comments
 (0)