Extract player entity setup into a Player class

Moves the capsule/physics/renderable/PLAYER setup out of
overworldscene.js's inline init() into assets/scripts/Player.js so the
scene module just instantiates it.
This commit is contained in:
2026-08-02 21:06:31 -05:00
parent f8607d114c
commit 42cb84b610
2 changed files with 29 additions and 14 deletions
+26
View File
@@ -0,0 +1,26 @@
// Copyright (c) 2026 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
// Player: dynamic capsule body, moved relative to the camera by PLAYER's
// own update callback (see entityplayer.c).
class Player {
constructor() {
this.entity = new Entity();
this.position = this.entity.add(POSITION);
this.position.setLocalPosition(0.0, 2.0, 0.0);
this.physics = this.entity.add(PHYSICS);
this.physics.setShape(PHYSICS_SHAPE_CAPSULE, 0.5, 0.5);
this.renderable = this.entity.add(RENDERABLE);
this.renderable.setMesh(0, MESH_CAPSULE);
this.renderable.setColor(0, 0, 255, 255);
this.entity.add(PLAYER);
}
}
module.exports = Player;
+3 -14
View File
@@ -12,6 +12,8 @@ var CAMERA_ORBIT_RADIUS = 18.0;
var CAMERA_ORBIT_HEIGHT = 10.0;
var CAMERA_ORBIT_SPEED = 0.5;
var Player = require('./Player.js');
var cameraOrbitAngle = 0.0;
var cameraPosition = null;
@@ -55,20 +57,7 @@ module.exports = {
planeRenderable.setMesh(0, MESH_PLANE);
planeRenderable.setColor(128, 128, 128, 255);
// Player: dynamic capsule body, moved relative to the camera by
// PLAYER's own update callback (see entityplayer.c).
var player = new Entity();
var playerPosition = player.add(POSITION);
playerPosition.setLocalPosition(0.0, 2.0, 0.0);
var playerPhysics = player.add(PHYSICS);
playerPhysics.setShape(PHYSICS_SHAPE_CAPSULE, 0.5, 0.5);
var playerRenderable = player.add(RENDERABLE);
playerRenderable.setMesh(0, MESH_CAPSULE);
playerRenderable.setColor(0, 0, 255, 255);
player.add(PLAYER);
new Player();
},
// Called once per engine frame while this module is the active scene