minicraft.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. "use strict";
  2. const FPS = 24;
  3. let sprites;
  4. let player;
  5. function preload () {
  6. sprites = loadImage('img/sprites.png');
  7. }
  8. function setup() {
  9. // Create the canvas.
  10. createCanvas(500, 500);
  11. frameRate(FPS);
  12. // Create a new player.
  13. player = new Player(0, 0);
  14. }
  15. function draw() {
  16. // Clear the background.
  17. background(255);
  18. // Get input.
  19. getInput();
  20. // Check for interactions.
  21. update();
  22. // Draw the characters.
  23. drawCharacters();
  24. }
  25. function getInput() {
  26. // Check to see if a key is pressed.
  27. if (keyIsPressed) {
  28. // Check for the arrow keys.
  29. // Left Arrow Key.
  30. if (keyIsDown(LEFT_ARROW)) {
  31. console.log('Left Arrow');
  32. }
  33. // Right Arrow Key.
  34. else if (keyIsDown(RIGHT_ARROW)) {
  35. console.log('Right Arrow');
  36. }
  37. // Up Arrow Key.
  38. if (keyIsDown(UP_ARROW)) {
  39. console.log('Up Arrow');
  40. }
  41. // Down Arrow Key.
  42. else if (keyIsDown(DOWN_ARROW)) {
  43. console.log('Down Arrow');
  44. }
  45. }
  46. }
  47. function keyPressed() {
  48. // Space Bar.
  49. if (keyCode == 32) {
  50. console.log('Space Bar');
  51. }
  52. // X Key.
  53. if (keyCode == 88) {
  54. console.log('X Key');
  55. }
  56. }
  57. function update(delta) {
  58. player.update(delta);
  59. }
  60. function drawCharacters() {
  61. player.draw();
  62. }