Skip to content

Commit

Permalink
ingredient adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
CodedRedGIT committed Aug 19, 2024
1 parent bf8eee4 commit 126a0e8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
16 changes: 15 additions & 1 deletion ingredients/Detecting Collisions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,21 @@ import { Behavior, Entity, EntityCollision } from "@dreamlab/engine";
import HealthBar from "./health-bar.ts";
import PlayerBehavior from "./player.ts";

// Example of entity collision
/*
Handling Collisions in Game Entities:
The `EntityCollision` signal in "@dreamlab/engine"
helps detect when two entities collide. This signal provides details like whether the collision
has just started and the other entity involved.
Key Points:
- **Listening for Collisions:** Use the `listen` method to react to collision events.
- **Collision Filtering:** Handle collisions only with specific entities by checking their properties.
- **Responding to Collisions:** For example, decrease health or destroy an entity when a collision occurs.
Below is an `EnemyBehavior` that reduces health when hit by a bullet and increases the player's score if the enemy is destroyed.
*/

export default class EnemyBehavior extends Behavior {
private healthBar!: HealthBar;

Expand Down
5 changes: 2 additions & 3 deletions ingredients/Handling Input.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Behavior, BehaviorContext, Vector2 } from "@dreamlab/engine";
import { Behavior, Vector2 } from "@dreamlab/engine";
import PlayerBehavior from "./player.ts";

/*
Expand Down Expand Up @@ -43,8 +43,7 @@ export default class Movement extends Behavior {

velocity = Vector2.ZERO;

constructor(ctx: BehaviorContext) {
super(ctx);
onInitialize() {
this.defineValues(Movement, "speed");
}

Expand Down
6 changes: 2 additions & 4 deletions ingredients/Handling Local State (values).ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Behavior, BehaviorContext, Vector2 } from "@dreamlab/engine";
import { Behavior, Vector2 } from "@dreamlab/engine";

/*
Handling Values in Behaviors:
Expand Down Expand Up @@ -34,9 +34,7 @@ export default class PlayerMovement extends Behavior {
#right = this.inputs.create("@movement/right", "Move Right", "KeyD");
#boost = this.inputs.create("@movement/boost", "Speed Boost", "ShiftLeft");

constructor(ctx: BehaviorContext) {
super(ctx);

onInitialize() {
/*
Defining the `speed` value to be managed by the behavior.
- The `defineValues` method is used to specify which properties should be treated as values.
Expand Down
9 changes: 8 additions & 1 deletion ingredients/Moving Entities (scale, position, rotation).ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
// Example of changing an entities position through a behavior. This one is more basic.
import { Behavior, BehaviorContext, Vector2 } from "@dreamlab/engine";
import { Behavior, Vector2 } from "@dreamlab/engine";

/*
Key Points:
- **Basic Movement:** Calculate the new position by adding a direction vector to the current position.
- **Transform Properties:** Use properties like `position`, `rotation`, and `scale` to control entity movement and appearance.
This example moves an asteroid in a random direction at a constant speed.
*/
export default class AsteroidMovement extends Behavior {
readonly #direction = new Vector2(
Math.random() * 2 - 1,
Expand Down
5 changes: 2 additions & 3 deletions ingredients/Rendering User Interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Behavior, BehaviorContext, UILayer } from "@dreamlab/engine";
import { Behavior, UILayer } from "@dreamlab/engine";
import { element } from "@dreamlab/ui";
import { spawnPlayer } from "./start-screen.ts";

Expand Down Expand Up @@ -44,8 +44,7 @@ export default class DeathScreen extends Behavior {
#element!: HTMLDivElement;
score: number = 0;

constructor(ctx: BehaviorContext) {
super(ctx);
onInitialize() {
this.defineValues(DeathScreen, "score");
}

Expand Down

0 comments on commit 126a0e8

Please sign in to comment.