generated from nighthawkcoders/teacher_portfolio
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from vs26625/main
Integrating Winter Level (animations team)
- Loading branch information
Showing
24 changed files
with
567 additions
and
6 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,39 @@ | ||
import Background from './Background.js'; | ||
|
||
export class BackgroundSnow extends Background { | ||
constructor(canvas, image, data) { | ||
super(canvas, image, data); | ||
|
||
this.parallaxSpeed = 0.3; // Speed for vertical parallax scrolling | ||
} | ||
|
||
// Update method to handle vertical scrolling | ||
update() { | ||
this.y += this.parallaxSpeed; // Move vertically based on parallax speed | ||
super.update(); | ||
|
||
// Reset the position once the entire image has scrolled through the canvas | ||
if (this.y >= this.image.height) { | ||
this.y -= this.image.height; // Reset to the top of the image | ||
} | ||
} | ||
|
||
// Draw method to render the background image vertically | ||
draw() { | ||
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height); | ||
|
||
// Calculate the vertical positions for drawing | ||
const firstImageY = this.y % this.image.height; | ||
const secondImageY = firstImageY - this.image.height; | ||
|
||
// Draw the first image | ||
this.ctx.drawImage(this.image, 0, firstImageY, this.canvas.width, this.image.height); | ||
|
||
// Draw the second image above the first one for seamless scrolling | ||
this.ctx.drawImage(this.image, 0, secondImageY, this.canvas.width, this.image.height); | ||
|
||
super.draw(); | ||
} | ||
} | ||
|
||
export default BackgroundSnow; |
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,25 @@ | ||
import GameEnv from './GameEnv.js'; | ||
import Background from './Background.js'; | ||
|
||
export class BackgroundWinter extends Background { | ||
constructor(canvas, image, data) { | ||
super(canvas, image, data); | ||
|
||
this.parallaxSpeed = 0.4; | ||
} | ||
|
||
// speed is used to background parallax behavior | ||
update() { | ||
this.speed = GameEnv.backgroundDirection * this.parallaxSpeed; | ||
super.update(); | ||
} | ||
|
||
//Cause of limited bg cutout, keeping just incase it causes issues later | ||
draw() { | ||
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height); | ||
super.draw(); | ||
} | ||
|
||
} | ||
|
||
export default BackgroundWinter; |
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,35 @@ | ||
import GameEnv from './GameEnv.js'; | ||
import GameObject from './GameObject.js'; | ||
export class Cabin extends GameObject { | ||
constructor(canvas, image, data) { | ||
super(canvas, image, data); | ||
} | ||
// Required, but no update action | ||
update() { | ||
} | ||
// Draw position is always 0,0 | ||
draw() { | ||
this.ctx.drawImage(this.image, 0, 0, this.canvas.width, this.canvas.height); | ||
} | ||
// Set Cabin position | ||
size() { | ||
// Formula for Height should be on constant ratio, using a proportion of 832 | ||
const scaledHeight = GameEnv.innerHeight * (600/832); | ||
// Formula for Width is scaled: scaledWidth/scaledHeight == this.width/this.height | ||
const scaledWidth = scaledHeight * this.aspect_ratio; | ||
const cabinX = .80 * GameEnv.innerWidth; | ||
const cabinY = (GameEnv.bottom - (.18 * scaledHeight)); | ||
// set variables used in Display and Collision algorithms | ||
this.bottom = cabinY; | ||
this.collisionHeight = scaledHeight; | ||
this.collisionWidth = scaledWidth; | ||
//this.canvas.width = this.width; | ||
//this.canvas.height = this.height; | ||
this.canvas.style.Width = `${scaledWidth}px`; | ||
this.canvas.style.Height = `${scaledHeight}px`; | ||
this.canvas.style.position = 'absolute'; | ||
this.canvas.style.left = `${cabinX}px`; | ||
this.canvas.style.top = `${cabinY}px`; | ||
} | ||
} | ||
export default Cabin; |
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
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,84 @@ | ||
import Character from './Character.js'; | ||
import FlyingGoomba from './FlyingGoomba.js'; | ||
import GameEnv from './GameEnv.js'; | ||
|
||
export class Snowman extends FlyingGoomba { | ||
|
||
// constructors sets up Character object | ||
constructor(canvas, image, data, xPercentage, yPercentage, name, minPosition){ | ||
super(canvas, image, data); | ||
|
||
//Unused but must be defined | ||
this.name = name; | ||
this.yPercentage = yPercentage; | ||
|
||
//Initial Position of Goomba | ||
this.x = xPercentage * GameEnv.innerWidth; | ||
this.y = 0.4 * GameEnv.innerHeight; | ||
|
||
//Access in which a Goomba can travel | ||
this.minPosition = minPosition * GameEnv.innerWidth; | ||
this.maxPosition = this.x + xPercentage * GameEnv.innerWidth; | ||
|
||
this.immune = 0; | ||
|
||
// Define Speed of Enemy | ||
if (GameEnv.difficulty === "normal") { | ||
this.speed = this.speed; | ||
} else if (GameEnv.difficulty === "hard") { | ||
this.speed = this.speed * 2; | ||
} else if (GameEnv.difficulty === "easy") { | ||
this.speed = this.speed * 1; | ||
} else if (GameEnv.difficulty === "impossible") { | ||
this.speed = this.speed * 3; | ||
} | ||
} | ||
|
||
update() { | ||
super.update(); | ||
|
||
if (this.x <= this.minPosition || (this.x + this.canvasWidth >= this.maxPosition) || this.x > (GameEnv.innerWidth - 100) ) { | ||
this.speed = -this.speed; | ||
} | ||
|
||
if (this.speed < 0) { | ||
this.canvas.style.transform = 'scaleX(1)'; | ||
} else { | ||
this.canvas.style.transform = 'scaleX(-1)'; | ||
} | ||
|
||
this.dropGoomba(); | ||
|
||
// Every so often change direction | ||
if (Math.random() < 0.005) { | ||
this.speed = Math.random() < 0.5 ? -this.speed : this.speed; | ||
} | ||
|
||
//Chance for Goomba to turn Gold | ||
if (["normal","hard"].includes(GameEnv.difficulty)) { | ||
if (Math.random() < 0.00001) { | ||
this.canvas.style.filter = 'brightness(1000%)'; | ||
this.immune = 1; | ||
} | ||
} | ||
|
||
//Immunize Goomba & Texture It | ||
if (GameEnv.difficulty === "hard") { | ||
this.canvas.style.filter = "invert(100%)"; | ||
this.canvas.style.scale = 1.25; | ||
this.immune = 1; | ||
} else if (GameEnv.difficulty === "impossible") { | ||
this.canvas.style.filter = 'brightness(1000%)'; | ||
this.canvas.style.transform = "rotate(180deg)" | ||
this.immune = 1; | ||
} | ||
|
||
// Move the enemy | ||
this.x -= this.speed; | ||
} | ||
|
||
// Player action on collisions | ||
} | ||
|
||
|
||
export default Snowman; |
Oops, something went wrong.