table.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. : game_over(false)
  54. , balls_released(false)
  55. , plunger(nullptr) {
  56. }
  57. ~Table();
  58. std::vector<FixedObject*> objects;
  59. std::vector<Ball> balls; // current state of balls
  60. std::vector<Ball> balls_initial; // original positions, before release
  61. std::vector<Flipper> flippers;
  62. bool game_over;
  63. bool balls_released; // is ball in play?
  64. Lives lives;
  65. Score score;
  66. Plunger* plunger;
  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);