User prompt
Has que la pared sea una línea recta
User prompt
Las partes sin textura ponle el número (1)
User prompt
Has que el piso y el techo sean parte del escenario ósea pseudo-3D
User prompt
Haz que el piso que es el símbolo (8) siempre esté abajo del personaje actuando como piso y poder caminar sobre el
User prompt
Has que el piso siempre esté abajo del personaje
User prompt
Haz que las paredes tengan este símbolo (7) el piso el símbolo (8) y el techo el símbolo (9)
User prompt
Pon que el jugador siempre aparezca en la coordenada ( 0 ) y has que las paredes tengan la altura de ( y 1 )hasta el máximo de( y 5 )
User prompt
Okey, crea una detección automática del piso techo y paredes para evitar confusiones con estas
User prompt
Haz que las paredes tengan colision
User prompt
Haz que las paredes tengan textura del famoso juego Backrooms
User prompt
No mira estas son la regla. 1- vamos a usar toda la pantalla 2- no uses cosas 2D 3- haz y imita lo que te diga pero usando la técnica llamada pseudo-3D
User prompt
Borra todo el código
User prompt
Borra todo compénsenos de nuevo
User prompt
Haz que el jugador tenga la visión en primera persona vamos a usar la isometría para el techo y el piso para dar el efecto 3D que no es 3D para los lados haz paredes y pilares que se puedan colisionar
User prompt
Please fix the bug: 'undefined is not an object (evaluating 'isoFloor.skew.x = -0.3')' in or related to this line: 'isoFloor.skew.x = -0.3;' Line Number: 183
User prompt
Haz espacios isométricos para el piso el techo
User prompt
Haz un sistema de rotación de cámara que deslizando el dedo se vea para una dirección u otra ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'TypeError: undefined is not an object (evaluating 'sanityText.style.fill = sanityColor')' in or related to this line: 'sanityText.style.fill = sanityColor;' Line Number: 369
Code edit (1 edits merged)
Please save this source code
User prompt
Backrooms Infinite Escape
Initial prompt
Hola Ava, mi juego trata de una temática de juego muy popular llamada Backrooms estuvo de moda en el 2020. Quiero que crees habitaciones infinitas y que allá monstruos que te dire más adelante
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Monster = Container.expand(function () { var self = Container.call(this); var monsterGraphic = self.attachAsset('monster', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 1.5; self.alertLevel = 0; self.patrolAngle = Math.random() * Math.PI * 2; self.patrolTimer = 0; self.update = function () { if (!player) return; var dx = player.x - self.x; var dy = player.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); self.patrolTimer++; if (distance < 200) { // Player detected - chase self.alertLevel = Math.min(100, self.alertLevel + 2); if (self.alertLevel > 50) { // Active chase var moveX = dx / distance * self.speed * 1.5; var moveY = dy / distance * self.speed * 1.5; self.x += moveX; self.y += moveY; if (LK.ticks % 120 === 0) { LK.getSound('monster_growl').play(); } } } else { // Patrol behavior self.alertLevel = Math.max(0, self.alertLevel - 1); if (self.patrolTimer % 90 === 0) { self.patrolAngle = Math.random() * Math.PI * 2; } self.x += Math.cos(self.patrolAngle) * self.speed; self.y += Math.sin(self.patrolAngle) * self.speed; } // Keep monster in bounds self.x = Math.max(-320, Math.min(320, self.x)); self.y = Math.max(-320, Math.min(320, self.y)); // Visual alert indication if (self.alertLevel > 50) { monsterGraphic.tint = 0xff4444; } else if (self.alertLevel > 20) { monsterGraphic.tint = 0xff8888; } else { monsterGraphic.tint = 0x8b0000; } }; return self; }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphic = self.attachAsset('player_dot', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 4; self.sanity = 100; self.moving = false; self.moveTo = function (targetX, targetY) { if (self.moving) return; // Check bounds if (targetX < -350 || targetX > 350 || targetY < -350 || targetY > 350) return; self.moving = true; tween(self, { x: targetX, y: targetY }, { duration: 400, easing: tween.easeOut, onFinish: function onFinish() { self.moving = false; LK.getSound('step').play(); } }); }; self.update = function () { // Sanity decreases over time if (LK.ticks % 180 === 0) { self.sanity = Math.max(0, self.sanity - 1); } // Check monster proximity if (currentRoom && currentRoom.monster) { var dx = self.x - currentRoom.monster.x; var dy = self.y - currentRoom.monster.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < 100) { self.sanity -= 0.3; } if (distance < 30) { LK.showGameOver(); } } // Check exit if (currentRoom && currentRoom.exit) { var dx = self.x - currentRoom.exit.x; var dy = self.y - currentRoom.exit.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < 50) { roomsEscaped++; LK.setScore(roomsEscaped); LK.getSound('escape').play(); generateNewRoom(); if (roomsEscaped >= 15) { LK.showYouWin(); } } } if (self.sanity <= 0) { LK.showGameOver(); } }; return self; }); var Room = Container.expand(function () { var self = Container.call(this); // Floor var floor = self.attachAsset('room_floor', { anchorX: 0.5, anchorY: 0.5 }); // Walls var topWall = self.attachAsset('room_wall', { anchorX: 0.5, anchorY: 0.5, x: 0, y: -400, scaleX: 14 }); var bottomWall = self.attachAsset('room_wall', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 400, scaleX: 14 }); var leftWall = self.attachAsset('room_wall', { anchorX: 0.5, anchorY: 0.5, x: -400, y: 0, rotation: Math.PI / 2, scaleX: 14 }); var rightWall = self.attachAsset('room_wall', { anchorX: 0.5, anchorY: 0.5, x: 400, y: 0, rotation: Math.PI / 2, scaleX: 14 }); // Lighting var light1 = self.attachAsset('light_fixture', { anchorX: 0.5, anchorY: 0.5, x: -150, y: -150, alpha: 0.8 }); var light2 = self.attachAsset('light_fixture', { anchorX: 0.5, anchorY: 0.5, x: 150, y: 150, alpha: 0.8 }); // Doors self.doors = []; self.createDoors = function () { var numDoors = Math.floor(Math.random() * 3) + 2; var positions = [{ x: 0, y: -380, dir: 'north' }, { x: 0, y: 380, dir: 'south' }, { x: -380, y: 0, dir: 'west' }, { x: 380, y: 0, dir: 'east' }]; for (var i = 0; i < numDoors; i++) { var pos = positions[Math.floor(Math.random() * positions.length)]; var door = self.attachAsset('door', { anchorX: 0.5, anchorY: 0.5, x: pos.x + (Math.random() - 0.5) * 100, y: pos.y }); door.direction = pos.dir; self.doors.push(door); } }; // Exit self.hasExit = Math.random() < 0.2; if (self.hasExit) { self.exit = self.attachAsset('exit_portal', { anchorX: 0.5, anchorY: 0.5, x: (Math.random() - 0.5) * 600, y: (Math.random() - 0.5) * 600 }); // Pulsing effect for exit tween(self.exit, { alpha: 0.3 }, { duration: 1000, easing: tween.easeInOut, yoyo: true, repeat: -1 }); } // Monster if (Math.random() < 0.4) { self.monster = self.addChild(new Monster()); self.monster.x = (Math.random() - 0.5) * 500; self.monster.y = (Math.random() - 0.5) * 500; } return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1a1a1a }); /**** * Game Code ****/ var player; var currentRoom; var roomsEscaped = 0; // UI var sanityBar = new Text2('Sanity: 100', { size: 50, fill: 0x00ff00 }); sanityBar.anchor.set(0, 0); LK.gui.topRight.addChild(sanityBar); var escapeCounter = new Text2('Rooms Escaped: 0', { size: 50, fill: 0xffffff }); escapeCounter.anchor.set(0, 0); escapeCounter.y = 70; LK.gui.topRight.addChild(escapeCounter); function generateNewRoom() { // Clear current room if (currentRoom) { game.removeChild(currentRoom); } // Create new room currentRoom = game.addChild(new Room()); currentRoom.x = 1024; currentRoom.y = 1366; currentRoom.createDoors(); // Reset player position if (player) { player.x = 0; player.y = 0; player.sanity = Math.min(100, player.sanity + 10); // Small sanity boost for progress } } function initGame() { player = game.addChild(new Player()); player.x = 1024; player.y = 1366; generateNewRoom(); } game.down = function (x, y, obj) { if (!player || player.moving) return; var gamePos = game.toLocal({ x: x, y: y }); var targetX = gamePos.x - 1024; var targetY = gamePos.y - 1366; // Check door clicks if (currentRoom && currentRoom.doors) { for (var i = 0; i < currentRoom.doors.length; i++) { var door = currentRoom.doors[i]; var dx = targetX - door.x; var dy = targetY - door.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < 60) { LK.getSound('door_sound').play(); generateNewRoom(); return; } } } // Move player player.moveTo(targetX, targetY); }; game.update = function () { // Update UI if (player) { var sanityColor = 0x00ff00; if (player.sanity < 50) sanityColor = 0xffff00; if (player.sanity < 25) sanityColor = 0xff0000; sanityBar.setText('Sanity: ' + Math.floor(player.sanity)); sanityBar.tint = sanityColor; } escapeCounter.setText('Rooms Escaped: ' + roomsEscaped); // Flickering lights if (currentRoom && LK.ticks % 60 === 0) { for (var i = 0; i < currentRoom.children.length; i++) { var child = currentRoom.children[i]; if (child.alpha !== undefined && Math.random() < 0.1) { var originalAlpha = child.alpha; child.alpha = 0.2; tween(child, { alpha: originalAlpha }, { duration: 100 }); } } } }; // Start the game initGame();
===================================================================
--- original.js
+++ change.js
@@ -5,468 +5,337 @@
/****
* Classes
****/
-var Door = Container.expand(function () {
- var self = Container.call(this);
- var doorGraphic = self.attachAsset('door', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.direction = 'north';
- self.isOpen = false;
- self.down = function (x, y, obj) {
- if (!self.isOpen && player.intersects(self)) {
- self.open();
- }
- };
- self.open = function () {
- self.isOpen = true;
- LK.getSound('door_open').play();
- // Trigger room transition
- if (self.direction === 'north') {
- generateNewRoom(0, -1);
- } else if (self.direction === 'south') {
- generateNewRoom(0, 1);
- } else if (self.direction === 'west') {
- generateNewRoom(-1, 0);
- } else if (self.direction === 'east') {
- generateNewRoom(1, 0);
- }
- };
- return self;
-});
var Monster = Container.expand(function () {
var self = Container.call(this);
var monsterGraphic = self.attachAsset('monster', {
anchorX: 0.5,
anchorY: 0.5
});
- self.speed = 1;
- self.patrolDirection = Math.random() * Math.PI * 2;
+ self.speed = 1.5;
+ self.alertLevel = 0;
+ self.patrolAngle = Math.random() * Math.PI * 2;
self.patrolTimer = 0;
- self.chasing = false;
self.update = function () {
+ if (!player) return;
+ var dx = player.x - self.x;
+ var dy = player.y - self.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
self.patrolTimer++;
- // Check if player is nearby
- var distance = Math.sqrt(Math.pow(self.x - player.x, 2) + Math.pow(self.y - player.y, 2));
- if (distance < 150) {
- self.chasing = true;
- LK.getSound('monster_growl').play();
- } else if (distance > 300) {
- self.chasing = false;
- }
- if (self.chasing) {
- // Chase player
- var dx = player.x - self.x;
- var dy = player.y - self.y;
- var dist = Math.sqrt(dx * dx + dy * dy);
- if (dist > 0) {
- self.x += dx / dist * self.speed * 2;
- self.y += dy / dist * self.speed * 2;
+ if (distance < 200) {
+ // Player detected - chase
+ self.alertLevel = Math.min(100, self.alertLevel + 2);
+ if (self.alertLevel > 50) {
+ // Active chase
+ var moveX = dx / distance * self.speed * 1.5;
+ var moveY = dy / distance * self.speed * 1.5;
+ self.x += moveX;
+ self.y += moveY;
+ if (LK.ticks % 120 === 0) {
+ LK.getSound('monster_growl').play();
+ }
}
- // Check collision with player
- if (distance < 40) {
- LK.showGameOver();
- }
} else {
// Patrol behavior
- if (self.patrolTimer % 120 === 0) {
- self.patrolDirection = Math.random() * Math.PI * 2;
+ self.alertLevel = Math.max(0, self.alertLevel - 1);
+ if (self.patrolTimer % 90 === 0) {
+ self.patrolAngle = Math.random() * Math.PI * 2;
}
- self.x += Math.cos(self.patrolDirection) * self.speed;
- self.y += Math.sin(self.patrolDirection) * self.speed;
- // Keep monster within room bounds
- if (self.x < -180) self.x = -180;
- if (self.x > 180) self.x = 180;
- if (self.y < -180) self.y = -180;
- if (self.y > 180) self.y = 180;
+ self.x += Math.cos(self.patrolAngle) * self.speed;
+ self.y += Math.sin(self.patrolAngle) * self.speed;
}
+ // Keep monster in bounds
+ self.x = Math.max(-320, Math.min(320, self.x));
+ self.y = Math.max(-320, Math.min(320, self.y));
+ // Visual alert indication
+ if (self.alertLevel > 50) {
+ monsterGraphic.tint = 0xff4444;
+ } else if (self.alertLevel > 20) {
+ monsterGraphic.tint = 0xff8888;
+ } else {
+ monsterGraphic.tint = 0x8b0000;
+ }
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
- var playerGraphic = self.attachAsset('player', {
+ var playerGraphic = self.attachAsset('player_dot', {
anchorX: 0.5,
- anchorY: 0.5,
- alpha: 0 // Hide player for first-person view
+ anchorY: 0.5
});
- self.speed = 3;
+ self.speed = 4;
self.sanity = 100;
- self.targetX = 0;
- self.targetY = 0;
self.moving = false;
- self.moveTo = function (x, y) {
- // Check wall collisions before moving
- var newX = Math.max(-170, Math.min(170, x)); // Wall collision bounds
- var newY = Math.max(-170, Math.min(170, y)); // Wall collision bounds
- // Check pillar collisions
- if (currentRoom && currentRoom.pillars) {
- for (var i = 0; i < currentRoom.pillars.length; i++) {
- var pillar = currentRoom.pillars[i];
- var dx = newX - pillar.x;
- var dy = newY - pillar.y;
- var distance = Math.sqrt(dx * dx + dy * dy);
- if (distance < 45) {
- // Collision radius
- // Push player away from pillar
- var pushX = dx / distance * 45;
- var pushY = dy / distance * 45;
- newX = pillar.x + pushX;
- newY = pillar.y + pushY;
- }
- }
- }
- self.targetX = newX;
- self.targetY = newY;
+ self.moveTo = function (targetX, targetY) {
+ if (self.moving) return;
+ // Check bounds
+ if (targetX < -350 || targetX > 350 || targetY < -350 || targetY > 350) return;
self.moving = true;
tween(self, {
- x: newX,
- y: newY
+ x: targetX,
+ y: targetY
}, {
- duration: 500,
- easing: tween.linear,
+ duration: 400,
+ easing: tween.easeOut,
onFinish: function onFinish() {
self.moving = false;
- LK.getSound('footstep').play();
+ LK.getSound('step').play();
}
});
};
self.update = function () {
- // Check for monster proximity - decrease sanity
+ // Sanity decreases over time
+ if (LK.ticks % 180 === 0) {
+ self.sanity = Math.max(0, self.sanity - 1);
+ }
+ // Check monster proximity
if (currentRoom && currentRoom.monster) {
- var distance = Math.sqrt(Math.pow(self.x - currentRoom.monster.x, 2) + Math.pow(self.y - currentRoom.monster.y, 2));
+ var dx = self.x - currentRoom.monster.x;
+ var dy = self.y - currentRoom.monster.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 100) {
- self.sanity -= 0.5;
- if (self.sanity <= 0) {
- LK.showGameOver();
- }
+ self.sanity -= 0.3;
}
+ if (distance < 30) {
+ LK.showGameOver();
+ }
}
- // Check for exit collision
- if (currentRoom && currentRoom.hasExit && currentRoom.exitObject) {
- if (self.intersects(currentRoom.exitObject)) {
- level++;
- LK.setScore(level);
- generateNewRoom(0, 0);
- if (level >= 10) {
+ // Check exit
+ if (currentRoom && currentRoom.exit) {
+ var dx = self.x - currentRoom.exit.x;
+ var dy = self.y - currentRoom.exit.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance < 50) {
+ roomsEscaped++;
+ LK.setScore(roomsEscaped);
+ LK.getSound('escape').play();
+ generateNewRoom();
+ if (roomsEscaped >= 15) {
LK.showYouWin();
}
}
}
+ if (self.sanity <= 0) {
+ LK.showGameOver();
+ }
};
return self;
});
var Room = Container.expand(function () {
var self = Container.call(this);
- self.roomId = Math.floor(Math.random() * 1000000);
- self.doors = [];
- self.hasExit = false;
- self.monster = null;
- self.pillars = [];
- // Create room floor
- var floor = self.attachAsset('room', {
+ // Floor
+ var floor = self.attachAsset('room_floor', {
anchorX: 0.5,
anchorY: 0.5
});
- // Create isometric floor
- var isoFloor = self.attachAsset('floor_iso', {
+ // Walls
+ var topWall = self.attachAsset('room_wall', {
anchorX: 0.5,
anchorY: 0.5,
- y: 120,
- scaleY: 0.6,
- alpha: 0.8
+ x: 0,
+ y: -400,
+ scaleX: 14
});
- // Apply isometric perspective transformation
- if (isoFloor.transform) {
- isoFloor.transform.skew.x = -0.3;
- } else {
- isoFloor.skewX = -0.3;
- }
- // Create isometric ceiling
- var isoCeiling = self.attachAsset('ceiling_iso', {
+ var bottomWall = self.attachAsset('room_wall', {
anchorX: 0.5,
anchorY: 0.5,
- y: -120,
- scaleY: 0.6,
- alpha: 0.6
+ x: 0,
+ y: 400,
+ scaleX: 14
});
- // Apply isometric perspective transformation
- if (isoCeiling.transform) {
- isoCeiling.transform.skew.x = 0.3;
- } else {
- isoCeiling.skewX = 0.3;
- }
- // Create walls
- var topWall = self.attachAsset('wall', {
+ var leftWall = self.attachAsset('room_wall', {
anchorX: 0.5,
anchorY: 0.5,
- scaleX: 20,
- y: -200
+ x: -400,
+ y: 0,
+ rotation: Math.PI / 2,
+ scaleX: 14
});
- var bottomWall = self.attachAsset('wall', {
+ var rightWall = self.attachAsset('room_wall', {
anchorX: 0.5,
anchorY: 0.5,
- scaleX: 20,
- y: 200
+ x: 400,
+ y: 0,
+ rotation: Math.PI / 2,
+ scaleX: 14
});
- var leftWall = self.attachAsset('wall', {
+ // Lighting
+ var light1 = self.attachAsset('light_fixture', {
anchorX: 0.5,
anchorY: 0.5,
- scaleY: 20,
- x: -200
- });
- var rightWall = self.attachAsset('wall', {
- anchorX: 0.5,
- anchorY: 0.5,
- scaleY: 20,
- x: 200
- });
- // Add fluorescent lights
- var light1 = self.attachAsset('light', {
- anchorX: 0.5,
- anchorY: 0.5,
- x: -100,
+ x: -150,
y: -150,
- alpha: 0.7
+ alpha: 0.8
});
- var light2 = self.attachAsset('light', {
+ var light2 = self.attachAsset('light_fixture', {
anchorX: 0.5,
anchorY: 0.5,
- x: 100,
+ x: 150,
y: 150,
- alpha: 0.7
+ alpha: 0.8
});
- // Add ceiling shadow for depth
- var ceilingShadow = self.attachAsset('ceiling_iso', {
- anchorX: 0.5,
- anchorY: 0.5,
- y: -110,
- scaleY: 0.6,
- scaleX: 0.95,
- alpha: 0.3,
- tint: 0x666666
- });
- if (ceilingShadow.transform) {
- ceilingShadow.transform.skew.x = 0.3;
- } else {
- ceilingShadow.skewX = 0.3;
- }
+ // Doors
+ self.doors = [];
self.createDoors = function () {
- // Create random doors (1-4 doors per room)
- var numDoors = Math.floor(Math.random() * 4) + 1;
- var sides = ['top', 'bottom', 'left', 'right'];
+ var numDoors = Math.floor(Math.random() * 3) + 2;
+ var positions = [{
+ x: 0,
+ y: -380,
+ dir: 'north'
+ }, {
+ x: 0,
+ y: 380,
+ dir: 'south'
+ }, {
+ x: -380,
+ y: 0,
+ dir: 'west'
+ }, {
+ x: 380,
+ y: 0,
+ dir: 'east'
+ }];
for (var i = 0; i < numDoors; i++) {
- var side = sides[Math.floor(Math.random() * sides.length)];
- var door = self.addChild(new Door());
- switch (side) {
- case 'top':
- door.x = (Math.random() - 0.5) * 200;
- door.y = -200;
- door.direction = 'north';
- break;
- case 'bottom':
- door.x = (Math.random() - 0.5) * 200;
- door.y = 200;
- door.direction = 'south';
- break;
- case 'left':
- door.x = -200;
- door.y = (Math.random() - 0.5) * 200;
- door.direction = 'west';
- break;
- case 'right':
- door.x = 200;
- door.y = (Math.random() - 0.5) * 200;
- door.direction = 'east';
- break;
- }
- self.doors.push(door);
- }
- };
- self.addExit = function () {
- if (Math.random() < 0.1) {
- // 10% chance for exit
- self.hasExit = true;
- var exit = self.attachAsset('exit', {
+ var pos = positions[Math.floor(Math.random() * positions.length)];
+ var door = self.attachAsset('door', {
anchorX: 0.5,
anchorY: 0.5,
- x: (Math.random() - 0.5) * 300,
- y: (Math.random() - 0.5) * 300
+ x: pos.x + (Math.random() - 0.5) * 100,
+ y: pos.y
});
- self.exitObject = exit;
+ door.direction = pos.dir;
+ self.doors.push(door);
}
};
- self.addMonster = function () {
- if (Math.random() < 0.3) {
- // 30% chance for monster
- self.monster = self.addChild(new Monster());
- self.monster.x = (Math.random() - 0.5) * 300;
- self.monster.y = (Math.random() - 0.5) * 300;
- }
- };
- self.addPillars = function () {
- // Add 1-3 pillars randomly in the room
- var numPillars = Math.floor(Math.random() * 3) + 1;
- for (var i = 0; i < numPillars; i++) {
- var pillar = self.attachAsset('pillar', {
- anchorX: 0.5,
- anchorY: 0.5,
- x: (Math.random() - 0.5) * 250,
- y: (Math.random() - 0.5) * 250
- });
- self.pillars.push(pillar);
- }
- };
+ // Exit
+ self.hasExit = Math.random() < 0.2;
+ if (self.hasExit) {
+ self.exit = self.attachAsset('exit_portal', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: (Math.random() - 0.5) * 600,
+ y: (Math.random() - 0.5) * 600
+ });
+ // Pulsing effect for exit
+ tween(self.exit, {
+ alpha: 0.3
+ }, {
+ duration: 1000,
+ easing: tween.easeInOut,
+ yoyo: true,
+ repeat: -1
+ });
+ }
+ // Monster
+ if (Math.random() < 0.4) {
+ self.monster = self.addChild(new Monster());
+ self.monster.x = (Math.random() - 0.5) * 500;
+ self.monster.y = (Math.random() - 0.5) * 500;
+ }
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x2a2a2a
+ backgroundColor: 0x1a1a1a
});
/****
* Game Code
****/
var player;
var currentRoom;
-var level = 1;
-var rooms = [];
-var cameraOffsetX = 0;
-var cameraOffsetY = 0;
-var cameraRotation = 0;
-var isDragging = false;
-var lastDragX = 0;
-var rotationSpeed = 0.003;
-// UI Elements
-var levelText = new Text2('Level: 1', {
- size: 60,
- fill: 0xFFFFFF
+var roomsEscaped = 0;
+// UI
+var sanityBar = new Text2('Sanity: 100', {
+ size: 50,
+ fill: 0x00ff00
});
-levelText.anchor.set(0, 0);
-LK.gui.topRight.addChild(levelText);
-var sanityText = new Text2('Sanity: 100', {
+sanityBar.anchor.set(0, 0);
+LK.gui.topRight.addChild(sanityBar);
+var escapeCounter = new Text2('Rooms Escaped: 0', {
size: 50,
- fill: 0x00FF00
+ fill: 0xffffff
});
-sanityText.anchor.set(0, 0);
-sanityText.y = 80;
-LK.gui.topRight.addChild(sanityText);
-function generateNewRoom(deltaX, deltaY) {
+escapeCounter.anchor.set(0, 0);
+escapeCounter.y = 70;
+LK.gui.topRight.addChild(escapeCounter);
+function generateNewRoom() {
// Clear current room
if (currentRoom) {
game.removeChild(currentRoom);
}
// Create new room
currentRoom = game.addChild(new Room());
currentRoom.x = 1024;
- currentRoom.y = 1466; // Adjust for first-person camera height
- currentRoom.rotation = cameraRotation;
+ currentRoom.y = 1366;
currentRoom.createDoors();
- currentRoom.addExit();
- currentRoom.addMonster();
- currentRoom.addPillars();
// Reset player position
- if (deltaX !== 0 || deltaY !== 0) {
- player.x = -deltaX * 100;
- player.y = -deltaY * 100;
- } else {
+ if (player) {
player.x = 0;
player.y = 0;
+ player.sanity = Math.min(100, player.sanity + 10); // Small sanity boost for progress
}
}
-// Initialize game
function initGame() {
player = game.addChild(new Player());
player.x = 1024;
- player.y = 1466; // Adjust for first-person camera height
- generateNewRoom(0, 0);
+ player.y = 1366;
+ generateNewRoom();
}
game.down = function (x, y, obj) {
- // Start camera rotation drag
- isDragging = true;
- lastDragX = x;
- if (!player.moving) {
- // Convert screen coordinates to game coordinates
- var gamePos = game.toLocal({
- x: x,
- y: y
- });
- // Check if clicking on a door
- var clickedDoor = false;
- if (currentRoom) {
- for (var i = 0; i < currentRoom.doors.length; i++) {
- var door = currentRoom.doors[i];
- var doorGlobalPos = currentRoom.toGlobal(door.position);
- var distance = Math.sqrt(Math.pow(gamePos.x - doorGlobalPos.x, 2) + Math.pow(gamePos.y - doorGlobalPos.y, 2));
- if (distance < 50) {
- door.open();
- clickedDoor = true;
- break;
- }
+ if (!player || player.moving) return;
+ var gamePos = game.toLocal({
+ x: x,
+ y: y
+ });
+ var targetX = gamePos.x - 1024;
+ var targetY = gamePos.y - 1366;
+ // Check door clicks
+ if (currentRoom && currentRoom.doors) {
+ for (var i = 0; i < currentRoom.doors.length; i++) {
+ var door = currentRoom.doors[i];
+ var dx = targetX - door.x;
+ var dy = targetY - door.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance < 60) {
+ LK.getSound('door_sound').play();
+ generateNewRoom();
+ return;
}
}
- // If not clicking on door, move player
- if (!clickedDoor) {
- var localPos = currentRoom.toLocal(gamePos);
- // Keep player within room bounds
- localPos.x = Math.max(-180, Math.min(180, localPos.x));
- localPos.y = Math.max(-180, Math.min(180, localPos.y));
- player.moveTo(localPos.x, localPos.y);
- }
}
+ // Move player
+ player.moveTo(targetX, targetY);
};
-game.up = function (x, y, obj) {
- isDragging = false;
-};
-game.move = function (x, y, obj) {
- if (isDragging) {
- var deltaX = x - lastDragX;
- cameraRotation += deltaX * rotationSpeed;
- // Apply rotation to the current room
- if (currentRoom) {
- tween.stop(currentRoom, {
- rotation: true
- });
- tween(currentRoom, {
- rotation: cameraRotation
- }, {
- duration: 100,
- easing: tween.easeOut
- });
- }
- lastDragX = x;
- }
-};
game.update = function () {
// Update UI
- levelText.setText('Level: ' + level);
if (player) {
var sanityColor = 0x00ff00;
if (player.sanity < 50) sanityColor = 0xffff00;
if (player.sanity < 25) sanityColor = 0xff0000;
- sanityText.setText('Sanity: ' + Math.floor(player.sanity));
- sanityText.tint = sanityColor;
- // Gradual sanity decrease over time
- if (LK.ticks % 300 === 0) {
- // Every 5 seconds
- player.sanity = Math.max(0, player.sanity - 1);
- }
+ sanityBar.setText('Sanity: ' + Math.floor(player.sanity));
+ sanityBar.tint = sanityColor;
}
- // Flickering light effects
- if (currentRoom) {
+ escapeCounter.setText('Rooms Escaped: ' + roomsEscaped);
+ // Flickering lights
+ if (currentRoom && LK.ticks % 60 === 0) {
for (var i = 0; i < currentRoom.children.length; i++) {
var child = currentRoom.children[i];
- if (child.alpha !== undefined && child.alpha < 1) {
- if (Math.random() < 0.05) {
- child.alpha = Math.random() * 0.3 + 0.4;
- }
+ if (child.alpha !== undefined && Math.random() < 0.1) {
+ var originalAlpha = child.alpha;
+ child.alpha = 0.2;
+ tween(child, {
+ alpha: originalAlpha
+ }, {
+ duration: 100
+ });
}
}
}
};
-// Initialize the game
+// Start the game
initGame();
\ No newline at end of file