daily pastebin goal
9%
SHARE
TWEET

Untitled

a guest Mar 20th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <canvas id= 'game' width= '400' height='400'></canvas>
  2.  
  3. <script>
  4. class SnakeGame {
  5. constructor()
  6. this.canvas = document.getElementByID('game');
  7. this.context = this.canvas.getContext('2d');
  8.  document.addEventListener ('keydown' , this.onKeyPress.bind(this));
  9. }
  10.  
  11. init()
  12. this.positionX = this.positionY = 10;
  13. this.AppleX = this.appleY = 5;
  14. this.tailSize = 5;
  15. this.trail = [];
  16. this.gridSize = this.tileCount = 20;
  17. this.velocityX = this.velocityY = 0;
  18.  
  19. this.timer = setInterval(this.loop.bind(this), 1000 / 15);
  20.  }
  21.  
  22.  reset() {
  23.  clearInterval(this.timer);
  24.  this.init();
  25.  }
  26.  
  27.  loop() {
  28.  this.update();
  29.  this.draw()
  30.  }
  31.  
  32.  update() {
  33.  
  34.  }
  35.  
  36.  draw() {
  37.  this.context.fillStyle = 'black';
  38.  this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
  39.  
  40.  this.context.fillRect = 'red';
  41.  this.context.font = '20px Arial;
  42.  this.context.fillText(this.tailSize, 20, 40);
  43.  
  44.  this.context.fillStyle = 'yellow';
  45.  this.trail.forEach(t => {
  46.  this.context.fillRect(t.positionX * this.gridSize, t.positionY * this.gridSize, this.gridSize - 5, this.gridSize - 5,);
  47.  });
  48.  this.context.fillStyle =
  49.  
  50.  
  51.  onKeyPress(e) {
  52. }
  53.  
  54. const game = new SnakeGame();
  55. window.onload = () => game.init ();
  56. /script>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top