Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bullet.h"
- #include <godot_cpp/core/class_db.hpp>
- #include <godot_cpp/classes/engine.hpp>
- #include <godot_cpp/variant/utility_functions.hpp>
- #include <godot_cpp/classes/scene_tree.hpp>
- #include <godot_cpp/classes/window.hpp>
- #include <godot_cpp/classes/node.hpp>
- #include <godot_cpp/classes/node2D.hpp>
- using namespace godot;
- // Add member variable declaration for target_entity
- // (This should also be added to the header file, bullet.h)
- void Bullet::_bind_methods() {
- // Aquí puedes usar D_METHOD o BIND_METHOD para registrar los métodos
- ClassDB::bind_method(D_METHOD("set_speed", "p_speed"), &Bullet::set_speed);
- ClassDB::bind_method(D_METHOD("get_speed"), &Bullet::get_speed);
- ClassDB::bind_method(D_METHOD("set_radio", "p_radio"), &Bullet::set_radio);
- ClassDB::bind_method(D_METHOD("get_radio"), &Bullet::get_radio);
- ClassDB::bind_method(D_METHOD("initialize", "p_direction", "p_rotation", "p_shape"), &Bullet::initialize);
- ClassDB::bind_method(D_METHOD("die"), &Bullet::die);
- ClassDB::bind_method(D_METHOD("disable"), &Bullet::disable);
- ClassDB::bind_method(D_METHOD("is_active"), &Bullet::is_active);
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "speed"), "set_speed", "get_speed");
- }
- Bullet::Bullet() {
- speed = 50;
- radio = 5;
- direction_vector = Vector2(1, 1); // Dirección por defecto
- bullet_position = Vector2(0, 0);
- radio = 5;
- direction_vector = Vector2(1, 1); // Dirección por defecto
- }
- Bullet::~Bullet() {
- // Si el nodo es padre de area, Godot lo liberará
- }
- void Bullet::initialize(const Vector2 &p_position, const Vector2 &p_direction, int p_radio, int p_speed, int p_z_index) {
- direction_vector = p_direction;
- bullet_position = p_position;
- set_bullet_position(p_position);
- radio = p_radio;
- speed = p_speed;
- direction_vector *= speed;
- set_z_index(p_z_index);
- set_visible(true);
- _is_active = true;
- // Node* target = get_node<Node>("/root/Global");
- // target->call("add_num_balas");
- }
- void Bullet::_ready() {
- // Llama al ready de la clase padre (AnimatedSprite2D)
- Sprite2D::_ready();
- // Node2D* target_entity =
- disable();
- }
- void Bullet::disable() {
- _is_active = false;
- set_visible(false);
- }
- bool Bullet::is_active() {
- return _is_active;
- }
- void Bullet::set_radio(const int p_radio) {
- radio = p_radio;
- }
- int Bullet::get_radio() const {
- return radio;
- }
- void Bullet::set_speed(const float p_speed) {
- speed = p_speed;
- }
- float Bullet::get_speed() const {
- return speed;
- }
- void Bullet::set_bullet_position(const Vector2 &p_position) {
- bullet_position = p_position;
- set_global_position(bullet_position);
- }
- Vector2 Bullet::get_bullet_position() {
- return bullet_position;
- }
- Vector2 Bullet:: get_direction_vector() {
- return direction_vector;
- }
- void Bullet::die() {
- // Node* target = get_node<Node>("/root/Global");
- // target->call("remove_num_balas");
- // queue_free();
- }
Advertisement
Add Comment
Please, Sign In to add comment