Compare commits

...

33 Commits

Author SHA1 Message Date
Chris Cromer 16fb77e0de Merge pull request 'develop' (#63) from develop into master
Reviewed-on: #63
2023-03-01 22:25:14 -03:00
Chris Cromer 33d9401445 Merge branch 'master' into develop 2023-03-01 22:25:08 -03:00
Chris Cromer 77d844c911 Merge pull request 'feature/finishing_touches' (#62) from feature/finishing_touches into develop
Reviewed-on: #62
2023-03-01 22:24:46 -03:00
Chris Cromer 368ca33006
prepare 1.1.0 2023-03-01 22:19:56 -03:00
Chris Cromer 9068d4fb25
enhance the AI movement process 2023-03-01 09:19:25 -03:00
Chris Cromer acf6ed6f73
update the knowledge base for the dreadtooth enemy type 2023-03-01 09:14:36 -03:00
Chris Cromer 4860855cc8
swap second shelly for a dreadtooth 2023-03-01 09:13:53 -03:00
Chris Cromer 354a3c6946 Merge pull request 'develop' (#61) from develop into master
Reviewed-on: #61
2023-02-26 21:49:11 -03:00
Chris Cromer bb56fff04e Merge branch 'master' into develop 2023-02-26 21:49:05 -03:00
Chris Cromer 27403e7e9a Merge pull request 'thesislvl' (#60) from thesislvl into develop
Reviewed-on: #60
2023-02-26 21:48:09 -03:00
Chris Cromer b84ed69198
integrate obelisk into alai 2023-02-26 21:45:25 -03:00
Martin Araneda 937e173fce thesis lvl fix 2023-02-22 23:12:21 -03:00
Martin Araneda 1a317042c2 New lvl and related config 2023-02-22 21:16:23 -03:00
Chris Cromer 3cc4252684 Merge pull request 'develop' (#59) from develop into master
Reviewed-on: #59
2022-10-10 22:37:32 -03:00
Chris Cromer 91b55ca6e1 Merge branch 'master' into develop 2022-10-10 22:37:26 -03:00
Chris Cromer 1e60846d3c Merge pull request 'remove license adding from pre-commit' (#58) from feature/copyright into develop
Reviewed-on: #58
2022-10-10 22:37:11 -03:00
Chris Cromer 498d575d29
remove license adding from pre-commit 2022-10-10 22:36:15 -03:00
Chris Cromer 581d8e71cf Merge pull request 'develop' (#57) from develop into master
Reviewed-on: #57
2022-10-10 22:05:25 -03:00
Chris Cromer dd58fac7a7 Merge branch 'master' into develop 2022-10-10 22:04:55 -03:00
Chris Cromer 17fe82323c Merge pull request 'add pre-commit hook' (#56) from feature/clang-format into develop
Reviewed-on: #56
2022-10-10 22:04:07 -03:00
Chris Cromer 364b9ac898 add pre-commit hook 2022-10-10 22:03:14 -03:00
Chris Cromer 298a21d516 Merge pull request 'develop' (#55) from develop into master
Reviewed-on: #55
2022-10-10 21:57:13 -03:00
Chris Cromer b76ef9cda5 Merge branch 'master' into develop 2022-10-10 21:57:04 -03:00
Chris Cromer 4482c8af6a Merge pull request 'feature/clang-format' (#54) from feature/clang-format into develop
Reviewed-on: #54
2022-10-10 21:56:16 -03:00
Chris Cromer 3b533fb03d
used clang-format to format the code 2022-10-10 21:54:12 -03:00
Chris Cromer 57cc75c249
add .clang-format 2022-10-10 21:25:56 -03:00
Chris Cromer 4298dfb4c0 Merge pull request 'disable monitor key if not debugging' (#53) from feature/disable_monitor_key into develop
Reviewed-on: #53
2022-09-22 16:48:44 -03:00
Chris Cromer 73b41dcde3
disable monitor key if not debugging 2022-09-22 16:47:51 -03:00
Chris Cromer dad3e6581a Merge pull request 'feature/anonymous_monitor' (#52) from feature/anonymous_monitor into develop
Reviewed-on: #52
2022-09-22 16:43:14 -03:00
Chris Cromer b8146bd002
allow anonymous player monitoring 2022-09-22 16:42:24 -03:00
Chris Cromer aae40bf6e7
update to version 1.1.0 2022-09-22 16:01:09 -03:00
Chris Cromer 7ecaa95045 Merge pull request 'fix bug that causes monitor's start time to be higher than 0 when entering player info' (#51) from feature/fix_monitor into develop
Reviewed-on: #51
2022-09-22 15:58:58 -03:00
Chris Cromer 0a54849e5f
fix bug that causes monitor's start time to be higher than 0 when entering player info 2022-09-03 22:46:35 -04:00
60 changed files with 2377 additions and 184 deletions

220
.clang-format Normal file
View File

@ -0,0 +1,220 @@
---
AccessModifierOffset: 0
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: Always
IndentAccessModifiers: true
TabWidth: 4
UseTab: Never
UseCRLF: false
Language: Cpp
IndentWidth: 4
AlignAfterOpenBracket: DontAlign
AlignArrayOfStructures: Left
AlignConsecutiveAssignments: AcrossComments
AlignConsecutiveBitFields: AcrossComments
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: AcrossComments
AlignEscapedNewlines: Left
AlignOperands: AlignAfterOperator
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: None
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: No
BinPackArguments: false
BinPackParameters: false
AttributeMacros:
- __capability
BitFieldColonSpacing: Both
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: Always
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: true
BeforeWhile: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBraces: Custom
BreakAfterJavaFieldAnnotations: false
BreakBeforeBinaryOperators: All
BreakBeforeConceptDeclarations: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterColon
BreakStringLiterals: false
ColumnLimit: 0
CommentPragmas: "^ IWYU pragma:"
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: true
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Regroup
IncludeCategories:
- Regex: ^<ext/.*\.h>
Priority: 2
CaseSensitive: false
SortPriority: 0
- Regex: ^<.*\.h>
Priority: 1
CaseSensitive: false
SortPriority: 0
- Regex: ^<.*
Priority: 2
CaseSensitive: false
SortPriority: 0
- Regex: .*
Priority: 0
CaseSensitive: false
SortPriority: 0
IncludeIsMainRegex: ([-_](test|unittest))?$
IncludeIsMainSourceRegex: ""
IndentCaseBlocks: true
IndentCaseLabels: true
IndentExternBlock: Indent
IndentGotoLabels: false
IndentPPDirectives: BeforeHash
IndentRequires: true
IndentWrappedFunctionNames: true
InsertTrailingCommas: None
JavaScriptQuotes: Double
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
LambdaBodyIndentation: OuterScope
MacroBlockBegin: ""
MacroBlockEnd: ""
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 4
ObjCBreakBeforeNestedBlockParam: false
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PPIndentWidth: 4
PackConstructorInitializers: Never
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyIndentedWhitespace: 0
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
QualifierAlignment: Left
RawStringFormats:
- Language: Cpp
BasedOnStyle: google
Delimiters:
- cc
- CC
- cpp
- Cpp
- CPP
- c++
- C++
CanonicalDelimiter: ""
- Language: TextProto
EnclosingFunctions:
- EqualsProto
- EquivToProto
- PARSE_PARTIAL_TEXT_PROTO
- PARSE_TEST_PROTO
- PARSE_TEXT_PROTO
- ParseTextOrDie
- ParseTextProtoOrDie
- ParseTestProto
- ParsePartialTestProto
BasedOnStyle: google
Delimiters:
- pb
- PB
- proto
- PROTO
CanonicalDelimiter: pb
ReferenceAlignment: Left
ReflowComments: false
RemoveBracesLLVM: false
SeparateDefinitionBlocks: Always
ShortNamespaceLines: 0
SortIncludes: CaseSensitive
SortJavaStaticImport: Before
SortUsingDeclarations: true
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: true
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: Custom
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: false
AfterFunctionDeclarationName: false
AfterFunctionDefinitionName: false
AfterIfMacros: false
AfterOverloadedOperator: true
BeforeNonEmptyParentheses: false
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: 1
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
- NS_SWIFT_NAME
- CF_SWIFT_NAME

28
.pre-commit-config.yaml Normal file
View File

@ -0,0 +1,28 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-case-conflict
- id: mixed-line-ending
- id: check-added-large-files
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: detect-private-key
- id: no-commit-to-branch
args: [--branch, master, --branch, develop]
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v15.0.7
hooks:
- id: clang-format
types_or: [c++, c]
args: ["-style=file"]
#- repo: https://github.com/pocc/pre-commit-hooks
# rev: v1.3.5
# hooks:
# - id: clang-tidy
# args: [-checks=clang-diagnostic-return-type]
# files: src/.*\.cpp

9
SConstruct Normal file → Executable file
View File

@ -37,6 +37,9 @@ godot_headers_path = "godot-cpp/godot-headers/"
cpp_bindings_path = "godot-cpp/"
cpp_library = "libgodot-cpp"
obelisk_bindings_path = "obelisk/"
obelisk_library = "libobelisk"
# Updates the environment with the option variables.
opts.Update(env)
@ -112,9 +115,9 @@ else:
cpp_library += '.' + str(env['bits'])
# make sure our binding library is properly includes
env.Append(CPPPATH=['.', godot_headers_path, cpp_bindings_path + 'include/', cpp_bindings_path + 'include/core/', cpp_bindings_path + 'include/gen/'])
env.Append(LIBPATH=[cpp_bindings_path + 'bin/'])
env.Append(LIBS=[cpp_library])
env.Append(CPPPATH=['.', obelisk_bindings_path + 'include/', godot_headers_path, cpp_bindings_path + 'include/', cpp_bindings_path + 'include/core/', cpp_bindings_path + 'include/gen/'])
env.Append(LIBPATH=[cpp_bindings_path + 'bin/', obelisk_bindings_path + 'bin/'])
env.Append(LIBS=[cpp_library, obelisk_library])
# tweak this if you want to use different folders, or more folders, to store your source code in.
env.Append(CPPPATH=['src/'])

View File

@ -1,14 +1,14 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://Main.gdns" type="Script" id=1]
[ext_resource path="res://levels/PrototypeR.tscn" type="PackedScene" id=2]
[ext_resource path="res://levels/TestLevel.tscn" type="PackedScene" id=2]
[ext_resource path="res://gui/GameOver.tscn" type="PackedScene" id=3]
[ext_resource path="res://gui/GameWon.tscn" type="PackedScene" id=4]
[node name="Main" type="Node"]
pause_mode = 2
script = ExtResource( 1 )
game_version = "1.0.0"
game_version = "1.1.0"
level = ExtResource( 2 )
[node name="Level" type="Node" parent="."]

BIN
godot/alai.kb Normal file

Binary file not shown.

View File

@ -6,6 +6,7 @@ export var direction = -1
export var detect_edges = true
export var speed = 25
export var gravity = 9.8
var timer := Timer.new()
func _ready() -> void:
@ -15,6 +16,12 @@ func _ready() -> void:
$FloorChecker.enabled = detect_edges
Event.connect("level_loaded", self, "_on_level_loaded")
add_child(timer)
timer.wait_time = 0.1
var err = timer.connect("timeout", self, "_on_timer_timeout")
if err == OK:
timer.start()
func _physics_process(_delta: float) -> void:
if is_on_wall() or not $FloorChecker.is_colliding() and is_on_floor() and $FloorChecker.enabled:
@ -41,3 +48,8 @@ func squash() -> void:
func _on_level_loaded() -> void:
Event.emit_signal("object_created", self.get_name(), "Walking", global_position, Vector2(0, 0))
func _on_timer_timeout() -> void:
Event.emit_signal("report_object", self.get_name(), "walking", global_position, velocity)
timer.start()

View 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 = "AI"
class_name = "AI"
library = ExtResource( 1 )

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=10 format=2]
[gd_scene load_steps=11 format=2]
[ext_resource path="res://characters/player/sprites/green.tres" type="SpriteFrames" id=1]
[ext_resource path="res://characters/player/states/Idle.gdns" type="Script" id=2]
@ -8,6 +8,7 @@
[ext_resource path="res://characters/player/states/Jump.gdns" type="Script" id=6]
[ext_resource path="res://characters/player/states/Fall.gdns" type="Script" id=7]
[ext_resource path="res://assets/sounds/jump.wav" type="AudioStream" id=8]
[ext_resource path="res://characters/player/AI.gdns" type="Script" id=9]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 7, 12 )
@ -16,6 +17,9 @@ extents = Vector2( 7, 12 )
collision_mask = 10
script = ExtResource( 5 )
[node name="AI" type="Node" parent="."]
script = ExtResource( 9 )
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
frames = ExtResource( 1 )
animation = "idle"

View File

@ -0,0 +1,17 @@
extends Area2D
var timer := Timer.new()
func _ready() -> void:
add_child(timer)
timer.wait_time = 0.1
var err = timer.connect("timeout", self, "_on_timer_timeout")
if err == OK:
timer.start()
func _on_timer_timeout() -> void:
Event.emit_signal("report_object", self.get_name(), "not collected", global_position, Vector2())
timer.start()

View File

@ -1,10 +1,11 @@
[gd_scene load_steps=11 format=2]
[gd_scene load_steps=12 format=2]
[ext_resource path="res://assets/coin.png" type="Texture" id=1]
[ext_resource path="res://state_machine/StateMachine.gdns" type="Script" id=2]
[ext_resource path="res://collectables/coin/states/CoinNotCollected.gdns" type="Script" id=3]
[ext_resource path="res://collectables/coin/states/CoinCollected.gdns" type="Script" id=4]
[ext_resource path="res://assets/sounds/coin.wav" type="AudioStream" id=5]
[ext_resource path="res://collectables/coin/Coin.gd" type="Script" id=6]
[sub_resource type="CircleShape2D" id=1]
radius = 6.0
@ -43,6 +44,7 @@ tracks/0/keys = {
[node name="Coin" type="Area2D"]
collision_layer = 4
script = ExtResource( 6 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( 9, 9 )
@ -51,7 +53,6 @@ shape = SubResource( 1 )
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
frames = SubResource( 4 )
animation = "spin"
frame = 1
playing = true
centered = false

17
godot/goal/Goal.gd Normal file
View File

@ -0,0 +1,17 @@
extends Area2D
var timer := Timer.new()
func _ready() -> void:
add_child(timer)
timer.wait_time = 0.1
var err = timer.connect("timeout", self, "_on_timer_timeout")
if err == OK:
timer.start()
func _on_timer_timeout() -> void:
Event.emit_signal("report_object", self.get_name(), "not touched", global_position, Vector2())
timer.start()

View File

@ -1,9 +1,10 @@
[gd_scene load_steps=9 format=2]
[gd_scene load_steps=10 format=2]
[ext_resource path="res://assets/flag.png" type="Texture" id=1]
[ext_resource path="res://goal/GoalNotReached.gdns" type="Script" id=2]
[ext_resource path="res://goal/GoalReached.gdns" type="Script" id=3]
[ext_resource path="res://state_machine/StateMachine.gdns" type="Script" id=4]
[ext_resource path="res://goal/Goal.gd" type="Script" id=5]
[sub_resource type="RectangleShape2D" id=5]
extents = Vector2( 10, 18 )
@ -25,15 +26,13 @@ animations = [ {
} ]
[node name="Goal" type="Area2D"]
position = Vector2( 324, 378 )
collision_layer = 32
script = ExtResource( 5 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( 18, 18 )
shape = SubResource( 5 )
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
position = Vector2( 18, 18 )
frames = SubResource( 8 )
animation = "flagmove"
playing = true

112
godot/levels/TestLevel.tmx Normal file
View File

@ -0,0 +1,112 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.8" tiledversion="1.8.0" orientation="orthogonal" renderorder="right-down" width="39" height="32" tilewidth="18" tileheight="18" infinite="0" nextlayerid="5" nextobjectid="1">
<tileset firstgid="1" source="../tilesets/tiles.tsx"/>
<layer id="4" name="Background" width="39" height="32">
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,18,19,19,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,18,39,39,39,39,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,38,39,39,39,39,39,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,58,59,98,59,59,59,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,97,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,117,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,117,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,127,89,0,0,0,0,0,138,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</data>
</layer>
<layer id="1" name="Middleground" width="39" height="32">
<data encoding="csv">
122,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,124,
122,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,124,
122,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,124,
122,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,124,
122,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,124,
122,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,124,
122,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,124,
122,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,124,
122,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,124,
122,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,124,
122,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,124,
122,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,124,
122,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,124,
122,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,124,
122,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,124,
122,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,124,
122,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,124,
142,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,144,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,
123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,
123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123
</data>
</layer>
<layer id="3" name="Foreground" width="39" height="32">
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,136,0,0,0,0,136,0,0,0,136,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,55,0,0,0,0,55,0,0,0,55,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,55,0,0,0,0,55,0,0,0,55,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,55,0,0,0,0,55,0,0,0,55,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,55,0,0,0,0,55,0,0,0,55,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,55,0,0,0,0,55,0,0,0,55,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,55,0,0,0,0,55,0,0,0,55,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,55,0,0,0,0,55,0,0,0,55,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,55,0,0,0,0,55,0,0,0,55,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,55,0,0,0,0,55,0,0,0,55,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,127,127,0,0,0,0,0,75,0,0,0,0,75,0,126,0,75,0,0,0,0,126,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,35,0,0,0,0,35,0,0,0,35,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,55,0,0,0,0,55,0,0,0,55,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,55,0,0,0,0,55,0,0,0,55,0,0,0,0,0,0
</data>
</layer>
</map>

View File

@ -0,0 +1,24 @@
[remap]
importer="vnen.tiled_importer"
type="PackedScene"
path="res://.import/TestLevel.tmx-6c18e110a6e6432fa76e1b0b7b8bc560.scn"
[deps]
source_file="res://levels/TestLevel.tmx"
dest_files=[ "res://.import/TestLevel.tmx-6c18e110a6e6432fa76e1b0b7b8bc560.scn" ]
[params]
custom_properties=true
tile_metadata=false
uv_clip=true
y_sort=true
image_flags=7
collision_layer=2
collision_mask=0
embed_internal_images=false
save_tiled_properties=false
add_background=true
post_import_script=""

View File

@ -0,0 +1,84 @@
[gd_scene load_steps=11 format=2]
[ext_resource path="res://characters/enemies/shelly/Shelly.tscn" type="PackedScene" id=1]
[ext_resource path="res://collectables/coin/Coin.tscn" type="PackedScene" id=2]
[ext_resource path="res://goal/Goal.tscn" type="PackedScene" id=3]
[ext_resource path="res://hud/CoinHUD.tscn" type="PackedScene" id=4]
[ext_resource path="res://characters/player/Player.tscn" type="PackedScene" id=5]
[ext_resource path="res://assets/music/prototype_r.ogg" type="AudioStream" id=6]
[ext_resource path="res://assets/backgrounds/hills.png" type="Texture" id=7]
[ext_resource path="res://levels/TestLevel.tmx" type="PackedScene" id=8]
[ext_resource path="res://CameraLimit.gdns" type="Script" id=9]
[ext_resource path="res://characters/enemies/dreadtooth/Dreadtooth.tscn" type="PackedScene" id=10]
[node name="TestLevel" type="Node2D"]
[node name="Player" parent="." instance=ExtResource( 5 )]
position = Vector2( 36, 498 )
collision_layer = 5
[node name="Camera2D" type="Camera2D" parent="Player"]
current = true
limit_left = 0
limit_top = 0
limit_right = 512
limit_bottom = 288
drag_margin_h_enabled = true
drag_margin_v_enabled = true
__meta__ = {
"_edit_bone_": true
}
[node name="VisibilityNotifier2D" type="VisibilityNotifier2D" parent="Player/Camera2D"]
rect = Rect2( 0, 0, 24, 24 )
[node name="ParallaxBackground" type="ParallaxBackground" parent="."]
[node name="ParallaxLayer" type="ParallaxLayer" parent="ParallaxBackground"]
motion_scale = Vector2( 0.2, 0.1 )
motion_offset = Vector2( 0, -288 )
motion_mirroring = Vector2( 528, 0 )
[node name="Sprite" type="Sprite" parent="ParallaxBackground/ParallaxLayer"]
texture = ExtResource( 7 )
centered = false
[node name="Map" type="Node2D" parent="."]
[node name="TestLevel" parent="Map" instance=ExtResource( 8 )]
script = ExtResource( 9 )
[node name="CoinHUD" parent="." instance=ExtResource( 4 )]
[node name="Coins" type="Node" parent="."]
[node name="Coin" parent="Coins" instance=ExtResource( 2 )]
position = Vector2( 144, 504 )
[node name="Coin5" parent="Coins" instance=ExtResource( 2 )]
position = Vector2( 270, 468 )
[node name="Coin7" parent="Coins" instance=ExtResource( 2 )]
position = Vector2( 216, 504 )
[node name="Coin8" parent="Coins" instance=ExtResource( 2 )]
position = Vector2( 459, 468 )
[node name="Coin9" parent="Coins" instance=ExtResource( 2 )]
position = Vector2( 560, 468 )
[node name="BGM" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 6 )
volume_db = -25.0
autoplay = true
[node name="Goal" parent="." instance=ExtResource( 3 )]
position = Vector2( 656, 504 )
[node name="Enemies" type="Node" parent="."]
[node name="Shelly" parent="Enemies" instance=ExtResource( 1 )]
position = Vector2( 379, 510 )
[node name="Dreadtooth" parent="Enemies" instance=ExtResource( 10 )]
position = Vector2( 640, 510 )

View File

@ -2,6 +2,7 @@ extends Node
export var monitor_enabled: bool = false
export var anonymous: bool = true
export var debug: bool = false
export var development_url: String = "http://localhost:4050/api/v1"
var url_real: String = "https://alai.cromer.cl/api/v1"
@ -58,9 +59,10 @@ func _ready() -> void:
game_version = get_parent().game_version
player["rut"] = ""
player["name"] = ""
player["email"] = ""
if not anonymous:
player["rut"] = ""
player["name"] = ""
player["email"] = ""
var os_name = OS.get_name()
if os_name == "Android":
@ -82,7 +84,8 @@ func _ready() -> void:
else:
os_id = 0
game["player"] = player
if not anonymous:
game["player"] = player
game["level_id"] = 0
game["os_id"] = os_id
game["godot_version"] = godot_version
@ -108,9 +111,15 @@ func _ready() -> void:
func _physics_process(_delta: float) -> void:
if monitor_enabled:
if has_node("MonitorGUI") and not $MonitorGUI.visible:
$MonitorGUI.visible = true
if anonymous and has_node("MonitorGUI"):
$MonitorGUI.queue_free()
Event.emit_signal("monitor_loaded")
get_tree().paused = false
start_monitor()
else:
if has_node("MonitorGUI") and not $MonitorGUI.visible:
$MonitorGUI.visible = true
Event.emit_signal("monitor_loaded")
if started and not get_tree().paused:
var frame = empty_frame.duplicate(true)
@ -124,11 +133,11 @@ func _physics_process(_delta: float) -> void:
frames.append(frame)
if Input.is_action_just_pressed("Send"):
if debug and Input.is_action_just_pressed("Send"):
stop_monitor()
send_data()
else:
if Input.is_action_just_pressed("Send"):
if debug and Input.is_action_just_pressed("Send"):
start_monitor()
else:
get_tree().paused = false
@ -137,11 +146,13 @@ func _physics_process(_delta: float) -> void:
func _on_input_validated(validated_player: Dictionary) -> void:
$MonitorGUI.queue_free()
get_tree().paused = false
Event.emit_signal("game_started")
player = validated_player.duplicate(true)
game["player"] = player
if not anonymous:
$MonitorGUI.queue_free()
get_tree().paused = false
Event.emit_signal("game_started")
player = validated_player.duplicate(true)
game["player"] = player
start_monitor()
func _object_created(name: String, state: String, position: Vector2, velocity: Vector2) -> void:

17
obelisk/alai.obk Normal file
View File

@ -0,0 +1,17 @@
fact("coin" is "gold");
rule("gold coin" is "collectable" if "coin" is "gold");
fact("goal" is "touchable");
fact("shelly" is "dangerous");
fact("shelly" is "bouncable");
fact("shelly" can "walk");
fact("dreadtooth" is "dangerous");
fact("dreadtooth" can "walk");
action(if "shelly" is "bouncable" then "jump on" else "jump over");
action(if "dreadtooth" is "bouncable" then "jump on" else "jump over");
action(if "coin" is "collectable" then "collect" else "avoid");
action(if "goal" is "touchable" then "touch" else "avoid");

View File

@ -0,0 +1,292 @@
#ifndef OBELISK_KNOWLEDGE_BASE_H
#define OBELISK_KNOWLEDGE_BASE_H
#include "models/action.h"
#include "models/entity.h"
#include "models/fact.h"
#include "models/rule.h"
#include "models/suggest_action.h"
#include "models/verb.h"
#include <sqlite3.h>
#include <functional>
#include <iostream>
#include <memory>
#include <string>
namespace obelisk
{
/**
* @brief The KnowledgeBase class represents a collection of facts, rules,
* actions, and related language connectors.
*
*/
class KnowledgeBase
{
private:
/**
* @brief The filename of the opened KnowledgeBase.
*
*/
const char* filename_;
/**
* @brief The SQLite connection handle.
*
*/
sqlite3* dbConnection_ = nullptr;
/**
* @brief The user passed flags to use when opening the database.
*
*/
int flags_;
/**
* @brief Enable foreign key functionality in the open database.
*
* This must always be done when the connection is opened or it will
* not enforce the foreign key constraints.
*/
void enableForeignKeys();
/**
* @brief Create the tables in the database.
*
* @param[in] function This function is called to create the table.
*/
void createTable(std::function<const char*()> function);
public:
/**
* @brief Construct a new KnowledgeBase object.
*
* @param[in] filename The name of the file to save the knowledge
* base as.
* @param[in] flags The flags to open the KnowledgeBase with.
*/
KnowledgeBase(const char* filename, int flags);
/**
* @brief Construct a new KnowledgeBase object.
*
* @param[in] filename The name of the file to save the knowledge
* base as.
*/
KnowledgeBase(const char* filename) :
KnowledgeBase(filename,
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)
{
}
/**
* @brief Destroy the KnowledgeBase object.
*
* This will close the opened KnowledgeBase before destroying it.
*/
~KnowledgeBase();
/**
* @brief Add entities to the KnowledgeBase.
*
* @param[in,out] entities The entities to add. If the insert is
* successful it will have a row ID, if not the ID will be 0.
*/
void addEntities(std::vector<obelisk::Entity>& entities);
/**
* @brief Add verbs to the KnowledgeBase.
*
* @param[in,out] verbs The verbs to add. If the insert is
* successful it will have a row ID, if not the ID will be 0.
*/
void addVerbs(std::vector<obelisk::Verb>& verbs);
/**
* @brief Add actions to the KnowledgeBase.
*
* @param[in,out] actions The actions to add. If the insert is
* successful it will have a row ID, if nto the ID will be 0.
*/
void addActions(std::vector<obelisk::Action>& actions);
/**
* @brief Add facts to the KnowledgeBase.
*
* @param[in,out] facts The facts to add. If the insert is
* successful it will have a row ID, if not the ID will be 0.
*/
void addFacts(std::vector<obelisk::Fact>& facts);
/**
* @brief Add suggested actions to the KnowledgeBase.
*
* @param[in,out] suggestActions The suggested actions to add. If
* the insert is successful it will have a row ID, if not the ID
* will be 0.
*/
void addSuggestActions(
std::vector<obelisk::SuggestAction>& suggestActions);
/**
* @brief Add rules to the KnowledgeBase.
*
* @param[in,out] rules The rules to add. If the insert is
* successful it will have a row ID, if not the ID will be 0.
*/
void addRules(std::vector<obelisk::Rule>& rules);
/**
* @brief Get an Entity object based on the ID it contains.
*
* @param[in,out] entity The Entity object should contain just the
* ID and the rest will be filled in.
*/
void getEntity(obelisk::Entity& entity);
/**
* @brief Get a Verb object based on the ID it contains.
*
* @param[in,out] verb The Verb object should contain just the ID
* and the rest will be filled in.
*/
void getVerb(obelisk::Verb& verb);
/**
* @brief Get an Action based on the ID it contains.
*
* @param[in] action The Action object should contain just the ID
* and the rest will be filled in.
*/
void getAction(obelisk::Action& action);
/**
* @brief Get a Fact object based on the ID it contains.
*
* @param[in,out] fact The Fact object should contain just the ID
* and the rest will be filled in.
*/
void getFact(obelisk::Fact& fact);
/**
* @brief Get a SuggestAction based on the ID it contains.
*
* @param[in,out] suggestAction The SuggestAction object should
* contain just the ID and the rest will be filled in.
*/
void getSuggestAction(obelisk::SuggestAction& suggestAction);
/**
* @brief Get a Rule based on the ID it contains.
*
* @param[in,out] rule The Rule object should contain just the ID
* and the rest will be filled in.
*/
void getRule(obelisk::Rule& rule);
/**
* @brief Check if a rule looks for this Fact, if so update its
* truth.
*
* @param[in,out] fact The Fact to check for existing rules.
*/
void checkRule(obelisk::Fact& fact);
/**
* @brief Update the is true field in the KnowledgeBase.
*
* @param[in,out] fact The fact to update.
*/
void updateIsTrue(obelisk::Fact& fact);
/**
* @brief Query the KnowledgeBase to see if a Fact is true or false.
*
* @param[in] fact The Fact to check.
*/
void queryFact(obelisk::Fact& fact);
/**
* @brief Query the KnowledgeBase to get a suggested action based
* on a Fact.
* If a SuggestAction doesn't exist, it will return an empty Action.
*
* @param[in] fact The Fact to search for.
* @param[out] action The Action that is suggested to take.
*/
void querySuggestAction(obelisk::Fact& fact,
obelisk::Action& action);
/**
* @brief Take a float and divide it into 2 floats.
*
* This is useful to store doubles in SQLite since SQLite doesn't
* have a double type. Instead just store the 2 floats in the
* database. Then after selecting them combine them.
*
* @param[out] result1 The first float generated from the double.
* @param[out] result2 The second float generated from the double.
* @param[in] var The double to split into the 2 floats.
*/
void getFloat(float& result1, float& result2, double var);
/**
* @brief Combines 2 separated floats back into a double.
*
* This will recombine the separated floats from the getFloat
* method.
*
* @param[out] result The double generated from the combined floats.
* @param[in] var1 The first float to combine.
* @param[in] var2 The second float to combine.
*/
void getDouble(double& result, float var1, float var2);
};
/**
* @brief Exception thrown by the KnowledgeBase.
*
*/
class KnowledgeBaseException : public std::exception
{
private:
/**
* @brief The error message given.
*
*/
const std::string errorMessage_;
public:
/**
* @brief Construct a new KnowledgeBaseException object.
*
*/
KnowledgeBaseException() :
errorMessage_("an unknown error ocurred")
{
}
/**
* @brief Construct a new KnowledgeBaseException object.
*
* @param[in] errorMessage The error message given when thrown.
*/
KnowledgeBaseException(const std::string& errorMessage) :
errorMessage_(errorMessage)
{
}
/**
* @brief Get the error message that occurred.
*
* @return const char* Returns the error message.
*/
const char* what() const noexcept
{
return errorMessage_.c_str();
}
};
} // namespace obelisk
#endif

View File

@ -0,0 +1,128 @@
#ifndef OBELISK_MODELS_ACTION_H
#define OBELISK_MODELS_ACTION_H
#include <sqlite3.h>
#include <string>
namespace obelisk
{
/**
* @brief The Action model represents an action to take when a fact is true
* or false.
*
*/
class Action
{
private:
/**
* @brief The ID of the Action in the KnowledgeBase.
*
*/
int id_;
/**
* @brief The name of the Action.
*
*/
std::string name_;
public:
/**
* @brief Construct a new Action object.
*
*/
Action() :
id_(0),
name_("")
{
}
/**
* @brief Construct a new Action object.
*
* @param[in] id The ID of the Action.
*/
Action(int id) :
id_(id),
name_("")
{
}
/**
* @brief Construct a new Action object.
*
* @param[in] name The name of the Action.
*/
Action(std::string name) :
id_(0),
name_(name)
{
}
/**
* @brief Construct a new Action object.
*
* @param[in] id The ID of the Action.
* @param[in] name The name of the Action.
*/
Action(int id, std::string name) :
id_(id),
name_(name)
{
}
/**
* @brief Create the Action table in the KnowledgeBase.
*
* @return const char* Returns the query used to create the table.
*/
static const char* createTable();
/**
* @brief Get the ID of the Action.
*
* @return int& Returns the ID.
*/
int& getId();
/**
* @brief Set the ID of the Action.
*
* @param[in] id Set the ID of the Action.
*/
void setId(int id);
/**
* @brief Get the name of the Action.
*
* @return std::string& The Action name.
*/
std::string& getName();
/**
* @brief Set the name of the Action.
*
* @param[in] name The name of the Action.
*/
void setName(std::string name);
/**
* @brief Select an Action from the datbase based on the object
* name.
*
* @param[in] dbConnection The database connection to use.
*/
void selectByName(sqlite3* dbConnection);
/**
* @brief Insert an Action into the KnowledgeBase based on the
* object's fields.
*
* @param[in] dbConnection The database connection to use.
*/
void insert(sqlite3* dbConnection);
};
} // namespace obelisk
#endif

View File

@ -0,0 +1,128 @@
#ifndef OBELISK_MODELS_ENTITY_H
#define OBELISK_MODELS_ENTITY_H
#include <sqlite3.h>
#include <string>
namespace obelisk
{
/**
* @brief The Entity model represents either a left or right side entity,
* typically used in facts and rules.
*
*/
class Entity
{
private:
/**
* @brief The ID of the Entity in the KnowledgeBase.
*
*/
int id_;
/**
* @brief The name of the Entity.
*
*/
std::string name_;
public:
/**
* @brief Construct a new Entity object.
*
*/
Entity() :
id_(0),
name_("")
{
}
/**
* @brief Construct a new Entity object.
*
* @param[in] id The ID of the Entity.
*/
Entity(int id) :
id_(id),
name_("")
{
}
/**
* @brief Construct a new Entity object.
*
* @param[in] name The name of the Entity.
*/
Entity(std::string name) :
id_(0),
name_(name)
{
}
/**
* @brief Construct a new Entity object.
*
* @param[in] id The ID of the Entity.
* @param[in] name The name of the Entity.
*/
Entity(int id, std::string name) :
id_(id),
name_(name)
{
}
/**
* @brief Create the table in the KnowledgeBase.
*
* @return const char* Returns the query used to create the table.
*/
static const char* createTable();
/**
* @brief Get the ID of the Entity.
*
* @return int& Returns the ID.
*/
int& getId();
/**
* @brief Set the ID of the Entity.
*
* @param[in] id The ID of the Entity.
*/
void setId(int id);
/**
* @brief Get the name of the Entity.
*
* @return std::string& The name of the Entity.
*/
std::string& getName();
/**
* @brief Set the name of the Entity.
*
* @param[in] name The name of the Entity.
*/
void setName(std::string name);
/**
* @brief Select an Entity from the KnowledgeBase based on the
* object's name.
*
* @param[in] dbConnection The database connection to use.
*/
void selectByName(sqlite3* dbConnection);
/**
* @brief Insert an Entity into the KnowledgeBase based on the
* object's fields.
*
* @param[in] dbConnection The database connection to use.
*/
void insert(sqlite3* dbConnection);
};
} // namespace obelisk
#endif

View File

@ -0,0 +1,247 @@
#ifndef OBELISK_MODELS_FACT_H
#define OBELISK_MODELS_FACT_H
#include "models/action.h"
#include "models/entity.h"
#include "models/fact.h"
#include "models/verb.h"
#include <string>
namespace obelisk
{
/**
* @brief The Fact model represents truth in the releationship between two
* entities separated by a verb.
*
*/
class Fact
{
private:
/**
* @brief The ID of the Fact in the KnowledgeBase.
*
*/
int id_;
/**
* @brief The Entity from the left side of the expression.
*
*/
obelisk::Entity leftEntity_;
/**
* @brief The Entity from the right side of the expression.
*
*/
obelisk::Entity rightEntity_;
/**
* @brief The Verb that represents the relationship in the
* expression.
*
*/
obelisk::Verb verb_;
/**
* @brief Whether or not the fact is considered true or not.
*
*/
double isTrue_;
public:
/**
* @brief Construct a new Fact object.
*
*/
Fact() :
id_(0),
leftEntity_(),
rightEntity_(),
verb_(),
isTrue_(0)
{
}
/**
* @brief Construct a new Fact object.
*
* @param[in] id The ID of the Fact in the KnowledgeBase.
*/
Fact(int id) :
id_(id),
leftEntity_(),
rightEntity_(),
verb_(),
isTrue_(0)
{
}
/**
* @brief Construct a new Fact object.
*
* @param[in] leftEntity The Entity on the left side of the
* expression.
* @param[in] rightEntity The Entity on the right side of the
* expression.
* @param[in] verb The Verb separating the entities.
* @param[in] isTrue Whether or not the fact is true.
*/
Fact(obelisk::Entity leftEntity,
obelisk::Entity rightEntity,
obelisk::Verb verb,
double isTrue = 0) :
id_(0),
leftEntity_(leftEntity),
rightEntity_(rightEntity),
verb_(verb),
isTrue_(isTrue)
{
}
/**
* @brief Construct a new Fact object.
*
* @param[in] id The ID of the Fact in the KnowledgeBase.
* @param[in] leftEntity The Entity on the left side of the
* expression.
* @param[in] rightEntity The Entity on the right side of the
* expression.
* @param[in] verb The Verb separating the entities.
* @param[in] isTrue Whether or not the fact is true.
*/
Fact(int id,
obelisk::Entity leftEntity,
obelisk::Entity rightEntity,
obelisk::Verb verb,
double isTrue = 0) :
id_(id),
leftEntity_(leftEntity),
rightEntity_(rightEntity),
verb_(verb),
isTrue_(isTrue)
{
}
/**
* @brief Create the Fact table in the KnowledgeBase.
*
* @return const char* Returns the query used to create the table.
*/
static const char* createTable();
/**
* @brief Get the ID of the Fact
*
* @return int& Returns the ID.
*/
int& getId();
/**
* @brief Set the ID of the Fact.
*
* @param[in] id Set the ID of the Fact.
*/
void setId(int id);
/**
* @brief Get the left Entity object.
*
* @return Entity& The left Entity.
*/
Entity& getLeftEntity();
/**
* @brief Set the left Entity object.
*
* @param[in] leftEntity The left Entity to set.
*/
void setLeftEntity(obelisk::Entity leftEntity);
/**
* @brief Get the right Entity object.
*
* @return Entity& The right Entity.
*/
Entity& getRightEntity();
/**
* @brief Set the right Entity object.
*
* @param[in] rightEntity The right Entity to set.
*/
void setRightEntity(obelisk::Entity rightEntity);
/**
* @brief Get the Verb object.
*
* @return Verb& The Verb.
*/
Verb& getVerb();
/**
* @brief Set the Verb object.
*
* @param[in] verb The Verb.
*/
void setVerb(obelisk::Verb verb);
/**
* @brief Gets the isTrue value.
*
* @return true If the Fact is considered true.
* @return false If the Fact is considered false.
*/
double& getIsTrue();
/**
* @brief Set the Fact as true or false.
*
* @param[in] isTrue Whether or not the Fact is true.
*/
void setIsTrue(double isTrue);
/**
* @brief Select the Fact from the KnowledgeBase by IDs of the
* sub-objects.
*
* @param[in] dbConnection The database connection to use.
*/
void selectById(sqlite3* dbConnection);
/**
* @brief Select the Fact from the KnowledgeBase by the name's of
* the entities and verb.
*
* @param[in] dbConnection The database connection to use.
*/
void selectByName(sqlite3* dbConnection);
/**
* @brief Select an Action from the KnowledgeBase using the provided
* Fact.
*
* @param[in] dbConnection The database connection to use.
* @param[out] action The Action to take based on the provided fact.
*/
void selectActionByFact(sqlite3* dbConnection,
obelisk::Action& action);
/**
* @brief Insert the Fact into the KnowledgeBase.
*
* @param[in] dbConnection The database connection to use.
*/
void insert(sqlite3* dbConnection);
/**
* @brief Update whether or not the fact is true in the
* KnowledgeBase.
*
* @param[in] dbConnection The database connection.
*/
void updateIsTrue(sqlite3* dbConnection);
};
} // namespace obelisk
#endif

View File

@ -0,0 +1,163 @@
#ifndef OBELISK_MODELS_RULE_H
#define OBELISK_MODELS_RULE_H
#include "models/fact.h"
#include <string>
#include <vector>
namespace obelisk
{
/**
* @brief The Rule model represents a truth relation between 2 Facts.
*
*/
class Rule
{
private:
/**
* @brief The ID of the Rule in the KnowledgeBase.
*
*/
int id_;
/**
* @brief The Fact that depends on the Fact reason being true.
*
*/
obelisk::Fact fact_;
/**
* @brief The Fact that makes the other Fact true or false.
*
*/
obelisk::Fact reason_;
public:
/**
* @brief Construct a new Rule object.
*
*/
Rule() :
id_(0),
fact_(),
reason_()
{
}
/**
* @brief Construct a new Rule object.
*
* @param[in] id The ID of the Rule in the KnowledgeBase.
*/
Rule(int id) :
id_(id),
fact_(),
reason_()
{
}
/**
* @brief Construct a new Rule object.
*
* @param[in] fact The Fact.
* @param[in] reason The reason Fact.
*/
Rule(obelisk::Fact fact, obelisk::Fact reason) :
id_(0),
fact_(fact),
reason_(reason)
{
}
/**
* @brief Construct a new Rule object.
*
* @param[in] id The ID of the Rule.
* @param[in] fact The Fact.
* @param[in] reason The reason Fact.
*/
Rule(int id, obelisk::Fact fact, obelisk::Fact reason) :
id_(id),
fact_(fact),
reason_(reason)
{
}
/**
* @brief Create the Rule table in the KnowledgeBase.
*
* @return const char* Returns the query used to create the table.
*/
static const char* createTable();
/**
* @brief Get the ID of the Rule.
*
* @return int& The ID.
*/
int& getId();
/**
* @brief Set the ID of the Rule.
*
* @param[in] id The ID.
*/
void setId(int id);
/**
* @brief Get the Fact object.
*
* @return obelisk::Fact& The Fact.
*/
obelisk::Fact& getFact();
/**
* @brief Set the Fact object.
*
* @param[in] fact The Fact.
*/
void setFact(obelisk::Fact fact);
/**
* @brief Get the reason Fact object.
*
* @return obelisk::Fact& The reason Fact.
*/
obelisk::Fact& getReason();
/**
* @brief Set the reason Fact object.
*
* @param[in] reason The reason Fact.
*/
void setReason(obelisk::Fact reason);
/**
* @brief Select the Rule from the KnowledgeBase by IDs of the
* sub-objects.
*
* @param[in] dbConnection The database connection to use.
*/
void selectById(sqlite3* dbConnection);
/**
* @brief Get the rules that match the reason.
*
* @param[in] dbConnection The database connection to use.
* @param[out] rules The rules to fill in from the database.
*/
static void selectByReason(sqlite3* dbConnection,
int reasonId,
std::vector<obelisk::Rule>& rules);
/**
* @brief Insert the Rule into the KnowledgeBase.
*
* @param[in] dbConnection The database connection to use.
*/
void insert(sqlite3* dbConnection);
};
} // namespace obelisk
#endif

View File

@ -0,0 +1,185 @@
#ifndef OBELISK_MODELS_SUGGEST_ACTION_H
#define OBELISK_MODELS_SUGGEST_ACTION_H
#include "models/action.h"
#include "models/fact.h"
#include <string>
namespace obelisk
{
/**
* @brief The SuggestAction model representas the actions to take depending
* on if the Fact is true or false.
*
*/
class SuggestAction
{
private:
/**
* @brief The ID of the SuggestAction.
*
*/
int id_;
/**
* @brief The Fact to check the truth of.
*
*/
obelisk::Fact fact_;
/**
* @brief The Action to take if the Fact is true.
*
*/
obelisk::Action trueAction_;
/**
* @brief The Action to take if the Fact is false.
*
*/
obelisk::Action falseAction_;
public:
/**
* @brief Construct a new SuggestAction object.
*
*/
SuggestAction() :
id_(0),
fact_(),
trueAction_(),
falseAction_()
{
}
/**
* @brief Construct a new SuggestAction object.
*
* @param[in] id The ID of the SuggestAction in the KnowledgeBase.
*/
SuggestAction(int id) :
id_(id),
fact_(),
trueAction_(),
falseAction_()
{
}
/**
* @brief Construct a new SuggestAction object.
*
* @param[in] fact The Fact.
* @param[in] trueAction The true Action.
* @param[in] falseAction The false Action.
*/
SuggestAction(obelisk::Fact fact,
obelisk::Action trueAction,
obelisk::Action falseAction) :
id_(0),
fact_(fact),
trueAction_(trueAction),
falseAction_(falseAction)
{
}
/**
* @brief Construct a new SuggestAction object.
*
* @param[in] id The ID of the SuggestAction in the KnowledgeBase.
* @param[in] fact The Fact.
* @param[in] trueAction The true Action.
* @param[in] falseAction The false Action.
*/
SuggestAction(int id,
obelisk::Fact fact,
obelisk::Action trueAction,
obelisk::Action falseAction) :
id_(id),
fact_(fact),
trueAction_(trueAction),
falseAction_(falseAction)
{
}
/**
* @brief Create the SuggestAction table in the database.
*
* @return const char* Returns the query used to create the table.
*/
static const char* createTable();
/**
* @brief Get the ID of the SuggestAction.
*
* @return int& Returns the ID.
*/
int& getId();
/**
* @brief Set the ID of the SuggestAction.
*
* @param[in] id The new ID.
*/
void setId(int id);
/**
* @brief Get the Fact object.
*
* @return obelisk::Fact& Returns the Fact.
*/
obelisk::Fact& getFact();
/**
* @brief Set the Fact object.
*
* @param[in] fact The new Fact.
*/
void setFact(obelisk::Fact fact);
/**
* @brief Get the true Action object.
*
* @return obelisk::Action& Returns the true Action.
*/
obelisk::Action& getTrueAction();
/**
* @brief Set the true Action object.
*
* @param[in] trueAction The new true Action.
*/
void setTrueAction(obelisk::Action trueAction);
/**
* @brief Get the false Action object.
*
* @return obelisk::Action& Returns the false Action.
*/
obelisk::Action& getFalseAction();
/**
* @brief Set the false Action object.
*
* @param[in] falseAction The new false Action.
*/
void setFalseAction(obelisk::Action falseAction);
/**
* @brief Select the SuggestAction from the KnowledgeBase by IDs of
* the sub-objects.
*
* @param[in] dbConnection The database connection to use.
*/
void selectById(sqlite3* dbConnection);
/**
* @brief Insert the SuggestAction into the KnowledgeBase.
*
* @param[in] dbConnection The database connection to use.
*/
void insert(sqlite3* dbConnection);
};
} // namespace obelisk
#endif

View File

@ -0,0 +1,126 @@
#ifndef OBELISK_MODELS_VERB_H
#define OBELISK_MODELS_VERB_H
#include <sqlite3.h>
#include <string>
namespace obelisk
{
/**
* @brief The Verb model represents a verb which is used to connnect
* entities.
*
*/
class Verb
{
private:
/**
* @brief The ID of the Verb in the KnowledgeBase.
*
*/
int id_;
/**
* @brief The name of the Verb.
*
*/
std::string name_;
public:
/**
* @brief Construct a new Verb object.
*
*/
Verb() :
id_(0),
name_("")
{
}
/**
* @brief Construct a new Verb object.
*
* @param[in] id The ID of the Verb.
*/
Verb(int id) :
id_(id),
name_("")
{
}
/**
* @brief Construct a new Verb object.
*
* @param[in] name The name of the Verb.
*/
Verb(std::string name) :
id_(0),
name_(name)
{
}
/**
* @brief Construct a new Verb object.
*
* @param[in] id The ID of the Verb.
* @param[in] name The name of the Verb.
*/
Verb(int id, std::string name) :
id_(id),
name_(name)
{
}
/**
* @brief Create the Verb table in the KnowledgeBase.
*
* @return const char* Returns the query used to create the table.
*/
static const char* createTable();
/**
* @brief Get the ID of the Verb.
*
* @return int& Returns the ID.
*/
int& getId();
/**
* @brief Set the ID of the Verb.
*
* @param[in] id Set the ID of the Verb.
*/
void setId(int id);
/**
* @brief Get the name of the Verb.
*
* @return std::string& The Verb name.
*/
std::string& getName();
/**
* @brief Set the name of the Verb.
*
* @param[in] name The Verb name.
*/
void setName(std::string name);
/**
* @brief Select a verb by name from the KnowledgeBase.
*
* @param[in] dbConnection The database connection to use.
*/
void selectByName(sqlite3* dbConnection);
/**
* @brief Insert a new verb into the KnowledgeBase.
*
* @param[in] dbConnection The database connection to use.
*/
void insert(sqlite3* dbConnection);
};
} // namespace obelisk
#endif

82
obelisk/include/obelisk.h Normal file
View File

@ -0,0 +1,82 @@
#ifndef OBELISK_INCLUDE_OBELISK_H
#define OBELISK_INCLUDE_OBELISK_H
#include "knowledge_base.h"
#include <memory>
#include <string>
/**
* @brief The obelisk namespace contains everything needed to compile obelisk
* code.
*
*/
namespace obelisk
{
/**
* @brief The obelisk library provides everything needed to consult the
* KnowledgeBase.
*
*/
class Obelisk
{
private:
std::unique_ptr<obelisk::KnowledgeBase> kb_;
public:
/**
* @brief Construct a new Obelisk object.
*
*/
Obelisk(std::string filename);
/**
* @brief Destroy the Obelisk object.
*
*/
~Obelisk() = default;
/**
* @brief Get the obelisk version.
*
* @return std::string The version.
*/
std::string getVersion();
/**
* @brief Get the obelisk library so version.
*
* @return int The version.
*/
int getLibVersion();
/**
* @brief Query the obelisk KnowledgeBase to see if a Fact is true
* or not.
*
* @param[in] p_obelisk The obelisk object pointer.
* @param[in] left_entity The left entity.
* @param[in] verb The verb.
* @param[in] right_entity The right entity.
* @return double Returns whether or not the Fact is true.
*/
double query(const std::string& leftEntity,
const std::string& verb,
const std::string& rightEntity);
/**
* @brief Query the Obelisk KnowledgeBase and return the suggested
* action to take.
*
* @param[in] leftEntity The left entity.
* @param[in] verb The verb.
* @param[in] rightEntity The right entity.
* @return std::string Returns the suggested action.
*/
std::string queryAction(const std::string& leftEntity,
const std::string& verb,
const std::string& rightEntity);
};
} // namespace obelisk
#endif

View File

@ -24,14 +24,14 @@ void alai::CameraLimit::_init()
void alai::CameraLimit::_ready()
{
auto node = find_node("Middleground");
auto node = find_node("Middleground");
auto middle_ground = cast_to<godot::TileMap>(node);
if (middle_ground != NULL)
{
auto used_rect = middle_ground->get_used_rect();
auto bounds = godot::Vector2(used_rect.position.x + used_rect.size.x, used_rect.position.y + used_rect.size.y);
node = get_tree()->get_root()->find_node("Camera2D", true, false);
auto camera = cast_to<godot::Camera2D>(node);
auto bounds = godot::Vector2(used_rect.position.x + used_rect.size.x, used_rect.position.y + used_rect.size.y);
node = get_tree()->get_root()->find_node("Camera2D", true, false);
auto camera = cast_to<godot::Camera2D>(node);
if (camera != NULL)
{
camera->set_limit(2, bounds.x * middle_ground->get_cell_size().x);

View File

@ -11,9 +11,9 @@ namespace alai
*
* @details The camera will be limited based on the used width and height of the Middleground tilemap.
*/
class CameraLimit: public godot::Node2D
class CameraLimit : public godot::Node2D
{
GODOT_CLASS(CameraLimit, godot::Node2D)
GODOT_CLASS(CameraLimit, godot::Node2D)
public:
/**
@ -49,5 +49,5 @@ namespace alai
*/
void _ready();
};
}
} // namespace alai
#endif

View File

@ -12,7 +12,7 @@ void alai::Event::_register_methods()
godot::register_signal<Event>("player_died");
godot::register_signal<Event>("player_won");
godot::register_signal<Event>("player_touched", "damage", GODOT_VARIANT_TYPE_INT);
godot::register_signal<Event>("report_object", "name", GODOT_VARIANT_TYPE_STRING, "state", GODOT_VARIANT_TYPE_STRING, "position", GODOT_VARIANT_TYPE_VECTOR2, "velocity", GODOT_VARIANT_TYPE_VECTOR2);
}
alai::Event::Event()

View File

@ -14,7 +14,8 @@ namespace alai
*/
class Event : public godot::Node
{
GODOT_CLASS(Event, godot::Node)
GODOT_CLASS(Event, godot::Node)
public:
/**
* @brief This method registers classes with Godot.
@ -42,6 +43,6 @@ namespace alai
*/
void _init();
};
}
} // namespace alai
#endif

View File

@ -1,6 +1,6 @@
#include "Main.h"
#include "Event.h"
#include "Main.h"
#include "obelisk.h"
#include <SceneTree.hpp>
@ -27,10 +27,10 @@ alai::Main::~Main()
void alai::Main::_init()
{
_os = godot::OS::get_singleton();
_input = godot::Input::get_singleton();
_os = godot::OS::get_singleton();
_input = godot::Input::get_singleton();
_project_settings = godot::ProjectSettings::get_singleton();
_resource_loader = godot::ResourceLoader::get_singleton();
_resource_loader = godot::ResourceLoader::get_singleton();
set_game_version(godot::String(default_game_version.c_str()));
set_full_screen(default_full_screen);
@ -40,6 +40,10 @@ void alai::Main::_init()
void alai::Main::_ready()
{
auto obelisk = std::unique_ptr<obelisk::Obelisk> {new obelisk::Obelisk("alai.kb")};
godot::Godot::print("Obelisk version: " + godot::String(obelisk->getVersion().c_str()));
godot::Godot::print("Obelisk library version: " + godot::String(std::to_string(obelisk->getLibVersion()).c_str()));
auto success = _project_settings->load_resource_pack("monitor.pck");
if (success)
{
@ -66,8 +70,7 @@ void alai::Main::_ready()
{
_os->set_window_size(window_size);
_os->set_window_position(
_os->get_screen_position(get_launch_screen()) + _os->get_screen_size() * 0.5 - _os->get_window_size() * 0.5
);
_os->get_screen_position(get_launch_screen()) + _os->get_screen_size() * 0.5 - _os->get_window_size() * 0.5);
}
success = _project_settings->load_resource_pack("crt.pck");
@ -106,9 +109,9 @@ void alai::Main::load_level()
{
if (level != nullptr)
{
auto path = level->get_path();
auto path = level->get_path();
auto loaded_level = level->instance();
auto level_node = get_node("Level");
auto level_node = get_node("Level");
level_node->add_child(loaded_level);
}
}
@ -153,7 +156,7 @@ bool alai::Main::get_full_screen()
void alai::Main::set_window_size(godot::Vector2 window_size)
{
this-> window_size = window_size;
this->window_size = window_size;
}
godot::Vector2 alai::Main::get_window_size()

View File

@ -1,7 +1,6 @@
#ifndef ALAI_MAIN_H
#define ALAI_MAIN_H
#include <string>
#include <Godot.hpp>
#include <Input.hpp>
#include <Node.hpp>
@ -10,6 +9,7 @@
#include <ProjectSettings.hpp>
#include <Ref.hpp>
#include <ResourceLoader.hpp>
#include <string>
/**
* @brief This is the alai namespace for all the code included in the game.
@ -25,7 +25,7 @@ namespace alai
*/
class Main : public godot::Node
{
GODOT_CLASS(Main, godot::Node)
GODOT_CLASS(Main, godot::Node)
private:
/**
@ -52,12 +52,12 @@ namespace alai
* @brief The default value for the game version.
*
*/
inline static const std::string default_game_version = "0.1.0";
inline static const std::string default_game_version = "0.1.0";
/**
* @brief The default value for if the game should start in full screen.
*
*/
inline static const bool default_full_screen = false;
inline static const bool default_full_screen = false;
/**
* @brief The default resolution for the game window.
*
@ -68,7 +68,7 @@ namespace alai
*
* @details -1 opens it on the currently active screen. And 0 and above are the screens to use.
*/
inline static const int8_t default_launch_screen = -1;
inline static const int8_t default_launch_screen = -1;
/**
* @brief The first level to load
*
@ -227,6 +227,6 @@ namespace alai
*/
void load_level();
};
}
} // namespace alai
#endif

View File

@ -1,9 +1,8 @@
#include "Event.h"
#include "coin/CoinCollected.h"
#include "Event.h"
#include <AudioStreamPlayer.hpp>
#include <AnimationPlayer.hpp>
#include <AudioStreamPlayer.hpp>
void alai::CoinCollected::_register_methods()
{

View File

@ -14,7 +14,7 @@ namespace alai
*/
class CoinCollected : public alai::State
{
GODOT_CLASS(CoinCollected, alai::State)
GODOT_CLASS(CoinCollected, alai::State)
private:
/**
@ -68,6 +68,6 @@ namespace alai
*/
void _on_animation_finished(godot::String anim_name);
};
}
} // namespace alai
#endif

View File

@ -1,6 +1,5 @@
#include "coin/CoinCounter.h"
#include "Event.h"
#include "coin/CoinCounter.h"
#include <String.hpp>
@ -36,14 +35,15 @@ void alai::CoinCounter::_on_coin_collected(int amount)
if (coins >= 100)
{
auto extra = coins - 100;
coins = extra;
}
coins = extra;
}
godot::String coin_string = godot::String();
if (coins <= 9)
{
coin_string = "0" + godot::String::num(coins);
}
else{
else
{
coin_string = godot::String::num(coins);
}
set_text(coin_string);

View File

@ -12,7 +12,7 @@ namespace alai
*/
class CoinCounter : public godot::Label
{
GODOT_CLASS(CoinCounter, godot::Label)
GODOT_CLASS(CoinCounter, godot::Label)
private:
uint8_t coins;
@ -52,9 +52,8 @@ namespace alai
void _on_CoinHUD_ready();
void _on_coin_collected(int amount);
void _ready();
};
}
} // namespace alai
#endif

View File

@ -41,6 +41,6 @@ void alai::CoinNotCollected::_on_body_entered(Node *node)
auto coin = Object::cast_to<godot::Area2D>(parent_node);
coin->set_collision_mask_bit(0, false);
}
get_state_machine()->change("CoinCollected");
}

View File

@ -14,7 +14,7 @@ namespace alai
*/
class CoinNotCollected : public alai::State
{
GODOT_CLASS(CoinNotCollected, alai::State)
GODOT_CLASS(CoinNotCollected, alai::State)
private:
/**
@ -69,6 +69,6 @@ namespace alai
*/
void _on_body_entered(Node *node);
};
}
} // namespace alai
#endif

View File

@ -14,7 +14,7 @@ namespace alai
*/
class GoalNotReached : public alai::State
{
GODOT_CLASS(GoalNotReached, alai::State)
GODOT_CLASS(GoalNotReached, alai::State)
private:
/**
@ -69,6 +69,6 @@ namespace alai
*/
void _on_Goal_body_entered(Node *node);
};
}
} // namespace alai
#endif

View File

@ -1,6 +1,5 @@
#include "goal/GoalReached.h"
#include "Event.h"
#include "goal/GoalReached.h"
#include <Area2D.hpp>

View File

@ -14,7 +14,7 @@ namespace alai
*/
class GoalReached : public alai::State
{
GODOT_CLASS(GoalReached, alai::State)
GODOT_CLASS(GoalReached, alai::State)
private:
/**
@ -67,6 +67,6 @@ namespace alai
*
*/
};
}
} // namespace alai
#endif

View File

@ -1,26 +1,27 @@
#include <Godot.hpp>
#include "Event.h"
#include "state_machine/StateMachine.h"
#include "state_machine/State.h"
#include "Main.h"
#include "CameraLimit.h"
#include "player/Player.h"
#include "player/states/PlayerIdle.h"
#include "player/states/PlayerMove.h"
#include "player/states/PlayerJump.h"
#include "player/states/PlayerFall.h"
#include "coin/CoinNotCollected.h"
#include "Event.h"
#include "Main.h"
#include "coin/CoinCollected.h"
#include "coin/CoinCounter.h"
#include "goal/GoalReached.h"
#include "coin/CoinNotCollected.h"
#include "goal/GoalNotReached.h"
#include "goal/GoalReached.h"
#include "gui/game_over/GameOverScreen.h"
#include "gui/game_won/GameWonScreen.h"
#include "player/AI.h"
#include "player/Player.h"
#include "player/states/PlayerFall.h"
#include "player/states/PlayerIdle.h"
#include "player/states/PlayerJump.h"
#include "player/states/PlayerMove.h"
#include "state_machine/State.h"
#include "state_machine/StateMachine.h"
#include <Godot.hpp>
/**
* @brief This function connects the gdnative init function.
*
*
*/
extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *o)
{
@ -29,7 +30,7 @@ extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *o)
/**
* @brief This function connects the gdnative terminate function.
*
*
*/
extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options *o)
{
@ -41,18 +42,19 @@ extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_opt
/**
* @brief This function connects the init methods in the classes to godot's gdnative.
*
*
*/
extern "C" void GDN_EXPORT godot_nativescript_init(void *handle)
{
godot::Godot::nativescript_init(handle);
godot::register_class<alai::Event>();
godot::register_class<alai::Event>();
godot::register_class<alai::StateMachine>();
godot::register_class<alai::State>();
godot::register_class<alai::Main>();
godot::register_class<alai::CameraLimit>();
godot::register_class<alai::player::Player>();
godot::register_class<alai::player::AI>();
godot::register_class<alai::player::PlayerIdle>();
godot::register_class<alai::player::PlayerMove>();
godot::register_class<alai::player::PlayerJump>();

View File

@ -1,6 +1,5 @@
#include "gui/game_over/GameOverScreen.h"
#include "Event.h"
#include "gui/game_over/GameOverScreen.h"
#include <AudioStreamPlayer.hpp>
#include <PackedScene.hpp>
@ -16,7 +15,7 @@ void alai::GameOverScreen::_register_methods()
godot::register_method("restart_game", &GameOverScreen::restart_game);
godot::register_method("connect_signal", &GameOverScreen::connect_signal);
godot::register_method("_on_player_died", &GameOverScreen::_on_player_died);
godot::register_method("_on_visibility_changed", &GameOverScreen::_on_visibility_changed);
godot::register_method("_on_visibility_changed", &GameOverScreen::_on_visibility_changed);
}
alai::GameOverScreen::GameOverScreen()
@ -39,11 +38,11 @@ void alai::GameOverScreen::_ready()
void alai::GameOverScreen::_on_restart_button_pressed()
{
if (_resource_loader->exists("res://levels/PrototypeR.tscn"))
if (_resource_loader->exists("res://levels/TestLevel.tscn"))
{
godot::Ref<godot::PackedScene> level_scene = _resource_loader->load("res://levels/PrototypeR.tscn");
auto level = level_scene->instance();
auto level_node = get_tree()->get_root()->get_node("Main")->find_node("Level");
godot::Ref<godot::PackedScene> level_scene = _resource_loader->load("res://levels/TestLevel.tscn");
auto level = level_scene->instance();
auto level_node = get_tree()->get_root()->get_node("Main")->find_node("Level");
if (level_node != nullptr)
{
@ -66,7 +65,7 @@ void alai::GameOverScreen::_on_player_died()
auto level_node = get_tree()->get_root()->get_node("Main")->find_node("Level");
if (level_node != nullptr)
{
auto child = level_node->get_child(0);
auto child = level_node->get_child(0);
if (child != nullptr)
{
// Delete the currently active level from the tree.
@ -99,8 +98,8 @@ void alai::GameOverScreen::connect_signal()
void alai::GameOverScreen::_on_visibility_changed()
{
auto gameoversound = get_node<godot::AudioStreamPlayer>("GameOverMusic");
if (is_visible())
{
if (is_visible())
{
gameoversound->play();
}
else

View File

@ -5,7 +5,6 @@
#include <Godot.hpp>
#include <ResourceLoader.hpp>
namespace alai
{
/**
@ -14,7 +13,7 @@ namespace alai
*/
class GameOverScreen : public godot::CanvasLayer
{
GODOT_CLASS(GameOverScreen, godot::CanvasLayer)
GODOT_CLASS(GameOverScreen, godot::CanvasLayer)
private:
godot::ResourceLoader *_resource_loader;
@ -57,6 +56,6 @@ namespace alai
void connect_signal();
void _on_visibility_changed();
};
}
} // namespace alai
#endif

View File

@ -1,13 +1,12 @@
#include "gui/game_won/GameWonScreen.h"
#include "Event.h"
#include "gui/game_won/GameWonScreen.h"
#include <AudioStreamPlayer.hpp>
#include <SceneTree.hpp>
#include <Viewport.hpp>
void alai::GameWonScreen::_register_methods()
{
{
godot::register_method("_ready", &GameWonScreen::_ready);
godot::register_method("connect_signal", &GameWonScreen::connect_signal);
godot::register_method("_on_player_won", &GameWonScreen::_on_player_won);
@ -45,7 +44,7 @@ void alai::GameWonScreen::_on_player_won()
auto level_node = get_tree()->get_root()->get_node("Main")->find_node("Level");
if (level_node != nullptr)
{
auto child = level_node->get_child(0);
auto child = level_node->get_child(0);
if (child != nullptr)
{
child->queue_free();
@ -70,8 +69,8 @@ void alai::GameWonScreen::connect_signal()
void alai::GameWonScreen::_on_visibility_changed()
{
auto victorysound = get_node<godot::AudioStreamPlayer>("VictorySound");
if (is_visible())
{
if (is_visible())
{
victorysound->play();
}
else

View File

@ -12,7 +12,7 @@ namespace alai
*/
class GameWonScreen : public godot::CanvasLayer
{
GODOT_CLASS(GameWonScreen, godot::CanvasLayer)
GODOT_CLASS(GameWonScreen, godot::CanvasLayer)
public:
/**
@ -47,6 +47,6 @@ namespace alai
void connect_signal();
void _on_visibility_changed();
};
}
} // namespace alai
#endif

171
src/player/AI.cpp Normal file
View File

@ -0,0 +1,171 @@
#include "player/AI.h"
#include <InputEventAction.hpp>
void alai::player::AI::_register_methods()
{
godot::register_method("_ready", &AI::_ready);
godot::register_method("_physics_process", &AI::_physics_process);
godot::register_method("_on_object_report", &AI::_on_object_report);
godot::register_method("_on_timer_timeout", &AI::_on_timer_timeout);
}
alai::player::AI::AI()
{
}
alai::player::AI::~AI()
{
}
void alai::player::AI::_init()
{
_input = godot::Input::get_singleton();
obelisk = std::unique_ptr<obelisk::Obelisk> {new obelisk::Obelisk("alai.kb")};
}
void alai::player::AI::_ready()
{
parent = Object::cast_to<Player>(get_parent());
event = get_node<alai::Event>("/root/Event");
event->connect("report_object", this, "_on_object_report");
add_child(timer);
timer->set_wait_time(1);
auto err = timer->connect("timeout", this, "_on_timer_timeout");
if (err != godot::Error::OK)
{
godot::Godot::print("Timer could not be connected!");
}
}
void alai::player::AI::_physics_process(float delta)
{
auto player_position = parent->get_global_position();
auto player_direction = parent->get_velocity();
bool walking = false;
std::sort(entities.begin(), entities.end(), [](const Entity &a, const Entity &b) -> bool
{
return a.position.x < b.position.x;
});
while (!entities.empty())
{
const auto &entity = entities.front();
auto entityName = entity.name.utf8().get_data();
double distance = std::abs(player_position.x - entity.position.x);
int jump_distance = -1;
auto action = obelisk->queryAction(entityName, "is", "bouncable");
if (action == "jump on")
{
jump_distance = 100;
}
else if (action == "jump over")
{
jump_distance = 50;
}
if (lastEntity == "")
{
if (jump_distance != -1 && distance < jump_distance)
{
lastEntity = entity.originalName;
timer->start();
if (player_position.x < entity.position.x)
{
auto ev = godot::InputEventAction()._new();
ev->set_action("jump");
ev->set_pressed(true);
_input->parse_input_event(ev);
}
else if (player_position.x > entity.position.x)
{
auto ev = godot::InputEventAction()._new();
ev->set_action("jump");
ev->set_pressed(true);
_input->parse_input_event(ev);
}
}
}
if (obelisk->query(entityName, "is", "gold") > 0 && obelisk->query(std::string("gold ") + entityName, "is", "collectable") > 0)
{
if (entity.position.x > player_position.x)
{
if (!walking && !_input->is_action_pressed("left") && !_input->is_action_pressed("right"))
{
walking = true;
_input->action_press("right");
}
}
else
{
if (!walking && !_input->is_action_pressed("left") && !_input->is_action_pressed("right"))
{
walking = true;
_input->action_press("left");
}
}
if (distance > -10 && distance < 10 && player_position.y - entity.position.y > 20)
{
timer->stop();
lastEntity = "";
if (!_input->is_action_pressed("jump"))
{
_input->action_press("jump");
}
}
}
if (obelisk->query(entityName, "is", "touchable") > 0)
{
if (!walking && !_input->is_action_pressed("left") && !_input->is_action_pressed("right"))
{
walking = true;
if (entity.position.x > player_position.x)
{
_input->action_press("right");
}
else
{
_input->action_press("left");
}
}
}
entities.pop_front();
}
}
void alai::player::AI::unset_action(godot::String action)
{
auto ev = godot::InputEventAction()._new();
ev->set_action(action);
ev->set_pressed(false);
_input->parse_input_event(ev);
}
void alai::player::AI::_on_timer_timeout()
{
unset_action("left");
unset_action("right");
unset_action("jump");
lastEntity = "";
}
void alai::player::AI::_on_object_report(godot::String name, godot::String state, godot::Vector2 position, godot::Vector2 velocity)
{
auto entity = Entity();
entity.originalName = name;
entity.name = name.to_lower().rstrip("0123456789");
entity.state = state;
entity.position = position;
entity.velocity = velocity;
entities.emplace_front(entity);
}

115
src/player/AI.h Normal file
View File

@ -0,0 +1,115 @@
#ifndef ALAI_PLAYER_AI_H
#define ALAI_PLAYER_AI_H
#include "Event.h"
#include "obelisk.h"
#include "player/Player.h"
#include <Godot.hpp>
#include <Input.hpp>
#include <Node.hpp>
#include <Timer.hpp>
#include <Vector2.hpp>
#include <queue>
namespace alai
{
namespace player
{
class Entity
{
public:
godot::String originalName;
godot::String name;
godot::String state;
godot::Vector2 position;
godot::Vector2 velocity;
};
class AI : public godot::Node
{
GODOT_CLASS(AI, godot::Node)
private:
/**
* @brief Input singleton.
*
*/
godot::Input* _input;
/**
* @brief The obelisk object.
*
*/
std::unique_ptr<obelisk::Obelisk> obelisk;
alai::Event* event;
std::deque<alai::player::Entity> entities;
alai::player::Player* parent;
godot::String lastEntity;
godot::Timer* timer = godot::Timer()._new();
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 AI object.
*
*/
AI();
/**
* @brief Destroy the AI object.
*
*/
~AI();
/**
* @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 Code to be run when ready.
*
* @details This method is run when all the children of this node are ready.
*/
void _ready();
/**
* @brief The physics processed every delta time.
*
* @param[in] delta The time since the method was last run.
*/
void _physics_process(float delta);
void _on_timer_timeout();
void unset_action(godot::String action);
/**
* @brief Callback that receives information about the game environment.
*
* @param[in] name The name of the object.
* @param[in] state The state the object is in.
* @param[in] position The position of the object.
* @param[in] velocity The object's velocity.
*/
void _on_object_report(godot::String name, godot::String state, godot::Vector2 position, godot::Vector2 velocity);
};
} // namespace player
} // namespace alai
#endif

View File

@ -1,6 +1,5 @@
#include "player/Player.h"
#include "Event.h"
#include "player/Player.h"
#include <AudioStreamPlayer.hpp>
#include <Camera2D.hpp>
@ -83,7 +82,8 @@ void alai::player::Player::_ready()
}
}
void alai::player::Player::_on_level_loaded() {
void alai::player::Player::_on_level_loaded()
{
auto state = get_node("StateMachine")->get_child(0);
if (state != nullptr)
{
@ -106,27 +106,27 @@ void alai::player::Player::_physics_process(float delta)
snap_vector = godot::Vector2::DOWN * 20.0;
}
auto is_on_platform = false;
auto is_on_platform = false;
auto platform_detector = get_node<godot::RayCast2D>("PlatformDetector");
if (platform_detector != nullptr)
{
is_on_platform = platform_detector->is_colliding();
is_on_platform = platform_detector->is_colliding();
}
else
{
WARN_PRINT("PlatformDetector not found!");
}
velocity = move_and_slide_with_snap(velocity, snap_vector, godot::Vector2::UP, !is_on_platform, 4, 0.9, false);
velocity = move_and_slide_with_snap(velocity, snap_vector, godot::Vector2::UP, !is_on_platform, 4, 0.9, false);
//velocity = move_and_slide(velocity, Vector2::UP, !is_on_platform);
velocity.x = godot::Math::lerp((float) velocity.x, (float) 0, (float) 0.2);
auto count = get_slide_count();
for (int64_t i = 0; i < count; i++)
{
auto collision = get_slide_collision(i);
auto collision = get_slide_collision(i);
auto collision_object = collision->get_collider();
auto collider = Object::cast_to<Node>(collision_object);
auto collider = Object::cast_to<Node>(collision_object);
if (collider->is_in_group("squashable") && godot::Vector2::UP.dot(collision->get_normal()) > 0.1)
{
collider->call_deferred("squash");
@ -169,14 +169,15 @@ void alai::player::Player::_physics_process(float delta)
auto camera = get_node<godot::Camera2D>("Camera2D");
if (camera != nullptr)
{
auto position = get_global_position();
auto position = get_global_position();
auto sprite_node = get_node<godot::AnimatedSprite>("AnimatedSprite");
if (sprite_node != nullptr)
{
position.x = godot::Math::clamp((float) position.x, (float) camera->get_limit(0), (float) camera->get_limit(2) - sprite_node->get_sprite_frames()->get_frame("idle", 0)->get_size().x);
position.y = godot::Math::clamp((float) position.y, (float) camera->get_limit(1), (float) camera->get_limit(3) + sprite_node->get_sprite_frames()->get_frame("idle", 0)->get_size().y);
}
else {
else
{
WARN_PRINT("Could not clamp player based on sprite frame size!");
position.x = godot::Math::clamp((float) position.x, (float) camera->get_limit(0), (float) camera->get_limit(2));
position.y = godot::Math::clamp((float) position.y, (float) camera->get_limit(1), (float) camera->get_limit(3));
@ -196,11 +197,13 @@ void alai::player::Player::_physics_process(float delta)
{
// The first time the notifier is checked always returns false in the first frame
// So skip the check from the first frame
if (notifier_initialized) {
if (notifier_initialized)
{
auto event = get_node<alai::Event>("/root/Event");
event->emit_signal("player_died");
}
else {
else
{
notifier_initialized = true;
}
}

View File

@ -24,32 +24,32 @@ namespace alai
* @brief The default speed of the player.
*
*/
const float speed = 60.0;
const float speed = 60.0;
/**
* @brief The default jump force applied when jumping.
*
*/
const float jump_force = 300.0;
const float jump_force = 300.0;
/**
* @brief The default bounce force applied when bouncing on something.
*
*/
const float bounce_force = 200.0;
const float bounce_force = 200.0;
/**
* @brief The default gravity applied to the player.
*
*/
const float gravity = 9.81;
const float gravity = 9.81;
/**
* @brief The default run speed multiplier.
*
*/
const float run_speed = 2.0;
const float run_speed = 2.0;
/**
* @brief The default double jump activation state.
*
*/
const bool double_jump = true;
const bool double_jump = true;
/**
* @brief This class is used to control the player.
@ -58,7 +58,7 @@ namespace alai
*/
class Player : public godot::KinematicBody2D
{
GODOT_CLASS(Player, godot::KinematicBody2D)
GODOT_CLASS(Player, godot::KinematicBody2D)
private:
/**
@ -291,7 +291,7 @@ namespace alai
*/
void _on_level_loaded();
};
}
}
} // namespace player
} // namespace alai
#endif

View File

@ -1,6 +1,5 @@
#include "player/states/PlayerFall.h"
#include "player/Player.h"
#include "player/states/PlayerFall.h"
void alai::player::PlayerFall::_register_methods()
{
@ -46,8 +45,8 @@ void alai::player::PlayerFall::_physics_process(float delta)
}
auto current_speed = parent->get_speed();
auto velocity = parent->get_velocity();
velocity.x = 0;
auto velocity = parent->get_velocity();
velocity.x = 0;
if (_input->is_action_pressed("run"))
{
current_speed *= parent->get_run_speed();

View File

@ -17,7 +17,7 @@ namespace alai
*/
class PlayerFall : public State
{
GODOT_CLASS(PlayerFall, State)
GODOT_CLASS(PlayerFall, State)
private:
/**
@ -78,7 +78,7 @@ namespace alai
*/
void _physics_process(float delta);
};
}
}
} // namespace player
} // namespace alai
#endif

View File

@ -1,6 +1,5 @@
#include "player/states/PlayerIdle.h"
#include "player/Player.h"
#include "player/states/PlayerIdle.h"
void alai::player::PlayerIdle::_register_methods()
{

View File

@ -17,7 +17,7 @@ namespace alai
*/
class PlayerIdle : public State
{
GODOT_CLASS(PlayerIdle, State)
GODOT_CLASS(PlayerIdle, State)
private:
/**
@ -77,7 +77,7 @@ namespace alai
*/
void _physics_process(float delta);
};
}
}
} // namespace player
} // namespace alai
#endif

View File

@ -1,6 +1,5 @@
#include "player/states/PlayerJump.h"
#include "player/Player.h"
#include "player/states/PlayerJump.h"
#include <AudioStreamPlayer.hpp>
@ -42,16 +41,16 @@ void alai::player::PlayerJump::_state_enter(const godot::String state)
double_jumped = false;
}
auto parent = Object::cast_to<Player>(get_parent());
auto parent = Object::cast_to<Player>(get_parent());
auto velocity = parent->get_velocity();
velocity.y = -parent->get_jump_force();
velocity.y = -parent->get_jump_force();
parent->set_velocity(velocity);
}
void alai::player::PlayerJump::_state_exit()
{
animated_sprite->set_animation("move");
animated_sprite->set_frame(1);
animated_sprite->set_animation("move");
animated_sprite->set_frame(1);
}
void alai::player::PlayerJump::_physics_process(float delta)
@ -64,8 +63,8 @@ void alai::player::PlayerJump::_physics_process(float delta)
}
auto current_speed = parent->get_speed();
auto velocity = parent->get_velocity();
velocity.x = 0;
auto velocity = parent->get_velocity();
velocity.x = 0;
if (_input->is_action_pressed("run"))
{
current_speed *= parent->get_run_speed();

View File

@ -17,7 +17,7 @@ namespace alai
*/
class PlayerJump : public State
{
GODOT_CLASS(PlayerJump, State)
GODOT_CLASS(PlayerJump, State)
private:
/**
@ -85,7 +85,7 @@ namespace alai
*/
void _physics_process(float delta);
};
}
}
} // namespace player
} // namespace alai
#endif

View File

@ -1,6 +1,5 @@
#include "player/states/PlayerMove.h"
#include "player/Player.h"
#include "player/states/PlayerMove.h"
void alai::player::PlayerMove::_register_methods()
{
@ -40,8 +39,8 @@ void alai::player::PlayerMove::_physics_process(float delta)
auto direction_pressed = false;
auto current_speed = parent->get_speed();
auto velocity = parent->get_velocity();
velocity.x = 0;
auto velocity = parent->get_velocity();
velocity.x = 0;
if (_input->is_action_pressed("run"))
{
current_speed *= parent->get_run_speed();

View File

@ -3,9 +3,9 @@
#include "state_machine/State.h"
#include <AnimatedSprite.hpp>
#include <Godot.hpp>
#include <Input.hpp>
#include <AnimatedSprite.hpp>
namespace alai
{
@ -17,7 +17,7 @@ namespace alai
*/
class PlayerMove : public State
{
GODOT_CLASS(PlayerMove, State)
GODOT_CLASS(PlayerMove, State)
private:
/**
@ -77,7 +77,7 @@ namespace alai
*/
void _physics_process(float delta);
};
}
}
} // namespace player
} // namespace alai
#endif

View File

@ -13,7 +13,7 @@ namespace alai
*/
class State : public StateMachine
{
GODOT_CLASS(State, Node)
GODOT_CLASS(State, Node)
private:
/**
@ -98,6 +98,6 @@ namespace alai
*/
virtual StateMachine *get_state_machine() final;
};
}
} // namespace alai
#endif

View File

@ -1,6 +1,5 @@
#include "state_machine/StateMachine.h"
#include "state_machine/State.h"
#include "state_machine/StateMachine.h"
void alai::StateMachine::_register_methods()
{
@ -54,7 +53,7 @@ void alai::StateMachine::setup()
if (children.size() > 0)
{
WARN_PRINT("The state machine doesn't have a default state set, using first child!");
auto child = Object::cast_to<Node>(children[0].operator Object*());
auto child = Object::cast_to<Node>(children[0].operator Object * ());
set_current_state(child->get_name());
}
else
@ -66,7 +65,7 @@ void alai::StateMachine::setup()
for (uint8_t i = 0; i < children.size(); i++)
{
auto child = Object::cast_to<Node>(children[i].operator Object*());
auto child = Object::cast_to<Node>(children[i].operator Object * ());
child->call("set_state_machine", this);
@ -83,7 +82,8 @@ void alai::StateMachine::setup()
{
this->call("_state_enter", get_current_state());
}
else {
else
{
WARN_PRINT("The state " + get_current_state() + " doesn't have a _state_enter method!");
}
}
@ -93,7 +93,7 @@ void alai::StateMachine::add_states()
auto children = get_children();
for (uint8_t i = 0; i < children.size(); i++)
{
auto child = Object::cast_to<Node>(children[i].operator Object*());
auto child = Object::cast_to<Node>(children[i].operator Object * ());
add_state(child->get_name(), child);
}
}
@ -120,7 +120,7 @@ bool alai::StateMachine::has(const godot::String state)
return states.has(state);
}
void alai::StateMachine::restart(const godot::String state, const godot::Array& args)
void alai::StateMachine::restart(const godot::String state, const godot::Array &args)
{
this->call("_state_exit", state, args);
this->call("_state_enter", state, args);
@ -162,7 +162,7 @@ void alai::StateMachine::change(const godot::String state, const godot::Array &a
if (get_current_state() != "")
{
auto child = Object::cast_to<Node>(states[get_current_state()].operator Object*());
auto child = Object::cast_to<Node>(states[get_current_state()].operator Object * ());
if (child != nullptr)
{
this->remove_child(child);
@ -175,7 +175,7 @@ void alai::StateMachine::change(const godot::String state, const godot::Array &a
}
set_current_state(state);
auto child = Object::cast_to<Node>(states[get_current_state()].operator Object*());
auto child = Object::cast_to<Node>(states[get_current_state()].operator Object * ());
this->add_child(child);
state_node = Object::cast_to<Node>(this->states[get_current_state()]);
@ -204,7 +204,7 @@ void alai::StateMachine::change(const godot::String state, const godot::Array &a
godot::Variant alai::StateMachine::call(const godot::String method, const godot::Array &args)
{
auto node = Object::cast_to<Node>(states[get_current_state()].operator Object*());
auto node = Object::cast_to<Node>(states[get_current_state()].operator Object * ());
if (node)
{
if (node->has_method(method))
@ -269,7 +269,7 @@ void alai::StateMachine::_on_StateMachine_tree_exiting()
auto keys = states.keys();
for (uint8_t i = 0; i < keys.size(); i++)
{
auto child = Object::cast_to<Node>(states[keys[i]].operator Object*());
auto child = Object::cast_to<Node>(states[keys[i]].operator Object * ());
if (child)
{
auto children = get_children();

View File

@ -12,7 +12,7 @@ namespace alai
*/
class StateMachine : public godot::Node
{
GODOT_CLASS(StateMachine, godot::Node)
GODOT_CLASS(StateMachine, godot::Node)
private:
/**
@ -126,7 +126,7 @@ namespace alai
* @param[in] state The state that is being restarted.
* @param[in] args The arguments to pass to the state on exit and enter.
*/
void restart(const godot::String state, const godot::Array& args = godot::Array());
void restart(const godot::String state, const godot::Array &args = godot::Array());
/**
* @brief Change to a different state.
@ -214,7 +214,7 @@ namespace alai
* @param[in] state The state being restarted.
* @param[in] args The arguments to pass when restarting.
*/
template <class ...Args> void restart(const godot::String state, Args ...args)
template<class... Args> void restart(const godot::String state, Args... args)
{
return restart(state, godot::Array::make(args...));
}
@ -226,7 +226,7 @@ namespace alai
* @param[in] state The state to change to.
* @param[in] args The arguments to pass to the new state.
*/
template <class ...Args> void change(const godot::String state, Args ...args)
template<class... Args> void change(const godot::String state, Args... args)
{
return change(state, godot::Array::make(args...));
}
@ -239,7 +239,7 @@ namespace alai
* @param[in] args The arguments to pass to it.
* @return Variant The Variant object returned by the method called.
*/
template <class ...Args> godot::Variant call(const godot::String method, Args ...args)
template<class... Args> godot::Variant call(const godot::String method, Args... args)
{
return call(method, godot::Array::make(args...));
}
@ -252,11 +252,11 @@ namespace alai
* @param[in] args The arguments to pass.
* @return Variant The Variant object returned by the method called.
*/
template <class ...Args> godot::Variant _call(const godot::String method, Args ...args)
template<class... Args> godot::Variant _call(const godot::String method, Args... args)
{
return _call(method, godot::Array::make(args...));
}
};
}
} // namespace alai
#endif