table.h 2.0 KB

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