Skip to content

Commit

Permalink
Merge pull request #60 from vs26625/main
Browse files Browse the repository at this point in the history
Integrating Winter Level (animations team)
  • Loading branch information
vs26625 authored May 2, 2024
2 parents 76d6974 + d9ca6f1 commit a6011e9
Show file tree
Hide file tree
Showing 24 changed files with 567 additions and 6 deletions.
39 changes: 39 additions & 0 deletions assets/js/platformer3x/BackgroundSnow.js
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;
25 changes: 25 additions & 0 deletions assets/js/platformer3x/BackgroundWinter.js
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;
35 changes: 35 additions & 0 deletions assets/js/platformer3x/Cabin.js
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;
15 changes: 15 additions & 0 deletions assets/js/platformer3x/GameEnv.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,21 @@ export class GameEnv {
GameEnv.backgroundDirection = 1;
}
break;
case "s":
if (keys.includes("a") && keys.includes("s")) {
// If both "a" and "s" are clicked
if (GameEnv.player?.x > 2) {
GameEnv.backgroundDirection = -5;
}
} else if (keys.includes("d") && keys.includes("s")) {
// If both "d" and "s" are clicked
if (GameEnv.player?.x < (GameEnv.innerWidth - 2)) {
GameEnv.backgroundDirection = 5;
}
} else {
GameEnv.backgroundDirection = 0;
}
break;
default:
GameEnv.backgroundDirection = 0;
break;
Expand Down
103 changes: 100 additions & 3 deletions assets/js/platformer3x/GameSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,31 @@ import BackgroundHills from './BackgroundHills.js';
import BackgroundMountains from './BackgroundMountains.js';
import BackgroundTransitions from './BackgroundTransitions.js';
import BackgroundClouds from './BackgroundClouds.js';
import BackgroundWinter from './BackgroundWinter.js';
import BackgroundSnow from './BackgroundSnow.js';
import Platform from './Platform.js';
import JumpPlatform from './JumpPlatform.js';
import Player from './Player.js';
import PlayerHills from './PlayerHills.js';
import PlayerWinter from './PlayerWinter.js';
import PlayerMini from './PlayerMini.js';
import PlayerBase from './PlayerBase.js';
import Tube from './Tube.js';
import Tube1 from './Tube1.js';
import Tree from './Tree.js';
import Cabin from './Cabin.js';
import Goomba from './Goomba.js';
import FlyingGoomba from './FlyingGoomba.js';
import BlockPlatform from './BlockPlatform.js';
import Mushroom from './Mushroom.js';
import Coin from './Coin.js';
import Snowflake from './Snowflake.js';
import FlyingUFO from './FlyingUFO.js';
import Alien from './Alien.js';
import GameControl from './GameControl.js';
import Enemy from './Enemy.js';
import Owl from './Owl.js';
import Snowman from './Snowman.js';
import Cerberus from './Cerberus.js';
import PlayerGreece from './PlayerGreece.js';
import Flag from './Flag.js';
Expand Down Expand Up @@ -207,12 +214,15 @@ const GameSetup = {
tube: { src: "/images/platformer/obstacles/blue-tube-up.png",
hitbox: { widthPercentage: 0.5, heightPercentage: 0.5}
},
cabin: { src: "/images/platformer/obstacles/cabin.png",
hitbox: { widthPercentage: 0.5, heightPercentage: 0.5}
},
coin: { src: "/images/platformer/obstacles/coin.png"},
snowflake: { src: "/images/platformer/obstacles/snowflake.png"},
tubeD: { src: "/images/platformer/obstacles/blue-tube.png",
hitbox: { widthPercentage: 0.5, heightPercentage: 0.5}
},
star: { src: "/images/platformer/obstacles/star.png"},
coin: { src: "/images/platformer/obstacles/coin.png"},
star: { src: "/images/platformer/obstacles/star.png"},
tree: { src: "/images/platformer/obstacles/tree.png",
hitbox: { widthPercentage: 0.5, heightPercentage: 0.5}
},
Expand All @@ -222,6 +232,8 @@ const GameSetup = {
},
platforms: {
grass: { src: "/images/platformer/platforms/grass.png" },
snowyfloor: { src: "/images/platformer/platforms/snowyfloor.png" },
snowywood: { src: "/images/platformer/platforms/snowywood.png" },
alien: { src: "/images/platformer/platforms/alien.png" },
bricks: { src: "/images/platformer/platforms/brick_wall.png" },
lava: { src: "/images/platformer/platforms/lava.jpg" },
Expand Down Expand Up @@ -250,8 +262,11 @@ const GameSetup = {
loading: { src: "/images/platformer/backgrounds/greenscreen.png" },
complete: { src: "/images/platformer/backgrounds/OneStar.png" },
complete2: { src: "/images/platformer/backgrounds/TwoStar.png" },
complete3: {src: "/images/platformer/backgrounds/ThreeStar.png" },
end: { src: "/images/platformer/backgrounds/Congratulations!!!.png" },
winter: {src: "/images/platformer/backgrounds/winter.png" },
snow: {src: "/images/platformer/backgrounds/snowfall.png" },
mini: { src: "/images/platformer/backgrounds/mini.png" },
end: { src: "/images/platformer/backgrounds/Congratulations!!!.png" }
},
players: {
mario: {
Expand All @@ -277,6 +292,30 @@ const GameSetup = {
right: { row: 10, frames: 15 },
},
hitbox: { widthPercentage: 0.3, heightPercentage: 0.8 }
},
whitemario: {
src: "/images/platformer/sprites/white_mario.png",
width: 256,
height: 256,
scaleSize: 80,
speedRatio: 0.7,
idle: {
left: { row: 1, frames: 15 },
right: { row: 0, frames: 15},
},
walk: {
left: { row: 3, frames: 7 },
right: { row: 2, frames: 7 },
},
run: {
left: { row: 5, frames: 15 },
right: { row: 4, frames: 15 },
},
jump: {
left: { row: 11, frames: 15 },
right: { row: 10, frames: 15 },
},
hitbox: { widthPercentage: 0.3, heightPercentage: 0.8 }
},
monkey: {
src: "/images/platformer/sprites/monkey.png",
Expand Down Expand Up @@ -340,6 +379,27 @@ const GameSetup = {
xPercentage: 0.6,
hitbox: { widthPercentage: 0.0, heightPercentage: 0.2}
},
Snowman: {
src: "/images/platformer/sprites/snowman.png",
width: 308,
height: 327,
scaleSize: 60,
speedRatio: 0.7,
xPercentage: 0.6,
hitbox: { widthPercentage: 0.0, heightPercentage: 0.2},
wa: {row: 0, frames: 0}, // Up-Left Movement
wd: {row: 0, frames: 0}, // Up-Right Movement
a: { row: 0, frames: 0, idleFrame: { column: 0, frames: 0 } }, // Left Movement
s: {row: 0, frames: 0}, // Stop the movement
d: { row: 0, frames: 0, idleFrame: { column: 0, frames: 0 } }, // Right Movement
},
Owl: {
src: "/images/platformer/sprites/owl.png",
width: 499,
height: 500,
scaleSize: 60,
speedRatio: 0.8,
},
flyingGoomba: {
src: "/images/platformer/sprites/flying-goomba.png",
width: 448,
Expand Down Expand Up @@ -644,6 +704,43 @@ const GameSetup = {
// Space Game Level added to the GameEnv ...
new GameLevel( {tag: "mini", callback: this.playerOffScreenCallBack, objects: miniGameObjects} );

const winterObjects = [
// GameObject(s), the order is important to z-index...
{ name: 'winter', id: 'background', class: BackgroundWinter, data: this.assets.backgrounds.winter },
{ name: 'snow', id: 'background', class: BackgroundSnow, data: this.assets.backgrounds.snow },
{ name: 'snowyfloor', id: 'platform', class: Platform, data: this.assets.platforms.snowyfloor },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.snowywood, xPercentage: 0.2, yPercentage: 0.82 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.snowywood, xPercentage: 0.2368, yPercentage: 0.82 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.snowywood, xPercentage: 0.2736 , yPercentage: 0.82 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.snowywood, xPercentage: 0.3104, yPercentage: 0.82 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.snowywood, xPercentage: 0.3472, yPercentage: 0.82 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.snowywood, xPercentage: 0.384, yPercentage: 0.74 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.snowywood, xPercentage: 0.4208, yPercentage: 0.66 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.snowywood, xPercentage: 0.5090, yPercentage: 0.56 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.snowywood, xPercentage: 0.5090, yPercentage: 0.48 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.snowywood, xPercentage: 0.5090, yPercentage: 0.40 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.snowywood, xPercentage: 0.5090, yPercentage: 0.32 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.snowywood, xPercentage: 0.69, yPercentage: 0.76 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.snowywood, xPercentage: 0.655, yPercentage: 0.68 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.snowywood, xPercentage: 0.62, yPercentage: 0.68 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.snowywood, xPercentage: 0.72, yPercentage: 0.76 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.snowywood, xPercentage: 0.755, yPercentage: 1 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.snowywood, xPercentage: 0.755, yPercentage: 0.92 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.snowywood, xPercentage: 0.755, yPercentage: 0.84 },
{ name: 'snowflake', id: 'snowflake', class: Snowflake, data: this.assets.obstacles.snowflake, xPercentage: 0.2100, yPercentage: 0.75 },
{ name: 'snowflake', id: 'snowflake', class: Snowflake, data: this.assets.obstacles.snowflake, xPercentage: 0.2619, yPercentage: 0.75 },
{ name: 'snowflake', id: 'snowflake', class: Snowflake, data: this.assets.obstacles.snowflake, xPercentage: 0.3136, yPercentage: 0.75 },
{ name: 'owl', id: 'owl', class: Owl, data: this.assets.enemies.Owl, xPercentage: 0.3, minPosition: 0.05},
{ name: 'owl', id: 'owl', class: Owl, data: this.assets.enemies.Owl, xPercentage: 0.8, minPosition: 0.05},
{ name: 'snowman', id: 'snowman', class: Snowman, data: this.assets.enemies.Snowman, xPercentage: 0.2, minPosition: 0.1, difficulties: ["normal", "hard", "impossible"]},
{ name: 'snowman', id: 'snowman', class: Snowman, data: this.assets.enemies.Snowman, xPercentage: 0.35, minPosition: 0.1, difficulties: ["normal", "hard", "impossible"]},
{ name: 'snowman', id: 'snowman', class: Snowman, data: this.assets.enemies.Snowman, xPercentage: 0.5, minPosition: 0.1, difficulties: ["normal", "hard", "impossible"]},
{ name: 'mario', id: 'player', class: PlayerWinter, data: this.assets.players.whitemario },
{ name: 'cabin', id: 'cabin', class: Cabin, data: this.assets.obstacles.cabin },
{ name: 'complete', id: 'background', class: BackgroundTransitions, data: this.assets.backgrounds.complete },
];
// Winter Game Level added to the GameEnv ...
new GameLevel( {tag: "winter", callback: this.playerOffScreenCallBack, objects: winterObjects} );
// Game Over Level definition...
const endGameObjects = [
{ name:'background', class: Background, id: 'background', data: this.assets.backgrounds.end}
Expand Down
84 changes: 84 additions & 0 deletions assets/js/platformer3x/Owl.js
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;
Loading

0 comments on commit a6011e9

Please sign in to comment.