Guest User

Untitled

a guest
Nov 20th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. if(x == 557 && y == 533){
  2. x = 300;
  3. y = 300;
  4. };
  5. },1000);
  6.  
  7. var canvas = document.querySelector("#myCanvas");
  8. var context = canvas.getContext("2d");
  9. var canvasWidth = context.canvas.width, canvasHeight = context.canvas.height;
  10. context.fillStyle = "black";
  11. context.fillRect(0, 0, canvasWidth, canvasHeight);
  12. var x = 300;
  13. var y = 300;
  14. trash();
  15. mrTrumpet();
  16. function trash(){
  17. var trsh = new Image();
  18. trsh.src = "trash.png";
  19. trsh.onload = function(){
  20. context.drawImage(trsh, 559, 550);
  21. };
  22. };
  23. function mrTrumpet(){
  24. var img = new Image();
  25. img.src = "character.png";
  26. img.onload = function(){
  27. context.drawImage(img, x, y);
  28. };
  29. };
  30. function move(e){
  31. if(e.keyCode==68){x++};
  32. if(e.keyCode==65){x--};
  33. if(e.keyCode==87){y--};
  34. if(e.keyCode==83){y++};
  35. canvas.width=canvas.width;
  36. trash();
  37. mrTrumpet();
  38. };
  39. setInterval(function(){
  40. console.log("x = " + x + ", y = " + y);
  41. },1000);
  42. setInterval(function(x, y){
  43. if(x == 557 && y == 533){
  44. x = 300;
  45. y = 300;
  46. };
  47. },1000);
  48. document.onkeydown = move;
Add Comment
Please, Sign In to add comment