minicraft.js 979 B

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