Kaplay

by blueur

HTML

<!DOCTYPE html>
<html lang="fr">
  <head>
    <title>Kaplay</title>
    <script src="https://unpkg.com/kaplay@3001/dist/kaplay.js"></script>
  </head>
  <body>
    <script src="./main.js"></script>
  </body>
</html>

JavaScript

kaplay({
  width: 640,
  height: 480,
  background: '#000000',
  letterbox: true,
});

add(['background', rect(width(), height()), pos(0, 0), color('#eee8d5')]);

add(['text', text('Hello world'), pos(128, 128), color('#073642')]);

setGravity(1600);

const player = add([
  'player',
  circle(32),
  color('#dc322f'),
  pos(128, 256),
  area(),
  body(),
]);

add([
  "ground",
  rect(width(), 64),
  color("#859900"),
  pos(0, height() - 64),
  area(),
  body({ isStatic: true }),
]);

onKeyPress('space', () => {
  player.jump();
});

onKeyDown('right', () => {
  player.move(256, 0);
});