Skip to content

Commit

Permalink
Implement parts of the door logics
Browse files Browse the repository at this point in the history
  • Loading branch information
h-d-jin committed Feb 28, 2025
1 parent c1f4abb commit bddedb6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 16 deletions.
Binary file added docs/public/assets/background/room_tutorial.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 16 additions & 1 deletion docs/src/controllers/InputHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class InputHandler {
}

update() {
this.currentRoom.update();
player.updateVelocity();
player.updatePosition();
const collideWithEnemies = this.collisionDetector.detectPlayerCollision(player, this.currentRoom.enemies);
Expand All @@ -28,6 +29,7 @@ class InputHandler {
this.updateBullets();
this.collisionDetector.detectBulletEnemyCollision(player.bullets, this.currentRoom.enemies);
this.removeEnemies(this.currentRoom.enemies);
this.moveToNextRoom();
}

handlePlayerShooting() {
Expand All @@ -53,7 +55,6 @@ class InputHandler {
});
}


decreasePlayerHp() {
// The player will not receive any damage in the future 2 seconds.
if (millis() - this.lastCollisionTime < this.collisionCoolDownTime) {
Expand All @@ -65,4 +66,18 @@ class InputHandler {
hurtSound.currentTime = 0;
hurtSound.play();
}

moveToNextRoom(tolerance=player.size.x) {
if (!this.currentRoom.checkClearCondition()) return;

const playerMidX = player.position.x + player.size.x / 2;
const playerMidY = player.position.y + player.size.y / 2;
const doorX = this.currentRoom.door.position.x;
const doorY = this.currentRoom.door.position.y + this.currentRoom.door.size.y / 2;

if (dist(playerMidX, playerMidY, doorX, doorY) < tolerance) {
console.log("Move to the next room!");
loadRoom();
}
}
}
4 changes: 4 additions & 0 deletions docs/src/core/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,7 @@ function isGameOver() {
return player.hp <= 0;
}

function loadRoom() {

}

4 changes: 2 additions & 2 deletions docs/src/core/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function preload() {
startMenuImg = loadImage('assets/background/menu_start.png');
closedDoorImg = loadImage('assets/door/door_close.png');
openDoorImg = loadImage('assets/door/door_open.png');
officeRoomImg = loadImage('assets/background/room_office.jpg');
officeRoomImg = loadImage('assets/background/room_tutorial.png');
}

function setup() {
Expand All @@ -41,7 +41,7 @@ function draw() {
}
else {
displayTutorial();
room.update();
// room.update();
inputHandler.update();
player.display();
drawUiHub();
Expand Down
9 changes: 4 additions & 5 deletions docs/src/entities/Room.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class Room {
this.obstacles = [];
const maxEntitySize = heightInPixel / 8;
for (let i = 0; i < obstacleCount; i++) {
let x = random(boundaryInPixel.w, widthInPixel - boundaryInPixel.w - maxEntitySize);
let y = random(boundaryInPixel.h, heightInPixel - boundaryInPixel.h - maxEntitySize);
let x = random(leftBoundary, rightBoundary - maxEntitySize);
let y = random(topBoundary, bottomBoundary - maxEntitySize);
this.obstacles.push(new Obstacle(x, y));
}
}
Expand All @@ -37,8 +37,8 @@ class Room {
this.enemies = [];
const maxEntitySize = heightInPixel / 8;
for (let i = 0; i < enemyCount; i++) {
let x = random(boundaryInPixel.w, widthInPixel - boundaryInPixel.w - maxEntitySize);
let y = random(boundaryInPixel.h, heightInPixel - boundaryInPixel.h - maxEntitySize);
let x = random(leftBoundary, rightBoundary - maxEntitySize);
let y = random(topBoundary, bottomBoundary - maxEntitySize);
let hp = random([smallEnemyHp, largeEnemyHp]);
this.enemies.push(new Enemy(x, y, hp));
}
Expand All @@ -63,5 +63,4 @@ class Room {
checkClearCondition() {
return (this.enemies.length === 0 && player.hp > 0);
}

}
15 changes: 7 additions & 8 deletions docs/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ let timeSpent = 0;
let currentLevel = 1;
let currentStage = 1;

const uiTextSize = 20;
const hPadding = 50;
const vPadding = 20;

let nearSavedPosition = false;
let lastSavedPosition = { xPos: null, yPos: null };
let minDistanceToSave = 50;
Expand All @@ -28,7 +32,7 @@ const largeEnemyHp = 100;
const largeEnemySize = { w: 50, h: 60 };

let player;
let enemyCount = 5;
let enemyCount = 1;
let obstacleCount = 5;

// Add variables and functions from feature_enemies_lyz_before0225
Expand Down Expand Up @@ -66,11 +70,6 @@ const leftBoundary = boundaryInPixel.w;
const rightBoundary = widthInPixel - boundaryInPixel.w;
const topBoundary = boundaryInPixel.h;
const bottomBoundary = heightInPixel - boundaryInPixel.h;
const smallEntitySize = heightInPixel / 12;

const playerX = 100;
const playerY = 100;

const uiTextSize = 20;
const hPadding = 50;
const vPadding = 20;
const playerX = leftBoundary;
const playerY = heightInPixel / 2;

0 comments on commit bddedb6

Please sign in to comment.