Skip to content

Commit

Permalink
Merge pull request #62 from kaylale124/main
Browse files Browse the repository at this point in the history
Team Level - Quidditch
  • Loading branch information
kaylale124 authored May 3, 2024
2 parents c1bf56e + 355c85d commit 7d02c9f
Show file tree
Hide file tree
Showing 4 changed files with 257 additions and 16 deletions.
80 changes: 80 additions & 0 deletions assets/js/platformer3x/Dementor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import Character from './Character.js';
import FlyingGoomba from './FlyingGoomba.js';
import GameEnv from './GameEnv.js';

export class Dementor 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 {
this.speed = this.speed * 2;
}
}

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 Dementor;
59 changes: 59 additions & 0 deletions assets/js/platformer3x/Draco.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import Character from './Character.js';
import GameEnv from './GameEnv.js';
import GameControl from './GameControl.js';
import Enemy from './Enemy.js';

export class Draco extends Enemy {
// 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.y = yPercentage;

//Initial Position of Goomba
this.x = xPercentage * GameEnv.innerWidth;

//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 (["easy", "normal"].includes(GameEnv.difficulty)) {
this.speed = this.speed * Math.floor(Math.random() * 1.5 + 2);
} else if (GameEnv.difficulty === "hard") {
this.speed = this.speed * Math.floor(Math.random() * 3 + 3);
} else {
this.speed = this.speed * 5
}
}

updateMovement(){
if (this.direction === "d") {
this.speed = Math.abs(this.storeSpeed)
}
else if (this.direction === "a") {
this.speed = -Math.abs(this.storeSpeed);
}
else if (this.direction === "idle") {
this.speed = 0
}


// Move the enemy\
this.x += this.speed;
}

update() {
super.update();
super.checkBoundaries();
this.updateMovement();
}


}

export default Draco;
118 changes: 116 additions & 2 deletions assets/js/platformer3x/GameSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Player from './Player.js';
import PlayerHills from './PlayerHills.js';
import PlayerWinter from './PlayerWinter.js';
import PlayerMini from './PlayerMini.js';
import PlayerQuidditch from './PlayerQuidditch.js';
import PlayerBase from './PlayerBase.js';
import Tube from './Tube.js';
import Tube1 from './Tube1.js';
Expand All @@ -39,6 +40,8 @@ import PlayerGreece from './PlayerGreece.js';
import Flag from './Flag.js';
import Dragon from './Dragon.js';
import Star from './Star.js';
import Dementor from './Dementor.js';
import Draco from './Draco.js';

//test comment

Expand Down Expand Up @@ -231,6 +234,10 @@ const GameSetup = {
flag: { src: "/images/platformer/obstacles/flag.png",
hitbox: { widthPercentage: 0.5, heightPercentage: 0.5}
},
snitch: { src: "/images/platformer/obstacles/snitch.png"},
whompingwillow: { src: "/images/platformer/obstacles/whompingwillowtree.png",
hitbox: { widthPercentage: 0.5, heightPercentage: 0.5}
},
},
platforms: {
grass: { src: "/images/platformer/platforms/grass.png" },
Expand All @@ -241,6 +248,11 @@ const GameSetup = {
bricks: { src: "/images/platformer/platforms/brick_wall.png" },
lava: { src: "/images/platformer/platforms/lava.jpg" },
sandstone: { src: "/images/platformer/platforms/sandstone.png" },
cobblestone: { src: "/images/platformer/platforms/cobblestone.png"},
yellowpattern: { src: "/images/platformer/platforms/yellowtowerpattern.jpg"},
yellowredpattern: { src: "/images/platformer/platforms/yellowredpattern.jpg"},
lionpattern: {src: "/images/platformer/platforms/lionpattern.jpg"},
turf: {src:"/images/platformer/platforms/turf.png"},
block: { src: "/images/platformer/platforms/brick_block.png" }, //MAY need 3 new variables: sizeRatio, widthRatio, and heightRatio
itemBlock: {
src: "/images/platformer/platforms/mario_block_spritesheet_v2.png",
Expand All @@ -263,7 +275,7 @@ const GameSetup = {
water: { src: "/images/platformer/backgrounds/water.png" },
fish : { src: "/images/platformer/backgrounds/school-fish.png"},
reef: { src: "/images/platformer/backgrounds/reef.png" },

quidditch: { src: "/images/platformer/backgrounds/quidditch2.jpg"},
space: { src: "/images/platformer/backgrounds/planet.jpg" },
castles: { src: "/images/platformer/backgrounds/castles.png" },
loading: { src: "/images/platformer/backgrounds/greenscreen.png" },
Expand Down Expand Up @@ -359,6 +371,29 @@ const GameSetup = {
right: { row: 2, frames: 23 },
},
hitbox: { widthPercentage: 0.3, heightPercentage: 0.8 }
}, harry: {
src: "/images/platformer/sprites/harryanimation3.png",
width: 32,
height: 32,
scaleSize: 60,
speedRatio: 0.7,
idle: {
left: { row: 1, frames: 1 },
right: { row: 2, frames: 1 },
},
walk: {
left: { row: 1, frames: 5 },
right: { row: 2, frames: 5 },
},
run: {
left: { row: 1, frames: 5 },
right: { row: 2, frames: 5 },
},
jump: {
left: { row: 1, frames: 1 },
right: { row: 2, frames: 1 },
},
hitbox: { widthPercentage: 0.3, heightPercentage: 0.8 }
},
lopez: {
src: "/images/platformer/sprites/lopezanimation.png",
Expand Down Expand Up @@ -452,7 +487,26 @@ const GameSetup = {
height: 119,
scaleSize: 60,
speedRatio: 0.7,
},dementor: {
src: "/images/platformer/sprites/dementor2.png",
width: 400,
height: 400,
scaleSize: 80,
speedRatio: 0.7,
},
draco: {
src: "/images/platformer/sprites/dracomalfoy.png",
width: 301,
height: 261,
scaleSize: 80,
speedRatio: 0.7,
xPercentage: 0.6,
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
},
}
},

Expand Down Expand Up @@ -747,6 +801,66 @@ const GameSetup = {
new GameLevel( {tag: "water", callback: this.playerOffScreenCallBack, objects: waterGameObjects } );


// Quidditch Game Level definition...
const quidditchGameObjects = [
// GameObject(s), the order is important to z-index...
{ name: 'quidditch', id: 'background', class: Background, data: this.assets.backgrounds.quidditch },
{ name: 'turf', id: 'platform', class: Platform, data: this.assets.platforms.turf },

{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.cobblestone, xPercentage: 0.1, yPercentage: 0.81 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.cobblestone, xPercentage: 0.14, yPercentage: 0.81 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.cobblestone, xPercentage: 0.18, yPercentage: 0.81 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.cobblestone, xPercentage: 0.22, yPercentage: 0.81 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.cobblestone, xPercentage: 0.22, yPercentage: 0.69 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.cobblestone, xPercentage: 0.30, yPercentage: 0.81 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.cobblestone, xPercentage: 0.30, yPercentage: 0.69 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.cobblestone, xPercentage: 0.30, yPercentage: 0.57 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.cobblestone, xPercentage: 0.30, yPercentage: 0.33 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.cobblestone, xPercentage: 0.30, yPercentage: 0.21 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.cobblestone, xPercentage: 0.34, yPercentage: 0.81 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.cobblestone, xPercentage: 0.38, yPercentage: 0.81 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.cobblestone, xPercentage: 0.42, yPercentage: 0.81 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.cobblestone, xPercentage: 0.38, yPercentage: 0.57 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.cobblestone, xPercentage: 0.38, yPercentage: 0.45 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.cobblestone, xPercentage: 0.38, yPercentage: 0.33 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.cobblestone, xPercentage: 0.38, yPercentage: 0.21 },

{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.cobblestone, xPercentage: 0.536, yPercentage: 0.72 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.cobblestone, xPercentage: 0.616, yPercentage: 0.81 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.cobblestone, xPercentage: 0.696, yPercentage: 0.90 },

{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.lionpattern, xPercentage: 0.456, yPercentage: 0.4 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.yellowpattern, xPercentage: 0.456, yPercentage: 0.515 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.yellowredpattern, xPercentage: 0.456, yPercentage: 0.63 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.yellowpattern, xPercentage: 0.456, yPercentage: 0.745 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.lionpattern, xPercentage: 0.456, yPercentage: 0.85 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.yellowpattern, xPercentage: 0.456, yPercentage: 0.965 },
{ name: 'blocks', id: 'jumpPlatform', class: BlockPlatform, data: this.assets.platforms.yellowredpattern, xPercentage: 0.456, yPercentage: 1.08 },

{ name: 'draco', id: 'draco', class: Draco, data: this.assets.enemies.draco, xPercentage: 0.3, minPosition: 0.05, difficulties: ["normal", "hard", "impossible"]},
{ name: 'draco', id: 'draco', class: Draco, data: this.assets.enemies.draco, xPercentage: 0.5, minPosition: 0.3, difficulties: ["normal", "hard", "impossible"] },
{ name: 'draco', id: 'draco', class: Draco, data: this.assets.enemies.draco, xPercentage: 0.75, minPosition: 0.5, difficulties: ["normal", "hard", "impossible"] }, //this special name is used for random event 2 to make sure that only one of the Goombas ends the random event
{ name: 'dementor', id: 'dementor', class: Dementor, data: this.assets.enemies.dementor, xPercentage: 0.5, minPosition: 0.05},
{ name: 'dementor', id: 'dementor', class: Dementor, data: this.assets.enemies.dementor, xPercentage: 0.9, minPosition: 0.5},

{ name: 'coin', id: 'coin', class: Coin, data: this.assets.obstacles.snitch, xPercentage: 0.095, yPercentage: 0.7 },
{ name: 'coin', id: 'coin', class: Coin, data: this.assets.obstacles.snitch, xPercentage: 0.135, yPercentage: 0.7 },
{ name: 'coin', id: 'coin', class: Coin, data: this.assets.obstacles.snitch, xPercentage: 0.175, yPercentage: 0.7 },
{ name: 'coin', id: 'coin', class: Coin, data: this.assets.obstacles.snitch, xPercentage: 0.295, yPercentage: 0.46 },

{ name: 'coin', id: 'coin', class: Coin, data: this.assets.obstacles.snitch, xPercentage: 0.687, yPercentage: 0.79, },
{ name: 'coin', id: 'coin', class: Coin, data: this.assets.obstacles.snitch, xPercentage: 0.611, yPercentage: 0.7 },
{ name: 'coin', id: 'coin', class: Coin, data: this.assets.obstacles.snitch, xPercentage: 0.529, yPercentage: 0.61 },

{ name: 'harry', id: 'player', class: PlayerQuidditch, data: this.assets.players.harry },
{ name: 'tube', id: 'tube', class: Tube, data: this.assets.obstacles.tube },
//{ name: 'loading', id: 'background', class: BackgroundTransitions, data: this.assets.backgrounds.loading },
];

// Quidditch Game Level added to the GameEnv ...
new GameLevel( {tag: "quidditch", callback: this.playerOffScreenCallBack, objects: quidditchGameObjects } );


const winterObjects = [
// GameObject(s), the order is important to z-index...
{ name: 'winter', id: 'background', class: BackgroundWinter, data: this.assets.backgrounds.winter },
Expand Down Expand Up @@ -785,7 +899,7 @@ const GameSetup = {
// 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
16 changes: 2 additions & 14 deletions assets/js/platformer3x/PlayerQuidditch.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ export class PlayerQuidditch extends PlayerBase {
super.handleCollisionStart(); // calls the super class method
// adds additional collision events
this.handleCollisionEvent("tube");
this.handleCollisionEvent("goomba");
this.handleCollisionEvent("mushroom");
this.handleCollisionEvent("draco");
}

/**
Expand Down Expand Up @@ -84,7 +83,7 @@ export class PlayerQuidditch extends PlayerBase {
this.state.movement.right = true;
}
break;
case "goomba": // Note: Goomba.js and Player.js could be refactored
case "draco": // Note: Goomba.js and Player.js could be refactored
// 1. Player jumps on goomba, interaction with Goomba.js
if (this.collisionData.touchPoints.this.top && this.collisionData.touchPoints.other.bottom && this.state.isDying == false) {
// GoombaBounce deals with player.js and goomba.js
Expand Down Expand Up @@ -116,17 +115,6 @@ export class PlayerQuidditch extends PlayerBase {

}
break;
case "mushroom": //
// Player touches mushroom
if (GameEnv.destroyedMushroom === false) {
GameEnv.destroyedMushroom = true;
this.canvas.style.filter = 'invert(1)';
// Invert state lasts for 2 seconds
setTimeout(() => {
this.canvas.style.filter = 'invert(0)';
}, 2000); // 2000 milliseconds = 2 seconds
}
break;
}

}
Expand Down

0 comments on commit 7d02c9f

Please sign in to comment.