Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Praccen committed Sep 30, 2023
1 parent c8a161a commit 619ca1e
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 40 deletions.
4 changes: 1 addition & 3 deletions code/src/Engine/ECS/Systems/ParticleSpawnerSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ export default class ParticleSpawnerSystem extends System {
e.getComponent(ComponentTypeEnum.POSITIONPARENT)
);
if (posComp == undefined) {
posComp = <PositionComponent>(
e.getComponent(ComponentTypeEnum.POSITION)
);
posComp = <PositionComponent>e.getComponent(ComponentTypeEnum.POSITION);
}

if (particleComp) {
Expand Down
48 changes: 25 additions & 23 deletions code/src/Engine/Utils/ESCUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,33 @@ import Vec3 from "../Maths/Vec3";

export module ECSUtils {
export function CalculatePosition(entity: Entity): Vec3 {
let posComp = <PositionComponent>entity.getComponent(ComponentTypeEnum.POSITION);
let posParentComp = <PositionParentComponent>entity.getComponent(ComponentTypeEnum.POSITIONPARENT);
let posComp = <PositionComponent>(
entity.getComponent(ComponentTypeEnum.POSITION)
);
let posParentComp = <PositionParentComponent>(
entity.getComponent(ComponentTypeEnum.POSITIONPARENT)
);

let tempMatrix = new Matrix4(null);
if (posComp == undefined) {
if (posParentComp == undefined) {
return null;
}
let tempMatrix = new Matrix4(null);
if (posComp == undefined) {
if (posParentComp == undefined) {
return null;
}

posParentComp.calculateMatrix(tempMatrix);
}
else {
if (posParentComp != undefined) {
posParentComp.calculateMatrix(tempMatrix);
}
posComp.calculateMatrix(tempMatrix);
}
posParentComp.calculateMatrix(tempMatrix);
} else {
if (posParentComp != undefined) {
posParentComp.calculateMatrix(tempMatrix);
}
posComp.calculateMatrix(tempMatrix);
}

let posVector = tempMatrix.multiplyVector4(new Vector4([0, 0, 0, 1]));
let pos = new Vec3()
.setValues(
posVector.elements[0],
posVector.elements[1],
posVector.elements[2]
);
return pos;
let posVector = tempMatrix.multiplyVector4(new Vector4([0, 0, 0, 1]));
let pos = new Vec3().setValues(
posVector.elements[0],
posVector.elements[1],
posVector.elements[2]
);
return pos;
}
}
30 changes: 20 additions & 10 deletions code/src/Game/PlayerCharacter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ export default class PlayerCharacter {
this.groupPositionComp.scale.setValues(0.25, 0.25, 0.25);

this.bodyEntity = this.ecsManager.createEntity();
this.ecsManager.addComponent(this.bodyEntity, new GraphicsComponent(bodyMesh));
this.ecsManager.addComponent(
this.bodyEntity,
new GraphicsComponent(bodyMesh)
);
let posComp = new PositionComponent();
posComp.rotation.y = 90.0;
this.ecsManager.addComponent(this.bodyEntity, posComp);
Expand Down Expand Up @@ -84,13 +87,21 @@ export default class PlayerCharacter {
nrOfFireParticles
);
for (let i = 0; i < nrOfFireParticles; i++) {
let dir = new Vec3([Math.random() * 8.0 - 4.0, 7.0, Math.random() * 8.0 - 4.0]);
let dir = new Vec3([
Math.random() * 8.0 - 4.0,
7.0,
Math.random() * 8.0 - 4.0,
]);
fireParticles.setParticleData(
i,
new Vec3(),
0.1,
dir,
new Vec3(dir).flip().multiply(10.0).setValues(null, 0.0, null).add(new Vec3([0.0, -8.0, 0.0]))
new Vec3(dir)
.flip()
.multiply(10.0)
.setValues(null, 0.0, null)
.add(new Vec3([0.0, -8.0, 0.0]))
);
}
fireParticles.sizeChangePerSecond = -0.2;
Expand Down Expand Up @@ -170,7 +181,7 @@ export default class PlayerCharacter {
// Handle rotation
let targetRotation =
90 - Math.atan2(accVec.z, accVec.x) * (180 / Math.PI);
let diff = targetRotation - (this.groupPositionComp.rotation.y);
let diff = targetRotation - this.groupPositionComp.rotation.y;
if (diff > 180) {
diff -= 360;
} else if (diff < -180) {
Expand Down Expand Up @@ -230,10 +241,11 @@ export default class PlayerCharacter {
);
} else if (input.joystickRightDirection.length2() > 0.0) {
this.cameraFocusComp.offset.add(
new Vec3(this.rendering.camera.getRight()).multiply(dt * 8.0 * input.joystickRightDirection.x)
new Vec3(this.rendering.camera.getRight()).multiply(
dt * 8.0 * input.joystickRightDirection.x
)
);
}
else if (this.movComp) {
} else if (this.movComp) {
this.cameraFocusComp.offset.subtract(
new Vec3(this.movComp.velocity).multiply(dt * 3.0)
);
Expand Down Expand Up @@ -290,9 +302,7 @@ export default class PlayerCharacter {
// }
}

private resetAnimation() {

}
private resetAnimation() {}

private walkAnimation(animationSpeed: number = 7.5) {
this.resetAnimation();
Expand Down
18 changes: 15 additions & 3 deletions code/src/Game/States/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ export default class Game extends State {
dirLight.direction.setValues(0.2, -0.4, -0.7);
dirLight.colour.setValues(0.1, 0.1, 0.4);

this.playerCharacter = new PlayerCharacter(this.scene, this.rendering, this.ecsManager);
this.playerCharacter = new PlayerCharacter(
this.scene,
this.rendering,
this.ecsManager
);

this.menuButton = this.overlayRendering.getNewButton();
this.menuButton.position.x = 0.9;
Expand Down Expand Up @@ -144,13 +148,21 @@ export default class Game extends State {
nrOfFireParticles
);
for (let i = 0; i < nrOfFireParticles; i++) {
let dir = new Vec3([Math.random() * 8.0 - 4.0, 2.5, Math.random() * 8.0 - 4.0]);
let dir = new Vec3([
Math.random() * 8.0 - 4.0,
2.5,
Math.random() * 8.0 - 4.0,
]);
fireParticles.setParticleData(
i,
new Vec3(),
0.1,
dir,
new Vec3(dir).flip().multiply(2.3).setValues(null, 0.0, null).add(new Vec3([0.0, 1.5, 0.0]))
new Vec3(dir)
.flip()
.multiply(2.3)
.setValues(null, 0.0, null)
.add(new Vec3([0.0, 1.5, 0.0]))
);
}
fireParticles.sizeChangePerSecond = -0.05;
Expand Down
1 change: 0 additions & 1 deletion code/src/Game/States/Menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export default class Menu extends State {
async init() {
super.init();
this.overlayRendering.show();

}

reset() {
Expand Down

0 comments on commit 619ca1e

Please sign in to comment.