-
Notifications
You must be signed in to change notification settings - Fork 16
/
bullet_server.h
101 lines (71 loc) · 2.22 KB
/
bullet_server.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef BULLETSERVER_H
#define BULLETSERVER_H
#include "bullet.h"
#include "bullet_server_relay.h"
#include "bullet_type.h"
#include "core/config/engine.h"
#include "core/os/os.h"
#include "scene/2d/node_2d.h"
#include "scene/resources/world_2d.h"
#include "servers/physics_server_2d.h"
#include <vector>
class BulletServer : public Node2D {
GDCLASS(BulletServer, Node2D);
public:
enum AreaMode {
VIEWPORT,
MANUAL,
INFINITE,
};
private:
int bullet_pool_size;
bool pop_on_collide;
float max_lifetime;
int max_collisions_per_bullet;
Vector<Bullet *> live_bullets;
Vector<Bullet *> dead_bullets;
AreaMode play_area_mode;
Rect2 play_area_rect;
float play_area_margin;
bool play_area_allow_incoming;
bool relay_autoconnect;
void _process_bullets(float delta);
void _handle_collisions(Bullet *bullet, PhysicsDirectSpaceState2D *space_state);
void _init_bullets();
void _create_bullet();
void _uninit_bullets();
void _update_play_area();
protected:
static void _bind_methods();
void _notification(int p_what);
void _validate_property(PropertyInfo &property) const;
public:
BulletServer();
~BulletServer();
void spawn_bullet(const Ref<BulletType> &p_type, const Vector2 &p_position, const Vector2 &p_direction);
void spawn_volley(const Ref<BulletType> &p_type, const Vector2 &p_position, const Array &p_volley);
void clear_bullets();
int get_live_bullet_count();
Array get_live_bullets();
Array get_live_bullet_positions();
void set_bullet_pool_size(int p_size);
int get_bullet_pool_size() const;
void set_pop_on_collide(bool p_enabled);
bool get_pop_on_collide() const;
void set_max_lifetime(float p_time);
float get_max_lifetime() const;
void set_max_collisions_per_bullet(int p_count);
int get_max_collisions_per_bullet() const;
void set_play_area_mode(AreaMode p_mode);
AreaMode get_play_area_mode() const;
void set_play_area_rect(const Rect2 &p_rect);
Rect2 get_play_area_rect() const;
void set_play_area_margin(float p_margin);
float get_play_area_margin() const;
void set_play_area_allow_incoming(bool p_enabled);
bool get_play_area_allow_incoming() const;
void set_relay_autoconnect(bool p_enabled);
bool get_relay_autoconnect() const;
};
VARIANT_ENUM_CAST(BulletServer::AreaMode)
#endif