Skip to content

Commit

Permalink
Revert "For chuseok"
Browse files Browse the repository at this point in the history
This reverts commit 0508f33.
  • Loading branch information
lazygyu committed Sep 18, 2024
1 parent 0508f33 commit 1c2f5c0
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 46 deletions.
Binary file removed assets/images/moon.png
Binary file not shown.
2 changes: 1 addition & 1 deletion src/IPhysics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface IPhysics {

removeMarble(id: number): void;

getMarblePosition(id: number): { x: any; y: any, angle: number };
getMarblePosition(id: number): { x: any; y: any };

getWheels(): WheelState[];

Expand Down
32 changes: 13 additions & 19 deletions src/marble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class Marble {
id: number;

get position() {
return this.physics.getMarblePosition(this.id) || {x: 0, y: 0, angle: 0};
return this.physics.getMarblePosition(this.id) || {x: 0, y: 0};
}

get x() {
Expand All @@ -46,10 +46,6 @@ export class Marble {
this.position.y = v;
}

get angle() {
return this.position.angle;
}

constructor(physics: IPhysics, order: number, max: number, name?: string, weight: number = 1) {
this.name = name || `M${order}`;
this.weight = weight;
Expand Down Expand Up @@ -103,12 +99,12 @@ export class Marble {
}
}

render(ctx: CanvasRenderingContext2D, zoom: number, outline: boolean, isMinimap: boolean = false, skin?: CanvasImageSource) {
render(ctx: CanvasRenderingContext2D, zoom: number, outline: boolean, isMinimap: boolean = false) {
ctx.save();
if (isMinimap) {
this._renderMinimap(ctx);
} else {
this._renderNormal(ctx, zoom, outline, skin);
this._renderNormal(ctx, zoom, outline)
}
ctx.restore();
}
Expand All @@ -124,25 +120,15 @@ export class Marble {
ctx.fill();
}

private _renderNormal(ctx: CanvasRenderingContext2D, zoom: number, outline: boolean, skin?: CanvasImageSource) {
private _renderNormal(ctx: CanvasRenderingContext2D, zoom: number, outline: boolean) {
ctx.fillStyle = `hsl(${this.hue} 100% ${70 + (25 * Math.min(1, this.impact / 500))}%`;
if (this._stuckTime > 0) {
ctx.fillStyle = `hsl(${this.hue} 100% ${70 + (25 * Math.min(1, this._stuckTime / STUCK_DELAY))}%`;
}

ctx.shadowColor = this.color;
ctx.shadowBlur = zoom / 2;
if (skin) {
const hs = this.size / 2;
ctx.save();
ctx.translate(this.x, this.y);
ctx.rotate(this.angle);
ctx.drawImage(skin, -hs, -hs, hs*2, hs*2);
ctx.restore();
// ctx.arc(this.x, this.y, isMinimap ? this.size : this.size / 2, 0, Math.PI * 2);
} else {
this._drawMarbleBody(ctx, false);
}
this._drawMarbleBody(ctx, false);

ctx.shadowColor = '';
ctx.shadowBlur = 0;
Expand Down Expand Up @@ -189,4 +175,12 @@ export class Marble {
ctx.arc(this.x, this.y, this.size / 2 + (2 / zoom), rad(270), rad(270 + 360 * this._coolTime / this._maxCoolTime));
ctx.stroke();
}

private _renderStuck(ctx: CanvasRenderingContext2D, zoom: number) {
ctx.strokeStyle = 'green';
ctx.lineWidth = 1 / zoom;
ctx.beginPath();
ctx.arc(this.x, this.y, this.size / 2 + (3/zoom), rad(270), rad(270 + 360 * (1 - (this._stuckTime / STUCK_DELAY))));
ctx.stroke();
}
}
7 changes: 3 additions & 4 deletions src/physics-box2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,12 @@ export class Box2dPhysics implements IPhysics {
delete this.marbleMap[id];
}
}
getMarblePosition(id: number): { x: any; y: any; angle: number } {
getMarblePosition(id: number): { x: any; y: any; } {
const marble = this.marbleMap[id];
if (marble) {
const pos = marble.GetPosition();
return { x: pos.x, y: pos.y, angle: marble.GetAngle() };
return marble.GetPosition();
} else {
return {x: 0, y: 0, angle: 0}
return {x: 0, y: 0}
}
}
getWheels(): WheelState[] {
Expand Down
9 changes: 4 additions & 5 deletions src/roulette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,10 @@ export class Roulette extends EventTarget {

constructor() {
super();
this._renderer.init().then(() => {
this._init().then(() => {
this._isReady = true;
this._update();
});
this._renderer.init();
this._init().then(() => {
this._isReady = true;
this._update();
});
}

Expand Down
19 changes: 2 additions & 17 deletions src/rouletteRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export class RouletteRenderer {
private _canvas!: HTMLCanvasElement;
private ctx!: CanvasRenderingContext2D;
public sizeFactor = 1;
private _image!: HTMLImageElement;

constructor() {
}
Expand All @@ -46,10 +45,7 @@ export class RouletteRenderer {
return this._canvas;
}

async init() {

await this._load();

init() {
this._canvas = document.createElement('canvas');
this._canvas.width = canvasWidth;
this._canvas.height = canvasHeight;
Expand All @@ -73,17 +69,6 @@ export class RouletteRenderer {
resizing();
}

private async _load(): Promise<void> {
return new Promise((rs) => {
const imageUrl = new URL('/assets/images/moon.png', import.meta.url);
this._image = new Image();
this._image.src = imageUrl.toString();
this._image.addEventListener('load', () => {
rs();
});
});
}

render(renderParameters: RenderParameters, uiObjects: UIObject[]) {
this.ctx.fillStyle = 'black';
this.ctx.fillRect(0, 0, this._canvas.width, this._canvas.height);
Expand Down Expand Up @@ -187,7 +172,7 @@ export class RouletteRenderer {
private renderMarbles({marbles, camera, winnerRank, winners}: RenderParameters) {
const winnerIndex = winnerRank - winners.length;
marbles.forEach((marble, i) => {
marble.render(this.ctx, camera.zoom * initialZoom, i === winnerIndex, false, this._image);
marble.render(this.ctx, camera.zoom * initialZoom, i === winnerIndex, false);
});
}

Expand Down

0 comments on commit 1c2f5c0

Please sign in to comment.