Skip to content

Commit

Permalink
update flappydante
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueLovin committed May 16, 2024
1 parent 91bcc33 commit 2c966bd
Show file tree
Hide file tree
Showing 31 changed files with 67 additions and 73 deletions.
Binary file removed flappy-dante/Images/bird.png
Binary file not shown.
Binary file added flappy-dante/Images/dante.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion flappy-dante/JS/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Config from "./config.js";

export default class Canvas {
constructor() {
this.element = document.getElementById("flappy-bird");
this.element = document.getElementById("flappy-dante");
this.context = this.element.getContext("2d");

this.element.width = window.innerWidth;
Expand Down
65 changes: 33 additions & 32 deletions flappy-dante/JS/bird.js → flappy-dante/JS/dante.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import Canvas from "./canvas.js";
import Config from "./config.js";

export default class Bird {
export default class dante {
constructor() {
this.canvas = new Canvas();
this.config = new Config();

this.imageBird = new Image();
this.imageBird.src = "Images/bird.png";
this.imageDante = new Image();
this.imageDante.src = "Images/dante.png";

this.flyBird = new Audio();
this.flyBird.src = "audio/fly.wav";
this.flyDante = new Audio();
this.flyDante.src = "audio/fly.wav";

this.dieBird = new Audio();
this.dieBird.src = "audio/die.wav";
this.dieDante = new Audio();
this.dieDante.src = "audio/die.wav";

this.birdWidth = 35;
this.birdHeight = 25;
this.birdJump = 1;
this.danteWidth = 35;
this.danteHeight = 25;
this.danteJump = 1;

this.birdX = 0;
this.birdPositionX = this.canvas.element.width / 2 - this.birdWidth / 1.5;
this.danteX = 0;
this.dantePositionX = this.canvas.element.width / 2 - this.danteWidth / 1.5;

this.birdY;
this.birdPositionY = 239;
this.danteY;
this.dantePositionY = 239;

this.targetBirdPositionY = this.canvas.height; // Set the initial target position to be the bottom of the screen
this.targetDantePositionY = this.canvas.height; // Set the initial target position to be the bottom of the screen
this.lerpRate = 0.3;
this.velocityY = 0;
this.lift = -8; // The force of the jump (negative because it goes up)
Expand All @@ -42,7 +42,7 @@ export default class Bird {
update() {
// Apply gravity
this.velocityY += this.config.gravity;
this.birdPositionY += this.velocityY;
this.dantePositionY += this.velocityY;

// Limit speed
if (this.velocityY > this.maxDownwardsSpeed) {
Expand All @@ -51,38 +51,39 @@ export default class Bird {
this.velocityY = this.maxUpwardsSpeed;
}

// Prevent bird from going off the top of the screen
if (this.birdPositionY < 0) {
this.birdPositionY = 0;
// Prevent dante from going off the top of the screen
if (this.dantePositionY < 0) {
this.dantePositionY = 0;
this.velocityY = 0;
}
}

draw() {
this.config.index += 0.3;
this.birdY = Math.floor((this.config.index % 9) / 3) * (this.birdWidth - 9);
this.danteY =
Math.floor((this.config.index % 9) / 3) * (this.danteWidth - 9);

let scaledBirdWidth = this.birdWidth * this.canvas.scaleFactor;
let scaledBirdHeight = this.birdHeight * this.canvas.scaleFactor;
let scaledPositionX = this.birdPositionX;
let scaledPositionY = this.birdPositionY * this.canvas.scaleFactor;
let scaledDanteWidth = this.danteWidth * this.canvas.scaleFactor;
let scaledDanteHeight = this.danteHeight * this.canvas.scaleFactor;
let scaledPositionX = this.dantePositionX;
let scaledPositionY = this.dantePositionY * this.canvas.scaleFactor;

this.canvas.context.drawImage(
this.imageBird,
this.birdX,
this.birdY,
this.birdWidth, // Original sprite crop width (if using sprite sheet)
this.birdHeight, // Original sprite crop height
this.imageDante,
this.danteX,
this.danteY,
this.danteWidth,
this.danteHeight,
scaledPositionX,
scaledPositionY,
scaledBirdWidth,
scaledBirdHeight
scaledDanteWidth,
scaledDanteHeight
);
}

jump() {
this.velocityY = this.lift;
this.flyBird.play();
this.flyDante.play();
}

control() {
Expand Down
10 changes: 5 additions & 5 deletions flappy-dante/JS/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Canvas from "./canvas.js";
import GameLoop from "./gameLoop.js";
import Pipe from "./pipe.js";
import Bird from "./bird.js";
import Dante from "./dante.js";
import Score from "./score.js";
import WindowGameOver from "./windowGameOver.js";
import Medal from "./medal.js";
Expand All @@ -12,7 +12,7 @@ class Game {
constructor() {
this.canvas = new Canvas();
this.pipe = new Pipe();
this.bird = new Bird();
this.dante = new Dante();
this.score = new Score();
this.windowGameOver = new WindowGameOver();
this.medal = new Medal(this.score);
Expand Down Expand Up @@ -40,20 +40,20 @@ class Game {
update() {
if (this.config.gamePlaying) {
this.pipe.update(
this.bird,
this.dante,
this.gameLoop,
this.windowGameOver,
this.score,
this.medal
);
this.bird.update();
this.dante.update();
}
}

draw() {
this.canvas.draw();
this.pipe.draw();
this.bird.draw();
this.dante.draw();
if (this.config.gamePlaying) this.score.draw();
if (!this.config.gamePlaying) this.windowGameStart.draw();
}
Expand Down
46 changes: 23 additions & 23 deletions flappy-dante/JS/pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,51 +34,51 @@ export default class Pipe {
},
];

this.btnRestart = document.querySelector(".btn-flappy-bird");
this.btnRestart = document.querySelector(".btn-flappy-dante");

this.birdCollisionPositionY = 485;
this.danteCollisionPositionY = 485;
}

didCollide(bird, pipe) {
didCollide(dante, pipe) {
const scaledForegroundHeight =
this.canvas.foreground.height * this.canvas.scaleFactor;

const birdBottomEdge = bird.birdPositionY + bird.birdHeight;
const danteBottomEdge = dante.dantePositionY + dante.danteHeight;

const playableAreaHeight =
(this.canvas.element.height - scaledForegroundHeight) /
this.canvas.scaleFactor;

const hitGround = birdBottomEdge >= playableAreaHeight;
const hitGround = danteBottomEdge >= playableAreaHeight;

const birdHitsPipeHorizontally =
bird.birdPositionX + bird.birdWidth * this.canvas.scaleFactor >= pipe.x &&
bird.birdPositionX <= pipe.x + this.pipeUp.width;
const birdHitsTopPipeVertically =
bird.birdPositionY <= pipe.y - 5 + this.pipeUp.height - 200;
const birdHitsBottomPipeVertically =
bird.birdPositionY + bird.birdHeight >=
const danteHitsPipeHorizontally =
dante.dantePositionX + dante.danteWidth * this.canvas.scaleFactor >=
pipe.x && dante.dantePositionX <= pipe.x + this.pipeUp.width;
const danteHitsTopPipeVertically =
dante.dantePositionY <= pipe.y - 5 + this.pipeUp.height - 200;
const danteHitsBottomPipeVertically =
dante.dantePositionY + dante.danteHeight >=
pipe.y + this.pipeUp.height + this.gap - 200;
return (
(birdHitsPipeHorizontally &&
(birdHitsTopPipeVertically || birdHitsBottomPipeVertically)) ||
(danteHitsPipeHorizontally &&
(danteHitsTopPipeVertically || danteHitsBottomPipeVertically)) ||
hitGround
);
}

doGameOver(gameLoop, bird, score, windowGameOver, medal) {
doGameOver(gameLoop, dante, score, windowGameOver, medal) {
gameLoop.cancelAnimation();

document.addEventListener("click", () => {
bird.flyBird.pause();
dante.flyDante.pause();
});

document.addEventListener("touchstart", () => {
bird.flyBird.pause();
dante.flyDante.pause();
});

bird.birdPositionY = this.birdCollisionPositionY;
bird.dieBird.play();
dante.dantePositionY = this.danteCollisionPositionY;
dante.dieDante.play();

score.bestScoreRecord();
windowGameOver.draw(score._score, score._bestScore, medal);
Expand All @@ -94,7 +94,7 @@ export default class Pipe {
});
}

update(bird, gameLoop, windowGameOver, score, medal) {
update(dante, gameLoop, windowGameOver, score, medal) {
this.pipes.forEach((pipe) => {
pipe.x -= this.speed;
if (pipe.x < this.spaceBetweenPipe && !pipe.newPipeAdded) {
Expand All @@ -111,16 +111,16 @@ export default class Pipe {
this.pipes.shift();
}

if (pipe.x < bird.birdPositionX && !pipe.hasBeenScored) {
if (pipe.x < dante.dantePositionX && !pipe.hasBeenScored) {
score.increaseScore();
score.audioScore.play();
pipe.hasBeenScored = true;
}

const didCollide = this.didCollide(bird, pipe);
const didCollide = this.didCollide(dante, pipe);

if (didCollide) {
this.doGameOver(gameLoop, bird, score, windowGameOver, medal);
this.doGameOver(gameLoop, dante, score, windowGameOver, medal);
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions flappy-dante/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
</head>

<body>
<canvas id="flappy-bird"></canvas>
<button class="btn-flappy-bird"></button>
<canvas id="flappy-dante"></canvas>
<button class="btn-flappy-dante"></button>

<script src="./JS/main.js" type="module"></script>
</body>
Expand Down
6 changes: 3 additions & 3 deletions flappy-dante/style/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ body {
align-items: center;
}

.btn-flappy-bird {
.btn-flappy-dante {
display: none;
padding: 20px 60px;
background: url('../Images/btnStartGame.png') no-repeat center / cover;
Expand All @@ -26,10 +26,10 @@ body {
position: absolute;
}

.btn-flappy-bird:active {
.btn-flappy-dante:active {
transform: translateY(5%);
}

.btn-flappy-bird.active {
.btn-flappy-dante.active {
display: inline-block
}
4 changes: 0 additions & 4 deletions img/portfolio/boxingdial.png:Zone.Identifier

This file was deleted.

3 changes: 0 additions & 3 deletions img/portfolio/boxingdialicon.png:Zone.Identifier

This file was deleted.

Binary file removed img/portfolio/budgetcalc.png
Binary file not shown.
Binary file removed img/portfolio/connect4.png
Binary file not shown.
Binary file removed img/portfolio/ecuador.png
Binary file not shown.
Binary file modified img/portfolio/flappydante.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed img/portfolio/genesiswebsite.png
Binary file not shown.
Binary file removed img/portfolio/img-1.jpg
Binary file not shown.
Binary file removed img/portfolio/img-10.jpg
Binary file not shown.
Binary file removed img/portfolio/img-11.jpg
Binary file not shown.
Binary file removed img/portfolio/img-2.jpg
Binary file not shown.
Binary file removed img/portfolio/img-3.jpg
Binary file not shown.
Binary file removed img/portfolio/img-4.jpg
Binary file not shown.
Binary file removed img/portfolio/img-5.jpg
Binary file not shown.
Binary file removed img/portfolio/img-6.jpg
Binary file not shown.
Binary file removed img/portfolio/img-7.jpg
Binary file not shown.
Binary file removed img/portfolio/img-8.jpg
Binary file not shown.
Binary file removed img/portfolio/img-9.jpg
Binary file not shown.
Binary file removed img/portfolio/kaboom.gif
Binary file not shown.
Binary file removed img/portfolio/snackmachine.png
Binary file not shown.
Binary file removed img/portfolio/snakegame.png
Binary file not shown.
Binary file removed img/portfolio/tetris.png
Binary file not shown.
Binary file removed img/portfolio/tictactoe.png
Binary file not shown.

0 comments on commit 2c966bd

Please sign in to comment.