-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlayer copy.js
122 lines (109 loc) · 4.01 KB
/
Player copy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import BallContainer from "./Object/BallContainer.js";
import BrickContainer from "./Object/BrickContainer.js";
import Paddle from "./Object/Paddle.js";
import StageEffectContainer from "./Object/StageEffectContainer.js";
export default class Player{
constructor(playerName, player,MAP){
this.playerName = playerName;
this.CANVAS = document.querySelector(`#${player}`);
this.stageWidth = 500;
this.stageHeight = 700;
this.ctx = this.CANVAS.getContext("2d");
let map = JSON.parse(MAP);
this.#stageEffectContainer = new StageEffectContainer(map.stageHitEffectInfo);
this.paddle = new Paddle(map.ballInfo, this.#stageEffectContainer);
this.brickContainer = new BrickContainer(map.brickInfo,this.paddle);
this.#ballContainer = new BallContainer(this.stageHeight);
this.#ballContainer.balls = this.paddle.launchedBalls;
this.count = 0;
// this.brickContainer.map = map;
this.brickContainer.loadNewBricks();
this.score = 0;
this.#status = "ready";
this.isPressingLeft = false;
this.isPressingRight = false;
}
run(){
this.count++;
this.ctx.save();
this.ctx.fillStyle = 'rgba(0, 0, 0,0.5)';
this.ctx.fillRect(0,0,this.CANVAS.width, this.CANVAS.height);
this.ctx.restore();
this.ctx.translate(20,20);
this.ctx.strokeStyle ="grey";
this.ctx.strokeRect(0,0,500,700);
this.paddle.draw(this.ctx, this.#status);
this.brickContainer.drawAll(this.ctx);
switch(this.#status){
case "ready":
this.paddle.reload();
if(this.isPressingLeft){
this.paddle.decreaseAngle();
}
if(this.isPressingRight){
this.paddle.increaseAngle();
}
break;
case "launching":
this.#stageEffectContainer.drawAll(this.ctx);
this.paddle.launchBall();
this.#ballContainer.moveAll();
this.#ballContainer.drawAll(this.ctx);
this.#ballContainer.checkStageHit(this.ctx);
this.#ballContainer.checkBrickHit(this.brickContainer);
this.#ballContainer.deleteArrivedBall();
if(this.count % 300 == 0){
this.#ballContainer.increaseSpeed();
}
if(this.paddle.numLaunchedBalls != 0 && this.#ballContainer.isEmpty()){
this.#status="finished";
}
break;
case "finished":
this.count = 0;
if (this.brickContainer.hasNoMoreBrick()){
this.win();
}
setTimeout(()=>{
let loadResult = this.brickContainer.loadNewBricks();
if(loadResult == false)
this.lose();
this.#stageEffectContainer.reset();
},2000);
this.#status = "rearranging";
break;
case "rearranging":
this.paddle.moveToNextPos();
if(this.paddle.hasArrivedNewPosition()){
this.paddle.getRandomPos();
this.#status = "wait";
}
break;
case "wait":
this.readyToContinue();
break;
}
this.ctx.translate(-20,-20);
}
set status(status){
this.#status = status;
}
get status(){
return this.#status;
}
quitTurn(){
this.paddle.stopLaunching();
this.#ballContainer.retriveAll();
}
fadeIn(){
if(!this.alpha) {
this.CANVAS.style.display = "";
this.CANVAS.setAttribute("class","fade-in");
console.log("check");
this.alpha = 1;
}
}
#status;
#ballContainer
#stageEffectContainer
}