Skip to content
This repository has been archived by the owner on Jan 8, 2023. It is now read-only.

Commit

Permalink
⚙️ chore: Beta version 1.0-b
Browse files Browse the repository at this point in the history
Some fixes
  • Loading branch information
xitowzys committed Dec 18, 2022
1 parent 2199394 commit 940e49d
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ canvas {
}

body {
background-color: rgb(0, 64, 70);
background-color: rgb(27, 31, 79);
}
12 changes: 7 additions & 5 deletions src/js/Audios.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
class Audios {
constructor(collection) {
this.collection = {
point: './assets/audio/point.wav',
flap: './assets/audio/wing.wav',
hit: './assets/audio/hit.wav',
swoosh: './assets/audio/swoosh.wav',
point: './assets/audio/point.ogg',
flap: './assets/audio/wing.ogg',
hit: './assets/audio/hit.ogg',
swoosh: './assets/audio/swoosh.ogg',
die: './assets/audio/die.ogg',
background: './assets/audio/background.ogg'
};
Expand All @@ -23,11 +23,13 @@ class Audios {
* Play a sound from the collection by its name
* @param {string} name
*/
play(name) {
play(name, volume = 1) {
if (this.collection[name].paused) {
this.collection[name].volume = volume;
this.collection[name].play();
} else {
this.collection[name].pause();
this.collection[name].volume = volume;
this.collection[name].currentTime = 0;
this.collection[name].play();
}
Expand Down
31 changes: 25 additions & 6 deletions src/js/Background.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ class Background {
this.ctx = ctx;

this.srcImageBackground = new Image();
this.srcImageBackground.src = "./assets/sprites/background-night.png";
this.srcImageBackground.src = "./assets/sprites/background.png";

this.srcImageBackground_1 = new Image();
this.srcImageBackground_1.src = "./assets/sprites/background_1.png";

this.srcImageBackground_2 = new Image();
this.srcImageBackground_2.src = "./assets/sprites/background_2.png";

this.srcImageForeground = new Image();
this.srcImageForeground.src = "./assets/sprites/base.png";
this.srcImageForeground.src = "./assets/sprites/base_pink.png";

this.foregroundSpeed = 0.3;
this.backgroundSpeed = 0.1;
this.backgroundSpeed = 1;
}


Expand All @@ -32,19 +38,32 @@ class Background {
}

#renderBackground() {

this.ctx.drawImage(
this.srcImageBackground,
0,
0
);

this.ctx.drawImage(
this.srcImageBackground_1,
0 - this.#xBackground,
0
);

this.ctx.drawImage(
this.srcImageBackground,
this.srcImageBackground.width - this.#xBackground - 1,
this.srcImageBackground_2,
this.srcImageBackground_2.width - this.#xBackground - 1,
0
);

this.ctx.drawImage(
this.srcImageBackground_1,
this.srcImageBackground_2.width * 2 - this.#xBackground - 1,
0
);

if (this.#xBackground >= this.srcImageBackground.width) {
if (this.#xBackground >= this.srcImageBackground_2.width * 2) {
this.#xBackground = 0.0;
}

Expand Down
10 changes: 5 additions & 5 deletions src/js/Bird.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ class Bird {
this.y = 210 + this.dy;
}

this.srcCurrentBird.src = "./assets/sprites/redbird-downflap.png";
this.srcCurrentBird.src = "./assets/sprites/pinkbird-downflap.png";


this.bird = function () {

let srcBirdDownFlap = new Image();
srcBirdDownFlap.src = "./assets/sprites/redbird-downflap.png";
srcBirdDownFlap.src = "./assets/sprites/pinkbird-downflap.png";

let srcBirdMidFlap = new Image();
srcBirdMidFlap.src = "./assets/sprites/redbird-midflap.png";
srcBirdMidFlap.src = "./assets/sprites/pinkbird-midflap.png";

let srcBirdUpFlap = new Image();
srcBirdUpFlap.src = "./assets/sprites/redbird-upflap.png";
srcBirdUpFlap.src = "./assets/sprites/pinkbird-upflap.png";


return {
Expand Down Expand Up @@ -156,7 +156,7 @@ class Bird {

pipe.pipe.emptyCollision.collision.used = false;
count.count += 1;
audio.play("point");
audio.play("point", 0.6);

}
})
Expand Down
9 changes: 5 additions & 4 deletions src/js/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ class Game {
}

restartGame(pipes) {
pipes.forEach((pipe) => {
// console.log(pipe);
pipes.shift();
});
// pipes.forEach((pipe) => {
// // console.log(pipe);
// pipes.shift();
// });
pipes.pipes = Array();

}

Expand Down
2 changes: 1 addition & 1 deletion src/js/Pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Pipe {


this.srcImagePipe = new Image();
this.srcImagePipe.src = "./assets/sprites/pipe-green.png";
this.srcImagePipe.src = "./assets/sprites/pipe-pink.png";

this.speed = 0.1;

Expand Down
14 changes: 8 additions & 6 deletions src/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,18 @@ function run() {
let gamesEvents = function () {
switch (game.state) {
case game.states.getReady:
count.count = 0;
game.state = game.states.game;
audio.playLoop("background");
break;
case game.states.game:
audio.play("flap");
audio.play("flap", 0.4);
bird.flap();
break;
case game.states.gameOver:
audio.play("swoosh");
audio.play("swoosh", 0.3);
game.state = game.states.getReady;
game.restartGame(pipes.pipes);
game.restartGame(pipes);
bird.resetBirdPosition();
break;
}
Expand All @@ -71,8 +72,9 @@ function run() {

update(params) {

speed = startSpeed + count.count * 0.02
speed = startSpeed + count.count * 0.08
pipes.speed = speed;
pipes.interval = (4000 / speed);
bg.foregroundSpeed = speed;
// console.log(speed);

Expand All @@ -82,8 +84,8 @@ function run() {
bird.update(params);

if (bird.detectCollision(pipes.pipes, bg, count, audio)) {
audio.play("hit");
audio.play("die");
audio.play("hit", 0.8);
audio.play("die", 0.8);
audio.stop("background");
game.state = game.states.gameOver;
}
Expand Down

0 comments on commit 940e49d

Please sign in to comment.