Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var canvas = document.getElementById("myCanvas");
  2. var context = canvas.getContext("2d");
  3.  
  4. var keyUp = false, keyDown = false, keyRight = false, keyLeft = false;
  5. var ships = [];
  6. var playerPos = new Vector2();
  7. var canvasMeasurements = new Vector2(canvas.width, canvas.height)
  8.  
  9.  
  10.  
  11. function update() {
  12.     context.clearRect(0, 0, canvas.width, canvas.height);
  13.     draw();
  14.     window.requestAnimationFrame(update);
  15.  
  16. }
  17.  
  18. GameStart();
  19. update();
  20.  
  21. function GameStart(){
  22.     playerPos.x = canvasMeasurements.x / 2;
  23.     playerPos.y = canvasMeasurements.y - 40;
  24. }
  25.  
  26. function draw(){
  27.     CannonBase();
  28.     CannonLoop();
  29. }
  30.  
  31. function CannonBase(){
  32.     context.fillStyle = "black";
  33.     context.arc(playerPos.x, playerPos.y, 50, Math.PI * 1, Math.PI * 2, false);
  34.     context.fill();
  35. }
  36.  
  37. function CannonLoop(){
  38.     var angle = 200;
  39.  
  40.     context.translate(playerPos.x, playerPos.y);
  41.     context.rotate(this.angle);
  42.     context.translate(-playerPos.x, -playerPos.y);
  43.     context.beginPath();
  44.     context.moveTo(playerPos.x, playerPos.y);
  45.     context.lineTo(playerPos.x + 15, playerPos.y - 100);
  46.     context.lineTo(playerPos.x - 15, playerPos.y - 100);
  47.     context.lineTo(playerPos.x, playerPos.y)
  48.     context.lineWidth = 3;
  49.     context.stroke();
  50.     context.endPath();
  51. }
  52.  
  53. function Vector2(x, y){
  54.     this.x = x;
  55.     this.y = y;
  56. }
  57.  
  58. update();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement