Skip to content

Commit

Permalink
feat: add board
Browse files Browse the repository at this point in the history
  • Loading branch information
noyyyy committed Dec 30, 2023
1 parent e7970c3 commit 93463fd
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 196 deletions.
Binary file modified packages/client/public/assets/tilesets/land.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed packages/client/src/assets/paper.png
Binary file not shown.
Binary file removed packages/client/src/assets/rock.png
Binary file not shown.
Binary file removed packages/client/src/assets/scissors.png
Binary file not shown.
83 changes: 0 additions & 83 deletions packages/client/src/assets/texture.json

This file was deleted.

Binary file removed packages/client/src/assets/texture.png
Binary file not shown.
Binary file removed packages/client/src/assets/tilesets/land.png
Binary file not shown.
4 changes: 1 addition & 3 deletions packages/client/src/assets/world.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
export enum Tileset {
Land = 0,
Forest = 1,
Sea = 2,
Desert = 3,
Board = 1,
}
export enum TileAnimationKey {}
export const TileAnimations: { [key in TileAnimationKey]: number[] } = {};
70 changes: 36 additions & 34 deletions packages/client/src/phaser/config/configurePhaser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import {
const ANIMATION_INTERVAL = 200;

const mainMap = defineMapConfig({
chunkSize: TILE_WIDTH * 64, // tile size * tile amount
chunkSize: TILE_WIDTH, // tile size * tile amount
tileWidth: TILE_WIDTH,
tileHeight: TILE_HEIGHT,
backgroundTile: [Tileset.Land],
backgroundTile: [Tileset.Land], // 4 is undefined
animationInterval: ANIMATION_INTERVAL,
tileAnimations: TileAnimations,
layers: {
Expand Down Expand Up @@ -63,36 +63,36 @@ export const phaserConfig = {
},
},
animations: [
{
key: Animations.RockIdle,
assetKey: Assets.MainAtlas,
startFrame: 0,
endFrame: 0,
frameRate: 6,
repeat: -1,
prefix: "sprites/rock/",
suffix: ".png",
},
{
key: Animations.ScissorsIdle,
assetKey: Assets.MainAtlas,
startFrame: 0,
endFrame: 0,
frameRate: 6,
repeat: -1,
prefix: "sprites/scissors/",
suffix: ".png",
},
{
key: Animations.PaperIdle,
assetKey: Assets.MainAtlas,
startFrame: 0,
endFrame: 0,
frameRate: 6,
repeat: -1,
prefix: "sprites/paper/",
suffix: ".png",
},
// {
// key: Animations.RockIdle,
// assetKey: Assets.MainAtlas,
// startFrame: 0,
// endFrame: 0,
// frameRate: 6,
// repeat: -1,
// prefix: "sprites/rock/",
// suffix: ".png",
// },
// {
// key: Animations.ScissorsIdle,
// assetKey: Assets.MainAtlas,
// startFrame: 0,
// endFrame: 0,
// frameRate: 6,
// repeat: -1,
// prefix: "sprites/scissors/",
// suffix: ".png",
// },
// {
// key: Animations.PaperIdle,
// assetKey: Assets.MainAtlas,
// startFrame: 0,
// endFrame: 0,
// frameRate: 6,
// repeat: -1,
// prefix: "sprites/paper/",
// suffix: ".png",
// },
],
tilesets: {
Default: {
Expand All @@ -105,7 +105,9 @@ export const phaserConfig = {
},
scale: defineScaleConfig({
parent: "phaser-game",
zoom: 1,
zoom: 2,
height: "32rem",
width: "32rem",
mode: Phaser.Scale.NONE,
}),
cameraConfig: defineCameraConfig({
Expand All @@ -114,5 +116,5 @@ export const phaserConfig = {
maxZoom: 3,
minZoom: 1,
}),
cullingChunkSize: TILE_HEIGHT * 16,
cullingChunkSize: TILE_HEIGHT,
};
9 changes: 5 additions & 4 deletions packages/client/src/phaser/phaserLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ export const PhaserLayer = ({ networkLayer }: Props) => {
ref={ref}
style={{
position: "absolute",
top: "0",
left: "0",
width: "100%",
height: "100%",
top: "20%",
left: "50%",
width: "32rem",
transform: "translateX(-50%)",
height: "32rem",
}}
/>
);
Expand Down
96 changes: 48 additions & 48 deletions packages/client/src/phaser/systems/controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,59 +12,59 @@ export const controls = (layer: PhaserLayer) => {
},
} = layer;

input.onKeyPress(
(keys) => keys.has("W"),
() => {
move({ signer, direction: Direction.Up });
}
);
// input.onKeyPress(
// (keys) => keys.has("W"),
// () => {
// move({ signer, direction: Direction.Up });
// }
// );

input.onKeyPress(
(keys) => keys.has("A"),
() => {
move({ signer, direction: Direction.Left });
}
);
// input.onKeyPress(
// (keys) => keys.has("A"),
// () => {
// move({ signer, direction: Direction.Left });
// }
// );

input.onKeyPress(
(keys) => keys.has("S"),
() => {
move({ signer, direction: Direction.Down });
}
);
// input.onKeyPress(
// (keys) => keys.has("S"),
// () => {
// move({ signer, direction: Direction.Down });
// }
// );

input.onKeyPress(
(keys) => keys.has("D"),
() => {
move({ signer, direction: Direction.Right });
}
);
// input.onKeyPress(
// (keys) => keys.has("D"),
// () => {
// move({ signer, direction: Direction.Right });
// }
// );

input.onKeyPress(
(keys) => keys.has("UP"),
() => {
move({ signer, direction: Direction.Up });
}
);
// input.onKeyPress(
// (keys) => keys.has("UP"),
// () => {
// move({ signer, direction: Direction.Up });
// }
// );

input.onKeyPress(
(keys) => keys.has("LEFT"),
() => {
move({ signer, direction: Direction.Left });
}
);
// input.onKeyPress(
// (keys) => keys.has("LEFT"),
// () => {
// move({ signer, direction: Direction.Left });
// }
// );

input.onKeyPress(
(keys) => keys.has("DOWN"),
() => {
move({ signer, direction: Direction.Down });
}
);
// input.onKeyPress(
// (keys) => keys.has("DOWN"),
// () => {
// move({ signer, direction: Direction.Down });
// }
// );

input.onKeyPress(
(keys) => keys.has("RIGHT"),
() => {
move({ signer, direction: Direction.Right });
}
);
// input.onKeyPress(
// (keys) => keys.has("RIGHT"),
// () => {
// move({ signer, direction: Direction.Right });
// }
// );
};
26 changes: 7 additions & 19 deletions packages/client/src/phaser/systems/mapSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,16 @@ export function mapSystem(layer: PhaserLayer) {
},
} = layer;

for (let x = 0; x < 50; x++) {
for (let y = 0; y < 50; y++) {
for (let x = 0; x < 8; x++) {
for (let y = 0; y < 8; y++) {
const coord = { x, y };
// Get a noise value between 0 and 100
const seed = Math.floor(
((snoise([x / MAP_AMPLITUDE, 0, y / MAP_AMPLITUDE]) + 1) / 2) *
100
);
// const seed = Math.floor(
// ((snoise([x / MAP_AMPLITUDE, 0, y / MAP_AMPLITUDE]) + 1) / 2) *
// 100
// );

if (seed > 70) {
// This would be the highest 'elevation'
putTileAt(coord, Tileset.Sea, "Foreground");
} else if (seed > 60) {
// Even lower, could be fields or plains
putTileAt(coord, Tileset.Desert, "Foreground");
} else if (seed > 53) {
// Close to water level, might be beach
putTileAt(coord, Tileset.Forest, "Foreground");
} else {
// Below a certain threshold, it is sea
putTileAt(coord, Tileset.Land, "Foreground");
}
putTileAt(coord, Tileset.Board, "Foreground");
}
}
}
4 changes: 2 additions & 2 deletions packages/client/src/phaser/systems/move.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const move = (layer: PhaserLayer) => {
const {
world,
scenes: {
Main: { objectPool, camera },
Main: { objectPool },
},
networkLayer: {
components: { Position },
Expand Down Expand Up @@ -56,7 +56,7 @@ export const move = (layer: PhaserLayer) => {
id: "position",
once: (sprite: any) => {
sprite.setPosition(pixelPosition?.x, pixelPosition?.y);
camera.centerOn(pixelPosition?.x, pixelPosition?.y);
// camera.centerOn(pixelPosition?.x, pixelPosition?.y);
},
});
});
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/ui/CreateAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export const CreateAccount = () => {
}`}
>
<div className="self-center border-2 p-4">
<h3 className="text-3xl mb-2">RPS</h3>
<h5 className="text-xl mb-4">Eat to survive</h5>
<h3 className="text-3xl mb-2">Auto Chess Battle</h3>
{/* <h5 className="text-xl mb-4">Auto battle</h5> */}
<div>
<ClickWrapper>
<div className="flex space-x-3 justify-between p-2 flex-wrap">
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/ui/Spawn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const Spawn = () => {
setLoggedIn();
}}
>
Spawn
Start
</Button>
</div>
);
Expand Down

0 comments on commit 93463fd

Please sign in to comment.