mustachio-game 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/.github/workflows/pr.yaml +0 -21
- package/.github/workflows/push.yaml +0 -26
- package/eslint.config.ts +0 -17
- package/index.html +0 -22
- package/src/assets/Mustachio.webp +0 -0
- package/src/assets/Mustachio_FacingLeft.webp +0 -0
- package/src/assets/Mustachio_FacingLeft_Fire.webp +0 -0
- package/src/assets/Mustachio_FacingRight.webp +0 -0
- package/src/assets/Mustachio_FacingRight_Fire.webp +0 -0
- package/src/assets/Mustachio_Fire.webp +0 -0
- package/src/assets/brick.webp +0 -0
- package/src/assets/cannonDown.webp +0 -0
- package/src/assets/cannonLeft.webp +0 -0
- package/src/assets/cannonRight.webp +0 -0
- package/src/assets/cannonUp.webp +0 -0
- package/src/assets/fallingFloor.webp +0 -0
- package/src/assets/homestead.webp +0 -0
- package/src/assets/homesteadClosed.webp +0 -0
- package/src/assets/itemBlock.webp +0 -0
- package/src/assets/obstacleBrick.webp +0 -0
- package/src/assets/punchedBlock.webp +0 -0
- package/src/assets/stacheSeed1.webp +0 -0
- package/src/assets/stacheSeed2.webp +0 -0
- package/src/assets/stacheSeedReversed1.webp +0 -0
- package/src/assets/stacheSeedReversed2.webp +0 -0
- package/src/assets/stacheShotDown.webp +0 -0
- package/src/assets/stacheShotLeft.webp +0 -0
- package/src/assets/stacheShotRight.webp +0 -0
- package/src/assets/stacheShotUp.webp +0 -0
- package/src/assets/stacheSlinger1.webp +0 -0
- package/src/assets/stacheSlinger2.webp +0 -0
- package/src/assets/stacheStalker.webp +0 -0
- package/src/assets/stacheStalkerReversed.webp +0 -0
- package/src/assets/stacheStreaker1.webp +0 -0
- package/src/assets/stacheStreaker2.webp +0 -0
- package/src/classes/game-objects/bg-objects/background.ts +0 -18
- package/src/classes/game-objects/bg-objects/cloud.ts +0 -37
- package/src/classes/game-objects/mustachio.ts +0 -482
- package/src/classes/game-objects/point-objects/enemies/enemy.ts +0 -64
- package/src/classes/game-objects/point-objects/enemies/stache-seed.ts +0 -124
- package/src/classes/game-objects/point-objects/enemies/stache-shot.ts +0 -68
- package/src/classes/game-objects/point-objects/enemies/stache-slinger.ts +0 -63
- package/src/classes/game-objects/point-objects/enemies/stache-stalker.ts +0 -41
- package/src/classes/game-objects/point-objects/enemies/stache-streaker.ts +0 -78
- package/src/classes/game-objects/point-objects/items/coin.ts +0 -72
- package/src/classes/game-objects/point-objects/items/fire-stache.ts +0 -48
- package/src/classes/game-objects/point-objects/items/item.ts +0 -27
- package/src/classes/game-objects/point-objects/items/stacheroom.ts +0 -48
- package/src/classes/game-objects/point-objects/point-item.ts +0 -10
- package/src/classes/game-objects/projectiles/brick-debris.ts +0 -44
- package/src/classes/game-objects/projectiles/enemy-projectiles/enemy-projectile.ts +0 -3
- package/src/classes/game-objects/projectiles/enemy-projectiles/fire-ball.ts +0 -87
- package/src/classes/game-objects/projectiles/enemy-projectiles/fire-bar.ts +0 -65
- package/src/classes/game-objects/projectiles/enemy-projectiles/fire-cross.ts +0 -67
- package/src/classes/game-objects/projectiles/enemy-projectiles/laser.ts +0 -41
- package/src/classes/game-objects/projectiles/projectile.ts +0 -3
- package/src/classes/game-objects/projectiles/stache-ball.ts +0 -57
- package/src/classes/game-objects/set-pieces/flag.ts +0 -34
- package/src/classes/game-objects/set-pieces/obstacles/blocks/block.ts +0 -17
- package/src/classes/game-objects/set-pieces/obstacles/blocks/cave-wall.ts +0 -21
- package/src/classes/game-objects/set-pieces/obstacles/blocks/falling-floor.ts +0 -65
- package/src/classes/game-objects/set-pieces/obstacles/blocks/fire-bar-block.ts +0 -31
- package/src/classes/game-objects/set-pieces/obstacles/blocks/fire-cross-block.ts +0 -28
- package/src/classes/game-objects/set-pieces/obstacles/blocks/punchable-blockS/brick.ts +0 -44
- package/src/classes/game-objects/set-pieces/obstacles/blocks/punchable-blockS/item-block.ts +0 -82
- package/src/classes/game-objects/set-pieces/obstacles/blocks/punchable-blockS/punchable-block.ts +0 -6
- package/src/classes/game-objects/set-pieces/obstacles/blocks/stache-cannon.ts +0 -54
- package/src/classes/game-objects/set-pieces/obstacles/blocks/wall.ts +0 -22
- package/src/classes/game-objects/set-pieces/obstacles/floor.ts +0 -27
- package/src/classes/game-objects/set-pieces/obstacles/obstacle-types.ts +0 -14
- package/src/classes/game-objects/set-pieces/obstacles/obstacle.ts +0 -3
- package/src/classes/game-objects/set-pieces/obstacles/pipe.ts +0 -35
- package/src/classes/game-objects/set-pieces/obstacles/warp-pipe.ts +0 -17
- package/src/classes/game-objects/set-pieces/set-piece.ts +0 -3
- package/src/classes/game-objects/ui-objects/score-display.ts +0 -10
- package/src/classes/game-objects/ui-objects/timer-display.ts +0 -15
- package/src/classes/game-objects/ui-objects/ui-object.ts +0 -16
- package/src/classes/game-objects/ui-objects/win-display.ts +0 -25
- package/src/dev.ts +0 -5
- package/src/index.ts +0 -3
- package/src/levels/caves/cave-one.ts +0 -90
- package/src/levels/level-helpers.ts +0 -101
- package/src/levels/level-one.ts +0 -379
- package/src/levels/test-levels/blocks-and-items.ts +0 -77
- package/src/levels/test-levels/cannon-and-cross.ts +0 -75
- package/src/levels/test-levels/caves-and-enemies.ts +0 -73
- package/src/levels/test-levels/win-game.ts +0 -24
- package/src/main.ts +0 -6
- package/src/mustachi-game-context.ts +0 -35
- package/src/shared/app-code.ts +0 -106
- package/src/shared/constants.ts +0 -1
- package/src/shared/game-context.ts +0 -547
- package/src/shared/game-objects/game-object.ts +0 -28
- package/src/shared/game-objects/moving-game-object.ts +0 -46
- package/src/shared/game-objects/rotating-game-object.ts +0 -58
- package/src/shared/game-objects/updating-game-object.ts +0 -7
- package/src/shared/player.ts +0 -73
- package/src/shared/types.ts +0 -21
- package/tsconfig.json +0 -26
- package/vite.config.ts +0 -13
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { BLOCK_SIZE } from "../../shared/constants";
|
|
2
|
-
import type { GameContext } from "../../shared/game-context";
|
|
3
|
-
import { StacheStalker } from "../../classes/game-objects/point-objects/enemies/stache-stalker";
|
|
4
|
-
import { Coin } from "../../classes/game-objects/point-objects/items/coin";
|
|
5
|
-
import { FireBarBlock } from "../../classes/game-objects/set-pieces/obstacles/blocks/fire-bar-block";
|
|
6
|
-
import { ItemBlock } from "../../classes/game-objects/set-pieces/obstacles/blocks/punchable-blockS/item-block";
|
|
7
|
-
import { Wall } from "../../classes/game-objects/set-pieces/obstacles/blocks/wall";
|
|
8
|
-
import { Floor } from "../../classes/game-objects/set-pieces/obstacles/floor";
|
|
9
|
-
import { Brick } from "../../classes/game-objects/set-pieces/obstacles/blocks/punchable-blockS/brick";
|
|
10
|
-
|
|
11
|
-
export function testLevelBlocksAndItems(gameContext: GameContext) {
|
|
12
|
-
gameContext.clearLevel();
|
|
13
|
-
|
|
14
|
-
gameContext.addGameObject(
|
|
15
|
-
new Floor(gameContext, {
|
|
16
|
-
x: 0,
|
|
17
|
-
y: BLOCK_SIZE * 17,
|
|
18
|
-
width: BLOCK_SIZE * 32,
|
|
19
|
-
height: BLOCK_SIZE,
|
|
20
|
-
}),
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
// The game canvas is 32 blocks wide
|
|
24
|
-
// and 18 blocks tall
|
|
25
|
-
|
|
26
|
-
const touchingFloor = BLOCK_SIZE * 16;
|
|
27
|
-
|
|
28
|
-
gameContext.addGameObject(
|
|
29
|
-
new Wall(gameContext, BLOCK_SIZE * 14, touchingFloor),
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
gameContext.addGameObject(
|
|
33
|
-
new Wall(gameContext, BLOCK_SIZE * 22, touchingFloor),
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
gameContext.addGameObject(
|
|
37
|
-
new StacheStalker(gameContext, BLOCK_SIZE * 16, BLOCK_SIZE * 15),
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
gameContext.addGameObject(
|
|
41
|
-
new Coin(gameContext, BLOCK_SIZE * 18, BLOCK_SIZE * 14),
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
gameContext.addGameObject(
|
|
45
|
-
new Brick(gameContext, BLOCK_SIZE * 11, BLOCK_SIZE * 14),
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
gameContext.addGameObject(
|
|
49
|
-
new ItemBlock(gameContext, BLOCK_SIZE * 12, BLOCK_SIZE * 14, false, "coin"),
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
gameContext.addGameObject(
|
|
53
|
-
new ItemBlock(
|
|
54
|
-
gameContext,
|
|
55
|
-
BLOCK_SIZE * 10,
|
|
56
|
-
BLOCK_SIZE * 14,
|
|
57
|
-
false,
|
|
58
|
-
"stacheroom",
|
|
59
|
-
),
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
gameContext.addGameObject(
|
|
63
|
-
new ItemBlock(
|
|
64
|
-
gameContext,
|
|
65
|
-
BLOCK_SIZE * 10,
|
|
66
|
-
BLOCK_SIZE * 11,
|
|
67
|
-
true,
|
|
68
|
-
"fire-stache",
|
|
69
|
-
),
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
gameContext.addGameObject(
|
|
73
|
-
new FireBarBlock(gameContext, BLOCK_SIZE * 18, BLOCK_SIZE * 12),
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
gameContext.startMainLoop();
|
|
77
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { BLOCK_SIZE } from "../../shared/constants";
|
|
2
|
-
import type { GameContext } from "../../shared/game-context";
|
|
3
|
-
import { direction } from "../../shared/types";
|
|
4
|
-
import { FallingFloor } from "../../classes/game-objects/set-pieces/obstacles/blocks/falling-floor";
|
|
5
|
-
import { FireCrossBlock } from "../../classes/game-objects/set-pieces/obstacles/blocks/fire-cross-block";
|
|
6
|
-
import { StacheCannon } from "../../classes/game-objects/set-pieces/obstacles/blocks/stache-cannon";
|
|
7
|
-
import { Floor } from "../../classes/game-objects/set-pieces/obstacles/floor";
|
|
8
|
-
|
|
9
|
-
export function testLevelCannonAndCross(gameContext: GameContext) {
|
|
10
|
-
gameContext.clearLevel();
|
|
11
|
-
|
|
12
|
-
gameContext.addGameObject(
|
|
13
|
-
new Floor(gameContext, {
|
|
14
|
-
x: 0,
|
|
15
|
-
y: BLOCK_SIZE * 17,
|
|
16
|
-
width: BLOCK_SIZE * 13,
|
|
17
|
-
height: BLOCK_SIZE,
|
|
18
|
-
}),
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
gameContext.addGameObject(
|
|
22
|
-
new FallingFloor(gameContext, BLOCK_SIZE * 14, BLOCK_SIZE * 17),
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
gameContext.addGameObject(
|
|
26
|
-
new Floor(gameContext, {
|
|
27
|
-
x: BLOCK_SIZE * 15,
|
|
28
|
-
y: BLOCK_SIZE * 17,
|
|
29
|
-
width: BLOCK_SIZE * 17,
|
|
30
|
-
height: BLOCK_SIZE,
|
|
31
|
-
}),
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
// gameContext.addGameObject(
|
|
35
|
-
// new StacheCannon(
|
|
36
|
-
// gameContext,
|
|
37
|
-
// BLOCK_SIZE * 16,
|
|
38
|
-
// BLOCK_SIZE * 16,
|
|
39
|
-
// direction.LEFT,
|
|
40
|
-
// ),
|
|
41
|
-
// )
|
|
42
|
-
|
|
43
|
-
gameContext.addGameObject(
|
|
44
|
-
new StacheCannon(
|
|
45
|
-
gameContext,
|
|
46
|
-
BLOCK_SIZE * 16,
|
|
47
|
-
BLOCK_SIZE * 15,
|
|
48
|
-
direction.RIGHT,
|
|
49
|
-
),
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
gameContext.addGameObject(
|
|
53
|
-
new StacheCannon(
|
|
54
|
-
gameContext,
|
|
55
|
-
BLOCK_SIZE * 16,
|
|
56
|
-
BLOCK_SIZE * 14,
|
|
57
|
-
direction.UP,
|
|
58
|
-
),
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
gameContext.addGameObject(
|
|
62
|
-
new StacheCannon(gameContext, BLOCK_SIZE * 15, 0, direction.DOWN),
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
gameContext.addGameObject(
|
|
66
|
-
new FireCrossBlock(gameContext, BLOCK_SIZE * 8, BLOCK_SIZE * 12, [
|
|
67
|
-
direction.UP,
|
|
68
|
-
direction.DOWN,
|
|
69
|
-
direction.LEFT,
|
|
70
|
-
direction.RIGHT,
|
|
71
|
-
]),
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
gameContext.startMainLoop();
|
|
75
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { BLOCK_SIZE } from "../../shared/constants";
|
|
2
|
-
import type { GameContext } from "../../shared/game-context";
|
|
3
|
-
import { StacheSlinger } from "../../classes/game-objects/point-objects/enemies/stache-slinger";
|
|
4
|
-
import { StacheStreaker } from "../../classes/game-objects/point-objects/enemies/stache-streaker";
|
|
5
|
-
import { Floor } from "../../classes/game-objects/set-pieces/obstacles/floor";
|
|
6
|
-
import { Pipe } from "../../classes/game-objects/set-pieces/obstacles/pipe";
|
|
7
|
-
import { WarpPipe } from "../../classes/game-objects/set-pieces/obstacles/warp-pipe";
|
|
8
|
-
import { caveOne } from "../caves/cave-one";
|
|
9
|
-
|
|
10
|
-
export function testLevelCaveAndEnemies(
|
|
11
|
-
gameContext: GameContext,
|
|
12
|
-
previousLevels: string[] = [],
|
|
13
|
-
) {
|
|
14
|
-
gameContext.clearLevel();
|
|
15
|
-
|
|
16
|
-
if (previousLevels.includes("caveOne")) {
|
|
17
|
-
gameContext.setPlayerLocation(BLOCK_SIZE * 18.5, BLOCK_SIZE * 2.5);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
gameContext.addGameObject(
|
|
21
|
-
new Floor(gameContext, {
|
|
22
|
-
x: 0,
|
|
23
|
-
y: BLOCK_SIZE * 17,
|
|
24
|
-
width: BLOCK_SIZE * 32,
|
|
25
|
-
height: BLOCK_SIZE,
|
|
26
|
-
}),
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
// The game canvas is 32 blocks wide
|
|
30
|
-
// and 18 blocks tall
|
|
31
|
-
|
|
32
|
-
const touchingFloor = BLOCK_SIZE * 16;
|
|
33
|
-
|
|
34
|
-
let pipe: Pipe;
|
|
35
|
-
if (previousLevels.includes("caveOne")) {
|
|
36
|
-
pipe = new Pipe(gameContext, {
|
|
37
|
-
x: BLOCK_SIZE * 10,
|
|
38
|
-
y: touchingFloor,
|
|
39
|
-
hasStacheSeed: true,
|
|
40
|
-
});
|
|
41
|
-
} else {
|
|
42
|
-
pipe = new WarpPipe(gameContext, {
|
|
43
|
-
x: BLOCK_SIZE * 10,
|
|
44
|
-
y: touchingFloor,
|
|
45
|
-
hasStacheSeed: true,
|
|
46
|
-
setNewLevel: (gc) => caveOne(gc, [...previousLevels, "testLevelTwo"]),
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
gameContext.addGameObject(pipe);
|
|
51
|
-
|
|
52
|
-
gameContext.addGameObject(
|
|
53
|
-
(pipe = new Pipe(gameContext, {
|
|
54
|
-
x: BLOCK_SIZE * 12,
|
|
55
|
-
y: touchingFloor,
|
|
56
|
-
hasStacheSeed: true,
|
|
57
|
-
})),
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
gameContext.addGameObject(
|
|
61
|
-
new Pipe(gameContext, { x: BLOCK_SIZE * 18, y: 0 }),
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
gameContext.addGameObject(
|
|
65
|
-
new StacheSlinger(gameContext, BLOCK_SIZE * 5, BLOCK_SIZE * 2),
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
gameContext.addGameObject(
|
|
69
|
-
new StacheStreaker(gameContext, BLOCK_SIZE * 10, BLOCK_SIZE * 2),
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
gameContext.startMainLoop();
|
|
73
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { BLOCK_SIZE } from "../../shared/constants";
|
|
2
|
-
import type { GameContext } from "../../shared/game-context";
|
|
3
|
-
import { Floor } from "../../classes/game-objects/set-pieces/obstacles/floor";
|
|
4
|
-
import { Flag } from "../../classes/game-objects/set-pieces/flag";
|
|
5
|
-
|
|
6
|
-
export function testLevelWinGame(gameContext: GameContext) {
|
|
7
|
-
gameContext.clearLevel();
|
|
8
|
-
|
|
9
|
-
gameContext.addGameObject(
|
|
10
|
-
new Floor(gameContext, {
|
|
11
|
-
x: 0,
|
|
12
|
-
y: BLOCK_SIZE * 17,
|
|
13
|
-
width: BLOCK_SIZE * 32,
|
|
14
|
-
height: BLOCK_SIZE,
|
|
15
|
-
}),
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
gameContext.addGameObject(
|
|
19
|
-
new Flag(gameContext, BLOCK_SIZE * 16, BLOCK_SIZE * 9),
|
|
20
|
-
true,
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
gameContext.startMainLoop();
|
|
24
|
-
}
|
package/src/main.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { BLOCK_SIZE } from "./shared/constants";
|
|
2
|
-
import { GameContext } from "./shared/game-context";
|
|
3
|
-
import { Background } from "./classes/game-objects/bg-objects/background";
|
|
4
|
-
import { Cloud } from "./classes/game-objects/bg-objects/cloud";
|
|
5
|
-
import { Mustachio } from "./classes/game-objects/mustachio";
|
|
6
|
-
import { ScoreDisplay } from "./classes/game-objects/ui-objects/score-display";
|
|
7
|
-
import { TimerDisplay } from "./classes/game-objects/ui-objects/timer-display";
|
|
8
|
-
|
|
9
|
-
export class MustachioGameContext extends GameContext {
|
|
10
|
-
protected timeDisplay: TimerDisplay;
|
|
11
|
-
protected scoreDisplay: ScoreDisplay;
|
|
12
|
-
protected readonly gameName = "Mustachio";
|
|
13
|
-
protected readonly player: Mustachio;
|
|
14
|
-
|
|
15
|
-
constructor(containerId: string) {
|
|
16
|
-
super(containerId);
|
|
17
|
-
|
|
18
|
-
// Start mustachio with default position
|
|
19
|
-
this.player = new Mustachio(this, BLOCK_SIZE * 4, BLOCK_SIZE * 13);
|
|
20
|
-
this.addGameObject(this.player);
|
|
21
|
-
|
|
22
|
-
// Add score and timer displays
|
|
23
|
-
this.scoreDisplay = new ScoreDisplay(this, BLOCK_SIZE, BLOCK_SIZE);
|
|
24
|
-
this.timeDisplay = new TimerDisplay(this, BLOCK_SIZE * 28, BLOCK_SIZE);
|
|
25
|
-
this.scoreDisplay.draw(this.uiContext);
|
|
26
|
-
this.timeDisplay.draw(this.uiContext);
|
|
27
|
-
|
|
28
|
-
this.addBgObject(new Background(this));
|
|
29
|
-
this.addBgObject(new Cloud(this, BLOCK_SIZE * 2, BLOCK_SIZE * 2));
|
|
30
|
-
this.addBgObject(new Cloud(this, BLOCK_SIZE * 8, BLOCK_SIZE * 3));
|
|
31
|
-
this.addBgObject(new Cloud(this, BLOCK_SIZE * 15, BLOCK_SIZE * 1));
|
|
32
|
-
this.addBgObject(new Cloud(this, BLOCK_SIZE * 23, BLOCK_SIZE * 4));
|
|
33
|
-
this.addBgObject(new Cloud(this, BLOCK_SIZE * 27, BLOCK_SIZE * 2));
|
|
34
|
-
}
|
|
35
|
-
}
|
package/src/shared/app-code.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import type { GameContext } from "./game-context";
|
|
2
|
-
import type { GameObject } from "./game-objects/game-object";
|
|
3
|
-
import { direction } from "./types";
|
|
4
|
-
import { Player } from "./player";
|
|
5
|
-
|
|
6
|
-
export function collisionDetection(
|
|
7
|
-
go1: GameObject,
|
|
8
|
-
go2: GameObject,
|
|
9
|
-
xOffset: number,
|
|
10
|
-
) {
|
|
11
|
-
const rect1 = go1.rect;
|
|
12
|
-
const rect2 = go2.rect;
|
|
13
|
-
|
|
14
|
-
let x = rect1.x;
|
|
15
|
-
if (!(go1 instanceof Player)) {
|
|
16
|
-
x += xOffset;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
let x2 = rect2.x;
|
|
20
|
-
if (!(go2 instanceof Player)) {
|
|
21
|
-
x2 += xOffset;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return (
|
|
25
|
-
x < x2 + rect2.width &&
|
|
26
|
-
x + rect1.width > x2 &&
|
|
27
|
-
rect1.y < rect2.y + rect2.height &&
|
|
28
|
-
rect1.y + rect1.height > rect2.y
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function getCollisionDirection(
|
|
33
|
-
go1: GameObject,
|
|
34
|
-
go2: GameObject,
|
|
35
|
-
xOffset: number,
|
|
36
|
-
): number | null {
|
|
37
|
-
if (!collisionDetection(go1, go2, xOffset)) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const rect1 = go1.rect;
|
|
42
|
-
const rect2 = go2.rect;
|
|
43
|
-
|
|
44
|
-
let x = rect1.x;
|
|
45
|
-
if (!(go1 instanceof Player)) {
|
|
46
|
-
x += xOffset;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
let x2 = rect2.x;
|
|
50
|
-
if (!(go2 instanceof Player)) {
|
|
51
|
-
x2 += xOffset;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const dx = x + rect1.width / 2 - (x2 + rect2.width / 2);
|
|
55
|
-
const dy = rect1.y + rect1.height / 2 - (rect2.y + rect2.height / 2);
|
|
56
|
-
|
|
57
|
-
const width = (rect1.width + rect2.width) / 2;
|
|
58
|
-
const height = (rect1.height + rect2.height) / 2;
|
|
59
|
-
|
|
60
|
-
const crossWidth = width * dy;
|
|
61
|
-
const crossHeight = height * dx;
|
|
62
|
-
|
|
63
|
-
if (Math.abs(dx) <= width && Math.abs(dy) <= height) {
|
|
64
|
-
if (crossWidth > crossHeight) {
|
|
65
|
-
return crossWidth > -crossHeight ? direction.UP : direction.LEFT;
|
|
66
|
-
} else {
|
|
67
|
-
return crossWidth > -crossHeight ? direction.RIGHT : direction.DOWN;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function getReverseDirection(dir: number) {
|
|
75
|
-
switch (dir) {
|
|
76
|
-
case direction.UP:
|
|
77
|
-
return direction.DOWN;
|
|
78
|
-
case direction.DOWN:
|
|
79
|
-
return direction.UP;
|
|
80
|
-
case direction.LEFT:
|
|
81
|
-
return direction.RIGHT;
|
|
82
|
-
case direction.RIGHT:
|
|
83
|
-
return direction.LEFT;
|
|
84
|
-
default:
|
|
85
|
-
return direction.NONE;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export function outOfBounds(go: GameObject, gameContext: GameContext) {
|
|
90
|
-
const maxX = gameContext.gameArea.width * 2;
|
|
91
|
-
const minX = -gameContext.gameArea.width / 2;
|
|
92
|
-
const maxY = gameContext.gameArea.height;
|
|
93
|
-
const minY = -gameContext.gameArea.height / 2;
|
|
94
|
-
|
|
95
|
-
let x = go.rect.x;
|
|
96
|
-
if (!(go instanceof Player)) {
|
|
97
|
-
x += gameContext.xOffset;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return (
|
|
101
|
-
x + go.rect.width < minX ||
|
|
102
|
-
x > maxX ||
|
|
103
|
-
go.rect.y + go.rect.height < minY ||
|
|
104
|
-
go.rect.y > maxY
|
|
105
|
-
);
|
|
106
|
-
}
|
package/src/shared/constants.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const BLOCK_SIZE = 60;
|