Out Put Code
Out Put Code
// Colors
const GRAY = 'rgb(50, 50, 50)';
const WHITE = 'rgb(255, 255, 255)';
const CAR_COLOR = 'rgb(150, 150, 255)';
const CHARS = ['rgb(255, 0, 0)', 'rgb(0, 255, 0)', 'rgb(0, 100, 255)'];
const CHAR_NAMES = ["Saim", "Addan", "Gulsher"];
let char_index = 0;
// Entities
const char = { x: 100, y: 100, width: 20, height: 20 };
const car = { x: 400, y: 300, width: 40, height: 20 };
const buildings = [];
for (let x = 1; x < 7; x++) {
for (let y = 1; y < 5; y++) {
buildings.push({ x: x * 100, y: y * 100, width: 80, height: 80 });
}
}
function draw() {
ctx.fillStyle = GRAY;
ctx.fillRect(0, 0, WIDTH, HEIGHT);
// Roads
ctx.strokeStyle = 'rgb(80, 80, 80)';
for (let x = 0; x < WIDTH; x += 100) {
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, HEIGHT);
ctx.stroke();
}
for (let y = 0; y < HEIGHT; y += 100) {
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(WIDTH, y);
ctx.stroke();
}
// Buildings
ctx.fillStyle = 'rgb(100, 100, 100)';
buildings.forEach(b => {
ctx.fillRect(b.x, b.y, b.width, b.height);
});
// Car
ctx.fillStyle = CAR_COLOR;
ctx.fillRect(car.x, car.y, car.width, car.height);
// Character
ctx.fillStyle = CHARS[char_index];
ctx.fillRect(char.x, char.y, char.width, char.height);
// UI
const name = CHAR_NAMES[char_index];
ctx.fillStyle = WHITE;
ctx.fillText(`Character: ${name}`, 10, 30);
}
gameLoop();