table.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. struct PinballApp;
  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. : game_over(false)
  55. , balls_released(false)
  56. , plunger(nullptr) {
  57. }
  58. ~Table();
  59. std::vector<FixedObject*> objects;
  60. std::vector<Ball> balls; // current state of balls
  61. std::vector<Ball> balls_initial; // original positions, before release
  62. std::vector<Flipper> flippers;
  63. bool game_over;
  64. bool balls_released; // is ball in play?
  65. Lives lives;
  66. Score score;
  67. Plunger* plunger;
  68. void draw(Canvas* canvas);
  69. bool handle_key_event(const PinballEvent& event);
  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);