Skip to content

Commit

Permalink
Merge branch 'bossFight' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
CorneliusPavlic committed Apr 10, 2024
2 parents bd0868f + 6c7e709 commit 2db3732
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 30 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified assets/.DS_Store
Binary file not shown.
Binary file added assets/GiantEye.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<script src="src/js/DebugMode.js"></script>
<script src="src/js/enemy.js"></script>
<script src="src/js/Flashlight.js"></script>
<script src="src/js/bossFight.js"></script>
<script src="src/js/Layers.js"></script>


Expand Down
48 changes: 33 additions & 15 deletions sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ const CANVAS_HEIGHT_PX=1080;
let darknessSprite;
// Main Menu Assets
// MENU, PLAYING, INVENTORY, PAUSED
let GIANTEYESPAWNED = false;
let GAMESTATE = "MENU";
let inventory;
let key;
let gun;
let bullet;
let bulletItem;
let mainMenu;
let pauseMenu;
let settingsMenu;
Expand All @@ -25,7 +26,10 @@ let mainMenuSound;
let CreepyPiano2;
let trapDoorImage;
let cellBarsImage;
let ENEMY42SPAWED = false;
let bullets;
//needs to be false when game is ready to play, is false for testing.
console.log("FIX THIS VALUE");
let ENEMY42SPAWED = true;
function preload() {
InventoryBackground = loadImage('assets/InventoryBackground.png');
keyImage = loadImage('assets/key.png');
Expand Down Expand Up @@ -100,17 +104,18 @@ function setup() {
flashlight.itemSprite.debug=false;
key = new Item(CANVAS_WIDTH_PX/2 ,CANVAS_HEIGHT_PX*4 - 500, "Key", 1,1,10,5,keyImage);
key.itemSprite.debug=false;
gun = new Item(CANVAS_WIDTH_PX * 5 + 500,CANVAS_HEIGHT_PX - 400, "gun", 2,1,6,33,gunImage);
gun.itemSprite.debug=false;

bullet = new Item(CANVAS_WIDTH_PX * 5 + 500,CANVAS_HEIGHT_PX - 400, "bullet", 1,1,4,3,bulletImage);
bullet.itemSprite.debug=false;

gun = new Item(CANVAS_WIDTH_PX * 5 + 500,CANVAS_HEIGHT_PX - 400, "Gun", 2,1,33,6,gunImage);
bulletItem = new Item(CANVAS_WIDTH_PX * 5 + 500,CANVAS_HEIGHT_PX - 400, "Bullet", 1,1,4,3,bulletImage);
// darkness overlayd

key.itemSprite.overlaps(RoomController.wallTile.group);
gun.itemSprite.overlaps(RoomController.wallTile.group);
flashlight.itemSprite.overlaps(RoomController.wallTile.group);
bulletItem.itemSprite.overlaps(RoomController.wallTile.group);

playerMovement = new MovementController(player,PLAYERSPEED,true);

setupStaticEnemyList();
console.log(staticEnemyList);
darknessSetup();
//Remove to turn off debug mode
// turnOnDebugMode(true, true);
Expand All @@ -121,8 +126,13 @@ function setup() {
//Makes a pause menu screen
pauseMenu = new PauseMenu();

//creates group for bullets
setUpBullets();

//Makes a new settings menu
settingsMenu = new SettingsMenu();

spawnEnemyAt(1,player.x,player.y);
}

function draw() {
Expand Down Expand Up @@ -165,9 +175,10 @@ function draw() {
else if (GAMESTATE === 'PLAYING') {
clear();
randomBackgroundSounds();
gunFunctionality();
gunFunctionality(bullets);
fadeInAndOut(fadeScreen);
movementSounds(player,footsteps);
bulletCollisions();
playerMovement.handleInput();
enemyHandler();
if(player.room["x"] == 4 && player.room["y"] == 2 && !ENEMY42SPAWED){
Expand All @@ -177,7 +188,14 @@ function draw() {
}

if(player.room["x"] == 9 && player.room["y"] == 2){
alert("You escaped out the window!!! Congrats!");
if(!GIANTEYESPAWNED) {
console.log("GIANT EYE SHOULD SPWAWN");
GIANTEYESPAWNED = true;
console.log(player.x, player.y);
spawnEnemyAt(1, player.x, player.y + 500);
}
giantEyeBossfight();

}
if(player.health <= 0) {
GAMESTATE = pauseMenu.exitGame(GAMESTATE);
Expand Down Expand Up @@ -210,13 +228,12 @@ function draw() {
if(player.overlaps(key.itemSprite)){
if (inventory.insertItem(key, inventory.hasSpace(key.InventoryX,key.InventoryY))) key.itemSprite.visible = false;
}
if(player.overlaps(bullet.itemSprite)){
if (inventory.insertItem(bullet, inventory.hasSpace(bullet.InventoryX,bullet.InventoryY))) bullet.itemSprite.visible = false;
if(player.overlaps(bulletItem.itemSprite)){
if (inventory.insertItem(bulletItem, inventory.hasSpace(bulletItem.InventoryX,bulletItem.InventoryY))) bulletItem.itemSprite.visible = false;
}

//Pause handle
if (kb.pressed('escape')) GAMESTATE = "PAUSE";

}
else if (GAMESTATE == "INVENTORY"){
clear();
Expand All @@ -240,7 +257,8 @@ function draw() {
dragItem(flashlight, inventory);
dragItem(key, inventory);
dragItem(gun, inventory);
dragItem(bullet,inventory);
dragItem(bulletItem,inventory)

}
else if (GAMESTATE == "PAUSE") {
console.log("PAUSED");
Expand Down
28 changes: 25 additions & 3 deletions src/js/enemy.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ function keyPressed(){
//Handles anything related to enemeis that needs to be done every frame
function enemyHandler(){
let previousMax = enemyList.length; //Prevents inf loop if enemey is created while handler is being run
for(let i = 0; i < previousMax; ++ i) {
for(let i = 0; i < previousMax; ++i) {
console.log(enemyList);
if(enemyList[i].enemy_id==1){
bullets.collides(enemyList[i].enemySprite, damageEnemy);
}
if(enemyList.enemy_id == 0){
if(nowBlinking == true && CANTELEPORT == true){
CANTELEPORT = false;
teleportCooldown();
Expand All @@ -119,19 +124,28 @@ function enemyHandler(){
enemyList[i].enemySprite.y = player.y + Math.floor(Math.random() * 100) * (Math.random() > 0.5 ? 1 : -1);
disappear(enemyList[i].enemySprite);
}
}

if(enemyList[i].health <= 0){
alert("Enemy " + enemyList[i].name + " has been defeated! YOU WIN!!!");
enemyList[i].enemySprite.remove();
enemyList.splice(i, 1);
if (enemyList.length == 0) return;
}

//Detects if player and enemy overlaps and changes red if true, currently need debug mode off to see this
if (enemyList[i].enemySprite.overlaps(player)) player.health -= 50;
}

}

}
//Loads at start
//Enemy data is harded coded and then pushed onto the staticEnemyList
function setupStaticEnemyList(){ //Add new enemies here

temp = new enemyData(0, 0, "test", 5, 0, 0, 10, "assets/GlowingEyesEnemy.png");
giantEye = new enemyData(1,0, "Giant Eye", 500, 256,256, 256,"assets/GiantEye.png");
staticEnemyList.push(temp);
staticEnemyList.push(giantEye);



Expand All @@ -156,3 +170,11 @@ async function teleportCooldown(){
await delay(2000);
CANTELEPORT = true;
}

function damageEnemy(bullet, enemy){
bullet.remove();
enemyList.forEach(enemy => {
if(enemy.enemy_id == 1){
enemy.health -= 50;}
});
}
80 changes: 68 additions & 12 deletions src/js/mainPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Player of the game - settings and other setup
*
*/

const BULLETSPEED = 15;


function setupPlayer(roomX=0,roomY=0){
Expand All @@ -19,6 +19,8 @@ function setupPlayer(roomX=0,roomY=0){
player.anis.frameDelay = 8;
player.layer = PLAYER_LAYER;
player.health = 101;
player.debug = true;

//Configures the collision settings based on presets
//turns on rotation lock (A MUST!!!), and sets the
//collider type as dynamic
Expand All @@ -45,21 +47,75 @@ function setupPlayer(roomX=0,roomY=0){

function gunFunctionality(){
if(
// inventory.hasItem("gun") &&
inventory.hasItem(gun) &&
kb.pressed(' ')
// && inventory.hasItem("bullet")
&& inventory.hasItem(bulletItem)
){
let bullet;
let bullet = new bullets.Sprite();
if(playerMovement.lastDirection == "left"){
bullet = new Sprite(player.x - 30,player.y,3,5);
bullet.x = player.x - 45;
bullet.y = player.y;
}
else {
bullet.x = player.x + 45;
bullet.y = player.y;
}

if(kb.pressing("w") && kb.pressing("a")){
bullet.direction = 225;
}
else if(kb.pressing("w") && kb.pressing("d")){
bullet.direction = -45;
}
else if(kb.pressing("s") && kb.pressing("a")){
bullet.direction = 135;
}
else if(kb.pressing("s") && kb.pressing("d")){
bullet.direction = 45;
}
else if(kb.pressing("w")){
bullet.direction = -90;
}
else if(kb.pressing("a")){
bullet.direction = 180;
}
else if(kb.pressing("s")){
bullet.direction = 90;
}
else if(kb.pressing("d")){
bullet.direction = 0;
}
else {
bullet = new Sprite(player.x + 30,player.y,3,5)
bullet.direction = playerMovement.lastDirection;
}
bullet.rotationLock = true;
bullet.direction = flashlightRotation - 90;
bullet.img = bulletImage;
bullet.speed = 10;
bullet.move(100000);
}
}
}


function setUpBullets(){
bullets = new Group();
bullets.img = bulletImage;
bullets.rotationLock = true;
bullets.img = bulletImage;
bullets.speed = BULLETSPEED;
}


function bulletCollisions(){
bullets.collides(RoomController.wallTile.group, bulletRemove)
bullets.collides(RoomController.barsTile.group, bulletRemove)
bullets.collides(RoomController.upDoor.group, bulletRemove)
bullets.collides(RoomController.rightDoor.group, bulletRemove)
bullets.collides(RoomController.leftDoor.group, bulletRemove)
bullets.collides(RoomController.downDoor.group, bulletRemove)
bullets.collides(RoomController.trapDoor.group, bulletRemove)
bullets.collides(RoomController.trapDoorBack.group, bulletRemove)
bullets.collides(RoomController.secretDoor.group, bulletRemove)
bullets.collides(RoomController.upstairsDoor.group, bulletRemove)
bullets.collides(RoomController.middleFloorDoor.group, bulletRemove)
}


function bulletRemove(bullet, tile){
bullet.remove();
}

0 comments on commit 2db3732

Please sign in to comment.