table.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #pragma once
  2. #include <furi.h>
  3. #include <vector>
  4. #include "pinball0.h"
  5. #include "objects.h"
  6. #include "signals.h"
  7. #define TABLE_SELECT 0
  8. #define TABLE_ERROR 1
  9. #define TABLE_SETTINGS 2
  10. #define TABLE_INDEX_OFFSET 3
  11. // Table display elements, rendered on the physical display coordinates,
  12. // not the table's scaled coords
  13. class DataDisplay {
  14. public:
  15. enum Align {
  16. Horizontal,
  17. Vertical
  18. };
  19. DataDisplay(const Vec2& pos, int val, bool disp, Align align)
  20. : p(pos)
  21. , value(val)
  22. , display(disp)
  23. , alignment(align) {
  24. }
  25. Vec2 p;
  26. int value;
  27. bool display;
  28. Align alignment;
  29. virtual void draw(Canvas* canvas) = 0;
  30. };
  31. class Lives : public DataDisplay {
  32. public:
  33. Lives()
  34. : DataDisplay(Vec2(), 3, false, Horizontal) {
  35. }
  36. void draw(Canvas* canvas);
  37. };
  38. class Score : public DataDisplay {
  39. public:
  40. Score()
  41. : DataDisplay(Vec2(64 - 1, 1), 0, false, Horizontal) {
  42. }
  43. void draw(Canvas* canvas);
  44. };
  45. // Defines all of the elements on a pinball table:
  46. // edges, bumpers, flipper locations, scoreboard
  47. //
  48. // Also used for other app "views", like the main menu (table select)
  49. // and the Settings screen.
  50. // TODO: make this better? eh, it works for now...
  51. class Table {
  52. public:
  53. Table();
  54. ~Table();
  55. std::vector<FixedObject*> objects;
  56. std::vector<Ball> balls; // current state of balls
  57. std::vector<Ball> balls_initial; // original positions, before release
  58. std::vector<Flipper> flippers;
  59. bool game_over;
  60. bool balls_released; // is ball in play?
  61. Lives lives;
  62. Score score;
  63. Plunger* plunger;
  64. // table bump / tilt tracking
  65. bool tilt_detect_enabled;
  66. uint32_t last_bump;
  67. uint32_t bump_count;
  68. SignalManager sm;
  69. void draw(Canvas* canvas);
  70. };
  71. // Read the list tables from the data folder and store in the state
  72. void table_table_list_init(void* ctx);
  73. // Reads the table file and creates the new table.
  74. Table* table_load_table_from_file(PinballApp* ctx, size_t index);
  75. // Loads the index'th table from the list
  76. bool table_load_table(void* ctx, size_t index);