Skip to content

Commit

Permalink
Non-working changes for switching between rooms.
Browse files Browse the repository at this point in the history
  • Loading branch information
CorneliusPavlic committed Feb 20, 2024
1 parent 5efd289 commit ac01d85
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 16 deletions.
2 changes: 2 additions & 0 deletions sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ function draw() {
movementSounds(player,footsteps);
playerMovement.handleInput();
enemyHandler();


//FPS counter, needs to be in draw to
//render properly
//Create a new room
Expand Down
22 changes: 13 additions & 9 deletions src/js/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function fadeIn(object){
return false;
}
else {
console.log('Hello');
object.opacity = 1;
return true;
}
Expand All @@ -61,19 +62,22 @@ function fadeOut(object){

//Moves the camera in the direction specified. takes "up", "down", "left", "right" as arguments.
function moveCamera(direction){
if (direction == "up") camera.y -= windowHeight;
else if (direction == "down") camera.y += windowHeight;
else if (direction == "left") camera.x -= windowWidth;
else if (direction == "right") camera.x += windowWidth;
if(!HASMOVEDCAMERA){
if (direction == "up") camera.y -= 1080;
else if (direction == "down") camera.y += 1080;
else if (direction == "left") camera.x -= 1920;
else if (direction == "right") camera.x += 1920;
}
HASMOVEDCAMERA = true;
}


//Moves the player in the direction specified. takes "up", "down", "left", "right" as arguments. Used to teleport to the next room.
function movePlayer(){
if (direction == "up") player.y -= 20;
else if (direction == "down") player.y += 20;
else if (direction == "left") player.x -= 20;
else if (direction == "right") player.x += 20;
function movePlayer(direction){
if (direction == "up") player.y -= 80;
else if (direction == "down") player.y += 80;
else if (direction == "left") player.x -= 80;
else if (direction == "right") player.x += 80;
}


Expand Down
33 changes: 28 additions & 5 deletions src/js/Rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,33 @@ let roomControl;
// Callback function, simply determines whether it is the player ob colliding with door tile or not
function doorCallback(a, b) {
if (b?.tag === "player") {
console.log("player at door");

} else {
console.log("not player: ", b.tag);
}

}

function upwardDoorCallback(a, b) {
fadeScreenNow();
if(HASFADEDIN === true){
moveCamera("up");
movePlayer("up");
}
}
function rightDoorCallback(a, b) {
fadeScreenNow();
if(HASFADEDIN === true){
moveCamera("right");
movePlayer("right");
}
}
function leftDoorCallback(a, b) {
fadeScreenNow();
moveCamera("left");
movePlayer("left");
}

// Class for managing the room layout
class RoomController {
static TILE_HEIGHT = 120;
Expand All @@ -20,7 +40,8 @@ class RoomController {
//Defining our tiles that we want to use, keeps them in memory. Not meant to be written to outside of class
static wallTile;
static floor;
static door;
static upDoor;
static rightDoor;

constructor() {
// If it's the first load, initialize the tiles
Expand All @@ -30,7 +51,9 @@ class RoomController {
RoomController.wallTile = new ImageTile(brickImage, '=', RoomController.TILE_WIDTH, RoomController.TILE_HEIGHT, 'static');
RoomController.floor = new ImageTile(floorBoardImage, 'o', RoomController.TILE_WIDTH, RoomController.TILE_HEIGHT, 'none',doorCallback);
RoomController.door = new ImageTile(doorImage, 'D', RoomController.TILE_WIDTH, RoomController.TILE_HEIGHT, 'static', doorCallback);

RoomController.upDoor = new ImageTile(doorImage, '^', RoomController.TILE_WIDTH, RoomController.TILE_HEIGHT, 'static', upwardDoorCallback);
RoomController.rightDoor = new ImageTile(doorImage, '>', RoomController.TILE_WIDTH, RoomController.TILE_HEIGHT, 'static', rightDoorCallback);
RoomController.leftDoor = new ImageTile(doorImage, '<', RoomController.TILE_WIDTH, RoomController.TILE_HEIGHT, 'static', leftDoorCallback);
}

this.map = [];
Expand All @@ -56,8 +79,8 @@ class RoomController {
'.'.repeat(10),
'.'.repeat(10),
'='.repeat(10),
'o'.repeat(10),
'o'.repeat(10),
'o'.repeat(2)+ '><' + 'o'.repeat(6),
'o'.repeat(2)+ '><' + 'o'.repeat(6),
'='.repeat(10),
'.'.repeat(10),
'.'.repeat(10),
Expand Down
2 changes: 0 additions & 2 deletions src/js/sound.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
function movementSounds(sprite,sound){
if(sprite.velocity.x!=0||sprite.velocity.y!=0){
console.log("starting sound");
if(!sound.isPlaying()){
sound.play();
}
}
else{
console.log("stopping sound");
sound.pause();
}
}

0 comments on commit ac01d85

Please sign in to comment.