mirror of
https://github.com/Heretek-AI/GDevelop.git
synced 2026-07-21 17:45:25 -04:00
29ad7308c3
- This is an AI agent that takes a request and takes actions on a project: it can create scenes, find and create objects, add, remove behaviors, modify them, put instances on the scene, create or modify events, and more to come (layers, setup leaderboards, etc...). - It's still in beta and there is room for improvement on many things, but is already useful for prototyping and learning - beginners notably are able to see what the AI can do and learn the concepts of GDevelop. For intermediate and power users, it's useful to try new things, or get things done while working on something else. - Experiment with it and always make backup of your project before starting - in the future restoration points will be added to go back to a previous state if the result is not good or broken.
240 lines
9.7 KiB
C++
240 lines
9.7 KiB
C++
/**
|
|
|
|
GDevelop - Platform Behavior Extension
|
|
Copyright (c) 2014-2016 Florian Rival (Florian.Rival@gmail.com)
|
|
This project is released under the MIT License.
|
|
*/
|
|
|
|
#include "PlatformerObjectBehavior.h"
|
|
|
|
#include <iostream>
|
|
#include <map>
|
|
#include <memory>
|
|
|
|
#include "GDCore/CommonTools.h"
|
|
#include "GDCore/Project/Layout.h"
|
|
#include "GDCore/Project/MeasurementUnit.h"
|
|
#include "GDCore/Project/PropertyDescriptor.h"
|
|
#include "GDCore/Serialization/SerializerElement.h"
|
|
#include "GDCore/Tools/Localization.h"
|
|
#include "PlatformBehavior.h"
|
|
|
|
void PlatformerObjectBehavior::InitializeContent(
|
|
gd::SerializerElement& behaviorContent) {
|
|
behaviorContent.SetAttribute("gravity", 1000);
|
|
behaviorContent.SetAttribute("maxFallingSpeed", 700);
|
|
behaviorContent.SetAttribute("ladderClimbingSpeed", 150);
|
|
behaviorContent.SetAttribute("acceleration", 1500);
|
|
behaviorContent.SetAttribute("deceleration", 1500);
|
|
behaviorContent.SetAttribute("maxSpeed", 250);
|
|
behaviorContent.SetAttribute("jumpSpeed", 600);
|
|
behaviorContent.SetAttribute("jumpSustainTime", 0.2);
|
|
behaviorContent.SetAttribute("ignoreDefaultControls", false);
|
|
behaviorContent.SetAttribute("slopeMaxAngle", 60);
|
|
behaviorContent.SetAttribute("canGrabPlatforms", false);
|
|
behaviorContent.SetAttribute("canGrabWithoutMoving", true);
|
|
behaviorContent.SetAttribute("yGrabOffset", 0);
|
|
behaviorContent.SetAttribute("xGrabTolerance", 10);
|
|
behaviorContent.SetAttribute("useLegacyTrajectory", false);
|
|
behaviorContent.SetAttribute("useRepeatedJump", false);
|
|
behaviorContent.SetAttribute("canGoDownFromJumpthru", true);
|
|
}
|
|
|
|
#if defined(GD_IDE_ONLY)
|
|
std::map<gd::String, gd::PropertyDescriptor>
|
|
PlatformerObjectBehavior::GetProperties(
|
|
const gd::SerializerElement& behaviorContent) const {
|
|
std::map<gd::String, gd::PropertyDescriptor> properties;
|
|
|
|
properties["Gravity"]
|
|
.SetLabel(_("Gravity"))
|
|
.SetGroup(_("Jump"))
|
|
.SetType("Number")
|
|
.SetMeasurementUnit(gd::MeasurementUnit::GetPixelAcceleration())
|
|
.SetValue(
|
|
gd::String::From(behaviorContent.GetDoubleAttribute("gravity")));
|
|
properties["JumpSpeed"]
|
|
.SetLabel(_("Jump speed"))
|
|
.SetGroup(_("Jump"))
|
|
.SetType("Number")
|
|
.SetMeasurementUnit(gd::MeasurementUnit::GetPixelSpeed())
|
|
.SetValue(
|
|
gd::String::From(behaviorContent.GetDoubleAttribute("jumpSpeed")));
|
|
properties["JumpSustainTime"]
|
|
.SetLabel(_("Jump sustain time"))
|
|
.SetQuickCustomizationVisibility(gd::QuickCustomization::Hidden)
|
|
.SetGroup(_("Jump"))
|
|
.SetType("Number")
|
|
.SetMeasurementUnit(gd::MeasurementUnit::GetSecond())
|
|
.SetValue(gd::String::From(
|
|
behaviorContent.GetDoubleAttribute("jumpSustainTime", 0)))
|
|
.SetDescription(
|
|
_("Maximum time (in seconds) during which the jump strength is "
|
|
"sustained if the jump key is held - allowing variable height "
|
|
"jumps."));
|
|
properties["MaxFallingSpeed"]
|
|
.SetLabel(_("Max. falling speed"))
|
|
.SetGroup(_("Jump"))
|
|
.SetType("Number")
|
|
.SetMeasurementUnit(gd::MeasurementUnit::GetPixelSpeed())
|
|
.SetValue(gd::String::From(
|
|
behaviorContent.GetDoubleAttribute("maxFallingSpeed")));
|
|
properties["LadderClimbingSpeed"]
|
|
.SetLabel(_("Ladder climbing speed"))
|
|
.SetQuickCustomizationVisibility(gd::QuickCustomization::Hidden)
|
|
.SetGroup(_("Ladder"))
|
|
.SetType("Number")
|
|
.SetMeasurementUnit(gd::MeasurementUnit::GetPixelSpeed())
|
|
.SetValue(gd::String::From(
|
|
behaviorContent.GetDoubleAttribute("ladderClimbingSpeed", 150)));
|
|
properties["Acceleration"]
|
|
.SetLabel(_("Acceleration"))
|
|
.SetGroup(_("Walk"))
|
|
.SetType("Number")
|
|
.SetMeasurementUnit(gd::MeasurementUnit::GetPixelAcceleration())
|
|
.SetValue(
|
|
gd::String::From(behaviorContent.GetDoubleAttribute("acceleration")));
|
|
properties["Deceleration"]
|
|
.SetLabel(_("Deceleration"))
|
|
.SetGroup(_("Walk"))
|
|
.SetType("Number")
|
|
.SetMeasurementUnit(gd::MeasurementUnit::GetPixelAcceleration())
|
|
.SetValue(
|
|
gd::String::From(behaviorContent.GetDoubleAttribute("deceleration")));
|
|
properties["MaxSpeed"]
|
|
.SetLabel(_("Max. speed"))
|
|
.SetGroup(_("Walk"))
|
|
.SetType("Number")
|
|
.SetMeasurementUnit(gd::MeasurementUnit::GetPixelSpeed())
|
|
.SetValue(
|
|
gd::String::From(behaviorContent.GetDoubleAttribute("maxSpeed")));
|
|
properties["IgnoreDefaultControls"]
|
|
.SetLabel(_("Disable default keyboard controls"))
|
|
.SetQuickCustomizationVisibility(gd::QuickCustomization::Hidden)
|
|
.SetValue(behaviorContent.GetBoolAttribute("ignoreDefaultControls")
|
|
? "true"
|
|
: "false")
|
|
.SetType("Boolean");
|
|
properties["SlopeMaxAngle"]
|
|
.SetLabel(_("Slope max. angle"))
|
|
.SetQuickCustomizationVisibility(gd::QuickCustomization::Hidden)
|
|
.SetGroup(_("Walk"))
|
|
.SetType("Number")
|
|
.SetMeasurementUnit(gd::MeasurementUnit::GetDegreeAngle())
|
|
.SetValue(gd::String::From(
|
|
behaviorContent.GetDoubleAttribute("slopeMaxAngle")));
|
|
properties["CanGrabPlatforms"]
|
|
.SetLabel(_("Can grab platform ledges"))
|
|
.SetQuickCustomizationVisibility(gd::QuickCustomization::Hidden)
|
|
.SetGroup(_("Ledge"))
|
|
.SetValue(behaviorContent.GetBoolAttribute("canGrabPlatforms", false)
|
|
? "true"
|
|
: "false")
|
|
.SetType("Boolean");
|
|
properties["CanGrabWithoutMoving"]
|
|
.SetLabel(_("Automatically grab platform ledges without having to move "
|
|
"horizontally"))
|
|
.SetQuickCustomizationVisibility(gd::QuickCustomization::Hidden)
|
|
.SetGroup(_("Ledge"))
|
|
.SetValue(behaviorContent.GetBoolAttribute("canGrabWithoutMoving", false)
|
|
? "true"
|
|
: "false")
|
|
.SetType("Boolean");
|
|
properties["YGrabOffset"]
|
|
.SetLabel(_("Grab offset on Y axis"))
|
|
.SetQuickCustomizationVisibility(gd::QuickCustomization::Hidden)
|
|
.SetGroup(_("Ledge"))
|
|
.SetType("Number")
|
|
.SetMeasurementUnit(gd::MeasurementUnit::GetPixel())
|
|
.SetValue(
|
|
gd::String::From(behaviorContent.GetDoubleAttribute("yGrabOffset")));
|
|
properties["XGrabTolerance"]
|
|
.SetLabel(_("Grab tolerance on X axis"))
|
|
.SetQuickCustomizationVisibility(gd::QuickCustomization::Hidden)
|
|
.SetGroup(_("Ledge"))
|
|
.SetType("Number")
|
|
.SetMeasurementUnit(gd::MeasurementUnit::GetPixel())
|
|
.SetValue(gd::String::From(
|
|
behaviorContent.GetDoubleAttribute("xGrabTolerance", 10)));
|
|
properties["UseLegacyTrajectory"]
|
|
.SetLabel(_("Use frame rate dependent trajectories "
|
|
"(deprecated — best left unchecked)"))
|
|
.SetGroup(_("Deprecated options"))
|
|
.SetDeprecated()
|
|
.SetValue(behaviorContent.GetBoolAttribute("useLegacyTrajectory", true)
|
|
? "true"
|
|
: "false")
|
|
.SetType("Boolean");
|
|
properties["UseRepeatedJump"]
|
|
.SetLabel(_("Allows repeated jumps while holding the jump key "
|
|
"(deprecated — best left unchecked)"))
|
|
.SetGroup(_("Deprecated options"))
|
|
.SetDeprecated()
|
|
.SetValue(behaviorContent.GetBoolAttribute("useRepeatedJump", true)
|
|
? "true"
|
|
: "false")
|
|
.SetType("Boolean");
|
|
properties["CanGoDownFromJumpthru"]
|
|
.SetLabel(_("Can go down from jumpthru platforms"))
|
|
.SetQuickCustomizationVisibility(gd::QuickCustomization::Hidden)
|
|
.SetGroup(_("Walk"))
|
|
.SetValue(behaviorContent.GetBoolAttribute("canGoDownFromJumpthru", false)
|
|
? "true"
|
|
: "false")
|
|
.SetType("Boolean");
|
|
return properties;
|
|
}
|
|
|
|
bool PlatformerObjectBehavior::UpdateProperty(
|
|
gd::SerializerElement& behaviorContent,
|
|
const gd::String& name,
|
|
const gd::String& value) {
|
|
if (name == "IgnoreDefaultControls")
|
|
behaviorContent.SetAttribute("ignoreDefaultControls", (value == "1"));
|
|
else if (name == "CanGrabPlatforms")
|
|
behaviorContent.SetAttribute("canGrabPlatforms", (value == "1"));
|
|
else if (name == "CanGrabWithoutMoving")
|
|
behaviorContent.SetAttribute("canGrabWithoutMoving", (value == "1"));
|
|
else if (name == "UseLegacyTrajectory")
|
|
behaviorContent.SetAttribute("useLegacyTrajectory", (value == "1"));
|
|
else if (name == "UseRepeatedJump")
|
|
behaviorContent.SetAttribute("useRepeatedJump", (value == "1"));
|
|
else if (name == "CanGoDownFromJumpthru")
|
|
behaviorContent.SetAttribute("canGoDownFromJumpthru", (value == "1"));
|
|
else if (name == "YGrabOffset")
|
|
behaviorContent.SetAttribute("yGrabOffset", value.To<double>());
|
|
else {
|
|
if (value.To<double>() < 0) return false;
|
|
|
|
if (name == "Gravity")
|
|
behaviorContent.SetAttribute("gravity", value.To<double>());
|
|
else if (name == "MaxFallingSpeed")
|
|
behaviorContent.SetAttribute("maxFallingSpeed", value.To<double>());
|
|
else if (name == "LadderClimbingSpeed")
|
|
behaviorContent.SetAttribute("ladderClimbingSpeed", value.To<double>());
|
|
else if (name == "Acceleration")
|
|
behaviorContent.SetAttribute("acceleration", value.To<double>());
|
|
else if (name == "Deceleration")
|
|
behaviorContent.SetAttribute("deceleration", value.To<double>());
|
|
else if (name == "MaxSpeed")
|
|
behaviorContent.SetAttribute("maxSpeed", value.To<double>());
|
|
else if (name == "JumpSpeed")
|
|
behaviorContent.SetAttribute("jumpSpeed", value.To<double>());
|
|
else if (name == "JumpSustainTime")
|
|
behaviorContent.SetAttribute("jumpSustainTime", value.To<double>());
|
|
else if (name == "SlopeMaxAngle") {
|
|
double newMaxAngle = value.To<double>();
|
|
if (newMaxAngle < 0 || newMaxAngle >= 90) return false;
|
|
|
|
behaviorContent.SetAttribute("slopeMaxAngle", newMaxAngle);
|
|
} else if (name == "XGrabTolerance")
|
|
behaviorContent.SetAttribute("xGrabTolerance", value.To<double>());
|
|
else
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
#endif
|