์ฝ˜ํ…์ธ  ๋Œ€ํ‘œ ์ด๋ฏธ์ง€ - ๐ŸŽฎ JavaScript๋กœ ๊ฒŒ์ž„ ๋งŒ๋“ค๊ธฐ2D & 3D ๊ฒŒ์ž„ ์—”์ง„ ์™„์ „ ์ •๋ณต
JavaScript ยท ๊ฒŒ์ž„ ๊ฐœ๋ฐœ

๐ŸŽฎ JavaScript๋กœ ๊ฒŒ์ž„ ๋งŒ๋“ค๊ธฐ
2D & 3D ๊ฒŒ์ž„ ์—”์ง„ ์™„์ „ ์ •๋ณต

๋ธŒ๋ผ์šฐ์ € ํ•˜๋‚˜๋กœ ์„ธ์ƒ์„ ์ •๋ณตํ•˜๋Š” ๊ฒŒ์ž„ ๊ฐœ๋ฐœ์ž์˜ ๊ธธ ๐Ÿš€

SCORE: 9999 LEVEL: 07 canvas.getContext('2d') requestAnimationFrame() ctx.fillRect(x, y, w, h) ๐ŸŽฎ 2D ๊ฒŒ์ž„ Canvas API ๐ŸŒ 3D ๊ฒŒ์ž„ WebGL / Three.js JavaScript Canvas 2D WebGL Three.js Phaser.js ๊ฒŒ์ž„ ์—”์ง„

์•ผ, ์†”์งํžˆ ๋งํ•ด๋ด. ์–ด๋ฆด ๋•Œ ๊ฒŒ์ž„ ํ•˜๋ฉด์„œ "๋‚˜๋„ ์ด๋Ÿฐ ๊ฑฐ ๋งŒ๋“ค ์ˆ˜ ์žˆ์„๊นŒ?" ํ•œ ๋ฒˆ์ฏค ์ƒ๊ฐํ•ด๋ดค์ž–์•„? ๐Ÿค”
๊ทธ๋Ÿฐ๋ฐ ๋†€๋ž๊ฒŒ๋„ JavaScript ํ•˜๋‚˜๋ฉด ์ง„์งœ๋กœ ๊ฒŒ์ž„์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์–ด. ๋ธŒ๋ผ์šฐ์ € ์—ด๊ณ , ์ฝ”๋“œ ๋ช‡ ์ค„ ์น˜๋ฉด ์บ๋ฆญํ„ฐ๊ฐ€ ์›€์ง์ด๊ณ , ์ด์•Œ์ด ๋‚ ์•„๋‹ค๋‹ˆ๊ณ , 3D ์„ธ๊ณ„๊ฐ€ ํŽผ์ณ์ง€๋Š” ๊ฑฐ์•ผ.

์ด ๊ธ€์—์„œ๋Š” JavaScript๋กœ ๊ฒŒ์ž„์„ ๋งŒ๋“œ๋Š” ํ•ต์‹ฌ ์›๋ฆฌ๋ถ€ํ„ฐ, 2D ๊ฒŒ์ž„ ์—”์ง„, 3D ๊ฒŒ์ž„ ์—”์ง„ ๊ตฌํ˜„๊นŒ์ง€ ์ง„์งœ ์‹ค์šฉ์ ์ธ ๋‚ด์šฉ์œผ๋กœ ์ญ‰ ํ’€์–ด๋ณผ๊ฒŒ. ์ค€๋น„๋์–ด? ๋ ˆ๋ฒจ 1๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜์ž! ๐ŸŽฎ


๐Ÿ•น๏ธ ์™œ JavaScript๋กœ ๊ฒŒ์ž„์„ ๋งŒ๋“œ๋ƒ๊ณ ?

๋จผ์ € "์™œ ๊ตณ์ด JavaScript์•ผ?" ๋ผ๋Š” ์งˆ๋ฌธ์— ๋‹ตํ•ด์•ผ๊ฒ ์ง€. Unity ์žˆ๊ณ , Unreal ์žˆ๊ณ , Godot๋„ ์žˆ๋Š”๋ฐ ๋ง์ด์•ผ.
๊ทผ๋ฐ JavaScript ๊ฒŒ์ž„ ๊ฐœ๋ฐœ์—๋Š” ์ง„์งœ ๊ฐ•๋ ฅํ•œ ์ด์œ ๋“ค์ด ์žˆ์–ด.

๐ŸŒ ํ”Œ๋žซํผ ๋…๋ฆฝ์„ฑ ๋ธŒ๋ผ์šฐ์ €๋งŒ ์žˆ์œผ๋ฉด Windows, Mac, Linux, ๋ชจ๋ฐ”์ผ ์–ด๋””์„œ๋“  ์‹คํ–‰. ์„ค์น˜ ๋ถˆํ•„์š”!
โšก ์ฆ‰๊ฐ์ ์ธ ํ”ผ๋“œ๋ฐฑ ์ฝ”๋“œ ์ €์žฅํ•˜๊ณ  F5 ๋ˆ„๋ฅด๋ฉด ๋ฐ”๋กœ ๊ฒฐ๊ณผ ํ™•์ธ. ๊ฐœ๋ฐœ ์‚ฌ์ดํด์ด ์—„์ฒญ ๋น ๋ฆ„.
๐Ÿ”— ๋ฐฐํฌ ์ดˆ๊ฐ„๋‹จ URL ํ•˜๋‚˜๋กœ ์ „ ์„ธ๊ณ„ ๊ณต์œ . GitHub Pages, Netlify ๋“ฑ์œผ๋กœ ๋ฌด๋ฃŒ ๋ฐฐํฌ ๊ฐ€๋Šฅ.
๐Ÿ“š ์ƒํƒœ๊ณ„ ํ’๋ถ€ Phaser, Three.js, Babylon.js ๋“ฑ ๊ฒ€์ฆ๋œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ๋„˜์ณ๋‚จ.
๐Ÿ’ฐ ๋น„์šฉ ์ œ๋กœ ๋ณ„๋„ ๋ผ์ด์„ ์Šค ์—†์ด ์‹œ์ž‘ ๊ฐ€๋Šฅ. ์˜คํ”ˆ์†Œ์Šค ์ƒํƒœ๊ณ„ ์ตœ๋Œ€ ํ™œ์šฉ.
๐ŸŽ“ ํ•™์Šต ๊ณก์„  ์›น ๊ฐœ๋ฐœ ์ง€์‹์ด ์žˆ๋‹ค๋ฉด ์ง„์ž… ์žฅ๋ฒฝ์ด ์ƒ๋Œ€์ ์œผ๋กœ ๋‚ฎ์Œ.
๐Ÿ’ก ์‹ค์ œ ์‚ฌ๋ก€: 2048, Flappy Bird ํด๋ก , ์ˆ˜๋งŽ์€ ์ธ๋”” ๊ฒŒ์ž„๋“ค์ด JavaScript๋กœ ๋งŒ๋“ค์–ด์กŒ์–ด. itch.io ๊ฐ™์€ ํ”Œ๋žซํผ์—์„œ HTML5 ๊ฒŒ์ž„ ์นดํ…Œ๊ณ ๋ฆฌ๋ฅผ ๋ณด๋ฉด JavaScript ๊ฒŒ์ž„์ด ์—„์ฒญ ๋งŽ๋‹ค๋Š” ๊ฑธ ์•Œ ์ˆ˜ ์žˆ์–ด!

๐ŸŽจ Canvas API - 2D ๊ฒŒ์ž„์˜ ์‹ฌ์žฅ

JavaScript 2D ๊ฒŒ์ž„์˜ ํ•ต์‹ฌ์€ HTML5 Canvas API์•ผ. Canvas๋Š” ๋ง ๊ทธ๋Œ€๋กœ "์บ”๋ฒ„์Šค", ์ฆ‰ ๊ทธ๋ฆผ์„ ๊ทธ๋ฆด ์ˆ˜ ์žˆ๋Š” ๊ณต๊ฐ„์ด์•ผ.
ํ”ฝ์…€ ๋‹จ์œ„๋กœ ์ง์ ‘ ์ œ์–ดํ•  ์ˆ˜ ์žˆ์–ด์„œ ๊ฒŒ์ž„ ๊ฐœ๋ฐœ์— ๋”ฑ์ด์ง€.

Canvas ๊ธฐ๋ณธ ์„ธํŒ…

๊ฒŒ์ž„ ๋ฃจํ”„๋ฅผ ๋งŒ๋“ค๊ธฐ ์ „์— Canvas๋ฅผ ์„ธํŒ…ํ•˜๋Š” ๋ฐฉ๋ฒ•๋ถ€ํ„ฐ ์•Œ์•„๋ณด์ž.

// HTML
<canvas id="gameCanvas" width="800" height="600"></canvas>

// JavaScript
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');

// ์บ”๋ฒ„์Šค ํฌ๊ธฐ๋ฅผ ํ™”๋ฉด์— ๋งž๊ฒŒ ์กฐ์ •
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;

// ๋ฆฌ์‚ฌ์ด์ฆˆ ๋Œ€์‘
window.addEventListener('resize', () => {
  canvas.width = window.innerWidth;
  canvas.height = window.innerHeight;
});

๐Ÿ”„ ๊ฒŒ์ž„ ๋ฃจํ”„ (Game Loop) - ๊ฒŒ์ž„์˜ ์‹ฌ์žฅ๋ฐ•๋™

๊ฒŒ์ž„ ๋ฃจํ”„๋Š” ๊ฒŒ์ž„์˜ ํ•ต์‹ฌ ์ค‘์˜ ํ•ต์‹ฌ์ด์•ผ. ๋งค ํ”„๋ ˆ์ž„๋งˆ๋‹ค ์—…๋ฐ์ดํŠธ โ†’ ๋ Œ๋”๋ง์„ ๋ฐ˜๋ณตํ•˜๋Š” ๊ตฌ์กฐ์•ผ.
requestAnimationFrame์„ ์‚ฌ์šฉํ•˜๋ฉด ๋ธŒ๋ผ์šฐ์ €์˜ ํ™”๋ฉด ๊ฐฑ์‹  ์ฃผ๊ธฐ(๋ณดํ†ต 60fps)์— ๋งž์ถฐ ์ตœ์ ํ™”๋œ ๋ฃจํ”„๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์–ด.

// ๊ธฐ๋ณธ ๊ฒŒ์ž„ ๋ฃจํ”„ ๊ตฌ์กฐ
let lastTime = 0;

function gameLoop(timestamp) {
  // delta time ๊ณ„์‚ฐ (ํ”„๋ ˆ์ž„ ๋…๋ฆฝ์  ์›€์ง์ž„์„ ์œ„ํ•ด)
  const deltaTime = timestamp - lastTime;
  lastTime = timestamp;

  // 1. ์—…๋ฐ์ดํŠธ: ๊ฒŒ์ž„ ๋กœ์ง ์ฒ˜๋ฆฌ
  update(deltaTime);

  // 2. ๋ Œ๋”๋ง: ํ™”๋ฉด ๊ทธ๋ฆฌ๊ธฐ
  render();

  // ๋‹ค์Œ ํ”„๋ ˆ์ž„ ์š”์ฒญ
  requestAnimationFrame(gameLoop);
}

// ๊ฒŒ์ž„ ์‹œ์ž‘
requestAnimationFrame(gameLoop);

function update(dt) {
  // ํ”Œ๋ ˆ์ด์–ด ์œ„์น˜ ์—…๋ฐ์ดํŠธ
  player.x += player.vx * (dt / 1000);
  player.y += player.vy * (dt / 1000);
}

function render() {
  // ํ™”๋ฉด ์ดˆ๊ธฐํ™”
  ctx.clearRect(0, 0, canvas.width, canvas.height);

  // ๋ฐฐ๊ฒฝ ๊ทธ๋ฆฌ๊ธฐ
  ctx.fillStyle = '#1a1a2e';
  ctx.fillRect(0, 0, canvas.width, canvas.height);

  // ํ”Œ๋ ˆ์ด์–ด ๊ทธ๋ฆฌ๊ธฐ
  ctx.fillStyle = '#5b9bd5';
  ctx.fillRect(player.x, player.y, player.width, player.height);
}
โš ๏ธ Delta Time์ด ์™œ ์ค‘์š”ํ•ด? Delta Time ์—†์ด ๋งŒ๋“ค๋ฉด 60fps ์ปดํ“จํ„ฐ์—์„œ๋Š” ๋น ๋ฅด๊ณ , 30fps ์ปดํ“จํ„ฐ์—์„œ๋Š” ๋А๋ฆฌ๊ฒŒ ์›€์ง์—ฌ. Delta Time์„ ๊ณฑํ•ด์ฃผ๋ฉด ์–ด๋–ค ํ™˜๊ฒฝ์—์„œ๋„ ๋™์ผํ•œ ์†๋„๋กœ ์›€์ง์ด๋Š” ๊ฒŒ์ž„์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์–ด!
๊ฒŒ์ž„ ๋ฃจํ”„ ํ๋ฆ„๋„ ๊ฒŒ์ž„ ์‹œ์ž‘ ์ดˆ๊ธฐํ™” & ๋ฆฌ์†Œ์Šค ๋กœ๋“œ requestAnimationFrame ํƒ€์ž„์Šคํƒฌํ”„ ์ˆ˜์‹  โ†’ deltaTime ๊ณ„์‚ฐ โš™๏ธ UPDATE ๋ฌผ๋ฆฌ ยท ์ถฉ๋Œ ยท ์ž…๋ ฅ ์ฒ˜๋ฆฌ ๊ฒŒ์ž„ ๋กœ์ง ์—…๋ฐ์ดํŠธ ๐ŸŽจ RENDER ํ™”๋ฉด ํด๋ฆฌ์–ด โ†’ ๋ฐฐ๊ฒฝ โ†’ ์˜ค๋ธŒ์ ํŠธ โ†’ UI ๊ทธ๋ฆฌ๊ธฐ ๋ฐ˜๋ณต ๋ฃจํ”„ ๊ฒŒ์ž„ ์˜ค๋ฒ„ / ์ข…๋ฃŒ

๐Ÿ—๏ธ 2D ๊ฒŒ์ž„ ์—”์ง„ ์ง์ ‘ ๊ตฌํ˜„ํ•˜๊ธฐ

๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์—†์ด ์ˆœ์ˆ˜ JavaScript๋กœ ๋ฏธ๋‹ˆ 2D ๊ฒŒ์ž„ ์—”์ง„์„ ๋งŒ๋“ค์–ด๋ณด์ž.
์ด๊ฑธ ์ดํ•ดํ•˜๋ฉด Phaser ๊ฐ™์€ ํ”„๋ ˆ์ž„์›Œํฌ๊ฐ€ ๋‚ด๋ถ€์ ์œผ๋กœ ์–ด๋–ป๊ฒŒ ๋™์ž‘ํ•˜๋Š”์ง€๋„ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ์ดํ•ด๋ผ. ๐Ÿง 

๐Ÿ“ฆ Entity-Component ๊ตฌ์กฐ

ํ˜„๋Œ€ ๊ฒŒ์ž„ ์—”์ง„์˜ ํ•ต์‹ฌ ํŒจํ„ด์€ Entity-Component System (ECS)์ด์•ผ.
๊ฒŒ์ž„ ์˜ค๋ธŒ์ ํŠธ(Entity)์— ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ถ™์—ฌ์„œ ๊ธฐ๋Šฅ์„ ์กฐํ•ฉํ•˜๋Š” ๋ฐฉ์‹์ด์ง€.

// ๊ธฐ๋ณธ Entity ํด๋ž˜์Šค
class Entity {
  constructor(x, y) {
    this.x = x;
    this.y = y;
    this.components = {};
    this.active = true;
  }

  addComponent(name, component) {
    this.components[name] = component;
    component.entity = this;
    return this;
  }

  getComponent(name) {
    return this.components[name];
  }

  update(dt) {
    Object.values(this.components).forEach(comp => {
      if (comp.update) comp.update(dt);
    });
  }

  render(ctx) {
    Object.values(this.components).forEach(comp => {
      if (comp.render) comp.render(ctx);
    });
  }
}

// Transform ์ปดํฌ๋„ŒํŠธ
class Transform {
  constructor(x, y, width, height) {
    this.x = x;
    this.y = y;
    this.width = width;
    this.height = height;
    this.rotation = 0;
    this.scaleX = 1;
    this.scaleY = 1;
  }
}

// Renderer ์ปดํฌ๋„ŒํŠธ
class SpriteRenderer {
  constructor(color) {
    this.color = color;
  }

  render(ctx) {
    const t = this.entity.getComponent('transform');
    ctx.save();
    ctx.translate(t.x + t.width / 2, t.y + t.height / 2);
    ctx.rotate(t.rotation);
    ctx.scale(t.scaleX, t.scaleY);
    ctx.fillStyle = this.color;
    ctx.fillRect(-t.width / 2, -t.height / 2, t.width, t.height);
    ctx.restore();
  }
}

// ์‚ฌ์šฉ ์˜ˆ์‹œ
const player = new Entity(100, 100);
player
  .addComponent('transform', new Transform(100, 100, 40, 40))
  .addComponent('renderer', new SpriteRenderer('#5b9bd5'));

๐Ÿ’ฅ ์ถฉ๋Œ ๊ฐ์ง€ (Collision Detection)

๊ฒŒ์ž„์—์„œ ์ถฉ๋Œ ๊ฐ์ง€๋Š” ํ•„์ˆ˜์•ผ. ๊ฐ€์žฅ ๊ธฐ๋ณธ์ ์ธ AABB (Axis-Aligned Bounding Box) ์ถฉ๋Œ๋ถ€ํ„ฐ ์•Œ์•„๋ณด์ž.

// AABB ์ถฉ๋Œ ๊ฐ์ง€
function checkAABB(a, b) {
  return (
    a.x < b.x + b.width &&
    a.x + a.width > b.x &&
    a.y < b.y + b.height &&
    a.y + a.height > b.y
  );
}

// ์›ํ˜• ์ถฉ๋Œ ๊ฐ์ง€
function checkCircle(a, b) {
  const dx = a.cx - b.cx;
  const dy = a.cy - b.cy;
  const distance = Math.sqrt(dx * dx + dy * dy);
  return distance < a.radius + b.radius;
}

// ์ถฉ๋Œ ์‘๋‹ต (๋ฐ˜๋ฐœ๋ ฅ ๊ณ„์‚ฐ)
function resolveCollision(a, b) {
  const overlapX = (a.x + a.width / 2) - (b.x + b.width / 2);
  const overlapY = (a.y + a.height / 2) - (b.y + b.height / 2);

  if (Math.abs(overlapX) > Math.abs(overlapY)) {
    // ์ขŒ์šฐ ์ถฉ๋Œ
    a.vx = -a.vx * 0.8; // ๋ฐ˜๋ฐœ ๊ณ„์ˆ˜
  } else {
    // ์ƒํ•˜ ์ถฉ๋Œ
    a.vy = -a.vy * 0.8;
    if (overlapY < 0) a.onGround = true; // ๋ฐ”๋‹ฅ ์ฐฉ์ง€
  }
}

โŒจ๏ธ ์ž…๋ ฅ ์‹œ์Šคํ…œ (Input Manager)

// ์ž…๋ ฅ ๊ด€๋ฆฌ์ž
class InputManager {
  constructor() {
    this.keys = {};
    this.mouse = { x: 0, y: 0, buttons: {} };
    this.touches = [];

    // ํ‚ค๋ณด๋“œ ์ด๋ฒคํŠธ
    window.addEventListener('keydown', e => {
      this.keys[e.code] = true;
    });
    window.addEventListener('keyup', e => {
      this.keys[e.code] = false;
    });

    // ๋งˆ์šฐ์Šค ์ด๋ฒคํŠธ
    window.addEventListener('mousemove', e => {
      this.mouse.x = e.clientX;
      this.mouse.y = e.clientY;
    });
    window.addEventListener('mousedown', e => {
      this.mouse.buttons[e.button] = true;
    });
    window.addEventListener('mouseup', e => {
      this.mouse.buttons[e.button] = false;
    });

    // ํ„ฐ์น˜ ์ด๋ฒคํŠธ (๋ชจ๋ฐ”์ผ ์ง€์›)
    window.addEventListener('touchstart', e => {
      this.touches = Array.from(e.touches).map(t => ({
        x: t.clientX, y: t.clientY, id: t.identifier
      }));
    });
  }

  isKeyDown(code) { return !!this.keys[code]; }
  isMouseDown(button = 0) { return !!this.mouse.buttons[button]; }
}

// ์‚ฌ์šฉ ์˜ˆ์‹œ
const input = new InputManager();

function update(dt) {
  if (input.isKeyDown('ArrowLeft')) player.vx = -200;
  if (input.isKeyDown('ArrowRight')) player.vx = 200;
  if (input.isKeyDown('Space') && player.onGround) {
    player.vy = -500; // ์ ํ”„!
    player.onGround = false;
  }
}

๐ŸŒ ์”ฌ ๊ด€๋ฆฌ (Scene Manager)

๊ฒŒ์ž„์—๋Š” ๋ฉ”์ธ ๋ฉ”๋‰ด, ๊ฒŒ์ž„ ํ”Œ๋ ˆ์ด, ๊ฒŒ์ž„ ์˜ค๋ฒ„ ๋“ฑ ์—ฌ๋Ÿฌ ์”ฌ์ด ์žˆ์–ด. ์”ฌ ๋งค๋‹ˆ์ €๋กœ ์ด๋ฅผ ๊ด€๋ฆฌํ•ด๋ณด์ž.

// ์”ฌ ๋งค๋‹ˆ์ €
class SceneManager {
  constructor() {
    this.scenes = {};
    this.currentScene = null;
  }

  addScene(name, scene) {
    this.scenes[name] = scene;
  }

  switchTo(name) {
    if (this.currentScene && this.currentScene.onExit) {
      this.currentScene.onExit();
    }
    this.currentScene = this.scenes[name];
    if (this.currentScene.onEnter) {
      this.currentScene.onEnter();
    }
  }

  update(dt) {
    if (this.currentScene) this.currentScene.update(dt);
  }

  render(ctx) {
    if (this.currentScene) this.currentScene.render(ctx);
  }
}

// ์”ฌ ์˜ˆ์‹œ
const mainMenuScene = {
  onEnter() { console.log('๋ฉ”์ธ ๋ฉ”๋‰ด ์ง„์ž…'); },
  update(dt) { /* ๋ฉ”๋‰ด ์• ๋‹ˆ๋ฉ”์ด์…˜ */ },
  render(ctx) {
    ctx.fillStyle = '#1a1a2e';
    ctx.fillRect(0, 0, canvas.width, canvas.height);
    ctx.fillStyle = '#fff';
    ctx.font = '48px Arial';
    ctx.textAlign = 'center';
    ctx.fillText('๊ฒŒ์ž„ ์‹œ์ž‘', canvas.width / 2, canvas.height / 2);
  }
};

const sceneManager = new SceneManager();
sceneManager.addScene('mainMenu', mainMenuScene);
sceneManager.switchTo('mainMenu');

๐ŸŽฏ Phaser.js - 2D ๊ฒŒ์ž„ ๊ฐœ๋ฐœ์˜ ๊ฐ•์ž

์ˆœ์ˆ˜ JavaScript๋กœ ์—”์ง„์„ ๋งŒ๋“œ๋Š” ๊ฑด ๊ณต๋ถ€์— ์ข‹์ง€๋งŒ, ์‹ค์ œ ๊ฒŒ์ž„์„ ๋น ๋ฅด๊ฒŒ ๋งŒ๋“ค๊ณ  ์‹ถ๋‹ค๋ฉด Phaser.js๋ฅผ ์จ์•ผ ํ•ด.
Phaser๋Š” ํ˜„์žฌ ๊ฐ€์žฅ ์ธ๊ธฐ ์žˆ๋Š” HTML5 2D ๊ฒŒ์ž„ ํ”„๋ ˆ์ž„์›Œํฌ์•ผ. GitHub ์Šคํƒ€ 37,000๊ฐœ ์ด์ƒ! โญ

๐Ÿ“Œ Phaser.js ์ฃผ์š” ํŠน์ง• WebGL + Canvas ๋ Œ๋”๋Ÿฌ ๋ฌผ๋ฆฌ ์—”์ง„ ๋‚ด์žฅ (Arcade, Matter.js) ํƒ€์ผ๋งต ์ง€์› ์• ๋‹ˆ๋ฉ”์ด์…˜ ์‹œ์Šคํ…œ ์˜ค๋””์˜ค ๋งค๋‹ˆ์ € ์นด๋ฉ”๋ผ ์‹œ์Šคํ…œ ํŠธ์œˆ ์• ๋‹ˆ๋ฉ”์ด์…˜ TypeScript ์ง€์›

Phaser 3 ๊ธฐ๋ณธ ๊ตฌ์กฐ

// Phaser 3 ๊ฒŒ์ž„ ์„ค์ •
const config = {
  type: Phaser.AUTO,  // WebGL ์šฐ์„ , ์—†์œผ๋ฉด Canvas
  width: 800,
  height: 600,
  backgroundColor: '#1a1a2e',
  physics: {
    default: 'arcade',
    arcade: {
      gravity: { y: 300 },
      debug: false
    }
  },
  scene: [BootScene, GameScene, UIScene]
};

const game = new Phaser.Game(config);

// ๊ฒŒ์ž„ ์”ฌ ํด๋ž˜์Šค
class GameScene extends Phaser.Scene {
  constructor() {
    super({ key: 'GameScene' });
  }

  preload() {
    // ๋ฆฌ์†Œ์Šค ๋กœ๋“œ
    this.load.image('player', 'assets/player.png');
    this.load.tilemapTiledJSON('map', 'assets/level1.json');
    this.load.spritesheet('explosion', 'assets/explosion.png', {
      frameWidth: 64, frameHeight: 64
    });
  }

  create() {
    // ํƒ€์ผ๋งต ์ƒ์„ฑ
    const map = this.make.tilemap({ key: 'map' });
    const tileset = map.addTilesetImage('tiles', 'tiles');
    const groundLayer = map.createLayer('Ground', tileset);
    groundLayer.setCollisionByProperty({ collides: true });

    // ํ”Œ๋ ˆ์ด์–ด ์ƒ์„ฑ
    this.player = this.physics.add.sprite(100, 300, 'player');
    this.player.setBounce(0.2);
    this.player.setCollideWorldBounds(true);

    // ๋ฌผ๋ฆฌ ์ถฉ๋Œ ์„ค์ •
    this.physics.add.collider(this.player, groundLayer);

    // ์นด๋ฉ”๋ผ ์„ค์ •
    this.cameras.main.setBounds(0, 0, map.widthInPixels, map.heightInPixels);
    this.cameras.main.startFollow(this.player, true, 0.08, 0.08);

    // ์ž…๋ ฅ ์„ค์ •
    this.cursors = this.input.keyboard.createCursorKeys();

    // ์• ๋‹ˆ๋ฉ”์ด์…˜ ์ƒ์„ฑ
    this.anims.create({
      key: 'explode',
      frames: this.anims.generateFrameNumbers('explosion', { start: 0, end: 15 }),
      frameRate: 20,
      repeat: 0
    });
  }

  update() {
    const { left, right, up } = this.cursors;

    if (left.isDown) {
      this.player.setVelocityX(-160);
      this.player.setFlipX(true);
    } else if (right.isDown) {
      this.player.setVelocityX(160);
      this.player.setFlipX(false);
    } else {
      this.player.setVelocityX(0);
    }

    if (up.isDown && this.player.body.blocked.down) {
      this.player.setVelocityY(-330);
    }
  }
}
๐Ÿ’ก Phaser์˜ ๋ฌผ๋ฆฌ ์—”์ง„ ์„ ํƒ ๊ฐ€์ด๋“œ Arcade Physics: ๊ฐ€๋ณ๊ณ  ๋น ๋ฆ„. ํ”Œ๋žซํฌ๋จธ, ์ŠˆํŒ… ๊ฒŒ์ž„์— ์ ํ•ฉ.
Matter.js: ์‹ค์ œ ๋ฌผ๋ฆฌ ์‹œ๋ฎฌ๋ ˆ์ด์…˜. ํผ์ฆ, ํ•€๋ณผ ๊ฒŒ์ž„์— ์ ํ•ฉ.
Impact Physics: Phaser 3์—์„œ๋Š” ์ž˜ ์•ˆ ์”€. ๋ ˆ๊ฑฐ์‹œ.
JavaScript ๊ฒŒ์ž„ ๊ฐœ๋ฐœ ์ƒํƒœ๊ณ„ ์ง€๋„ ๐ŸŽฎ 2D ๊ฒŒ์ž„ ๊ฐœ๋ฐœ Canvas 2D API ์ˆœ์ˆ˜ JS ๋ Œ๋”๋ง Phaser.js 2D ๊ฒŒ์ž„ ํ”„๋ ˆ์ž„์›Œํฌ PixiJS ๊ณ ์„ฑ๋Šฅ 2D ๋ Œ๋”๋Ÿฌ Konva.js Canvas 2D ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ Matter.js 2D ๋ฌผ๋ฆฌ ์—”์ง„ Planck.js Box2D JS ํฌํŠธ 2D ๊ฒŒ์ž„ ํŠน์ง• โœ“ ๋‚ฎ์€ ์ง„์ž… ์žฅ๋ฒฝ โœ“ ๋น ๋ฅธ ๊ฐœ๋ฐœ ์†๋„ โœ“ ๊ฐ€๋ฒผ์šด ์„ฑ๋Šฅ โœ“ ๋ชจ๋ฐ”์ผ ์ตœ์ ํ™” โœ“ ํ”Œ๋žซํฌ๋จธ, ํผ์ฆ, RPG, ์ŠˆํŒ… ๋“ฑ ๐ŸŒ 3D ๊ฒŒ์ž„ ๊ฐœ๋ฐœ Three.js 3D ๊ทธ๋ž˜ํ”ฝ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ Babylon.js ์™„์ „ํ•œ 3D ๊ฒŒ์ž„ ์—”์ง„ WebGL ์ €์ˆ˜์ค€ 3D API WebGPU ์ฐจ์„ธ๋Œ€ ๊ทธ๋ž˜ํ”ฝ API PlayCanvas ์›น ๊ธฐ๋ฐ˜ 3D ์—”์ง„ A-Frame VR/AR ์›น ํ”„๋ ˆ์ž„์›Œํฌ 3D ๊ฒŒ์ž„ ํŠน์ง• โœ“ ๋ชฐ์ž…๊ฐ ๋†’์€ ๊ฒฝํ—˜ โœ“ ๋ณต์žกํ•œ ์‹œ๊ฐ ํšจ๊ณผ โœ“ ์‰์ด๋” ํ”„๋กœ๊ทธ๋ž˜๋ฐ โœ“ ๋ฌผ๋ฆฌ ์‹œ๋ฎฌ๋ ˆ์ด์…˜ โœ“ FPS, ๋ ˆ์ด์‹ฑ, ์–ด๋“œ๋ฒค์ฒ˜ ๋“ฑ

๐ŸŒ WebGL๊ณผ 3D ๊ฒŒ์ž„์˜ ์„ธ๊ณ„

์ด์ œ ์ง„์งœ 3D์˜ ์„ธ๊ณ„๋กœ ๋“ค์–ด๊ฐ€๋ณด์ž! ๐Ÿš€
WebGL์€ ๋ธŒ๋ผ์šฐ์ €์—์„œ GPU๋ฅผ ์ง์ ‘ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋Š” ์ €์ˆ˜์ค€ API์•ผ. OpenGL ES 2.0 ๊ธฐ๋ฐ˜์ด๊ณ , ์‰์ด๋” ํ”„๋กœ๊ทธ๋ž˜๋ฐ์ด ํ•„์š”ํ•ด์„œ ์ง„์ž… ์žฅ๋ฒฝ์ด ๋†’์•„.
๊ทธ๋ž˜์„œ ๋Œ€๋ถ€๋ถ„์€ Three.js๋‚˜ Babylon.js ๊ฐ™์€ ์ถ”์ƒํ™” ๋ ˆ์ด์–ด๋ฅผ ์‚ฌ์šฉํ•ด.

WebGL ๊ธฐ๋ณธ ์›๋ฆฌ ์ดํ•ดํ•˜๊ธฐ

Three.js๋ฅผ ์“ฐ๋”๋ผ๋„ WebGL์˜ ๊ธฐ๋ณธ ๊ฐœ๋…์€ ์•Œ์•„์•ผ ํ•ด. ์™œ๋ƒ๋ฉด ์„ฑ๋Šฅ ์ตœ์ ํ™”๋‚˜ ์ปค์Šคํ…€ ์‰์ด๋”๋ฅผ ์“ธ ๋•Œ ๋ฐ˜๋“œ์‹œ ํ•„์š”ํ•˜๊ฑฐ๋“ .

๊ฐœ๋… ์„ค๋ช… ๋น„์œ 
Vertex Shader 3D ์ขŒํ‘œ๋ฅผ 2D ํ™”๋ฉด ์ขŒํ‘œ๋กœ ๋ณ€ํ™˜ ์นด๋ฉ”๋ผ ์œ„์น˜ ๊ณ„์‚ฐ
Fragment Shader ๊ฐ ํ”ฝ์…€์˜ ์ƒ‰์ƒ ๊ฒฐ์ • ํŽ˜์ธํŠธ์น 
Buffer GPU์— ์ „๋‹ฌํ•˜๋Š” ๋ฐ์ดํ„ฐ (์ •์ , UV ๋“ฑ) ์žฌ๋ฃŒ ์ฐฝ๊ณ 
Texture 3D ์˜ค๋ธŒ์ ํŠธ์— ์ž…ํžˆ๋Š” ์ด๋ฏธ์ง€ ๋ฒฝ์ง€/์Šคํ‹ฐ์ปค
MVP Matrix Model-View-Projection ๋ณ€ํ™˜ ํ–‰๋ ฌ ์นด๋ฉ”๋ผ ๋ Œ์ฆˆ ์„ค์ •
Framebuffer ๋ Œ๋”๋ง ๊ฒฐ๊ณผ๋ฅผ ์ €์žฅํ•˜๋Š” ๋ฒ„ํผ ์‚ฌ์ง„ ํ˜„์ƒ์ง€

๐Ÿ”บ Three.js๋กœ 3D ๊ฒŒ์ž„ ๋งŒ๋“ค๊ธฐ

Three.js๋Š” WebGL์„ ์ถ”์ƒํ™”ํ•ด์„œ ํ›จ์”ฌ ์‰ฝ๊ฒŒ 3D ๊ทธ๋ž˜ํ”ฝ์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค˜.
Scene, Camera, Renderer ์„ธ ๊ฐ€์ง€๊ฐ€ ํ•ต์‹ฌ์ด์•ผ.

import * as THREE from 'three';

// 1. ์”ฌ ์ƒ์„ฑ
const scene = new THREE.Scene();
scene.background = new THREE.Color('#1a1a2e');
scene.fog = new THREE.Fog('#1a1a2e', 10, 100); // ์•ˆ๊ฐœ ํšจ๊ณผ

// 2. ์นด๋ฉ”๋ผ ์„ค์ •
const camera = new THREE.PerspectiveCamera(
  75,                                    // FOV (์‹œ์•ผ๊ฐ)
  window.innerWidth / window.innerHeight, // ์ข…ํšก๋น„
  0.1,                                   // near clipping plane
  1000                                   // far clipping plane
);
camera.position.set(0, 5, 10);
camera.lookAt(0, 0, 0);

// 3. ๋ Œ๋”๋Ÿฌ ์„ค์ •
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(window.devicePixelRatio);
renderer.shadowMap.enabled = true; // ๊ทธ๋ฆผ์ž ํ™œ์„ฑํ™”
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.appendChild(renderer.domElement);

// 4. ์กฐ๋ช… ์„ค์ •
const ambientLight = new THREE.AmbientLight(0xffffff, 0.4);
scene.add(ambientLight);

const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
directionalLight.position.set(10, 20, 10);
directionalLight.castShadow = true;
directionalLight.shadow.mapSize.width = 2048;
directionalLight.shadow.mapSize.height = 2048;
scene.add(directionalLight);

// 5. ์ง€ํ˜• ์ƒ์„ฑ
const groundGeometry = new THREE.PlaneGeometry(50, 50);
const groundMaterial = new THREE.MeshLambertMaterial({ color: 0x3a5a3a });
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);

// 6. ํ”Œ๋ ˆ์ด์–ด (์บก์А ํ˜•ํƒœ)
const playerGeometry = new THREE.CapsuleGeometry(0.5, 1, 4, 8);
const playerMaterial = new THREE.MeshPhongMaterial({ color: 0x5b9bd5 });
const player = new THREE.Mesh(playerGeometry, playerMaterial);
player.position.set(0, 1.5, 0);
player.castShadow = true;
scene.add(player);

// 7. ๊ฒŒ์ž„ ๋ฃจํ”„
const clock = new THREE.Clock();

function animate() {
  requestAnimationFrame(animate);

  const delta = clock.getDelta();

  // ํ”Œ๋ ˆ์ด์–ด ์ด๋™
  if (keys['KeyW']) player.position.z -= 5 * delta;
  if (keys['KeyS']) player.position.z += 5 * delta;
  if (keys['KeyA']) player.position.x -= 5 * delta;
  if (keys['KeyD']) player.position.x += 5 * delta;

  // ์นด๋ฉ”๋ผ๊ฐ€ ํ”Œ๋ ˆ์ด์–ด ๋”ฐ๋ผ๊ฐ€๊ธฐ
  camera.position.x = player.position.x;
  camera.position.z = player.position.z + 10;
  camera.lookAt(player.position);

  renderer.render(scene, camera);
}

animate();

๐ŸŽจ ์ปค์Šคํ…€ ์‰์ด๋” (GLSL)

Three.js์—์„œ ์ปค์Šคํ…€ ์‰์ด๋”๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋…ํŠนํ•œ ์‹œ๊ฐ ํšจ๊ณผ๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์–ด.
GLSL(OpenGL Shading Language)๋กœ ์ž‘์„ฑํ•˜๋Š”๋ฐ, ์ด๊ฒŒ ์ง„์งœ ๊ฒŒ์ž„ ๊ทธ๋ž˜ํ”ฝ์˜ ๊ฝƒ์ด์•ผ! ๐ŸŒธ

// ์ปค์Šคํ…€ ์‰์ด๋” ๋จธํ‹ฐ๋ฆฌ์–ผ ์˜ˆ์‹œ (๋ฌผ๊ฒฐ ํšจ๊ณผ)
const waterMaterial = new THREE.ShaderMaterial({
  uniforms: {
    time: { value: 0 },
    color: { value: new THREE.Color(0x5b9bd5) }
  },
  vertexShader: `
    uniform float time;
    varying vec2 vUv;

    void main() {
      vUv = uv;
      vec3 pos = position;
      // ๋ฌผ๊ฒฐ ํšจ๊ณผ
      pos.y += sin(pos.x * 2.0 + time * 2.0) * 0.3;
      pos.y += cos(pos.z * 2.0 + time * 1.5) * 0.2;
      gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);
    }
  `,
  fragmentShader: `
    uniform vec3 color;
    uniform float time;
    varying vec2 vUv;

    void main() {
      // ๊นŠ์ด์— ๋”ฐ๋ฅธ ์ƒ‰์ƒ ๋ณ€ํ™”
      float depth = vUv.y;
      vec3 deepColor = vec3(0.1, 0.2, 0.5);
      vec3 shallowColor = color;
      vec3 finalColor = mix(deepColor, shallowColor, depth);

      // ๋ฐ˜์ง์ž„ ํšจ๊ณผ
      float sparkle = sin(vUv.x * 20.0 + time * 3.0) * 0.1 + 0.9;
      gl_FragColor = vec4(finalColor * sparkle, 0.8);
    }
  `,
  transparent: true
});

// ์• ๋‹ˆ๋ฉ”์ด์…˜์—์„œ time ์—…๋ฐ์ดํŠธ
function animate() {
  waterMaterial.uniforms.time.value += 0.016;
  renderer.render(scene, camera);
  requestAnimationFrame(animate);
}

โšก Babylon.js - ์™„์ „ํ•œ 3D ๊ฒŒ์ž„ ์—”์ง„

Three.js๊ฐ€ ๊ทธ๋ž˜ํ”ฝ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ผ๋ฉด, Babylon.js๋Š” ์ง„์งœ ๊ฒŒ์ž„ ์—”์ง„์ด์•ผ.
Microsoft๊ฐ€ ์ง€์›ํ•˜๊ณ , ๋ฌผ๋ฆฌ ์—”์ง„, ํŒŒํ‹ฐํด ์‹œ์Šคํ…œ, ์• ๋‹ˆ๋ฉ”์ด์…˜, GUI, ์˜ค๋””์˜ค ๋“ฑ ๊ฒŒ์ž„์— ํ•„์š”ํ•œ ๋ชจ๋“  ๊ฒƒ์ด ๋‚ด์žฅ๋˜์–ด ์žˆ์–ด.

๐Ÿ”ง Babylon.js ํ•ต์‹ฌ ๊ธฐ๋Šฅ
  • 1 ๋ฌผ๋ฆฌ ์—”์ง„: Havok, Cannon.js, Ammo.js ์ง€์›
  • 2 PBR ๋จธํ‹ฐ๋ฆฌ์–ผ: ๋ฌผ๋ฆฌ ๊ธฐ๋ฐ˜ ๋ Œ๋”๋ง
  • 3 ํŒŒํ‹ฐํด ์‹œ์Šคํ…œ: GPU ํŒŒํ‹ฐํด ์ง€์›
  • 4 ์• ๋‹ˆ๋ฉ”์ด์…˜: ์Šค์ผˆ๋ ˆํƒˆ ์• ๋‹ˆ๋ฉ”์ด์…˜
  • 5 XR ์ง€์›: WebXR (VR/AR)
  • 6 GUI: ๋‚ด์žฅ UI ์‹œ์Šคํ…œ
๐Ÿ“Š Three.js vs Babylon.js Three.js
- ๋” ๊ฐ€๋ฒผ์›€, ์œ ์—ฐ์„ฑ ๋†’์Œ
- ๊ทธ๋ž˜ํ”ฝ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ฑ๊ฒฉ
- ์ปค๋ฎค๋‹ˆํ‹ฐ ๋” ํผ
- ๊ฒŒ์ž„ ๊ธฐ๋Šฅ์€ ์ง์ ‘ ๊ตฌํ˜„

Babylon.js
- ์™„์ „ํ•œ ๊ฒŒ์ž„ ์—”์ง„
- ๋ฌผ๋ฆฌ, GUI ๋“ฑ ๋‚ด์žฅ
- TypeScript ๋„ค์ดํ‹ฐ๋ธŒ
- ๋” ๋ฌด๊ฑฐ์›€
// Babylon.js ๊ธฐ๋ณธ ์„ค์ •
const canvas = document.getElementById('renderCanvas');
const engine = new BABYLON.Engine(canvas, true);

const createScene = () => {
  const scene = new BABYLON.Scene(engine);

  // ์นด๋ฉ”๋ผ (ArcRotateCamera: ์˜ค๋ธŒ์ ํŠธ ์ค‘์‹ฌ ํšŒ์ „)
  const camera = new BABYLON.ArcRotateCamera(
    'camera', -Math.PI / 2, Math.PI / 4, 10,
    BABYLON.Vector3.Zero(), scene
  );
  camera.attachControl(canvas, true);

  // ์กฐ๋ช…
  const light = new BABYLON.HemisphericLight(
    'light', new BABYLON.Vector3(0, 1, 0), scene
  );
  light.intensity = 0.7;

  const dirLight = new BABYLON.DirectionalLight(
    'dirLight', new BABYLON.Vector3(-1, -2, -1), scene
  );
  dirLight.position = new BABYLON.Vector3(20, 40, 20);

  // ๊ทธ๋ฆผ์ž ์ƒ์„ฑ๊ธฐ
  const shadowGenerator = new BABYLON.ShadowGenerator(1024, dirLight);
  shadowGenerator.useBlurExponentialShadowMap = true;

  // ์ง€ํ˜•
  const ground = BABYLON.MeshBuilder.CreateGround(
    'ground', { width: 20, height: 20 }, scene
  );
  const groundMat = new BABYLON.StandardMaterial('groundMat', scene);
  groundMat.diffuseColor = new BABYLON.Color3(0.3, 0.5, 0.3);
  ground.material = groundMat;
  ground.receiveShadows = true;

  // ํ”Œ๋ ˆ์ด์–ด (์บก์А)
  const player = BABYLON.MeshBuilder.CreateCapsule(
    'player', { height: 2, radius: 0.5 }, scene
  );
  player.position.y = 1;
  const playerMat = new BABYLON.StandardMaterial('playerMat', scene);
  playerMat.diffuseColor = new BABYLON.Color3(0.36, 0.61, 0.84);
  player.material = playerMat;
  shadowGenerator.addShadowCaster(player);

  // ๋ฌผ๋ฆฌ ์—”์ง„ ํ™œ์„ฑํ™”
  scene.enablePhysics(
    new BABYLON.Vector3(0, -9.81, 0),
    new BABYLON.CannonJSPlugin()
  );
  player.physicsImpostor = new BABYLON.PhysicsImpostor(
    player, BABYLON.PhysicsImpostor.CapsuleImpostor,
    { mass: 1, restitution: 0.1 }, scene
  );
  ground.physicsImpostor = new BABYLON.PhysicsImpostor(
    ground, BABYLON.PhysicsImpostor.BoxImpostor,
    { mass: 0, restitution: 0.1 }, scene
  );

  // ํŒŒํ‹ฐํด ์‹œ์Šคํ…œ (ํญ๋ฐœ ํšจ๊ณผ)
  const particleSystem = new BABYLON.ParticleSystem('particles', 2000, scene);
  particleSystem.particleTexture = new BABYLON.Texture('flare.png', scene);
  particleSystem.emitter = player;
  particleSystem.minEmitBox = new BABYLON.Vector3(-0.5, 0, -0.5);
  particleSystem.maxEmitBox = new BABYLON.Vector3(0.5, 0, 0.5);
  particleSystem.color1 = new BABYLON.Color4(1, 0.5, 0, 1);
  particleSystem.color2 = new BABYLON.Color4(1, 0.2, 0, 1);
  particleSystem.minLifeTime = 0.3;
  particleSystem.maxLifeTime = 1.5;
  particleSystem.emitRate = 100;

  return scene;
};

const scene = createScene();

// ๋ Œ๋” ๋ฃจํ”„
engine.runRenderLoop(() => {
  scene.render();
});

// ๋ฆฌ์‚ฌ์ด์ฆˆ ๋Œ€์‘
window.addEventListener('resize', () => {
  engine.resize();
});

๐Ÿš€ ๊ฒŒ์ž„ ์„ฑ๋Šฅ ์ตœ์ ํ™” ์ „๋žต

๊ฒŒ์ž„์„ ๋งŒ๋“ค์—ˆ๋Š”๋ฐ ํ”„๋ ˆ์ž„์ด ๋š๋š ๋–จ์–ด์ง€๋ฉด ์•„๋ฌด๋„ ์•ˆ ํ•ด. ๐Ÿ˜…
JavaScript ๊ฒŒ์ž„ ์„ฑ๋Šฅ ์ตœ์ ํ™”๋Š” ํฌ๊ฒŒ ๋ Œ๋”๋ง ์ตœ์ ํ™”์™€ ๋กœ์ง ์ตœ์ ํ™”๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ์–ด.

๐ŸŽจ ๋ Œ๋”๋ง ์ตœ์ ํ™”

๐Ÿ“Œ Canvas 2D ์ตœ์ ํ™” ํ•ต์‹ฌ ํŒ
  • 1 ์˜คํ”„์Šคํฌ๋ฆฐ ์บ”๋ฒ„์Šค ์‚ฌ์šฉ: ๋ณต์žกํ•œ ๋ฐฐ๊ฒฝ์€ ๋ณ„๋„ ์บ”๋ฒ„์Šค์— ๋ฏธ๋ฆฌ ๊ทธ๋ ค๋‘๊ณ  ๋ณต์‚ฌ
  • 2 clearRect ์ตœ์†Œํ™”: ๋ณ€๊ฒฝ๋œ ์˜์—ญ๋งŒ ์ง€์šฐ๊ธฐ (dirty rectangle)
  • 3 ctx.save/restore ์ตœ์†Œํ™”: ์ƒํƒœ ๋ณ€๊ฒฝ ๋น„์šฉ์ด ํผ
  • 4 ์ด๋ฏธ์ง€ ์บ์‹ฑ: ์ž์ฃผ ์“ฐ๋Š” ์ด๋ฏธ์ง€๋Š” ๋ฏธ๋ฆฌ ๋กœ๋“œํ•ด์„œ ์บ์‹œ
  • 5 ๋ฐฐ์น˜ ๋ Œ๋”๋ง: ๊ฐ™์€ ํ…์Šค์ฒ˜์˜ ์˜ค๋ธŒ์ ํŠธ๋Š” ํ•œ ๋ฒˆ์— ๊ทธ๋ฆฌ๊ธฐ
// ์˜คํ”„์Šคํฌ๋ฆฐ ์บ”๋ฒ„์Šค ํ™œ์šฉ
const offscreenCanvas = document.createElement('canvas');
offscreenCanvas.width = 800;
offscreenCanvas.height = 600;
const offCtx = offscreenCanvas.getContext('2d');

// ๋ฐฐ๊ฒฝ์„ ์˜คํ”„์Šคํฌ๋ฆฐ์— ํ•œ ๋ฒˆ๋งŒ ๊ทธ๋ฆฌ๊ธฐ
function drawBackground() {
  offCtx.fillStyle = '#1a1a2e';
  offCtx.fillRect(0, 0, 800, 600);
  // ๋ณต์žกํ•œ ๋ฐฐ๊ฒฝ ์š”์†Œ๋“ค...
  for (let i = 0; i < 200; i++) {
    offCtx.fillStyle = `rgba(255,255,255,${Math.random() * 0.5})`;
    offCtx.fillRect(Math.random() * 800, Math.random() * 600, 2, 2);
  }
}
drawBackground(); // ํ•œ ๋ฒˆ๋งŒ ์‹คํ–‰

// ๋ฉ”์ธ ๋ Œ๋”๋ง์—์„œ๋Š” ๋ณต์‚ฌ๋งŒ
function render() {
  ctx.drawImage(offscreenCanvas, 0, 0); // ๋น ๋ฆ„!
  // ๋™์  ์š”์†Œ๋“ค๋งŒ ๊ทธ๋ฆฌ๊ธฐ
  drawPlayer();
  drawEnemies();
}

// Three.js ์ตœ์ ํ™”
// 1. ์ธ์Šคํ„ด์Šค ๋ฉ”์‹œ (๊ฐ™์€ ์˜ค๋ธŒ์ ํŠธ ์—ฌ๋Ÿฌ ๊ฐœ)
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshLambertMaterial({ color: 0x5b9bd5 });
const instancedMesh = new THREE.InstancedMesh(geometry, material, 1000);

const matrix = new THREE.Matrix4();
for (let i = 0; i < 1000; i++) {
  matrix.setPosition(
    Math.random() * 100 - 50,
    Math.random() * 10,
    Math.random() * 100 - 50
  );
  instancedMesh.setMatrixAt(i, matrix);
}
scene.add(instancedMesh);

// 2. LOD (Level of Detail)
const lod = new THREE.LOD();
lod.addLevel(highDetailMesh, 0);   // ๊ฐ€๊นŒ์šธ ๋•Œ
lod.addLevel(medDetailMesh, 50);   // ์ค‘๊ฐ„ ๊ฑฐ๋ฆฌ
lod.addLevel(lowDetailMesh, 200);  // ๋ฉ€ ๋•Œ
scene.add(lod);

โš™๏ธ ๋กœ์ง ์ตœ์ ํ™”

// ๊ณต๊ฐ„ ๋ถ„ํ•  (Spatial Partitioning) - ์ถฉ๋Œ ๊ฐ์ง€ ์ตœ์ ํ™”
class QuadTree {
  constructor(bounds, maxObjects = 10, maxLevels = 5, level = 0) {
    this.bounds = bounds;
    this.maxObjects = maxObjects;
    this.maxLevels = maxLevels;
    this.level = level;
    this.objects = [];
    this.nodes = [];
  }

  insert(obj) {
    if (this.nodes.length) {
      const index = this.getIndex(obj);
      if (index !== -1) {
        this.nodes[index].insert(obj);
        return;
      }
    }
    this.objects.push(obj);
    if (this.objects.length > this.maxObjects && this.level < this.maxLevels) {
      if (!this.nodes.length) this.split();
      // ๊ธฐ์กด ์˜ค๋ธŒ์ ํŠธ๋“ค ์žฌ๋ฐฐ์น˜
      this.objects = this.objects.filter(o => {
        const index = this.getIndex(o);
        if (index !== -1) { this.nodes[index].insert(o); return false; }
        return true;
      });
    }
  }

  retrieve(obj) {
    const index = this.getIndex(obj);
    let returnObjects = [...this.objects];
    if (this.nodes.length) {
      if (index !== -1) {
        returnObjects = returnObjects.concat(this.nodes[index].retrieve(obj));
      } else {
        this.nodes.forEach(node => {
          returnObjects = returnObjects.concat(node.retrieve(obj));
        });
      }
    }
    return returnObjects;
  }
}

// ์˜ค๋ธŒ์ ํŠธ ํ’€๋ง (Object Pooling) - GC ์ตœ์ ํ™”
class ObjectPool {
  constructor(createFn, resetFn, initialSize = 50) {
    this.createFn = createFn;
    this.resetFn = resetFn;
    this.pool = Array.from({ length: initialSize }, createFn);
  }

  get() {
    return this.pool.length > 0 ? this.pool.pop() : this.createFn();
  }

  release(obj) {
    this.resetFn(obj);
    this.pool.push(obj);
  }
}

// ์ด์•Œ ํ’€ ์˜ˆ์‹œ
const bulletPool = new ObjectPool(
  () => ({ x: 0, y: 0, vx: 0, vy: 0, active: false }),
  (bullet) => { bullet.active = false; }
);

// ์ด์•Œ ๋ฐœ์‚ฌ
function fireBullet(x, y, angle) {
  const bullet = bulletPool.get();
  bullet.x = x;
  bullet.y = y;
  bullet.vx = Math.cos(angle) * 500;
  bullet.vy = Math.sin(angle) * 500;
  bullet.active = true;
  activeBullets.push(bullet);
}

// ์ด์•Œ ์ œ๊ฑฐ (ํ’€๋กœ ๋ฐ˜ํ™˜)
function removeBullet(bullet) {
  bulletPool.release(bullet);
  activeBullets.splice(activeBullets.indexOf(bullet), 1);
}

๐ŸŽต ์˜ค๋””์˜ค, ์ €์žฅ, ๋„คํŠธ์›Œํฌ - ๊ฒŒ์ž„ ์™„์„ฑ๋„ ๋†’์ด๊ธฐ

๐Ÿ”Š Web Audio API๋กœ ๊ฒŒ์ž„ ์‚ฌ์šด๋“œ

// Web Audio API ๊ธฐ๋ฐ˜ ์‚ฌ์šด๋“œ ๋งค๋‹ˆ์ €
class AudioManager {
  constructor() {
    this.context = new AudioContext();
    this.masterGain = this.context.createGain();
    this.masterGain.connect(this.context.destination);
    this.sounds = {};
    this.bgmSource = null;
  }

  async loadSound(name, url) {
    const response = await fetch(url);
    const arrayBuffer = await response.arrayBuffer();
    this.sounds[name] = await this.context.decodeAudioData(arrayBuffer);
  }

  play(name, options = {}) {
    const { volume = 1, loop = false, pitch = 1 } = options;
    const source = this.context.createBufferSource();
    source.buffer = this.sounds[name];
    source.loop = loop;
    source.playbackRate.value = pitch;

    const gainNode = this.context.createGain();
    gainNode.gain.value = volume;

    source.connect(gainNode);
    gainNode.connect(this.masterGain);
    source.start(0);
    return source;
  }

  // 3D ๊ณต๊ฐ„ ์˜ค๋””์˜ค
  play3D(name, position, listenerPosition) {
    const source = this.context.createBufferSource();
    source.buffer = this.sounds[name];

    const panner = this.context.createPanner();
    panner.panningModel = 'HRTF';
    panner.distanceModel = 'inverse';
    panner.setPosition(position.x, position.y, position.z);

    source.connect(panner);
    panner.connect(this.masterGain);
    source.start(0);
  }

  setMasterVolume(value) {
    this.masterGain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  }
}

// ์‚ฌ์šฉ ์˜ˆ์‹œ
const audio = new AudioManager();
await audio.loadSound('jump', 'sounds/jump.mp3');
await audio.loadSound('bgm', 'sounds/bgm.mp3');

audio.play('bgm', { loop: true, volume: 0.5 });
// ์ ํ”„ ์‹œ
audio.play('jump', { pitch: 1 + Math.random() * 0.2 }); // ์•ฝ๊ฐ„์˜ ํ”ผ์น˜ ๋ณ€ํ™”

๐Ÿ’พ ๊ฒŒ์ž„ ์ €์žฅ ์‹œ์Šคํ…œ

// ๊ฒŒ์ž„ ์ €์žฅ/๋ถˆ๋Ÿฌ์˜ค๊ธฐ ์‹œ์Šคํ…œ
class SaveSystem {
  constructor(gameId) {
    this.gameId = gameId;
    this.dbName = `${gameId}_saves`;
  }

  // LocalStorage ๊ธฐ๋ฐ˜ (๊ฐ„๋‹จํ•œ ๋ฐ์ดํ„ฐ)
  saveLocal(slot, data) {
    const saveData = {
      ...data,
      timestamp: Date.now(),
      version: '1.0.0'
    };
    localStorage.setItem(`${this.gameId}_slot${slot}`, JSON.stringify(saveData));
  }

  loadLocal(slot) {
    const raw = localStorage.getItem(`${this.gameId}_slot${slot}`);
    return raw ? JSON.parse(raw) : null;
  }

  // IndexedDB ๊ธฐ๋ฐ˜ (๋Œ€์šฉ๋Ÿ‰ ๋ฐ์ดํ„ฐ)
  async saveDB(slot, data) {
    return new Promise((resolve, reject) => {
      const request = indexedDB.open(this.dbName, 1);
      request.onupgradeneeded = (e) => {
        e.target.result.createObjectStore('saves', { keyPath: 'slot' });
      };
      request.onsuccess = (e) => {
        const db = e.target.result;
        const tx = db.transaction('saves', 'readwrite');
        tx.objectStore('saves').put({ slot, data, timestamp: Date.now() });
        tx.oncomplete = resolve;
        tx.onerror = reject;
      };
    });
  }

  // ์ž๋™ ์ €์žฅ
  startAutoSave(getDataFn, interval = 60000) {
    this.autoSaveTimer = setInterval(() => {
      this.saveLocal('auto', getDataFn());
      console.log('์ž๋™ ์ €์žฅ ์™„๋ฃŒ!');
    }, interval);
  }
}

๐ŸŒ ๋ฉ€ํ‹ฐํ”Œ๋ ˆ์ด์–ด - WebSocket

// WebSocket ๊ธฐ๋ฐ˜ ๋ฉ€ํ‹ฐํ”Œ๋ ˆ์ด์–ด
class NetworkManager {
  constructor(serverUrl) {
    this.ws = new WebSocket(serverUrl);
    this.playerId = null;
    this.players = {};
    this.handlers = {};

    this.ws.onopen = () => console.log('์„œ๋ฒ„ ์—ฐ๊ฒฐ๋จ!');
    this.ws.onmessage = (e) => this.handleMessage(JSON.parse(e.data));
    this.ws.onclose = () => this.handleDisconnect();
  }

  handleMessage(msg) {
    switch (msg.type) {
      case 'INIT':
        this.playerId = msg.playerId;
        this.players = msg.players;
        break;
      case 'PLAYER_MOVE':
        if (this.players[msg.playerId]) {
          // ๋ณด๊ฐ„(Interpolation)์œผ๋กœ ๋ถ€๋“œ๋Ÿฝ๊ฒŒ ์ด๋™
          this.players[msg.playerId].targetX = msg.x;
          this.players[msg.playerId].targetY = msg.y;
        }
        break;
      case 'PLAYER_JOIN':
        this.players[msg.playerId] = msg.playerData;
        break;
      case 'PLAYER_LEAVE':
        delete this.players[msg.playerId];
        break;
    }
    if (this.handlers[msg.type]) this.handlers[msg.type](msg);
  }

  sendMove(x, y) {
    this.send({ type: 'MOVE', x, y });
  }

  send(data) {
    if (this.ws.readyState === WebSocket.OPEN) {
      this.ws.send(JSON.stringify(data));
    }
  }

  // ํด๋ผ์ด์–ธํŠธ ์‚ฌ์ด๋“œ ์˜ˆ์ธก (Client-Side Prediction)
  predictMove(player, input, dt) {
    const predictedX = player.x + input.vx * dt;
    const predictedY = player.y + input.vy * dt;
    // ์„œ๋ฒ„ ์‘๋‹ต ์ „์— ๋ฏธ๋ฆฌ ์ด๋™ ํ‘œ์‹œ
    player.x = predictedX;
    player.y = predictedY;
    this.sendMove(predictedX, predictedY);
  }
}

๐Ÿ“ฑ ๋ชจ๋ฐ”์ผ ๊ฒŒ์ž„ ์ตœ์ ํ™”์™€ ๋ฐฐํฌ

JavaScript ๊ฒŒ์ž„์˜ ํฐ ์žฅ์  ์ค‘ ํ•˜๋‚˜๋Š” ๋ชจ๋ฐ”์ผ์—์„œ๋„ ๋Œ์•„๊ฐ„๋‹ค๋Š” ๊ฑฐ์•ผ.
ํ•˜์ง€๋งŒ ๋ชจ๋ฐ”์ผ ํŠน์„ฑ์— ๋งž๊ฒŒ ์ตœ์ ํ™”๊ฐ€ ํ•„์š”ํ•ด.

๐Ÿ“ฒ ๋ชจ๋ฐ”์ผ ํ„ฐ์น˜ ์ปจํŠธ๋กค

// ๊ฐ€์ƒ ์กฐ์ด์Šคํ‹ฑ ๊ตฌํ˜„
class VirtualJoystick {
  constructor(canvas) {
    this.canvas = canvas;
    this.active = false;
    this.startX = 0;
    this.startY = 0;
    this.currentX = 0;
    this.currentY = 0;
    this.radius = 60;
    this.knobRadius = 25;

    canvas.addEventListener('touchstart', this.onTouchStart.bind(this));
    canvas.addEventListener('touchmove', this.onTouchMove.bind(this));
    canvas.addEventListener('touchend', this.onTouchEnd.bind(this));
  }

  onTouchStart(e) {
    e.preventDefault();
    const touch = e.touches[0];
    const rect = this.canvas.getBoundingClientRect();
    this.startX = touch.clientX - rect.left;
    this.startY = touch.clientY - rect.top;
    this.currentX = this.startX;
    this.currentY = this.startY;
    this.active = true;
  }

  onTouchMove(e) {
    e.preventDefault();
    if (!this.active) return;
    const touch = e.touches[0];
    const rect = this.canvas.getBoundingClientRect();
    const x = touch.clientX - rect.left;
    const y = touch.clientY - rect.top;

    const dx = x - this.startX;
    const dy = y - this.startY;
    const dist = Math.sqrt(dx * dx + dy * dy);

    if (dist > this.radius) {
      this.currentX = this.startX + (dx / dist) * this.radius;
      this.currentY = this.startY + (dy / dist) * this.radius;
    } else {
      this.currentX = x;
      this.currentY = y;
    }
  }

  onTouchEnd() { this.active = false; }

  getInput() {
    if (!this.active) return { x: 0, y: 0 };
    return {
      x: (this.currentX - this.startX) / this.radius,
      y: (this.currentY - this.startY) / this.radius
    };
  }

  render(ctx) {
    if (!this.active) return;
    // ๋ฒ ์ด์Šค ์›
    ctx.beginPath();
    ctx.arc(this.startX, this.startY, this.radius, 0, Math.PI * 2);
    ctx.fillStyle = 'rgba(255,255,255,0.2)';
    ctx.fill();
    ctx.strokeStyle = 'rgba(255,255,255,0.5)';
    ctx.lineWidth = 2;
    ctx.stroke();
    // ์กฐ์ด์Šคํ‹ฑ ๋…ธ๋ธŒ
    ctx.beginPath();
    ctx.arc(this.currentX, this.currentY, this.knobRadius, 0, Math.PI * 2);
    ctx.fillStyle = 'rgba(255,255,255,0.6)';
    ctx.fill();
  }
}

๐Ÿš€ ๋ฐฐํฌ ๋ฐฉ๋ฒ• ๋น„๊ต

ํ”Œ๋žซํผ ํŠน์ง• ๋น„์šฉ ์ถ”์ฒœ ์šฉ๋„
GitHub Pages ์ •์  ํŒŒ์ผ ํ˜ธ์ŠคํŒ…, CI/CD ์—ฐ๋™ ๋ฌด๋ฃŒ ๊ฐœ์ธ ํ”„๋กœ์ ํŠธ, ํฌํŠธํด๋ฆฌ์˜ค
Netlify ์ž๋™ ๋ฐฐํฌ, CDN, ํผ ์ฒ˜๋ฆฌ ๋ฌด๋ฃŒ (๊ธฐ๋ณธ) ์†Œ๊ทœ๋ชจ ~ ์ค‘๊ทœ๋ชจ ๊ฒŒ์ž„
itch.io ๊ฒŒ์ž„ ์ „์šฉ ํ”Œ๋žซํผ, ์ปค๋ฎค๋‹ˆํ‹ฐ ๋ฌด๋ฃŒ (์ˆ˜์ต ๊ณต์œ ) ์ธ๋”” ๊ฒŒ์ž„ ์ถœ์‹œ
Vercel ์—ฃ์ง€ ๋„คํŠธ์›Œํฌ, ์„œ๋ฒ„๋ฆฌ์Šค ๋ฌด๋ฃŒ (๊ธฐ๋ณธ) ๋ฉ€ํ‹ฐํ”Œ๋ ˆ์ด์–ด ๊ฒŒ์ž„
Electron ๋ฐ์Šคํฌํƒ‘ ์•ฑ์œผ๋กœ ํŒจํ‚ค์ง• ๋ฌด๋ฃŒ Steam ์ถœ์‹œ ๋ชฉํ‘œ
Capacitor ๋ชจ๋ฐ”์ผ ์•ฑ์œผ๋กœ ํŒจํ‚ค์ง• ๋ฌด๋ฃŒ ์•ฑ์Šคํ† ์–ด ์ถœ์‹œ
๐Ÿ’ก ์žฌ๋Šฅ๋„ท ํ™œ์šฉ ํŒ! JavaScript ๊ฒŒ์ž„ ๊ฐœ๋ฐœ ์‹ค๋ ฅ์„ ์Œ“์•˜๋‹ค๋ฉด ์žฌ๋Šฅ๋„ท์—์„œ ๊ฒŒ์ž„ ๊ฐœ๋ฐœ ์žฌ๋Šฅ์„ ๊ณต์œ ํ•ด๋ด! ๊ฐ„๋‹จํ•œ ๋ฏธ๋‹ˆ๊ฒŒ์ž„ ์ œ์ž‘, ๊ฒŒ์ž„ UI ๊ฐœ๋ฐœ, ๊ฒŒ์ž„ ๋กœ์ง ๊ตฌํ˜„ ๋“ฑ ๋‹ค์–‘ํ•œ ๋ฐฉ์‹์œผ๋กœ ์žฌ๋Šฅ์„ ๊ฑฐ๋ž˜ํ•  ์ˆ˜ ์žˆ์–ด. ์‹ค๋ ฅ์„ ์Œ“์œผ๋ฉด์„œ ์ˆ˜์ต๋„ ๋‚ผ ์ˆ˜ ์žˆ๋Š” ์ข‹์€ ๋ฐฉ๋ฒ•์ด์•ผ. ๐ŸŽฏ

๐Ÿ—บ๏ธ ํ•™์Šต ๋กœ๋“œ๋งต - ์–ด๋””์„œ๋ถ€ํ„ฐ ์‹œ์ž‘ํ• ๊นŒ?

JavaScript ๊ฒŒ์ž„ ๊ฐœ๋ฐœ์„ ์ฒ˜์Œ ์‹œ์ž‘ํ•˜๋Š” ์‚ฌ๋žŒ๋“ค์„ ์œ„ํ•œ ๋‹จ๊ณ„๋ณ„ ๋กœ๋“œ๋งต์ด์•ผ.
์ด ์ˆœ์„œ๋Œ€๋กœ ๋”ฐ๋ผ๊ฐ€๋ฉด 6๊ฐœ์›” ์•ˆ์— ๊ฝค ๊ทธ๋Ÿด๋“ฏํ•œ ๊ฒŒ์ž„์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์–ด! ๐Ÿ’ช

JavaScript ๊ฒŒ์ž„ ๊ฐœ๋ฐœ ํ•™์Šต ๋กœ๋“œ๋งต 1๋‹จ๊ณ„ (1-2๊ฐœ์›”) JS ๊ธฐ์ดˆ ์™„์„ฑ ES6+, DOM, ์ด๋ฒคํŠธ Canvas API ๊ธฐ์ดˆ ๊ฐ„๋‹จํ•œ ์• ๋‹ˆ๋ฉ”์ด์…˜ 2๋‹จ๊ณ„ (2-3๊ฐœ์›”) 2D ๊ฒŒ์ž„ ๊ธฐ์ดˆ ๊ฒŒ์ž„ ๋ฃจํ”„ ๊ตฌํ˜„ ์ถฉ๋Œ ๊ฐ์ง€ ์Šคํ”„๋ผ์ดํŠธ ์• ๋‹ˆ๋ฉ”์ด์…˜ 3๋‹จ๊ณ„ (3-4๊ฐœ์›”) Phaser.js ๋งˆ์Šคํ„ฐ ํƒ€์ผ๋งต, ๋ฌผ๋ฆฌ ์—”์ง„ ์”ฌ ๊ด€๋ฆฌ, ์˜ค๋””์˜ค ์™„์„ฑ ๊ฒŒ์ž„ 1๊ฐœ ์ถœ์‹œ 4๋‹จ๊ณ„ (4-6๊ฐœ์›”) 3D ๊ฒŒ์ž„ ์ž…๋ฌธ Three.js ๊ธฐ์ดˆ WebGL ๊ฐœ๋… ์ดํ•ด 3D ๊ฒŒ์ž„ ํ”„๋กœํ† ํƒ€์ž… ๋‹จ๊ณ„๋ณ„ ์ถ”์ฒœ ํ”„๋กœ์ ํŠธ ๐ŸŽฎ 1๋‹จ๊ณ„ ํ”„๋กœ์ ํŠธ โ€ข ๊ณต ํŠ€๊ธฐ๊ธฐ ๊ฒŒ์ž„ โ€ข ๋ฑ€ ๊ฒŒ์ž„ (Snake) โ€ข ํ…ŒํŠธ๋ฆฌ์Šค โ€ข ํ‹ฑํƒํ†  ๐Ÿƒ 2๋‹จ๊ณ„ ํ”„๋กœ์ ํŠธ โ€ข ํ”Œ๋žซํฌ๋จธ ๊ฒŒ์ž„ โ€ข ํƒ‘๋‹ค์šด ์ŠˆํŒ… โ€ข ํผ์ฆ ๊ฒŒ์ž„ โ€ข ๋Ÿฌ๋„ˆ ๊ฒŒ์ž„ โš”๏ธ 3๋‹จ๊ณ„ ํ”„๋กœ์ ํŠธ โ€ข 2D RPG โ€ข ํƒ€์›Œ ๋””ํŽœ์Šค โ€ข ๋ฉ€ํ‹ฐํ”Œ๋ ˆ์ด ๊ฒŒ์ž„ โ€ข ๋ชจ๋ฐ”์ผ ๊ฒŒ์ž„ ์ถœ์‹œ ๐ŸŒ 4๋‹จ๊ณ„ ํ”„๋กœ์ ํŠธ โ€ข 3D ๋ฏธ๋กœ ํƒˆ์ถœ โ€ข 3D ๋ ˆ์ด์‹ฑ ๊ฒŒ์ž„ โ€ข VR ์ฒดํ—˜ ๊ฒŒ์ž„ โ€ข 3D ๋ฉ€ํ‹ฐํ”Œ๋ ˆ์ด์–ด ๐Ÿ’ก ํ•™์Šต ํ•ต์‹ฌ ์กฐ์–ธ ์™„๋ฒฝํ•œ ๊ฒŒ์ž„์„ ๋งŒ๋“ค๋ ค ํ•˜์ง€ ๋ง๊ณ , ์ž‘์€ ๊ฒŒ์ž„์„ ์™„์„ฑํ•˜๋Š” ๊ฒฝํ—˜์„ ์Œ“์•„๊ฐ€๋Š” ๊ฒŒ ์ค‘์š”ํ•ด! ๊ฒŒ์ž„ ์žผ(Game Jam)์— ์ฐธ๊ฐ€ํ•˜๋ฉด ๋‹จ๊ธฐ๊ฐ„์— ์‹ค๋ ฅ์ด ํญ๋ฐœ์ ์œผ๋กœ ๋Š˜์–ด. Ludum Dare, Global Game Jam ์ถ”์ฒœ! ๋งŒ๋“  ๊ฒŒ์ž„์€ ๊ผญ GitHub์— ์˜ฌ๋ฆฌ๊ณ , itch.io์— ๋ฐฐํฌํ•ด๋ด. ํ”ผ๋“œ๋ฐฑ์ด ์ตœ๊ณ ์˜ ์Šค์Šน์ด์•ผ! ์žฌ๋Šฅ๋„ท ๊ฐ™์€ ํ”Œ๋žซํผ์—์„œ ๋‹ค๋ฅธ ๊ฐœ๋ฐœ์ž๋“ค๊ณผ ํ˜‘์—…ํ•˜๋ฉด ํ˜ผ์ž์„œ๋Š” ๋ชป ๋งŒ๋“œ๋Š” ๊ฒŒ์ž„๋„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์–ด!

๐Ÿ”ฅ ์‹ค์ „ ํŒ & ์ž์ฃผ ํ•˜๋Š” ์‹ค์ˆ˜๋“ค

๊ฒŒ์ž„ ๊ฐœ๋ฐœํ•˜๋ฉด์„œ ์ง„์งœ ๋งŽ์ด ํ•˜๋Š” ์‹ค์ˆ˜๋“ค์ด ์žˆ์–ด. ๋ฏธ๋ฆฌ ์•Œ์•„๋‘๋ฉด ์‹œ๊ฐ„ ๋‚ญ๋น„๋ฅผ ์—„์ฒญ ์ค„์ผ ์ˆ˜ ์žˆ์–ด! ๐Ÿ˜ค

โŒ ์ž์ฃผ ํ•˜๋Š” ์‹ค์ˆ˜๋“ค

โš ๏ธ ์‹ค์ˆ˜ 1: requestAnimationFrame ์—†์ด setInterval ์‚ฌ์šฉ setInterval์€ ํƒญ์ด ๋ฐฑ๊ทธ๋ผ์šด๋“œ์— ์žˆ์–ด๋„ ๊ณ„์† ์‹คํ–‰๋˜๊ณ , ํ™”๋ฉด ์ฃผ์‚ฌ์œจ๊ณผ ๋™๊ธฐํ™”๊ฐ€ ์•ˆ ๋ผ.
๋ฐ˜๋“œ์‹œ requestAnimationFrame์„ ์‚ฌ์šฉํ•ด์•ผ ํ•ด!
โš ๏ธ ์‹ค์ˆ˜ 2: ๋งค ํ”„๋ ˆ์ž„๋งˆ๋‹ค new ๊ฐ์ฒด ์ƒ์„ฑ new Vector2(), new Array() ๊ฐ™์€ ๊ฑธ ๋งค ํ”„๋ ˆ์ž„๋งˆ๋‹ค ๋งŒ๋“ค๋ฉด GC(๊ฐ€๋น„์ง€ ์ปฌ๋ ‰ํ„ฐ)๊ฐ€ ์ž์ฃผ ์‹คํ–‰๋˜์–ด ํ”„๋ ˆ์ž„ ๋“œ๋ž์ด ์ƒ๊ฒจ.
์˜ค๋ธŒ์ ํŠธ ํ’€๋ง์„ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜, ๋ฏธ๋ฆฌ ๋งŒ๋“ค์–ด๋‘” ๊ฐ์ฒด๋ฅผ ์žฌ์‚ฌ์šฉํ•ด์•ผ ํ•ด!
โš ๏ธ ์‹ค์ˆ˜ 3: ๋ชจ๋“  ์ถฉ๋Œ์„ O(nยฒ)์œผ๋กœ ์ฒดํฌ ์˜ค๋ธŒ์ ํŠธ๊ฐ€ 100๊ฐœ๋ฉด 10,000๋ฒˆ ์ถฉ๋Œ ์ฒดํฌ๋ฅผ ํ•ด์•ผ ํ•ด. ์ฟผ๋“œํŠธ๋ฆฌ๋‚˜ ๊ณต๊ฐ„ ํ•ด์‹ฑ์„ ์‚ฌ์šฉํ•ด์„œ O(n log n)์œผ๋กœ ์ค„์—ฌ์•ผ ํ•ด!
โš ๏ธ ์‹ค์ˆ˜ 4: ์ด๋ฏธ์ง€๋ฅผ ๋งค ํ”„๋ ˆ์ž„๋งˆ๋‹ค ๋กœ๋“œ new Image()๋ฅผ ๊ฒŒ์ž„ ๋ฃจํ”„ ์•ˆ์—์„œ ๋งŒ๋“ค๋ฉด ์•ˆ ๋ผ. ๊ฒŒ์ž„ ์‹œ์ž‘ ์ „์— ๋ชจ๋“  ๋ฆฌ์†Œ์Šค๋ฅผ ๋ฏธ๋ฆฌ ๋กœ๋“œํ•ด๋‘๊ณ  ์บ์‹œํ•ด์•ผ ํ•ด!

โœ… ํ”„๋กœ์ฒ˜๋Ÿผ ์ฝ”๋”ฉํ•˜๋Š” ํŒ

๐Ÿ’ก ํŒ 1: ๋ฒกํ„ฐ ์ˆ˜ํ•™ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋งŒ๋“ค๊ธฐ ๊ฒŒ์ž„์—์„œ ๋ฒกํ„ฐ ์—ฐ์‚ฐ์€ ํ•„์ˆ˜์•ผ. ๊ฐ„๋‹จํ•œ Vector2 ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค์–ด๋‘๋ฉด ์ฝ”๋“œ๊ฐ€ ํ›จ์”ฌ ๊น”๋”ํ•ด์ ธ.
// ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ Vector2 ํด๋ž˜์Šค
class Vector2 {
  constructor(x = 0, y = 0) {
    this.x = x;
    this.y = y;
  }

  add(v) { return new Vector2(this.x + v.x, this.y + v.y); }
  sub(v) { return new Vector2(this.x - v.x, this.y - v.y); }
  scale(s) { return new Vector2(this.x * s, this.y * s); }
  dot(v) { return this.x * v.x + this.y * v.y; }
  magnitude() { return Math.sqrt(this.x * this.x + this.y * this.y); }
  normalize() {
    const mag = this.magnitude();
    return mag > 0 ? this.scale(1 / mag) : new Vector2();
  }
  distance(v) { return this.sub(v).magnitude(); }
  angle() { return Math.atan2(this.y, this.x); }
  rotate(angle) {
    const cos = Math.cos(angle);
    const sin = Math.sin(angle);
    return new Vector2(
      this.x * cos - this.y * sin,
      this.x * sin + this.y * cos
    );
  }
  lerp(v, t) {
    return new Vector2(
      this.x + (v.x - this.x) * t,
      this.y + (v.y - this.y) * t
    );
  }
  clone() { return new Vector2(this.x, this.y); }
  toString() { return `Vector2(${this.x.toFixed(2)}, ${this.y.toFixed(2)})`; }
}

// ์‚ฌ์šฉ ์˜ˆ์‹œ
const playerPos = new Vector2(100, 200);
const enemyPos = new Vector2(300, 400);
const direction = enemyPos.sub(playerPos).normalize();
const speed = 150;
const velocity = direction.scale(speed);

// ๋ถ€๋“œ๋Ÿฌ์šด ์ด๋™ (๋ณด๊ฐ„)
player.position = player.position.lerp(targetPosition, 0.1);
๐Ÿ’ก ํŒ 2: ์ƒํƒœ ๋จธ์‹ (State Machine) ํ™œ์šฉ ํ”Œ๋ ˆ์ด์–ด์˜ ์ƒํƒœ(idle, run, jump, attack, die)๋ฅผ ์ƒํƒœ ๋จธ์‹ ์œผ๋กœ ๊ด€๋ฆฌํ•˜๋ฉด ๋ณต์žกํ•œ ๊ฒŒ์ž„ ๋กœ์ง์ด ํ›จ์”ฌ ๊น”๋”ํ•ด์ ธ.
// ์œ ํ•œ ์ƒํƒœ ๋จธ์‹  (FSM)
class StateMachine {
  constructor(initialState) {
    this.states = {};
    this.currentState = null;
    this.previousState = null;
    this.initialState = initialState;
  }

  addState(name, state) {
    this.states[name] = state;
    return this;
  }

  start() {
    this.transition(this.initialState);
  }

  transition(stateName, data = {}) {
    if (this.currentState && this.states[this.currentState].onExit) {
      this.states[this.currentState].onExit(data);
    }
    this.previousState = this.currentState;
    this.currentState = stateName;
    if (this.states[this.currentState].onEnter) {
      this.states[this.currentState].onEnter(data);
    }
  }

  update(dt, input) {
    const state = this.states[this.currentState];
    if (state && state.update) {
      const nextState = state.update(dt, input);
      if (nextState) this.transition(nextState);
    }
  }
}

// ํ”Œ๋ ˆ์ด์–ด ์ƒํƒœ ๋จธ์‹  ์˜ˆ์‹œ
const playerFSM = new StateMachine('idle');

playerFSM
  .addState('idle', {
    onEnter: () => player.playAnim('idle'),
    update: (dt, input) => {
      if (input.isKeyDown('ArrowLeft') || input.isKeyDown('ArrowRight')) return 'run';
      if (input.isKeyDown('Space')) return 'jump';
      if (input.isKeyDown('KeyZ')) return 'attack';
    }
  })
  .addState('run', {
    onEnter: () => player.playAnim('run'),
    update: (dt, input) => {
      if (!input.isKeyDown('ArrowLeft') && !input.isKeyDown('ArrowRight')) return 'idle';
      if (input.isKeyDown('Space')) return 'jump';
      // ์ด๋™ ๋กœ์ง
      if (input.isKeyDown('ArrowLeft')) player.vx = -200;
      if (input.isKeyDown('ArrowRight')) player.vx = 200;
    }
  })
  .addState('jump', {
    onEnter: () => {
      player.playAnim('jump');
      player.vy = -500;
    },
    update: (dt, input) => {
      if (player.onGround) return 'idle';
    }
  });

playerFSM.start();

๐ŸŽŠ ๋งˆ๋ฌด๋ฆฌ - ์ง€๊ธˆ ๋‹น์žฅ ์‹œ์ž‘ํ•ด!

์ž, ์—ฌ๊ธฐ๊นŒ์ง€ JavaScript ๊ฒŒ์ž„ ๊ฐœ๋ฐœ์˜ ํ•ต์‹ฌ์„ ์ญ‰ ํ›‘์–ด๋ดค์–ด.
Canvas API๋ถ€ํ„ฐ WebGL, Three.js, Babylon.js, Phaser.js๊นŒ์ง€ ์ •๋ง ๋‹ค์–‘ํ•œ ๋„๊ตฌ๋“ค์ด ์žˆ์ง€?

๊ทผ๋ฐ ์†”์งํžˆ ๋งํ• ๊ฒŒ. ๊ฐ€์žฅ ์ค‘์š”ํ•œ ๊ฑด ์ง€๊ธˆ ๋‹น์žฅ ๋ญ”๊ฐ€๋ฅผ ๋งŒ๋“ค์–ด๋ณด๋Š” ๊ฑฐ์•ผ. ๐Ÿ”ฅ
์™„๋ฒฝํ•œ ๊ฒŒ์ž„์„ ๋งŒ๋“ค๋ ค๊ณ  ํ•˜์ง€ ๋ง๊ณ , ๊ณต์ด ํŠ€๊ธฐ๋Š” ๊ฒƒ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด๋ด. ๊ทธ๊ฒŒ ์ง„์งœ ๊ฒŒ์ž„ ๊ฐœ๋ฐœ์˜ ์‹œ์ž‘์ด์•ผ.

๐Ÿš€ ์˜ค๋Š˜ ๋‹น์žฅ ํ•ด๋ณผ ์ˆ˜ ์žˆ๋Š” ๊ฒƒ๋“ค
  • 1 Canvas API๋กœ ๊ณต ํŠ€๊ธฐ๊ธฐ ๊ฒŒ์ž„ ๋งŒ๋“ค๊ธฐ (30๋ถ„)
  • 2 Phaser.js ๊ณต์‹ ํŠœํ† ๋ฆฌ์–ผ ๋”ฐ๋ผํ•˜๊ธฐ (2์‹œ๊ฐ„)
  • 3 Three.js Journey ๊ฐ•์˜ ์‹œ์ž‘ํ•˜๊ธฐ (๋ฌด๋ฃŒ ํŒŒํŠธ ์žˆ์Œ)
  • 4 itch.io์—์„œ HTML5 ๊ฒŒ์ž„ ์†Œ์Šค ๋ถ„์„ํ•˜๊ธฐ
  • 5 ๋‹ค์Œ Ludum Dare ๊ฒŒ์ž„ ์žผ ์ฐธ๊ฐ€ ์‹ ์ฒญํ•˜๊ธฐ

๊ทธ๋ฆฌ๊ณ  ๋งŒ์•ฝ ๊ฒŒ์ž„ ๊ฐœ๋ฐœ ์‹ค๋ ฅ์„ ํ‚ค์›Œ์„œ ํ”„๋ฆฌ๋žœ์„œ๋กœ ํ™œ๋™ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด, ์žฌ๋Šฅ๋„ท์—์„œ ๊ฒŒ์ž„ ๊ฐœ๋ฐœ ๊ด€๋ จ ์žฌ๋Šฅ์„ ๋“ฑ๋กํ•ด๋ด. ๋ฏธ๋‹ˆ๊ฒŒ์ž„ ์ œ์ž‘, ๊ฒŒ์ž„ UI ๊ฐœ๋ฐœ, ๊ฒŒ์ž„ ๋กœ์ง ๊ตฌํ˜„ ๋“ฑ ์ˆ˜์š”๊ฐ€ ๊ฝค ์žˆ๊ฑฐ๋“ ! ๐Ÿ’ฐ

JavaScript ๊ฒŒ์ž„ ๊ฐœ๋ฐœ, ์ƒ๊ฐ๋ณด๋‹ค ํ›จ์”ฌ ์žฌ๋ฐŒ๊ณ  ๊ฐ•๋ ฅํ•ด. ๋ธŒ๋ผ์šฐ์ € ํ•˜๋‚˜๋กœ ์„ธ์ƒ์„ ์ •๋ณตํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฑฐ, ์ด์ œ ๋А๊ปด์ง€์ง€? ๐Ÿ˜Ž
์ž, ์ด์ œ ์ฝ”๋“œ ์—๋””ํ„ฐ ์—ด๊ณ  ๊ฒŒ์ž„ ๋งŒ๋“ค๋Ÿฌ ๊ฐ€์ž! ๐ŸŽฎโœจ

๋Œ“๊ธ€ ์ž‘์„ฑ

์ด ๊ธ€์— ๋Œ€ํ•œ ์—ฌ๋Ÿฌ๋ถ„์˜ ์ƒ๊ฐ์„ ๋“ค๋ ค์ฃผ์„ธ์š”

๋Œ“๊ธ€ 0
๋Œ“๊ธ€์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ค‘์ž…๋‹ˆ๋‹ค.

์•„์ง ๋Œ“๊ธ€์ด ์—†์Šต๋‹ˆ๋‹ค.