Skip to content

Commit

Permalink
Added old changes
Browse files Browse the repository at this point in the history
Powerups: gun, big ball, big player
  • Loading branch information
Shadic78 committed Mar 13, 2024
1 parent 9cf003f commit ccaf00a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 5 deletions.
9 changes: 9 additions & 0 deletions js/class/Ball.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,13 @@ export class Ball extends ColliderObject {
this.pos.sub(previousSpeed);
}

increaseBaseSpeed(multiplier = 1) {
this.baseSpeed *= multiplier;
}

resetBaseSpeed() {
const gameArea = this.screenLayoutManager.getGameScreenData();
this.baseSpeed = (gameArea.width * CONSTANTS.BALL_SPEED) / CONSTANTS.GAME_AREA_HEIGHT_REFERENCE;
}

}
45 changes: 41 additions & 4 deletions js/class/BrickBreakerScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Block } from './Block.js';
import { Player } from './Player.js';
import { Ball } from './Ball.js';
import { PowerUp } from './PowerUp.js';
import { calculateCoordsToCenterItem } from '../utils/utils.js';
import { calculateCoordsToCenterItem, getRandomNum } from '../utils/utils.js';
import { PlayerPistol } from './PlayerPistol.js';
import { Bullet } from './Bullet.js';

Expand Down Expand Up @@ -292,7 +292,22 @@ export class BrickBreakerScreen extends GameArea {
height,
p5,
type: 'PowerUp',
callback: () => this.powerUpPistol(),
callback: () => {
const random = getRandomNum(1, 5);
switch (random) {
case 1:
this.powerUpPistol();
break;
case 2:
this.powerUpBigBall();
break;
case 3:
this.powerUpBiggerPlayer();
break;
default:
this.powerUpMultipleBalls(2);
}
},
//callback: this.powerUpMultipleBalls.bind(this, 2),
});
powerUp.setScreenLayoutManager(this.firstLayoutManager);
Expand All @@ -316,7 +331,7 @@ export class BrickBreakerScreen extends GameArea {

createBullet({ x, y, width, height }) {
//const bullet = new Bullet({ x, y: y - 5, width: 10, height: 20, p5: this.p5 });

const bullet = new Bullet({
x: x - width / 4,
y: y - 5,
Expand Down Expand Up @@ -348,7 +363,7 @@ export class BrickBreakerScreen extends GameArea {
});
bullet.addObserver(this);
bullet2.addObserver(this);

this.bullets.push(bullet);
this.bullets.push(bullet2);
}
Expand Down Expand Up @@ -403,4 +418,26 @@ export class BrickBreakerScreen extends GameArea {
}, 8000);
}

powerUpBigBall() {
if (this.balls.length === 0) return;
const currentBall = this.balls[0];
currentBall.width = currentBall.width * 2;
currentBall.increaseBaseSpeed(1.5);

setTimeout(() => {
currentBall.width = currentBall.width / 2;
currentBall.resetBaseSpeed();
}, 5000);
}

powerUpBiggerPlayer() {
const originalWidth = this.player.getWidth();
const newWidth = originalWidth * 1.8;

this.player.setWidth(newWidth);
setTimeout(() => {
this.player.setWidth(originalWidth);
}, 5000);
}

}
10 changes: 9 additions & 1 deletion js/class/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Collisionable } from '../core/Collisionable.js';
import { inputManager } from '../core/KeyInputManager.js';

export class Player extends Collisionable {

constructor({ type = 'Player', ...rest }) {
super({ type, ...rest });
this.speed = 0;
Expand Down Expand Up @@ -127,4 +127,12 @@ export class Player extends Collisionable {
this.speed += increase;
}

getWidth() {
return this.width;
}

setWidth(_width) {
this.width = _width;
}

}

0 comments on commit ccaf00a

Please # to comment.