Skip to content

Resident evil game coding #897

Description

@kross6772-commits

Bio Outbreak body { margin: 0; background: #000; color: #fff; font-family: sans-serif; touch-action: none; } canvas { display: block; margin: 0 auto; background: #111; } #ui { position: fixed; bottom: 10px; left: 0; right: 0; display: flex; justify-content: space-between; padding: 0 20px; } button { background: rgba(255,255,255,0.1); color: #fff; border: 1px solid #555; padding: 20px; border-radius: 50%; font-size: 16px; }

◀ ● ▶

const canvas = document.getElementById('game'); const ctx = canvas.getContext('2d');

let player = { x: 180, y: 520, hp: 100 }; let bullets = []; let zombies = []; let score = 0;

function spawnZombie() { zombies.push({ x: Math.random()*320+20, y: -40, hp: 3 }); } setInterval(spawnZombie, 1200);

function shoot() { bullets.push({ x: player.x, y: player.y }); }

document.getElementById('shoot').ontouchstart = shoot; document.getElementById('left').ontouchstart = () => player.x -= 20; document.getElementById('right').ontouchstart = () => player.x += 20;

function update() { bullets.forEach(b => b.y -= 10); zombies.forEach(z => z.y += 2);

bullets.forEach((b, bi) => { zombies.forEach((z, zi) => { if (Math.abs(b.x - z.x) < 20 && Math.abs(b.y - z.y) < 20) { z.hp--; bullets.splice(bi,1); if (z.hp <= 0) { zombies.splice(zi,1); score++; } } }); }); }

function draw() { ctx.clearRect(0,0,360,640); ctx.fillStyle='green'; ctx.fillRect(player.x-10, player.y-10,20,20); ctx.fillStyle='yellow'; bullets.forEach(b=>ctx.fillRect(b.x-2,b.y-5,4,10)); ctx.fillStyle='red'; zombies.forEach(z=>ctx.fillRect(z.x-15,z.y-15,30,30)); ctx.fillStyle='white'; ctx.fillText('Score: '+score,10,20); }

function loop() { update(); draw

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions