tavli

view src/board.h @ 21:c3fbf9616dbd

slot bounds, and ray testing
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 02 Jul 2015 00:01:39 +0300
parents 16a420432aa3
children c2a2069a49ec
line source
1 #ifndef BOARD_H_
2 #define BOARD_H_
4 #include <vector>
5 #include "object.h"
6 #include "mesh.h"
7 #include "image.h"
9 #define NUM_SLOTS 20
10 #define PLAYER_PIECES 15
11 #define MAX_PIECES (PLAYER_PIECES * 2)
13 enum { MINE, OTHER };
15 class Piece {
16 private:
17 int prev_slot, prev_level;
18 unsigned long move_start;
20 public:
21 int owner, slot, level;
23 Piece();
25 void move_to(int slot, int level, bool anim = true);
26 };
28 // for slot bounds
29 class Quad {
30 public:
31 Triangle tri0, tri1;
33 Quad();
34 Quad(const Vector3 &v0, const Vector3 &v1, const Vector3 &v2, const Vector3 &v3);
36 bool intersect(const Ray &ray, HitPoint *hit = 0) const;
37 };
39 class Board {
40 private:
41 Piece pieces[MAX_PIECES];
42 int hist[NUM_SLOTS + 1];
43 Quad slotbb[NUM_SLOTS];
45 std::vector<Object*> obj;
46 Object *piece_obj;
48 Image img_wood, img_field, img_hinge;
50 bool generate();
51 bool generate_textures();
53 public:
54 Board();
55 ~Board();
57 bool init();
58 void destroy();
60 void clear();
61 void setup();
63 int slot_pieces(int slot) const;
64 bool move_piece(int id, int slot, bool anim = true);
66 Vector3 piece_pos(int slot, int level = 0) const;
68 int slot_hit(const Ray &ray) const;
70 void draw() const;
71 };
73 #endif // BOARD_H_