add grass

This commit is contained in:
Elizabeth Hunt 2024-03-12 19:10:55 -06:00
parent de4f3fd2fe
commit 3d18643be0
Signed by: simponic
GPG Key ID: 52B3774857EB24B1
6 changed files with 59 additions and 11 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -46,7 +46,7 @@ export class TheAbstractionEngine {
new GridSpawner(), new GridSpawner(),
new Collision(), new Collision(),
new Life(), new Life(),
new Music(), // new Music(),
new Render(this.ctx), new Render(this.ctx),
].forEach((system) => this.game.addSystem(system)); ].forEach((system) => this.game.addSystem(system));
} }

View File

@ -22,29 +22,31 @@ export const LambdaTransformSound: SoundSpec = {
export const LambdaSave: SoundSpec = { export const LambdaSave: SoundSpec = {
name: "lambdaSave", name: "lambdaSave",
url: "/assets/sound/lambda_save.wav", url: "/assets/sound/lambda_save.wav",
volume: 0.3,
}; };
export const Failure: SoundSpec = { export const Failure: SoundSpec = {
name: "failure", name: "failure",
url: "/assets/sound/failure.wav", url: "/assets/sound/failure.wav",
volume: 0.5, volume: 0.3,
}; };
export const ModalOpen: SoundSpec = { export const ModalOpen: SoundSpec = {
name: "modalOpen", name: "modalOpen",
url: "/assets/sound/modal_open.wav", url: "/assets/sound/modal_open.wav",
volume: 0.5, volume: 0.3,
}; };
export const ModalClose: SoundSpec = { export const ModalClose: SoundSpec = {
name: "modalClose", name: "modalClose",
url: "/assets/sound/modal_close.wav", url: "/assets/sound/modal_close.wav",
volume: 0.5, volume: 0.3,
}; };
export const KeyOpen: SoundSpec = { export const KeyOpen: SoundSpec = {
name: "keyOpen", name: "keyOpen",
url: "/assets/sound/keyopen.wav", url: "/assets/sound/keyopen.wav",
volume: 0.5,
}; };
export const Music: SoundSpec = { export const Music: SoundSpec = {

View File

@ -1,5 +1,5 @@
import { Entity, EntityNames } from "."; import { Entity, EntityNames } from ".";
import { Grid, Sprite } from "../components"; import { BoundingBox, Grid, Sprite } from "../components";
import { IMAGES, SPRITE_SPECS, SpriteSpec, Sprites } from "../config"; import { IMAGES, SPRITE_SPECS, SpriteSpec, Sprites } from "../config";
import { Coord2D } from "../interfaces"; import { Coord2D } from "../interfaces";
@ -11,17 +11,28 @@ export class Grass extends Entity {
this.addComponent(new Grid(gridPosition)); this.addComponent(new Grid(gridPosition));
const dimensions = {
width: Grass.spriteSpec.width,
height: Grass.spriteSpec.height,
};
this.addComponent( this.addComponent(
new Sprite( new Sprite(
IMAGES.get(Grass.spriteSpec.sheet)!, IMAGES.get(Grass.spriteSpec.sheet)!,
{ x: 0, y: 0 }, { x: 0, y: 0 },
{ dimensions,
width: Grass.spriteSpec.width,
height: Grass.spriteSpec.height,
},
Grass.spriteSpec.msPerFrame, Grass.spriteSpec.msPerFrame,
Grass.spriteSpec.frames, Grass.spriteSpec.frames,
), ),
); );
this.addComponent(
new BoundingBox(
{
x: 0,
y: 0,
},
dimensions,
),
);
} }
} }

View File

@ -3,21 +3,49 @@ import { Game } from "..";
import { import {
Curry, Curry,
FunctionApplication, FunctionApplication,
Grass,
LambdaFactory, LambdaFactory,
LockedDoor, LockedDoor,
Player, Player,
Sign, Sign,
Wall, Wall,
} from "../entities"; } from "../entities";
import { Grid, SystemNames } from "../systems";
import { normalRandom } from "../utils";
export class Tutorial extends Level { export class Tutorial extends Level {
constructor() { constructor() {
super(LevelNames.Tutorial); super(LevelNames.Tutorial);
} }
public init(game: Game): void { public init(game: Game) {
const grid = game.getSystem<Grid>(SystemNames.Grid);
const dimensions = grid.getGridDimensions();
const grasses = Array.from({ length: dimensions.width })
.fill(0)
.map(() => {
// random grass
return new Grass({
x: Math.floor(
normalRandom(dimensions.width / 2, dimensions.width / 4, 1.5),
),
y: Math.floor(
normalRandom(dimensions.height / 2, dimensions.height / 4, 1.5),
),
});
});
const entities = [ const entities = [
new Sign("TODO: Explain entities", { x: 4, y: 3 }), ...grasses,
new Sign(
"this is a Lambda Factory<br><br>modify the produced term by interacting from the top or bottom ↕️<br><br>then produce the term by pressing the button on the left or right ↔️<br><br>",
{ x: 4, y: 3 },
),
new Sign(
"this is a Term Application; interact to view its code<br><br>push the term ➡️ created by the factory any direction into the Application to produce a new one 💭<br><br>. _INPUT is the term replaced by the pushed term<br><br>. in this case _KEY is applied to the function to make a new KEY! 🔑",
{ x: 4, y: 6 },
),
new Wall({ x: 10, y: 9 }), new Wall({ x: 10, y: 9 }),
new Wall({ x: 10, y: 11 }), new Wall({ x: 10, y: 11 }),
new Wall({ x: 11, y: 10 }), new Wall({ x: 11, y: 10 }),

View File

@ -28,6 +28,13 @@ export class Grid extends System {
.map(() => new Array(columns).fill(null).map(() => new Set())); .map(() => new Array(columns).fill(null).map(() => new Set()));
} }
public getGridDimensions() {
return {
width: this.grid[0].length,
height: this.grid.length,
};
}
public update(dt: number, game: Game) { public update(dt: number, game: Game) {
this.putUninitializedEntitiesInGrid(game); this.putUninitializedEntitiesInGrid(game);
this.rebuildGrid(game); this.rebuildGrid(game);