-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
811779e
commit 72e5519
Showing
4 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* eslint-disable max-lines */ | ||
import { AfterViewInit, Component, OnDestroy, OnInit } from '@angular/core'; | ||
import { CanvasComponent } from 'app/game/components/canvas/canvas.component'; | ||
import { BaseGameWindowComponent } from '../base-game.component'; | ||
import { ClimbHill, ClimbHillState } from './models/climbhill.class'; | ||
|
||
@Component({ | ||
selector: 'app-climbhill', | ||
standalone: true, | ||
imports: [CanvasComponent], | ||
template: `<div> | ||
score: <b>{{ game.state.score }}</b> | ||
</div> | ||
<app-canvas | ||
[displayMode]="'horizontal'" | ||
class="bg-zinc-300" | ||
#gameCanvas></app-canvas> | ||
<b>FPS: {{ fps }}</b> `, | ||
}) | ||
export class ClimbHillComponent | ||
extends BaseGameWindowComponent | ||
implements OnInit, AfterViewInit, OnDestroy | ||
{ | ||
public override game!: ClimbHill; | ||
|
||
public override ngOnInit(): void { | ||
super.ngOnInit(); | ||
this.game = this.game as ClimbHill; | ||
} | ||
|
||
public override ngAfterViewInit(): void { | ||
super.ngAfterViewInit(); | ||
this.render(); | ||
} | ||
|
||
public override restart(): void { | ||
this.game.state = new ClimbHillState(); | ||
} | ||
|
||
protected override update(): void { | ||
super.update(); | ||
|
||
//update | ||
|
||
this.render(); | ||
} | ||
|
||
// | ||
|
||
private render(): void { | ||
const context = this._canvas.getContext('2d'); | ||
if (!context) return; | ||
context.clearRect(0, 0, this._canvas.width, this._canvas.height); | ||
} | ||
|
||
private random(min: number, max: number): number { | ||
return Math.floor(Math.random() * (max - min + 1) + min); | ||
} | ||
|
||
private round(value: number, decimals = 2): number { | ||
return Math.round(value * Math.pow(10, decimals)) / Math.pow(10, decimals); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { TGameState } from '@gameModels/game-state.type'; | ||
import { Game } from '@gameModels/game.class'; | ||
import { Player } from '@gameModels/player.class'; | ||
|
||
export class ClimbHillState implements TGameState { | ||
public score = 0; | ||
} | ||
|
||
export class ClimbHill extends Game { | ||
public override name = 'climbhill'; | ||
public override state = new ClimbHillState(); | ||
public override outputSpec = ``; | ||
|
||
public override players = [ | ||
new Player( | ||
0, | ||
true, | ||
'Player 1', | ||
{ gas: 0, brake: 0 }, | ||
{ | ||
ArrowRight: { | ||
variableName: 'gas', | ||
pressedValue: 1, | ||
releasedValue: 0, | ||
}, | ||
ArrowLeft: { | ||
variableName: 'brake', | ||
pressedValue: 1, | ||
releasedValue: 0, | ||
}, | ||
}, | ||
'<gas>, <brake>: value of {0, 1}, 0: gas/brake released, 1: gas/brake pressed', | ||
{ gas: '[ArrowRight]', brake: '[ArrowLeft]' } | ||
), | ||
]; | ||
} |