Skip to content

Commit

Permalink
refactor new structure
Browse files Browse the repository at this point in the history
  • Loading branch information
khoakomlem committed Feb 18, 2024
1 parent 292cdf0 commit b3ff296
Show file tree
Hide file tree
Showing 75 changed files with 6,874 additions and 4,277 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = true
84 changes: 63 additions & 21 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,65 @@
{
"env": {
"node": true,
"browser": true,
"es2021": true
},
"extends": ["xo", "plugin:react/recommended"],
"overrides": [
{
"extends": ["xo-typescript"],
"files": ["*.ts", "*.tsx"],
"rules": {
"@typescript-eslint/naming-convention": "off"
}
}
],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["react"],
"rules": {}
"extends": [
"xo",
"xo-typescript/space",
"xo-react/space",
"next/core-web-vitals",
"prettier"
],
"parser": "@typescript-eslint/parser",
"overrides": [
{
"files": ["*.ts", "*.tsx"],
"rules": {
"react/react-in-jsx-scope": "off",
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/no-empty-function": "warn",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/triple-slash-reference": "off",
"capitalized-comments": "off",
"prettier/prettier": [
"error",
{
"editorconfig": true,
"singleQuote": true,
"jsxSingleQuote": true,
"trailingComma": "es5",
"importOrder": [
"^(react/(.*)$)|^(react$)",
"^(next/(.*)$)|^(next$)",
"<THIRD_PARTY_MODULES>",
"",
"^@/types/(.*)$",
"^@/lib/(.*)$",
"^(@/constants/(.*)$)|^(@/constants$)",
"^(@/utils/(.*)$)|^(@/utils$)",
"^(@/hooks/(.*)$)|^(@/hooks$)",
"^@/components/(.*)$",
"^(@/core/(.*)$)|^(@/core$)",
"^@/styles/(.*)$",
"^@/app/(.*)$",
"",
"^[./]"
],
"importOrderSeparation": false,
"importOrderSortSpecifiers": true,
"importOrderBuiltinModulesToTop": true,
"importOrderParserPlugins": [
"typescript",
"jsx",
"decorators-legacy"
],
"importOrderMergeDuplicateImports": true,
"importOrderCombineTypeAndValueImports": true,
"plugins": ["@ianvs/prettier-plugin-sort-imports"]
}
]
}
}
],
"plugins": ["prettier"],
"ignorePatterns": ["/*", "!src", "!/*.js", "!/*.cjs"],
"root": true
}
40 changes: 38 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
node_modules
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

yarn-error.log
# dependencies
**/node_modules
/.pnp
.pnp.js
/.history

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
**/.next

src/pages/test.tsx
25 changes: 25 additions & 0 deletions .swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "ecmascript",
"jsx": false,
"dynamicImport": false,
"privateMethod": false,
"functionBind": false,
"exportDefaultFrom": false,
"exportNamespaceFrom": false,
"decorators": false,
"decoratorsBeforeExport": false,
"topLevelAwait": false,
"importMeta": false
},
"transform": {},
"target": "es5",
"loose": false,
"externalHelpers": false,
// Requires v1.2.50 or upper and requires target to be es2016 or upper.
"keepClassNames": false
},
"minify": false
}
20 changes: 20 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.22621.0",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64"
}
],
"version": 4
}
94 changes: 94 additions & 0 deletions _game/Game.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { TextStyle } from '@pixi/text';
import { PixiFpsCounter } from 'pixi-fps-counter';
import Stats from 'stats.js';

import { type TickData } from '../types/TickData';
import { type PlayerClient, type WorldClient } from './index';

export class Game {
stats = {
fps: new Stats(),
ping: new Stats(),
};

counter?: PixiFpsCounter;

isMobile = false;
playerClient: PlayerClient | undefined;

private readonly internal = {
tps: 0,
targetDelta: 1000 / 60,
elapsedMs: 0,
elapseTick: 0,
accumulator: 0,
ping: 0,
tpsCountInterval: 0,
};

async connect() {}

init() {}

initDOM() {}

start(worldClient: WorldClient, playerClient: PlayerClient) {
// Const camera = new Camera(world.app.stage);
this.counter = new PixiFpsCounter(worldClient.app.ticker, {
backgroundColor: 0x9f3a0d,
backgroundPadding: 20,
dragParent: worldClient.app.stage,
textStyle: new TextStyle({
fill: '#fff7db',
fontSize: 32,
fontWeight: 'bolder',
strokeThickness: 9,
}),
updateCoefficient: 10,
});
worldClient.app.stage.addChild(this.counter);

worldClient.app.ticker.add((_delta) => {
const { deltaMS } = worldClient.app.ticker;
const { internal } = this;

internal.accumulator += deltaMS;
// This.stats.fps.begin();
while (internal.accumulator >= internal.targetDelta) {
internal.elapseTick++;
internal.accumulator -= internal.targetDelta;
const tickData: TickData = {
accumulator: internal.accumulator,
elapsedMs: internal.elapsedMs,
deltaMs: internal.targetDelta,
delta: 1,
};

if (playerClient.isReady()) {
playerClient.playerCore.nextTick(tickData);
playerClient.nextTick(tickData);
// Update camera
// camera.update();

// Update player angle to mouse
// const {entity} = player.playerCore;
// if (entity && !this.isMobile) {
// const playerX = entity.body.pos.x;
// const playerY = entity.body.pos.y;
// const playerScreenPos = worldClient.app.stage.toScreen(playerX, playerY);
// this.player.entity.body.angle = Math.atan2(
// this.pointerPos.y - playerScreenPos.y,
// this.pointerPos.x - playerScreenPos.x,
// );
// }
}

worldClient.worldCore.nextTick(tickData);
worldClient.nextTick(tickData);
internal.elapsedMs += internal.targetDelta;
}

// This.stats.fps.end();
});
}
}
64 changes: 64 additions & 0 deletions _game/client/background/RunningBackground.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import * as PIXI from 'pixi.js';

const backgroundWidth = 1366;
const backgroundHeight = 768;

export class RunningBackground {
bg: PIXI.Sprite[] = [];
runningBush: PIXI.Sprite[] = [];
runningCloud: PIXI.Sprite[] = [];
speed = 3;

displayObjects: PIXI.DisplayObject[] = [];

constructor(public app: PIXI.Application) {
const bg = PIXI.Sprite.from('images/bg.png');
bg.scale = { x: this.scale(), y: this.scale() };
this.displayObjects.push(bg);

for (let i = 0; i < Math.ceil(window.innerWidth / 1366) + 1; i++) {
const runningBush = PIXI.Sprite.from('images/running-bush.png');
const runningCloud = PIXI.Sprite.from('images/running-cloud.png');

runningBush.x = this.scale(i * backgroundWidth);
runningBush.y = window.outerHeight - this.scale(327);
runningBush.scale = { x: this.scale(), y: this.scale() };

runningCloud.x = i * this.scale(backgroundWidth);
runningCloud.y = window.outerHeight - this.scale(790);
runningCloud.scale = { x: this.scale(), y: this.scale() };

this.runningBush.push(runningBush);
this.runningCloud.push(runningCloud);
}

this.displayObjects.push(...this.runningCloud);
this.displayObjects.push(...this.runningBush);
}

nextTick() {
this.runningBush.forEach((runningBush) => {
runningBush.x -= this.speed;
if (runningBush.x < this.scale(-backgroundWidth)) {
runningBush.x =
this.runningBush[this.runningBush.length - 1].x +
backgroundWidth * this.scale();
this.runningBush.push(this.runningBush.shift()!);
}
});

this.runningCloud.forEach((runningCloud) => {
runningCloud.x -= this.speed * 0.5;
if (runningCloud.x < this.scale(-backgroundWidth)) {
runningCloud.x =
this.runningCloud[this.runningCloud.length - 1].x +
backgroundWidth * this.scale();
this.runningCloud.push(this.runningCloud.shift()!);
}
});
}

scale(x = 1) {
return x * (window.outerHeight / backgroundHeight);
}
}
10 changes: 10 additions & 0 deletions _game/constant/PipeType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export enum PipeType {
Normal,
UpDown,
Collapse,
Open,
Unstable,
Spin,
Small,
Big,
}
Loading

0 comments on commit b3ff296

Please sign in to comment.