Sure! Since you want to keep everything in a single HTML file (so only frontend) but make it more interactive and a bit more complicated, I’ll enhance the previous example with the following:
- Multiple avatars (simulate multiple users locally, you can control another avatar with different keys)
- Avatar color customization via UI (change avatar color)
- Furniture that can be dragged & repositioned
- Rooms divided into a grid to avoid overlaps for furniture and avatar movement
- Chat messages displayed above avatars in the room
- Avatar animation (simple) when moving (using CSS classes)
- Furniture placement snapping to grid
- Simple collision detection preventing avatars from overlapping furniture
This is still single-player, frontend only — but much more fun and interactive.
Here is the improved complete HTML file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Interactive Mini Habbo Demo</title>
<style>
body {
margin: 0;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: #7ec0ee; /* sky */
display: flex;
flex-direction: column;
align-items: center;
}
#gameContainer {
width: 640px;
height: 480px;
margin-top: 20px;
position: relative;
background: #a2d3a2; /* floor green */
border: 3px solid #333;
user-select: none;
}
/* Grid for room (16x12 grid of 40x40px) */
#roomGrid {
position: absolute;
width: 640px;
height: 480px;
display: grid;
grid-template-columns: repeat(16, 40px);
grid-template-rows: repeat(12, 40px);
}
.cell {
box-sizing: border-box;
border: 1px solid transparent;
/* Uncomment to see grid
border-color: #ddd;
*/
}
/* Furniture styles */
.furniture {
width: 80px;
height: 80px;
background-size: contain;
background-repeat: no-repeat;
background-position: center;
position: absolute;
cursor: grab;
z-index: 5;
transition: box-shadow 0.2s ease;
}
.furniture.dragging {
cursor: grabbing;
box-shadow: 0 0 15px 5px rgba(0,0,0,0.3);
}
#table {
background-image: url('https://i.imgur.com/A7zpH46.png');
}
#plant {
width: 40px;
height: 40px;
background-image: url('https://i.imgur.com/l5uZJLv.png');
}
/* Avatar container */
.avatar {
position: absolute;
width: 40px;
height: 40px;
cursor: default;
z-index: 10;
transition: top 0.1s, left 0.1s;
user-select: none;
}
/* Avatar circle for color */
.avatar .avatar-circle {
width: 40px;
height: 40px;
border-radius: 50%;
background-color: #666;
border: 2px solid #444;
}
/* Simple walking animation */
.avatar.walking .avatar-circle {
animation: walking-spin 0.6s linear infinite;
}
@keyframes walking-spin {
0% { box-shadow: 0 0 10px 2px rgba(255,255,255,0.7);}
50% { box-shadow: 0 0 25px 5px rgba(255,255,255,1);}
100% { box-shadow: 0 0 10px 2px rgba(255,255,255,0.7);}
}
/* Chat bubble */
.chat-bubble {
position: absolute;
bottom: 45px;
left: 50%;
transform: translateX(-50%);
max-width: 120px;
padding: 4px 8px;
background: rgba(0,0,0,0.7);
color: white;
border-radius: 12px;
font-size: 12px;
pointer-events: none;
opacity: 0;
transition: opacity 0.3s ease;
white-space: nowrap;
}
.chat-bubble.visible {
opacity: 1;
}
/* Controls panel */
#controls {
width: 640px;
margin-top: 10px;
background: #eee;
padding: 10px;
border-radius: 6px;
display: flex;
justify-content: space-between;
box-sizing: border-box;
}
#controls > div {
display: flex;
flex-direction: column;
}
label {
font-size: 14px;
margin-bottom: 4px;
font-weight: 600;
}
input[type=color], input[type=text] {
padding: 6px;
font-size: 14px;
}
button {
margin-top: 6px;
padding: 6px 10px;
font-size: 14px;
cursor: pointer;
}
/* Chat window */
#chatWindow {
width: 640px;
height: 140px;
overflow-y: auto;
background: white;
border: 1px solid #ccc;
margin-top: 10px;
padding: 6px;
box-sizing: border-box;
font-size: 14px;
}
#chatForm {
display: flex;
width: 640px;
margin-top: 8px;
}
#chatInput {
flex: 1;
font-size: 14px;
padding: 6px 8px;
}
#chatSend {
padding: 6px 16px;
font-size: 14px;
cursor: pointer;
}
</style>
</head>
<body>
<h1>Interactive Mini Habbo Demo</h1>
<div id="gameContainer" tabindex="0" aria-label="Habbo room">
<div id="roomGrid">
<!-- Grid cells generated by JS -->
</div>
<!-- Furniture -->
<div id="furniture1" class="furniture" style="top: 280px; left: 160px;" title="Table"></div>
<div id="furniture2" class="furniture" style="top: 80px; left: 400px;" title="Plant"></div>
<!-- Avatars -->
<!-- Avatar 1 -->
<div class="avatar" id="avatar1" style="top: 200px; left: 200px;" title="Player 1">
<div class="avatar-circle" style="background-color: #3498db;"></div>
<div class="chat-bubble"></div>
</div>
<!-- Avatar 2 -->
<div class="avatar" id="avatar2" style="top: 200px; left: 280px;" title="Player 2">
<div class="avatar-circle" style="background-color: #e74c3c;"></div>
<div class="chat-bubble"></div>
</div>
</div>
<div id="controls">
<div>
<label for="avatarSelect">Select Avatar</label>
<select id="avatarSelect">
<option value="avatar1">Player 1 (Use WASD)</option>
<option value="avatar2">Player 2 (Use Arrow Keys)</option>
</select>
</div>
<div>
<label for="colorPicker">Change Avatar Color</label>
<input type="color" id="colorPicker" value="#3498db" />
</div>
<div>
<label for="chatMessage">Send Chat</label>
<input type="text" id="chatMessage" placeholder="Type message..." />
<button id="sendChatBtn">Send</button>
</div>
</div>
<div id="chatWindow" aria-live="polite" aria-atomic="false"></div>
<script>
// Constants
const gridCols = 16;
const gridRows = 12;
const cellSize = 40;
const avatarSize = 40;
const furnitureSize = 80;
const gameContainer = document.getElementById('gameContainer');
const roomGrid = document.getElementById('roomGrid');
const avatarElements = {
avatar1: document.getElementById('avatar1'),
avatar2: document.getElementById('avatar2')
};
const furnitureElements = [
document.getElementById('furniture1'),
document.getElementById('furniture2')
];
const avatarSelect = document.getElementById('avatarSelect');
const colorPicker = document.getElementById('colorPicker');
const chatMessage = document.getElementById('chatMessage');
const sendChatBtn = document.getElementById('sendChatBtn');
const chatWindow = document.getElementById('chatWindow');
// State of avatars (positions in pixels, chat messages)
let avatars = {
avatar1: {
x: 200,
y: 200,
color: '#3498db',
chatTimeout: null,
},
avatar2: {
x: 280,
y: 200,
color: '#e74c3c',
chatTimeout: null,
}
};
// State of furniture positions (pixels)
let furniture = [
{ el: furnitureElements[0], x: 160, y: 280, width: 80, height: 80 },
{ el: furnitureElements[1], x: 400, y: 80, width: 40, height: 40 },
];
// Generate grid cells inside roomGrid for visual reference (optional for debugging)
function createGridCells() {
roomGrid.innerHTML = '';
for(let i=0; i < gridCols * gridRows; i++) {
const cell = document.createElement('div');
cell.className = 'cell';
roomGrid.appendChild(cell);
}
}
createGridCells();
// Utility functions
function snapToGrid(value) {
return Math.round(value / cellSize) * cellSize;
}
function rectsOverlap(r1, r2) {
return !(r2.x >= r1.x + r1.width ||
r2.x + r2.width <= r1.x ||
r2.y >= r1.y + r1.height ||
r2.y + r2.height <= r1.y);
}
function positionIsFree(x, y, width, height, ignoreFurniture = null) {
// Check boundaries
if (x < 0 || y < 0 || x + width > gameContainer.clientWidth || y + height > gameContainer.clientHeight) return false;
// Check furniture collisions
for (const f of furniture) {
if (f === ignoreFurniture) continue;
if (rectsOverlap({ x, y, width, height }, f)) return false;
}
// Check avatar collisions
for (const key in avatars) {
const a = avatars[key];
if (rectsOverlap({ x, y, width, height }, { x: a.x, y: a.y, width: avatarSize, height: avatarSize })) {
return false;
}
}
return true;
}
// Update positions of avatars elements according to state
function updateAvatarPositions() {
for (const id in avatars) {
const avatar = avatars[id];
const el = avatarElements[id];
el.style.left = avatar.x + 'px';
el.style.top = avatar.y + 'px';
el.querySelector('.avatar-circle').style.backgroundColor = avatar.color;
}
}
updateAvatarPositions();
// Furniture dragging
furniture.forEach(fur => {
const el = fur.el;
let offsetX, offsetY;
let dragging = false;
el.addEventListener('mousedown', (e) => {
dragging = true;
el.classList.add('dragging');
offsetX = e.clientX - el.getBoundingClientRect().left;
offsetY = e.clientY - el.getBoundingClientRect().top;
e.preventDefault();
});
document.addEventListener('mouseup', (e) => {
if (dragging) {
dragging = false;
el.classList.remove('dragging');
// Snap position to grid on drop
let newX = snapToGrid( el.offsetLeft );
let newY = snapToGrid( el.offsetTop );
// Boundary check
newX = Math.min( newX, gameContainer.clientWidth - fur.width );
newY = Math.min( newY, gameContainer.clientHeight - fur.height );
newX = Math.max(0, newX);
newY = Math.max(0, newY);
// Check collision with avatars
if (!positionIsFree(newX, newY, fur.width, fur.height, fur)) {
// Revert to old position if collides
newX = fur.x;
newY = fur.y;
}
fur.x = newX;
fur.y = newY;
el.style.left = fur.x + 'px';
el.style.top = fur.y + 'px';
}
});
document.addEventListener('mousemove', (e) => {
if (!dragging) return;
let newLeft = e.clientX - gameContainer.getBoundingClientRect().left - offsetX;
let newTop = e.clientY - gameContainer.getBoundingClientRect().top - offsetY;
// Boundaries
newLeft = Math.min(newLeft, gameContainer.clientWidth - fur.width);
newLeft = Math.max(0, newLeft);
newTop = Math.min(newTop, gameContainer.clientHeight - fur.height);
newTop = Math.max(0, newTop);
el.style.left = newLeft + 'px';
el.style.top = newTop + 'px';
});
});
// Control which avatar is active
let activeAvatarId = avatarSelect.value;
avatarSelect.addEventListener('change', () => {
activeAvatarId = avatarSelect.value;
colorPicker.value = avatars[activeAvatarId].color;
});
// Change avatar color
colorPicker.addEventListener('input', () => {
avatars[activeAvatarId].color = colorPicker.value;
updateAvatarPositions();
});
// Chat bubble display & chat window
function showChat(avatarId, message) {
if (!message) return;
// Add message to chat window
const chatLine = document.createElement('div');
chatLine.textContent = `${avatarId}: ${message}`;
chatWindow.appendChild(chatLine);
chatWindow.scrollTop = chatWindow.scrollHeight;
// Show bubble above avatar
const avatarEl = avatarElements[avatarId];
const bubble = avatarEl.querySelector('.chat-bubble');
bubble.textContent = message;
bubble.classList.add('visible');
// Clear after 5 seconds
if (avatars[avatarId].chatTimeout) clearTimeout(avatars[avatarId].chatTimeout);
avatars[avatarId].chatTimeout = setTimeout(() => {
bubble.classList.remove('visible');
}, 5000);
}
sendChatBtn.addEventListener('click', () => {
const msg = chatMessage.value.trim();
if (!msg) return;
showChat(activeAvatarId, msg);
chatMessage.value = '';
});
chatMessage.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
sendChatBtn.click();
e.preventDefault();
}
});
// Avatar movement with keyboard
// Controls:
// avatar1 = WASD keys
// avatar2 = Arrow keys
// Movement step = 40 pixels (one grid cell)
const moveStep = cellSize;
const keyState = {};
window.addEventListener('keydown', (e) => {
keyState[e.key] = true;
handleMovement();
});
window.addEventListener('keyup', (e) => {
keyState[e.key] = false;
// Remove walking animation for all avatars
Object.keys(avatars).forEach(id => {
avatarElements[id].classList.remove('walking');
});
});
// Movement includes collision detection
function handleMovement() {
// Avatar 1 - keys: W A S D
let moved = false;
let av1 = avatars.avatar1;
if (keyState['w'] || keyState['W']) {
let newY = av1.y - moveStep;
if (positionIsFree(av1.x, newY, avatarSize, avatarSize)) {
av1.y = newY;
moved = true;
}
}
if (keyState['s'] || keyState['S']) {
let newY = av1.y + moveStep;
if (positionIsFree(av1.x, newY, avatarSize, avatarSize)) {
av1.y = newY;
moved = true;
}
}
if (keyState['a'] || keyState['A']) {
let newX = av1.x - moveStep;
if (positionIsFree(newX, av1.y, avatarSize, avatarSize)) {
av1.x = newX;
moved = true;
}
}
if (keyState['d'] || keyState['D']) {
let newX = av1.x + moveStep;
if (positionIsFree(newX, av1.y, avatarSize, avatarSize)) {
av1.x = newX;
moved = true;
}
}
if(moved) {
avatarElements.avatar1.classList.add('walking');
} else {
avatarElements.avatar1.classList.remove('walking');
}
// Avatar 2 - arrow keys
moved = false;
let av2 = avatars.avatar2;
if (keyState['ArrowUp']) {
let newY = av2.y - moveStep;
if (positionIsFree(av2.x, newY, avatarSize, avatarSize)) {
av2.y = newY;
moved = true;
}
}
if (keyState['ArrowDown']) {
let newY = av2.y + moveStep;
if (positionIsFree(av2.x, newY, avatarSize, avatarSize)) {
av2.y = newY;
moved = true;
}
}
if (keyState['ArrowLeft']) {
let newX = av2.x - moveStep;
if (positionIsFree(newX, av2.y, avatarSize, avatarSize)) {
av2.x = newX;
moved = true;
}
}
if (keyState['ArrowRight']) {
let newX = av2.x + moveStep;
if (positionIsFree(newX, av2.y, avatarSize, avatarSize)) {
av2.x = newX;
moved = true;
}
}
if(moved) {
avatarElements.avatar2.classList.add('walking');
} else {
avatarElements.avatar2.classList.remove('walking');
}
updateAvatarPositions();
}
// Focus game container on load for keyboard events
window.onload = () => {
gameContainer.focus();
};
</script>
</body>
</html>
What new features are added and how to use:
- Multiple avatars: You control two avatars:
- Player 1: WASD to move
- Player 2: Arrow keys to move
- Furniture can be dragged: Drag the table and plant anywhere snapping to the grid (no overlap with avatars or outside of room allowed)
- Avatar color change: Use the color picker to change the color of the currently selected avatar.
- Chat messages:
- Type into chat box and send.
- Message appears in chat window below.
- Message shows as a bubble above the avatar for 5 seconds.
- Movement snapping: Avatars move in 40px steps that align with the grid.
- Collision detection: Avatars cannot walk over furniture or outside the room.
- Walking animation: When moving an avatar, a glow animation shows around it.
- Grid: Room is divided into 16x12 cells of 40x40 pixels for clean layout.
How to extend from here?
- Add more avatars and controls.
- Add furniture placement/removal UI.
- Add animations and avatar sprites.
- Connect to backend for real multiplayer & persistent rooms.
- Add more chat functionality, private message, emotes, status, etc.
Open the file in a modern desktop browser (Chrome, Firefox, Edge). Click inside the game container to ensure keyboard input is captured, then move the avatars! Drag furniture with mouse. Change colors and send chat.
This is a pretty neat foundation to prototype a frontend "habbo-like" room interaction in plain HTML/JS/CSS.
Let me know if you want me to add any additional feature!