This repository has been archived by the owner on Jul 9, 2021. It is now read-only.
-
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.
Start to separate game logic to classes
- Loading branch information
1 parent
8118c16
commit 1802113
Showing
13 changed files
with
6,446 additions
and
78 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
dist/ |
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,6 +1,18 @@ | ||
{ | ||
"name": "typescript", | ||
"name": "2d-breakout-game", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": {} | ||
} | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"clean-webpack-plugin": "^3.0.0", | ||
"html-webpack-plugin": "^4.4.1", | ||
"ts-loader": "^8.0.3", | ||
"typescript": "^4.0.2", | ||
"webpack": "^4.44.1", | ||
"webpack-cli": "^3.3.12", | ||
"webpack-dev-server": "^3.11.0" | ||
}, | ||
"scripts": { | ||
"start": "webpack-dev-server" | ||
} | ||
} |
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,32 @@ | ||
export class Ball { | ||
#ctx: BallConfig['ctx'] | ||
x: BallConfig['x'] | ||
y: BallConfig['y'] | ||
#color: BallConfig['color'] | ||
radius: BallConfig['radius'] | ||
|
||
constructor(config: BallConfig) { | ||
this.x = config.x; | ||
this.#ctx = config.ctx; | ||
this.y = config.y; | ||
this.#color = config.color; | ||
this.radius = config.radius; | ||
} | ||
|
||
draw() { | ||
this.#ctx.beginPath(); | ||
this.#ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2); | ||
this.#ctx.fillStyle = this.#color; | ||
this.#ctx.fill(); | ||
this.#ctx.closePath(); | ||
} | ||
|
||
} | ||
|
||
interface BallConfig { | ||
ctx: CanvasRenderingContext2D, | ||
x: number, | ||
y: number, | ||
color: string, | ||
radius: number, | ||
} |
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,57 @@ | ||
export class Brick { | ||
x: BrickConfig['x']; | ||
y: BrickConfig['y']; | ||
#ctx: BrickConfig['ctx'] | ||
width: BrickConfig['width'] | ||
height: BrickConfig['height'] | ||
padding: BrickConfig['padding'] | ||
offsetLeft: BrickConfig['offsetLeft'] | ||
offsetTop: BrickConfig['offsetTop'] | ||
column: BrickConfig['column'] | ||
row: BrickConfig['row'] | ||
|
||
status = true; | ||
|
||
constructor(config: BrickConfig) { | ||
this.x = config.x; | ||
this.y = config.y; | ||
|
||
this.#ctx = config.ctx; | ||
this.x = config.x; | ||
this.y = config.y; | ||
this.width = config.width; | ||
this.height = config.height; | ||
this.padding = config.padding; | ||
this.offsetLeft = config.offsetLeft; | ||
this.offsetTop = config.offsetTop; | ||
this.column = config.column; | ||
this.row = config.row; | ||
} | ||
|
||
draw() { | ||
if (this.status) { | ||
var brickX = this.column * (this.width + this.padding) + this.offsetLeft; | ||
var brickY = this.row * (this.height + this.padding) + this.offsetTop; | ||
this.x = brickX; | ||
this.y = brickY; | ||
this.#ctx.beginPath(); | ||
this.#ctx.rect(brickX, brickY, this.width, this.height); | ||
this.#ctx.fillStyle = "#0095DD"; | ||
this.#ctx.fill(); | ||
this.#ctx.closePath(); | ||
} | ||
} | ||
} | ||
|
||
interface BrickConfig { | ||
ctx: CanvasRenderingContext2D, | ||
x: number, | ||
y: number, | ||
width: number, | ||
height: number, | ||
padding: number, | ||
offsetLeft: number, | ||
offsetTop: number, | ||
column: number, | ||
row: number | ||
} |
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,39 @@ | ||
export class Paddle { | ||
#width: PaddleConfig['width'] | ||
#height: PaddleConfig['height'] | ||
#ctx: PaddleConfig['ctx'] | ||
x: PaddleConfig['x'] | ||
y: PaddleConfig['y'] | ||
|
||
constructor(config: PaddleConfig) { | ||
this.#width= config.width; | ||
this.#height= config.height; | ||
this.x = config.x; | ||
this.#ctx = config.ctx; | ||
this.y = config.y; | ||
} | ||
|
||
draw() { | ||
this.#ctx.beginPath(); | ||
this.#ctx.rect(this.x, this.#ctx.canvas.height - this.height, this.width, this.height); | ||
this.#ctx.fillStyle = "#0095DD"; | ||
this.#ctx.fill(); | ||
this.#ctx.closePath(); | ||
} | ||
|
||
get width() { | ||
return this.#width | ||
} | ||
|
||
get height() { | ||
return this.#height | ||
} | ||
} | ||
|
||
interface PaddleConfig { | ||
ctx: CanvasRenderingContext2D, | ||
x: number, | ||
y: number, | ||
height: number, | ||
width: number, | ||
} |
Oops, something went wrong.