Advertisement
Guest User

nou

a guest
Apr 24th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. function move(e) {
  2. // alert (e.keyCode)
  3. if (q == true) {
  4. if (e.keyCode == 90) {
  5. battle();
  6. }
  7. }
  8. else {
  9. if (event.keyCode == 37 || event.keyCode == 39 || e.keyCode == 38 || e.keyCode == 40) { event.preventDefault() };
  10. if (e.keyCode == 39 && e.keyCode == 38) {
  11. xpos += 5
  12. ypos -= 5
  13.  
  14. }
  15. if (e.keyCode == 37 && e.keyCode == 40) {
  16. xpos -= 5
  17. ypox += 5
  18. }
  19. if (e.keyCode == 38 && e.keyCode == 37) {
  20. ypos -= 5
  21. xpos -= 5
  22. }
  23. if (e.keyCode == 40 && e.keyCode == 39) {
  24. ypos += 5
  25. xpos += 5
  26.  
  27. }
  28. if (e.keyCode == 39) {
  29.  
  30. if (xpos >= 1255) { }
  31. else
  32. xpos += 5
  33. }
  34. if (e.keyCode == 37) {
  35.  
  36. if (xpos <= 15) { }
  37. else
  38. xpos -= 5
  39. }
  40. if (e.keyCode == 38) {
  41. if (ypos <= 5) { }
  42. else
  43. ypos -= 5
  44. }
  45. if (e.keyCode == 40) {
  46. if (ypos >= 238) { }
  47. else
  48. ypos += 5
  49. }
  50.  
  51. canvas.width = canvas.width
  52. context.drawImage(heart, xpos, ypos);
  53. heart.src = 'heart.png';
  54. context.drawImage(bone, bonex, boney);
  55. bone.src = 'boneup.png';
  56. }
  57. }
  58.  
  59. document.onkeydown = move;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement