feature/Coin #32
8
godot/levels/GoalNotReached.gdns
Normal file
8
godot/levels/GoalNotReached.gdns
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
[gd_resource type="NativeScript" load_steps=2 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://gdnative/alai.tres" type="GDNativeLibrary" id=1]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
resource_name = "GoalNotReached"
|
||||||
|
class_name = "GoalNotReached"
|
||||||
|
library = ExtResource( 1 )
|
@ -1,4 +1,4 @@
|
|||||||
[gd_scene load_steps=12 format=2]
|
[gd_scene load_steps=18 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://CameraLimit.gdns" type="Script" id=1]
|
[ext_resource path="res://CameraLimit.gdns" type="Script" id=1]
|
||||||
[ext_resource path="res://characters/player/Player.tscn" type="PackedScene" id=2]
|
[ext_resource path="res://characters/player/Player.tscn" type="PackedScene" id=2]
|
||||||
@ -7,6 +7,8 @@
|
|||||||
[ext_resource path="res://collectables/coin/Coin.tscn" type="PackedScene" id=5]
|
[ext_resource path="res://collectables/coin/Coin.tscn" type="PackedScene" id=5]
|
||||||
[ext_resource path="res://assets/coin.png" type="Texture" id=6]
|
[ext_resource path="res://assets/coin.png" type="Texture" id=6]
|
||||||
[ext_resource path="res://hud/coin/Counter.gdns" type="Script" id=7]
|
[ext_resource path="res://hud/coin/Counter.gdns" type="Script" id=7]
|
||||||
|
[ext_resource path="res://assets/flag.png" type="Texture" id=8]
|
||||||
|
[ext_resource path="res://levels/GoalNotReached.gdns" type="Script" id=9]
|
||||||
|
|
||||||
[sub_resource type="StyleBoxFlat" id=1]
|
[sub_resource type="StyleBoxFlat" id=1]
|
||||||
bg_color = Color( 0, 0, 0, 0.541176 )
|
bg_color = Color( 0, 0, 0, 0.541176 )
|
||||||
@ -27,6 +29,25 @@ animations = [ {
|
|||||||
"speed": 5.0
|
"speed": 5.0
|
||||||
} ]
|
} ]
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id=5]
|
||||||
|
extents = Vector2( 10, 18 )
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id=6]
|
||||||
|
atlas = ExtResource( 8 )
|
||||||
|
region = Rect2( 0, 0, 18, 36 )
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id=7]
|
||||||
|
atlas = ExtResource( 8 )
|
||||||
|
region = Rect2( 18, 0, 18, 36 )
|
||||||
|
|
||||||
|
[sub_resource type="SpriteFrames" id=8]
|
||||||
|
animations = [ {
|
||||||
|
"frames": [ SubResource( 6 ), SubResource( 7 ) ],
|
||||||
|
"loop": true,
|
||||||
|
"name": "flagmove",
|
||||||
|
"speed": 5.0
|
||||||
|
} ]
|
||||||
|
|
||||||
[node name="Prototype" type="Node2D"]
|
[node name="Prototype" type="Node2D"]
|
||||||
|
|
||||||
[node name="Player" parent="." instance=ExtResource( 2 )]
|
[node name="Player" parent="." instance=ExtResource( 2 )]
|
||||||
@ -91,7 +112,6 @@ script = ExtResource( 7 )
|
|||||||
position = Vector2( 162, 18 )
|
position = Vector2( 162, 18 )
|
||||||
frames = SubResource( 4 )
|
frames = SubResource( 4 )
|
||||||
animation = "spin"
|
animation = "spin"
|
||||||
frame = 1
|
|
||||||
playing = true
|
playing = true
|
||||||
centered = false
|
centered = false
|
||||||
|
|
||||||
@ -100,7 +120,32 @@ centered = false
|
|||||||
[node name="coin" parent="Coins" instance=ExtResource( 5 )]
|
[node name="coin" parent="Coins" instance=ExtResource( 5 )]
|
||||||
position = Vector2( 72, 450 )
|
position = Vector2( 72, 450 )
|
||||||
|
|
||||||
|
[node name="AnimatedSprite" parent="Coins/coin" index="1"]
|
||||||
|
frame = 0
|
||||||
|
|
||||||
[node name="coin2" parent="Coins" instance=ExtResource( 5 )]
|
[node name="coin2" parent="Coins" instance=ExtResource( 5 )]
|
||||||
position = Vector2( 234, 450 )
|
position = Vector2( 234, 450 )
|
||||||
|
|
||||||
|
[node name="Goal" type="Area2D" parent="."]
|
||||||
|
position = Vector2( 324, 378 )
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Goal"]
|
||||||
|
position = Vector2( 18, 18 )
|
||||||
|
shape = SubResource( 5 )
|
||||||
|
|
||||||
|
[node name="AnimatedSprite" type="AnimatedSprite" parent="Goal"]
|
||||||
|
position = Vector2( 18, 18 )
|
||||||
|
frames = SubResource( 8 )
|
||||||
|
animation = "flagmove"
|
||||||
|
playing = true
|
||||||
|
|
||||||
|
[node name="StateMachine" type="Node" parent="Goal"]
|
||||||
|
|
||||||
|
[node name="GoalReached" type="Node" parent="Goal/StateMachine"]
|
||||||
|
|
||||||
|
[node name="GoalNotReached" type="Node" parent="Goal/StateMachine"]
|
||||||
|
script = ExtResource( 9 )
|
||||||
|
|
||||||
|
[connection signal="body_entered" from="Goal" to="Goal/StateMachine/GoalNotReached" method="_on_Goal_body_entered"]
|
||||||
|
|
||||||
[editable path="Coins/coin"]
|
[editable path="Coins/coin"]
|
||||||
|
56
src/goal/GoalNotReached.cpp
Normal file
56
src/goal/GoalNotReached.cpp
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#include "goal/GoalNotReached.h"
|
||||||
|
#include <Area2D.hpp>
|
||||||
|
|
||||||
|
using namespace godot;
|
||||||
|
|
||||||
|
|
||||||
|
void GoalNotReached::_register_methods()
|
||||||
|
{
|
||||||
|
register_method("_state_enter", &GoalNotReached::_state_enter);
|
||||||
|
register_method("_state_exit", &GoalNotReached::_state_exit);
|
||||||
|
register_method("_on_Goal_body_entered", &GoalNotReached::_on_Goal_body_entered);
|
||||||
|
}
|
||||||
|
|
||||||
|
GoalNotReached::GoalNotReached()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
GoalNotReached::~GoalNotReached()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void GoalNotReached::_init()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void GoalNotReached::_state_enter()
|
||||||
|
{
|
||||||
|
animated_sprite = get_parent()->get_node<AnimatedSprite>("AnimatedSprite");
|
||||||
|
animated_sprite->set_animation("flagmove");
|
||||||
|
animated_sprite->play();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GoalNotReached::_state_exit()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void GoalNotReached::_on_Goal_body_entered(Node *node)
|
||||||
|
{
|
||||||
|
Godot::print("Flag touched");
|
||||||
|
/* auto parent_node = get_parent();
|
||||||
|
|
||||||
|
if (parent_node != nullptr)
|
||||||
|
{
|
||||||
|
auto goal = Object::cast_to<Area2D>(parent_node);
|
||||||
|
goal->set_collision_mask_bit(0, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
get_state_machine()->change("GoalReached");*/
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
76
src/goal/GoalNotReached.h
Normal file
76
src/goal/GoalNotReached.h
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
#ifndef ALAI_GOAL_NOT_REACHED
|
||||||
|
#define ALAI_GOAL_NOT_REACHED
|
||||||
|
|
||||||
|
#include "state_machine/State.h"
|
||||||
|
|
||||||
|
#include <Godot.hpp>
|
||||||
|
#include <Node.hpp>
|
||||||
|
#include <AnimatedSprite.hpp>
|
||||||
|
|
||||||
|
namespace godot
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @brief This class controls what happens when the Coin is in the not collected state.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class GoalNotReached : public State
|
||||||
|
{
|
||||||
|
GODOT_CLASS(GoalNotReached, State)
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* @brief The animated sprite of the Coin.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
AnimatedSprite *animated_sprite;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief This method registers classes with Godot.
|
||||||
|
*
|
||||||
|
* @details This method registers methods, properties, and signals with the Godot engine.
|
||||||
|
*/
|
||||||
|
static void _register_methods();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Construct a new GoalNotReached object.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
GoalNotReached();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Destroy the GoalNotReached object.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
~GoalNotReached();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initialize the class from Godot.
|
||||||
|
*
|
||||||
|
* @details This method is called just once when the Godot engine connects to the instance of the class.
|
||||||
|
*/
|
||||||
|
void _init();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Called when the not collected state of the coin is entered.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void _state_enter();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Called when the not collected state of the coin is exited.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void _state_exit();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Method called on body entered.
|
||||||
|
*
|
||||||
|
* @param[in] node Node interacting with whoever
|
||||||
|
*/
|
||||||
|
void _on_Goal_body_entered(Node *node);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
35
src/goal/GoalReached.cpp
Normal file
35
src/goal/GoalReached.cpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#include "goal/GoalReached.h"
|
||||||
|
|
||||||
|
using namespace godot;
|
||||||
|
|
||||||
|
void GoalReached::_register_methods()
|
||||||
|
{
|
||||||
|
register_method("_state_enter", &GoalReached::_state_enter);
|
||||||
|
register_method("_state_exit", &GoalReached::_state_exit);
|
||||||
|
//register_signal<GoalReached>("coin_collected", "amount", GODOT_VARIANT_TYPE_INT);
|
||||||
|
}
|
||||||
|
|
||||||
|
GoalReached::GoalReached()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
GoalReached::~GoalReached()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void GoalReached::_init()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void GoalReached::_state_enter()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void GoalReached::_state_exit()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
74
src/goal/GoalReached.h
Normal file
74
src/goal/GoalReached.h
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
#ifndef ALAI_GOAL_REACHED
|
||||||
|
#define ALAI_GOAL_REACHED
|
||||||
|
|
||||||
|
#include "state_machine/State.h"
|
||||||
|
|
||||||
|
#include <Godot.hpp>
|
||||||
|
#include <Node.hpp>
|
||||||
|
#include <AnimatedSprite.hpp>
|
||||||
|
|
||||||
|
namespace godot
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @brief This class controls what happens when the goal flag is in the reached state.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class GoalReached : public State
|
||||||
|
{
|
||||||
|
GODOT_CLASS(GoalReached, State)
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* @brief The animated sprite of the Coin.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
AnimatedSprite *animated_sprite;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief This method registers classes with Godot.
|
||||||
|
*
|
||||||
|
* @details This method registers methods, properties, and signals with the Godot engine.
|
||||||
|
*/
|
||||||
|
static void _register_methods();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Construct a new GoalReached object.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
GoalReached();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Destroy the GoalReached object.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
~GoalReached();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initialize the class from Godot.
|
||||||
|
*
|
||||||
|
* @details This method is called just once when the Godot engine connects to the instance of the class.
|
||||||
|
*/
|
||||||
|
void _init();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Called when the collected state of the coin is entered.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void _state_enter();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Called when the collected state of the coin is exited.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void _state_exit();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Called when the animation of the collected coin has finished.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -12,6 +12,8 @@
|
|||||||
#include "coin/CoinNotCollected.h"
|
#include "coin/CoinNotCollected.h"
|
||||||
#include "coin/CoinCollected.h"
|
#include "coin/CoinCollected.h"
|
||||||
#include "coin/CoinCounter.h"
|
#include "coin/CoinCounter.h"
|
||||||
|
#include "goal/GoalReached.h"
|
||||||
|
#include "goal/GoalNotReached.h"
|
||||||
|
|
||||||
using namespace godot;
|
using namespace godot;
|
||||||
|
|
||||||
@ -55,4 +57,6 @@ extern "C" void GDN_EXPORT godot_nativescript_init(void *handle)
|
|||||||
register_class<CoinNotCollected>();
|
register_class<CoinNotCollected>();
|
||||||
register_class<CoinCollected>();
|
register_class<CoinCollected>();
|
||||||
register_class<CoinCounter>();
|
register_class<CoinCounter>();
|
||||||
|
register_class<GoalReached>();
|
||||||
|
register_class<GoalNotReached>();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user