mirror of
https://github.com/godotengine/gdnative-demos.git
synced 2026-01-01 05:48:13 +03:00
Some changes and Clang Format
This commit is contained in:
98
cpp/kinematic_character/.clang-format
Normal file
98
cpp/kinematic_character/.clang-format
Normal file
@@ -0,0 +1,98 @@
|
||||
---
|
||||
BasedOnStyle: LLVM
|
||||
# Commented out parameters are those with the same value as base LLVM style
|
||||
# We can uncomment them if we want to change their value, or enforce the
|
||||
# chosen value in case the base style changes (initial sync: Clang 3.9.1).
|
||||
...
|
||||
Language: Cpp
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: DontAlign
|
||||
# AlignConsecutiveAssignments: false
|
||||
# AlignConsecutiveDeclarations: false
|
||||
# AlignEscapedNewlinesLeft: false
|
||||
# AlignOperands: true
|
||||
AlignTrailingComments: false
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
# AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: true
|
||||
AllowShortFunctionsOnASingleLine: Inline
|
||||
AllowShortIfStatementsOnASingleLine: true
|
||||
# AllowShortLoopsOnASingleLine: false
|
||||
# AlwaysBreakAfterDefinitionReturnType: None
|
||||
# AlwaysBreakAfterReturnType: None
|
||||
# AlwaysBreakBeforeMultilineStrings: false
|
||||
# AlwaysBreakTemplateDeclarations: false
|
||||
# BinPackArguments: true
|
||||
# BinPackParameters: true
|
||||
# BraceWrapping:
|
||||
# AfterClass: false
|
||||
# AfterControlStatement: false
|
||||
# AfterEnum: false
|
||||
# AfterFunction: false
|
||||
# AfterNamespace: false
|
||||
# AfterObjCDeclaration: false
|
||||
# AfterStruct: false
|
||||
# AfterUnion: false
|
||||
# BeforeCatch: false
|
||||
# BeforeElse: false
|
||||
# IndentBraces: false
|
||||
# BreakBeforeBinaryOperators: None
|
||||
# BreakBeforeBraces: Attach
|
||||
BreakBeforeTernaryOperators: false
|
||||
# BreakConstructorInitializersBeforeComma: false
|
||||
# BreakAfterJavaFieldAnnotations: false
|
||||
# BreakStringLiterals: true
|
||||
ColumnLimit: 0
|
||||
# CommentPragmas: '^ IWYU pragma:'
|
||||
# ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
# ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 8
|
||||
Cpp11BracedListStyle: false
|
||||
# DerivePointerAlignment: false
|
||||
# DisableFormat: false
|
||||
# ExperimentalAutoDetectBinPacking: false
|
||||
# ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
|
||||
IncludeCategories:
|
||||
- Regex: '".*"'
|
||||
Priority: 1
|
||||
- Regex: '^<.*\.h>'
|
||||
Priority: 2
|
||||
- Regex: '^<.*'
|
||||
Priority: 3
|
||||
# IncludeIsMainRegex: '$'
|
||||
IndentCaseLabels: true
|
||||
IndentWidth: 4
|
||||
# IndentWrappedFunctionNames: false
|
||||
# JavaScriptQuotes: Leave
|
||||
# JavaScriptWrapImports: true
|
||||
# KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
# MacroBlockBegin: ''
|
||||
# MacroBlockEnd: ''
|
||||
# MaxEmptyLinesToKeep: 1
|
||||
# NamespaceIndentation: None
|
||||
ObjCBlockIndentWidth: 4
|
||||
# ObjCSpaceAfterProperty: false
|
||||
# ObjCSpaceBeforeProtocolList: true
|
||||
# PenaltyBreakBeforeFirstCallParameter: 19
|
||||
# PenaltyBreakComment: 300
|
||||
# PenaltyBreakFirstLessLess: 120
|
||||
# PenaltyBreakString: 1000
|
||||
# PenaltyExcessCharacter: 1000000
|
||||
# PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerAlignment: Right
|
||||
# ReflowComments: true
|
||||
SortIncludes: true
|
||||
# SpaceAfterCStyleCast: false
|
||||
# SpaceBeforeAssignmentOperators: true
|
||||
# SpaceBeforeParens: ControlStatements
|
||||
# SpaceInEmptyParentheses: false
|
||||
# SpacesBeforeTrailingComments: 1
|
||||
# SpacesInAngles: false
|
||||
# SpacesInContainerLiterals: true
|
||||
# SpacesInCStyleCastParentheses: false
|
||||
# SpacesInParentheses: false
|
||||
# SpacesInSquareBrackets: false
|
||||
Standard: Cpp03
|
||||
TabWidth: 4
|
||||
UseTab: Always
|
||||
...
|
||||
2
cpp/kinematic_character/.gitignore
vendored
Normal file
2
cpp/kinematic_character/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
GDNative-demo.*
|
||||
SConstruct
|
||||
98
cpp/kinematic_character/Script/.clang-format
Normal file
98
cpp/kinematic_character/Script/.clang-format
Normal file
@@ -0,0 +1,98 @@
|
||||
---
|
||||
BasedOnStyle: LLVM
|
||||
# Commented out parameters are those with the same value as base LLVM style
|
||||
# We can uncomment them if we want to change their value, or enforce the
|
||||
# chosen value in case the base style changes (initial sync: Clang 3.9.1).
|
||||
...
|
||||
Language: Cpp
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: DontAlign
|
||||
# AlignConsecutiveAssignments: false
|
||||
# AlignConsecutiveDeclarations: false
|
||||
# AlignEscapedNewlinesLeft: false
|
||||
# AlignOperands: true
|
||||
AlignTrailingComments: false
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
# AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: true
|
||||
AllowShortFunctionsOnASingleLine: Inline
|
||||
AllowShortIfStatementsOnASingleLine: true
|
||||
# AllowShortLoopsOnASingleLine: false
|
||||
# AlwaysBreakAfterDefinitionReturnType: None
|
||||
# AlwaysBreakAfterReturnType: None
|
||||
# AlwaysBreakBeforeMultilineStrings: false
|
||||
# AlwaysBreakTemplateDeclarations: false
|
||||
# BinPackArguments: true
|
||||
# BinPackParameters: true
|
||||
# BraceWrapping:
|
||||
# AfterClass: false
|
||||
# AfterControlStatement: false
|
||||
# AfterEnum: false
|
||||
# AfterFunction: false
|
||||
# AfterNamespace: false
|
||||
# AfterObjCDeclaration: false
|
||||
# AfterStruct: false
|
||||
# AfterUnion: false
|
||||
# BeforeCatch: false
|
||||
# BeforeElse: false
|
||||
# IndentBraces: false
|
||||
# BreakBeforeBinaryOperators: None
|
||||
# BreakBeforeBraces: Attach
|
||||
BreakBeforeTernaryOperators: false
|
||||
# BreakConstructorInitializersBeforeComma: false
|
||||
# BreakAfterJavaFieldAnnotations: false
|
||||
# BreakStringLiterals: true
|
||||
ColumnLimit: 0
|
||||
# CommentPragmas: '^ IWYU pragma:'
|
||||
# ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
# ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 8
|
||||
Cpp11BracedListStyle: false
|
||||
# DerivePointerAlignment: false
|
||||
# DisableFormat: false
|
||||
# ExperimentalAutoDetectBinPacking: false
|
||||
# ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
|
||||
IncludeCategories:
|
||||
- Regex: '".*"'
|
||||
Priority: 1
|
||||
- Regex: '^<.*\.h>'
|
||||
Priority: 2
|
||||
- Regex: '^<.*'
|
||||
Priority: 3
|
||||
# IncludeIsMainRegex: '$'
|
||||
IndentCaseLabels: true
|
||||
IndentWidth: 4
|
||||
# IndentWrappedFunctionNames: false
|
||||
# JavaScriptQuotes: Leave
|
||||
# JavaScriptWrapImports: true
|
||||
# KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
# MacroBlockBegin: ''
|
||||
# MacroBlockEnd: ''
|
||||
# MaxEmptyLinesToKeep: 1
|
||||
# NamespaceIndentation: None
|
||||
ObjCBlockIndentWidth: 4
|
||||
# ObjCSpaceAfterProperty: false
|
||||
# ObjCSpaceBeforeProtocolList: true
|
||||
# PenaltyBreakBeforeFirstCallParameter: 19
|
||||
# PenaltyBreakComment: 300
|
||||
# PenaltyBreakFirstLessLess: 120
|
||||
# PenaltyBreakString: 1000
|
||||
# PenaltyExcessCharacter: 1000000
|
||||
# PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerAlignment: Right
|
||||
# ReflowComments: true
|
||||
SortIncludes: true
|
||||
# SpaceAfterCStyleCast: false
|
||||
# SpaceBeforeAssignmentOperators: true
|
||||
# SpaceBeforeParens: ControlStatements
|
||||
# SpaceInEmptyParentheses: false
|
||||
# SpacesBeforeTrailingComments: 1
|
||||
# SpacesInAngles: false
|
||||
# SpacesInContainerLiterals: true
|
||||
# SpacesInCStyleCastParentheses: false
|
||||
# SpacesInParentheses: false
|
||||
# SpacesInSquareBrackets: false
|
||||
Standard: Cpp03
|
||||
TabWidth: 4
|
||||
UseTab: Always
|
||||
...
|
||||
Binary file not shown.
@@ -17,36 +17,30 @@
|
||||
#include <colworld.h>
|
||||
#include <Label.hpp>
|
||||
|
||||
NS_GODOT_BEGIN
|
||||
|
||||
ColWorld::ColWorld () {
|
||||
using namespace godot;
|
||||
|
||||
ColWorld::ColWorld() {
|
||||
}
|
||||
|
||||
ColWorld::~ColWorld () {
|
||||
|
||||
ColWorld::~ColWorld() {
|
||||
}
|
||||
|
||||
void ColWorld::_init () {
|
||||
|
||||
void ColWorld::_init() {
|
||||
}
|
||||
|
||||
void ColWorld::_ready() {
|
||||
owner->get_node ("princess")->connect ("body_entered", owner, "_on_princess_body_enter");
|
||||
owner->get_node("princess")->connect("body_entered", owner, "_on_princess_body_enter");
|
||||
}
|
||||
|
||||
void ColWorld::_on_princess_body_enter (KinematicBody2D *body) {
|
||||
if (body->get_name () == "Character") {
|
||||
((Label*) owner->get_node ("youwin"))->show ();
|
||||
void ColWorld::_on_princess_body_enter(KinematicBody2D *body) {
|
||||
if (body->get_name() == "Character") {
|
||||
((Label *)owner->get_node("youwin"))->show();
|
||||
}
|
||||
}
|
||||
|
||||
void ColWorld::_register_methods () {
|
||||
register_method((char*)"_init", &ColWorld::_init);
|
||||
register_method((char*)"_ready", &ColWorld::_ready);
|
||||
void ColWorld::_register_methods() {
|
||||
register_method((char *)"_init", &ColWorld::_init);
|
||||
register_method((char *)"_ready", &ColWorld::_ready);
|
||||
|
||||
register_method((char*)"_on_princess_body_enter", &ColWorld::_on_princess_body_enter);
|
||||
register_method((char *)"_on_princess_body_enter", &ColWorld::_on_princess_body_enter);
|
||||
}
|
||||
|
||||
NS_GODOT_END
|
||||
|
||||
|
||||
@@ -17,12 +17,11 @@
|
||||
#ifndef COLWORLD_H
|
||||
#define COLWORLD_H
|
||||
|
||||
#include <common.h>
|
||||
#include <Godot.hpp>
|
||||
#include <Node2D.hpp>
|
||||
#include <KinematicBody2D.hpp>
|
||||
#include <Node2D.hpp>
|
||||
|
||||
NS_GODOT_BEGIN
|
||||
namespace godot {
|
||||
|
||||
class ColWorld : public GodotScript<Node2D> {
|
||||
GODOT_CLASS(ColWorld)
|
||||
@@ -35,9 +34,8 @@ public:
|
||||
void _ready();
|
||||
void _on_princess_body_enter(KinematicBody2D *body);
|
||||
|
||||
static void _register_methods ();
|
||||
static void _register_methods();
|
||||
};
|
||||
|
||||
NS_GODOT_END
|
||||
}
|
||||
|
||||
#endif // COLWORLD_H
|
||||
|
||||
@@ -15,21 +15,16 @@
|
||||
**/
|
||||
|
||||
#include <Godot.hpp>
|
||||
#include <common.h>
|
||||
|
||||
#include <player.h>
|
||||
#include <colworld.h>
|
||||
#include <player.h>
|
||||
|
||||
NS_GODOT_BEGIN
|
||||
using namespace godot;
|
||||
|
||||
GODOT_NATIVE_INIT(godot_native_init_options *options) {
|
||||
register_class<GDPlayer>();
|
||||
register_class<ColWorld>();
|
||||
}
|
||||
|
||||
GODOT_NATIVE_TERMINATE (godot_native_init_options *options) {
|
||||
|
||||
GODOT_NATIVE_TERMINATE(godot_native_init_options *options) {
|
||||
}
|
||||
|
||||
NS_GODOT_END
|
||||
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
/**
|
||||
* Copyright 2017 RameshRavone. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <stdio.h>
|
||||
|
||||
#define NS_GODOT_BEGIN namespace godot {
|
||||
#define NS_GODOT_END }
|
||||
#define USING_NS_GODOT using namespace godot;
|
||||
|
||||
#define WORLD_GRAVITY 9.8;
|
||||
|
||||
#endif // COMMON_H
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
#include <player.h>
|
||||
|
||||
#include <Input.hpp>
|
||||
#include <AnimatedSprite.hpp>
|
||||
#include <Input.hpp>
|
||||
#include <cmath>
|
||||
|
||||
NS_GODOT_BEGIN
|
||||
using namespace godot;
|
||||
|
||||
const static float _gravity = 500.0;
|
||||
|
||||
@@ -36,50 +36,38 @@ const static float _slide_stop_velocity = 1.0;
|
||||
const static float _slide_stop_min_travel = 1.0;
|
||||
|
||||
template <typename T>
|
||||
int sign (const T &val) { return (val > 0) - (val < 0); }
|
||||
int sign(const T &val) {
|
||||
return (val > 0) - (val < 0);
|
||||
}
|
||||
|
||||
GDPlayer::GDPlayer() {
|
||||
|
||||
}
|
||||
|
||||
GDPlayer::~GDPlayer () {
|
||||
|
||||
GDPlayer::~GDPlayer() {
|
||||
}
|
||||
|
||||
void GDPlayer::_init () {
|
||||
void GDPlayer::_init() {
|
||||
Vector2 _force = Vector2();
|
||||
|
||||
_jumping = false;
|
||||
_on_air_time = 100.0;
|
||||
_on_air_time = 0.0;
|
||||
_current_anim = "Default";
|
||||
}
|
||||
|
||||
void GDPlayer::_ready () {
|
||||
ray0 = ((RayCast2D*) owner->get_node ("Ray0"));
|
||||
ray1 = ((RayCast2D*) owner->get_node ("Ray1"));
|
||||
void GDPlayer::_ready() {
|
||||
ray0 = ((RayCast2D *)owner->get_node("Ray0"));
|
||||
ray1 = ((RayCast2D *)owner->get_node("Ray1"));
|
||||
|
||||
ray0->add_exception (owner);
|
||||
ray1->add_exception (owner);
|
||||
|
||||
_owner = owner;
|
||||
_is_ready = true;
|
||||
|
||||
std::printf("Owner class: %s\n", owner->get_class ().c_string ());
|
||||
Godot::print ("on Ready");
|
||||
ray0->add_exception(owner);
|
||||
ray1->add_exception(owner);
|
||||
}
|
||||
|
||||
void GDPlayer::_input (InputEvent *event) {
|
||||
|
||||
}
|
||||
|
||||
void GDPlayer::_fixed_process (const float delta) {
|
||||
if (!_is_ready) { return; }
|
||||
|
||||
void GDPlayer::_fixed_process(const float delta) {
|
||||
Vector2 _force = Vector2(0, _gravity);
|
||||
|
||||
bool left = Input::is_action_pressed ("ui_left");
|
||||
bool right = Input::is_action_pressed ("ui_right");
|
||||
bool jump = Input::is_action_pressed ("ui_up");
|
||||
bool left = Input::is_action_pressed("ui_left");
|
||||
bool right = Input::is_action_pressed("ui_right");
|
||||
bool jump = Input::is_action_pressed("ui_up");
|
||||
|
||||
bool stop = true;
|
||||
|
||||
@@ -101,7 +89,9 @@ void GDPlayer::_fixed_process (const float delta) {
|
||||
|
||||
vlen -= _stop_force * delta;
|
||||
|
||||
if (vlen < 0) { vlen = 0; }
|
||||
if (vlen < 0) {
|
||||
vlen = 0;
|
||||
}
|
||||
|
||||
_velocity.x = (vlen * vsign);
|
||||
}
|
||||
@@ -109,12 +99,11 @@ void GDPlayer::_fixed_process (const float delta) {
|
||||
// Integrate forces to velocity
|
||||
_velocity += _force * delta;
|
||||
// Integrate velocity into motion and move
|
||||
_velocity = owner->move_and_slide (_velocity, Vector2(0, -1));
|
||||
_velocity = owner->move_and_slide(_velocity, Vector2(0, -1));
|
||||
|
||||
Vector2 _floor_velocity = Vector2();
|
||||
bool floor_colliding = (ray0->is_colliding () || ray1->is_colliding ());
|
||||
bool floor_colliding = (ray0->is_colliding() || ray1->is_colliding());
|
||||
|
||||
if (_owner->is_on_floor ()) {
|
||||
if (owner->is_on_floor()) {
|
||||
_on_air_time = 0;
|
||||
}
|
||||
|
||||
@@ -126,43 +115,49 @@ void GDPlayer::_fixed_process (const float delta) {
|
||||
_on_air_time += delta;
|
||||
_prev_jump_pressed = jump;
|
||||
|
||||
/**
|
||||
* @brief Animating
|
||||
*
|
||||
* The following show's how to get the child nodes and access there functions..
|
||||
*/
|
||||
|
||||
bool animating = false;
|
||||
|
||||
if (left) {
|
||||
((AnimatedSprite*) owner->get_node ("AnimatedSprite"))->set_flip_h (true);
|
||||
if (floor_colliding) { _current_anim = "Run"; }
|
||||
((AnimatedSprite *)owner->get_node("AnimatedSprite"))->set_flip_h(true);
|
||||
if (floor_colliding) {
|
||||
_current_anim = "Run";
|
||||
}
|
||||
animating = true;
|
||||
}
|
||||
if (right) {
|
||||
((AnimatedSprite*) owner->get_node ("AnimatedSprite"))->set_flip_h (false);
|
||||
if (floor_colliding) { _current_anim = "Run"; }
|
||||
((AnimatedSprite *)owner->get_node("AnimatedSprite"))->set_flip_h(false);
|
||||
if (floor_colliding) {
|
||||
_current_anim = "Run";
|
||||
}
|
||||
animating = true;
|
||||
}
|
||||
|
||||
if (!floor_colliding) {
|
||||
if (_velocity.y > 0) { _current_anim = "JumpDown"; }
|
||||
if (_velocity.y < 0) { _current_anim = "JumpUp"; }
|
||||
} else if (!animating) { _current_anim = "Default"; }
|
||||
if (_velocity.y > 0) {
|
||||
_current_anim = "JumpDown";
|
||||
}
|
||||
if (_velocity.y < 0) {
|
||||
_current_anim = "JumpUp";
|
||||
}
|
||||
} else if (!animating) {
|
||||
_current_anim = "Default";
|
||||
}
|
||||
|
||||
|
||||
((AnimatedSprite*) owner->get_node ("AnimatedSprite"))->play (_current_anim);
|
||||
((AnimatedSprite *)owner->get_node("AnimatedSprite"))->play(_current_anim);
|
||||
}
|
||||
|
||||
void GDPlayer::_process (const float delta) {
|
||||
void GDPlayer::_register_methods() {
|
||||
|
||||
}
|
||||
register_method((char *)"_init", &GDPlayer::_init);
|
||||
register_method((char *)"_ready", &GDPlayer::_ready);
|
||||
|
||||
void GDPlayer::_register_methods () {
|
||||
|
||||
register_method((char*)"_init", &GDPlayer::_init);
|
||||
register_method((char*)"_ready", &GDPlayer::_ready);
|
||||
|
||||
register_method((char*)"_input", &GDPlayer::_input);
|
||||
//register_method((char*)"_process", &GDPlayer::_process);
|
||||
register_method((char*)"_fixed_process", &GDPlayer::_fixed_process);
|
||||
register_method((char *)"_fixed_process", &GDPlayer::_fixed_process);
|
||||
|
||||
register_signal<GDPlayer>("move");
|
||||
}
|
||||
|
||||
NS_GODOT_END
|
||||
|
||||
|
||||
@@ -18,14 +18,13 @@
|
||||
#define PLAYER_H
|
||||
|
||||
#include <Godot.hpp>
|
||||
#include <common.h>
|
||||
|
||||
#include <InputEvent.hpp>
|
||||
#include <RayCast2D.hpp>
|
||||
|
||||
#include <KinematicBody2D.hpp>
|
||||
|
||||
NS_GODOT_BEGIN
|
||||
using namespace godot;
|
||||
|
||||
class GDPlayer : public GodotScript<KinematicBody2D> {
|
||||
GODOT_CLASS(GDPlayer)
|
||||
@@ -37,16 +36,12 @@ public:
|
||||
void _init();
|
||||
void _ready();
|
||||
|
||||
void _input(InputEvent *event);
|
||||
void _fixed_process(const float delta);
|
||||
|
||||
void _process (const float delta);
|
||||
void _fixed_process (const float delta);
|
||||
|
||||
static void _register_methods ();
|
||||
static void _register_methods();
|
||||
|
||||
private:
|
||||
bool _jumping;
|
||||
bool _is_ready;
|
||||
bool _prev_jump_pressed;
|
||||
|
||||
float _on_air_time;
|
||||
@@ -56,10 +51,6 @@ private:
|
||||
|
||||
RayCast2D *ray0;
|
||||
RayCast2D *ray1;
|
||||
|
||||
KinematicBody2D *_owner;
|
||||
};
|
||||
|
||||
NS_GODOT_END
|
||||
|
||||
#endif // PLAYER_H_
|
||||
|
||||
Reference in New Issue
Block a user