diff --git a/.gitignore b/.gitignore
index b2b3eca..420d650 100644
--- a/.gitignore
+++ b/.gitignore
@@ -40,3 +40,5 @@ compile_commands.json
# docs
docs/
+# tiled session files
+*.tiled-session
diff --git a/godot/Main.tscn b/godot/Main.tscn
index d264a5c..0b5ed2e 100644
--- a/godot/Main.tscn
+++ b/godot/Main.tscn
@@ -1,9 +1,8 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://Main.gdns" type="Script" id=1]
-[ext_resource path="res://Level1.tscn" type="PackedScene" id=2]
+[ext_resource path="res://levels/Prototype.tscn" type="PackedScene" id=2]
[node name="Main" type="Node"]
script = ExtResource( 1 )
-
-[node name="Level1" parent="." instance=ExtResource( 2 )]
+level = ExtResource( 2 )
diff --git a/godot/addons/vnen.tiled_importer/tiled_import_plugin.gd b/godot/addons/vnen.tiled_importer/tiled_import_plugin.gd
index 4c5ee10..2612766 100644
--- a/godot/addons/vnen.tiled_importer/tiled_import_plugin.gd
+++ b/godot/addons/vnen.tiled_importer/tiled_import_plugin.gd
@@ -84,6 +84,11 @@ func get_import_options(preset):
"default_value": 1,
"property_hint": PROPERTY_HINT_LAYERS_2D_PHYSICS
},
+ {
+ "name": "collision_mask",
+ "default_value": 1,
+ "property_hint": PROPERTY_HINT_LAYERS_2D_PHYSICS
+ },
{
"name": "embed_internal_images",
"default_value": true if preset == PRESET_PIXEL_ART else false
diff --git a/godot/addons/vnen.tiled_importer/tiled_map_reader.gd b/godot/addons/vnen.tiled_importer/tiled_map_reader.gd
index 7a279a7..e488456 100644
--- a/godot/addons/vnen.tiled_importer/tiled_map_reader.gd
+++ b/godot/addons/vnen.tiled_importer/tiled_map_reader.gd
@@ -211,12 +211,12 @@ func make_layer(layer, parent, root, data):
var opacity = float(layer.opacity) if "opacity" in layer else 1.0
var visible = bool(layer.visible) if "visible" in layer else true
-
+
var z_index = 0
-
+
if "properties" in layer and "z_index" in layer.properties:
z_index = layer.properties.z_index
-
+
if layer.type == "tilelayer":
var layer_size = Vector2(int(layer.width), int(layer.height))
var tilemap = TileMap.new()
@@ -231,6 +231,7 @@ func make_layer(layer, parent, root, data):
tilemap.cell_y_sort = true
tilemap.cell_tile_origin = TileMap.TILE_ORIGIN_BOTTOM_LEFT
tilemap.collision_layer = options.collision_layer
+ tilemap.collision_mask = options.collision_mask
tilemap.z_index = z_index
var offset = Vector2()
@@ -280,7 +281,7 @@ func make_layer(layer, parent, root, data):
var gid = int_id & ~(FLIPPED_HORIZONTALLY_FLAG | FLIPPED_VERTICALLY_FLAG | FLIPPED_DIAGONALLY_FLAG)
var cell_x = cell_offset.x + chunk.x + (count % int(chunk.width))
- var cell_y = cell_offset.y + chunk.y + int(count / chunk.width)
+ var cell_y = cell_offset.y + chunk.y + int(count / chunk.width) + 1
tilemap.set_cell(cell_x, cell_y, gid, flipped_h, flipped_v, flipped_d)
count += 1
@@ -702,26 +703,26 @@ func build_tileset_for_scene(tilesets, source_path, options):
var i = 0
var column = 0
-
+
# Needed to look up textures for animations
var tileRegions = []
while i < tilecount:
var tilepos = Vector2(x, y)
var region = Rect2(tilepos, tilesize)
-
+
tileRegions.push_back(region)
-
+
column += 1
i += 1
-
+
x += int(tilesize.x) + spacing
if (columns > 0 and column >= columns) or x >= int(imagesize.x) - margin or (x + int(tilesize.x)) > int(imagesize.x):
x = margin
y += int(tilesize.y) + spacing
column = 0
-
+
i = 0
-
+
while i < tilecount:
var region = tileRegions[i]
@@ -778,7 +779,7 @@ func build_tileset_for_scene(tilesets, source_path, options):
result.tile_set_texture(gid, image)
if options.apply_offset:
result.tile_set_texture_offset(gid, Vector2(0, -image.get_height()))
-
+
if "tiles" in ts and rel_id in ts.tiles and "objectgroup" in ts.tiles[rel_id] \
and "objects" in ts.tiles[rel_id].objectgroup:
for object in ts.tiles[rel_id].objectgroup.objects:
@@ -803,10 +804,10 @@ func build_tileset_for_scene(tilesets, source_path, options):
result.tile_set_occluder_offset(gid, offset)
else:
result.tile_add_shape(gid, shape, Transform2D(0, offset), object.type == "one-way")
-
+
if "properties" in ts and "custom_material" in ts.properties:
result.tile_set_material(gid, load(ts.properties.custom_material))
-
+
if options.custom_properties and options.tile_metadata and "tileproperties" in ts \
and "tilepropertytypes" in ts and rel_id in ts.tileproperties and rel_id in ts.tilepropertytypes:
tile_meta[gid] = get_custom_properties(ts.tileproperties[rel_id], ts.tilepropertytypes[rel_id])
@@ -815,7 +816,7 @@ func build_tileset_for_scene(tilesets, source_path, options):
if property in ts.tiles[rel_id]:
if not gid in tile_meta: tile_meta[gid] = {}
tile_meta[gid][property] = ts.tiles[rel_id][property]
-
+
gid += 1
i += 1
@@ -1047,13 +1048,19 @@ func is_convex(vertices):
return true
# Decompress the data of the layer
-# Compression argument is a string, either "gzip" or "zlib"
+# Compression argument is a string, either "gzip", "zlib", or "zstd"
func decompress_layer_data(layer_data, compression, map_size):
- if compression != "gzip" and compression != "zlib":
- print_error("Unrecognized compression format: %s" % [compression])
- return ERR_INVALID_DATA
-
- var compression_type = File.COMPRESSION_DEFLATE if compression == "zlib" else File.COMPRESSION_GZIP
+ var compression_type = -1
+ match compression:
+ "zlib":
+ compression_type = File.COMPRESSION_DEFLATE
+ "gzip":
+ compression_type = File.COMPRESSION_GZIP
+ "zstd":
+ compression_type = File.COMPRESSION_ZSTD
+ _:
+ print_error("Unrecognized compression format: %s" % [compression])
+ return ERR_INVALID_DATA
var expected_size = int(map_size.x) * int(map_size.y) * 4
var raw_data = Marshalls.base64_to_raw(layer_data).decompress(expected_size, compression_type)
@@ -1220,7 +1227,7 @@ func validate_layer(layer):
print_error("Invalid data layer property.")
return ERR_INVALID_DATA
if "compression" in layer:
- if layer.compression != "gzip" and layer.compression != "zlib":
+ if layer.compression != "gzip" and layer.compression != "zlib" and layer.compression != "zstd":
print_error("Invalid compression type.")
return ERR_INVALID_DATA
"imagelayer":
diff --git a/godot/addons/vnen.tiled_importer/tiled_xml_to_dict.gd b/godot/addons/vnen.tiled_importer/tiled_xml_to_dict.gd
index 9064b90..a800f0b 100644
--- a/godot/addons/vnen.tiled_importer/tiled_xml_to_dict.gd
+++ b/godot/addons/vnen.tiled_importer/tiled_xml_to_dict.gd
@@ -247,7 +247,7 @@ func parse_tile_data(parser):
var prop_data = parse_properties(parser)
data["properties"] = prop_data.properties
data["propertytypes"] = prop_data.propertytypes
-
+
elif parser.get_node_name() == "animation":
var frame_list = []
var err2 = parser.read()
@@ -265,7 +265,7 @@ func parse_tile_data(parser):
if parser.get_node_name() == "animation":
break
err2 = parser.read()
-
+
data["animation"] = frame_list
err = parser.read()
diff --git a/godot/juego.tiled-project b/godot/alai.tiled-project
similarity index 100%
rename from godot/juego.tiled-project
rename to godot/alai.tiled-project
diff --git a/godot/camera_fix.gd b/godot/camera_fix.gd
new file mode 100644
index 0000000..31ad05f
--- /dev/null
+++ b/godot/camera_fix.gd
@@ -0,0 +1,10 @@
+extends Node2D
+
+
+# Called when the node enters the scene tree for the first time.
+func _ready() -> void:
+ var used_rect = get_node("Middleground").get_used_rect()
+ var bounds = Vector2(used_rect.position.x + used_rect.size.x, used_rect.position.y + used_rect.size.y - 1)
+ var camera : Camera2D = $"../../Player/Camera2D"
+ camera.limit_right = bounds.x * get_node("Middleground").cell_size.x
+ camera.limit_bottom = bounds.y * get_node("Middleground").cell_size.y
diff --git a/godot/characters/player/Player.tscn b/godot/characters/player/Player.tscn
index fd71fe2..fd14612 100644
--- a/godot/characters/player/Player.tscn
+++ b/godot/characters/player/Player.tscn
@@ -12,6 +12,7 @@
extents = Vector2( 7, 12 )
[node name="Player" type="KinematicBody2D"]
+collision_mask = 2
script = ExtResource( 5 )
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
diff --git a/godot/juego.tiled-session b/godot/juego.tiled-session
deleted file mode 100644
index 9b2b07d..0000000
--- a/godot/juego.tiled-session
+++ /dev/null
@@ -1,285 +0,0 @@
-{
- "Map/SizeTest": {
- "height": 4300,
- "width": 2
- },
- "activeFile": "levels/level01.tmx",
- "expandedProjectPaths": [
- "tilesets",
- "levels",
- ".",
- "parallax"
- ],
- "exportAsImage.useCurrentScale": false,
- "file.lastUsedOpenFilter": "All Files (*)",
- "fileStates": {
- "": {
- "scaleInDock": 1
- },
- "#backgrounds": {
- "scaleInDock": 1
- },
- "/home/cromer/projects/edx/games/azaraka/misc/new-graphics/tf_darkdimension_updated2020/RMMV/tf_dd_B_3.tsx": {
- "scaleInDock": 1,
- "scaleInEditor": 1
- },
- "/home/cromer/projects/edx/games/azaraka/misc/new-graphics/tf_darkdimension_updated2020/dd_waterfall_sheet.tsx": {
- "scaleInDock": 1,
- "scaleInEditor": 2
- },
- "/home/cromer/projects/edx/games/azaraka/misc/new-graphics/tf_darkdimension_updated2020/tf_darkdimension_sheet.tsx": {
- "scaleInDock": 2,
- "scaleInEditor": 2
- },
- "/home/cromer/projects/edx/games/azaraka/misc/new-graphics/tf_darkdimension_updated2020/untitled.tmx": {
- "scale": 2,
- "selectedLayer": 3,
- "viewCenter": {
- "x": 465.75,
- "y": 233.5
- }
- },
- "/home/cromer/tilemaps/Dungeon.tsx": {
- "scaleInDock": 1,
- "scaleInEditor": 1
- },
- "/home/cromer/tilemaps/Grassland.tsx": {
- "scaleInDock": 1,
- "scaleInEditor": 1
- },
- "/home/cromer/tilemaps/dungeon_entrance.tmx": {
- "scale": 0.53140625,
- "selectedLayer": 0,
- "viewCenter": {
- "x": 902.3228462216996,
- "y": 825.1690679211997
- }
- },
- "/home/cromer/tilemaps/untitled.tmx": {
- "scale": 0.53140625,
- "selectedLayer": 1,
- "viewCenter": {
- "x": 798.8238753307851,
- "y": 798.8238753307851
- }
- },
- "/mnt/data/godot/projects/Azaraka/maps/cloud_city.tsx": {
- "scaleInDock": 0.5
- },
- "/mnt/data/godot/projects/Azaraka/maps/dungeon1.tmx": {
- "scale": 0.75,
- "selectedLayer": 0,
- "viewCenter": {
- "x": 1209.3333333333333,
- "y": 672
- }
- },
- "/mnt/data/godot/projects/Azaraka/maps/shadowset.tsx": {
- "scaleInDock": 1
- },
- "/mnt/data/godot/projects/Azaraka/maps/terrain.tsx": {
- "scaleInDock": 0.75
- },
- "/mnt/data/godot/projects/Azaraka/maps/worldmap.tmx": {
- "scale": 0.03125,
- "selectedLayer": 0,
- "viewCenter": {
- "x": 10496,
- "y": 2592
- }
- },
- "/mnt/data/godot/projects/Azaraka/maps/worldmap.tsx": {
- "scaleInDock": 0.33
- },
- "/mnt/data/godot/projects/Platformer/asset/spritesheet_ground.tsx": {
- "scaleInDock": 0.125,
- "scaleInEditor": 0.75
- },
- "/mnt/data/godot/projects/Platformer/asset/world.tmx": {
- "scale": 0.5,
- "selectedLayer": 0,
- "viewCenter": {
- "x": 1326,
- "y": 1210
- }
- },
- "/mnt/data/godot/projects/Platformer/asset/world1.tmx": {
- "scale": 0.5714843749999999,
- "selectedLayer": 0,
- "viewCenter": {
- "x": 640.4374572795626,
- "y": 640.4374572795626
- }
- },
- "/mnt/data/projects/edx/games/azaraka/maps/tilesets/grassland_shadows.tsx": {
- "scaleInDock": 1
- },
- "/mnt/data/projects/edx/games/azaraka/maps/tilesets/grassland_spring.tsx": {
- "scaleInDock": 1
- },
- "/mnt/data/projects/edx/games/azaraka/maps/tilesets/grassland_spring_water.tsx": {
- "scaleInDock": 1
- },
- "/mnt/data/projects/edx/games/azaraka/maps/tilesets/grassland_spring_waterfall.tsx": {
- "scaleInDock": 1
- },
- "/mnt/data/projects/edx/games/project/graphics/dungeon.tsx": {
- "scaleInDock": 1,
- "scaleInEditor": 1.5
- },
- "/mnt/data/projects/edx/games/project/graphics/dungeon_entrance.tmx": {
- "scale": 1,
- "selectedLayer": 3,
- "viewCenter": {
- "x": 320,
- "y": 175.5
- }
- },
- "/mnt/data/projects/edx/games/project/graphics/flame.tsx": {
- "scaleInDock": 1,
- "scaleInEditor": 1
- },
- "/mnt/data/projects/edx/games/project/graphics/grassland.tsx": {
- "scaleInDock": 1,
- "scaleInEditor": 1
- },
- "/mnt/data/projects/edx/games/project/graphics/house.tsx": {
- "scaleInDock": 1,
- "scaleInEditor": 1
- },
- "/mnt/data/projects/edx/games/project/graphics/town.tsx": {
- "scaleInDock": 1,
- "scaleInEditor": 1
- },
- "/mnt/data/projects/edx/games/project/maps/dungeon.tsx": {
- "scaleInDock": 1,
- "scaleInEditor": 1
- },
- "/mnt/data/projects/edx/games/project/maps/dungeon/dungeon.tsx": {
- "scaleInDock": 1
- },
- "/mnt/data/projects/edx/games/project/maps/dungeon/entrance.tmx": {
- "scale": 1.3329687499999998,
- "selectedLayer": 4,
- "viewCenter": {
- "x": 320.3375923103974,
- "y": 176.67330910795923
- }
- },
- "/mnt/data/projects/edx/games/project/maps/dungeon/entrance.tmx#dungeon": {
- "scaleInDock": 1,
- "scaleInEditor": 1
- },
- "/mnt/data/projects/edx/games/project/maps/entrance.tmx": {
- "scale": 1.3332386363636362,
- "selectedLayer": 4,
- "viewCenter": {
- "x": 292.89580225868315,
- "y": 116.25825697847861
- }
- },
- "/mnt/data/projects/edx/games/project/maps/grassland.tsx": {
- "scaleInDock": 1,
- "scaleInEditor": 1.5
- },
- "/mnt/data/projects/edx/games/project/maps/outside_entrance.tmx": {
- "scale": 1.3332386363636362,
- "selectedLayer": 0,
- "viewCenter": {
- "x": 320.64777327935224,
- "y": -69.00490091625824
- }
- },
- "/mnt/data/projects/edx/games/project/maps/tilesets/dungeon.tsx": {
- "scaleInDock": 1,
- "scaleInEditor": 1
- },
- "/mnt/data/projects/edx/games/project/maps/tilesets/grassland.tsx": {
- "scaleInDock": 1,
- "scaleInEditor": 1
- },
- "levels/level01.tmx": {
- "scale": 0.75,
- "selectedLayer": 1,
- "viewCenter": {
- "x": 544,
- "y": 248
- }
- },
- "parallax/clouds.tmx": {
- "scale": 0.9252604166666667,
- "selectedLayer": 0,
- "viewCenter": {
- "x": 264.790318041092,
- "y": 384.7565437658316
- }
- },
- "parallax/hills.tmx": {
- "scale": 0.9252604166666667,
- "selectedLayer": 0,
- "viewCenter": {
- "x": 264.790318041092,
- "y": 384.7565437658316
- }
- },
- "parallax/snow.tmx": {
- "scale": 0.9252604166666667,
- "selectedLayer": 0,
- "viewCenter": {
- "x": 264.790318041092,
- "y": 384.7565437658316
- }
- },
- "tilesets/backgrounds.tsx": {
- "scaleInDock": 3,
- "scaleInEditor": 4
- },
- "tilesets/tiles.tsx": {
- "scaleInDock": 2,
- "scaleInEditor": 2
- }
- },
- "frame.defaultDuration": 300,
- "last.exportedFilePath": "/mnt/data/godot/projects/Platformer",
- "last.imagePath": "/mnt/data/godot/projects/juego/godot/assets/backgrounds",
- "lastUsedTilesetExportFilter": "Godot Tileset format (*.tres)",
- "loadedWorlds": [
- "/home/cromer/projects/edx/games/project/maps/azaraka"
- ],
- "map.fixedSize": true,
- "map.height": 12,
- "map.lastUsedExportFilter": "Godot Tilemap format (*.tscn)",
- "map.lastUsedFormat": "tmx",
- "map.tileHeight": 24,
- "map.tileWidth": 24,
- "map.width": 22,
- "openFiles": [
- "tilesets/tiles.tsx",
- "levels/level01.tmx"
- ],
- "project": "juego.tiled-project",
- "property.type": "int",
- "recentFiles": [
- "tilesets/tiles.tsx",
- "levels/level01.tmx",
- "tilesets/backgrounds.tsx",
- "parallax/snow.tmx",
- "parallax/hills.tmx",
- "/mnt/data/godot/projects/Azaraka/maps/worldmap.tsx",
- "/mnt/data/godot/projects/Azaraka/maps/worldmap.tmx",
- "/mnt/data/godot/projects/Platformer/asset/world1.tmx",
- "/mnt/data/godot/projects/Platformer/asset/spritesheet_ground.tsx",
- "/mnt/data/godot/projects/Platformer/asset/world.tmx",
- "/mnt/data/godot/projects/Azaraka/maps/dungeon1.tmx",
- "/mnt/data/projects/edx/games/azaraka/maps/outside_entrance.tmx"
- ],
- "tileset.embedInMap": false,
- "tileset.lastUsedFilter": "Tiled tileset files (*.tsx *.xml)",
- "tileset.lastUsedFormat": "tsx",
- "tileset.tileSize": {
- "height": 24,
- "width": 24
- },
- "tileset.transparentColor": "#000000",
- "tileset.useTransparentColor": false
-}
diff --git a/godot/levels/Level2.tmx b/godot/levels/Level2.tmx
new file mode 100644
index 0000000..5ba4922
--- /dev/null
+++ b/godot/levels/Level2.tmx
@@ -0,0 +1,29 @@
+
+
diff --git a/godot/levels/level01.tmx.import b/godot/levels/Level2.tmx.import
similarity index 54%
rename from godot/levels/level01.tmx.import
rename to godot/levels/Level2.tmx.import
index b5b61e8..0f2e4aa 100644
--- a/godot/levels/level01.tmx.import
+++ b/godot/levels/Level2.tmx.import
@@ -2,12 +2,12 @@
importer="vnen.tiled_importer"
type="PackedScene"
-path="res://.import/level01.tmx-65e129bada03d3bf56997e5be6fa923f.scn"
+path="res://.import/Level2.tmx-357d8ae9edfbc85f5abb1db3655640e1.scn"
[deps]
-source_file="res://levels/level01.tmx"
-dest_files=[ "res://.import/level01.tmx-65e129bada03d3bf56997e5be6fa923f.scn" ]
+source_file="res://levels/Level2.tmx"
+dest_files=[ "res://.import/Level2.tmx-357d8ae9edfbc85f5abb1db3655640e1.scn" ]
[params]
@@ -15,7 +15,7 @@ custom_properties=true
tile_metadata=false
uv_clip=true
image_flags=7
-collision_layer=1
+collision_layer=2
embed_internal_images=false
save_tiled_properties=false
add_background=true
diff --git a/godot/levels/Level2.tscn b/godot/levels/Level2.tscn
new file mode 100644
index 0000000..13c3651
--- /dev/null
+++ b/godot/levels/Level2.tscn
@@ -0,0 +1,41 @@
+[gd_scene load_steps=5 format=2]
+
+[ext_resource path="res://camera_fix.gd" type="Script" id=1]
+[ext_resource path="res://characters/player/Player.tscn" type="PackedScene" id=2]
+[ext_resource path="res://assets/backgrounds/hills.png" type="Texture" id=3]
+[ext_resource path="res://levels/Level2.tmx" type="PackedScene" id=4]
+
+[node name="Level2" type="Node2D"]
+
+[node name="Player" parent="." instance=ExtResource( 2 )]
+
+[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.2 )
+motion_offset = Vector2( 0, -288 )
+motion_mirroring = Vector2( 528, 0 )
+
+[node name="Sprite" type="Sprite" parent="ParallaxBackground/ParallaxLayer"]
+texture = ExtResource( 3 )
+centered = false
+
+[node name="Map" type="Node2D" parent="."]
+
+[node name="Level2" parent="Map" instance=ExtResource( 4 )]
+script = ExtResource( 1 )
diff --git a/godot/levels/Prototype.tmx b/godot/levels/Prototype.tmx
new file mode 100644
index 0000000..f6fb3da
--- /dev/null
+++ b/godot/levels/Prototype.tmx
@@ -0,0 +1,32 @@
+
+
diff --git a/godot/levels/Prototype.tmx.import b/godot/levels/Prototype.tmx.import
new file mode 100644
index 0000000..01f4b39
--- /dev/null
+++ b/godot/levels/Prototype.tmx.import
@@ -0,0 +1,23 @@
+[remap]
+
+importer="vnen.tiled_importer"
+type="PackedScene"
+path="res://.import/Prototype.tmx-1674122a110386791b767b1f6628b68b.scn"
+
+[deps]
+
+source_file="res://levels/Prototype.tmx"
+dest_files=[ "res://.import/Prototype.tmx-1674122a110386791b767b1f6628b68b.scn" ]
+
+[params]
+
+custom_properties=true
+tile_metadata=false
+uv_clip=true
+image_flags=7
+collision_layer=2
+collision_mask=0
+embed_internal_images=false
+save_tiled_properties=false
+add_background=true
+post_import_script=""
diff --git a/godot/Level1.tscn b/godot/levels/Prototype.tscn
similarity index 59%
rename from godot/Level1.tscn
rename to godot/levels/Prototype.tscn
index 4c3cddc..d33d09c 100644
--- a/godot/Level1.tscn
+++ b/godot/levels/Prototype.tscn
@@ -1,23 +1,22 @@
-[gd_scene load_steps=4 format=2]
+[gd_scene load_steps=5 format=2]
-[ext_resource path="res://assets/backgrounds/mountains.png" type="Texture" id=1]
-[ext_resource path="res://levels/level01.tmx" type="PackedScene" id=3]
-[ext_resource path="res://characters/player/Player.tscn" type="PackedScene" id=4]
+[ext_resource path="res://camera_fix.gd" type="Script" id=1]
+[ext_resource path="res://characters/player/Player.tscn" type="PackedScene" id=2]
+[ext_resource path="res://levels/Prototype.tmx" type="PackedScene" id=3]
+[ext_resource path="res://assets/backgrounds/mountains.png" type="Texture" id=4]
-[node name="Level1" type="Node2D"]
+[node name="Prototype" type="Node2D"]
-[node name="Player" parent="." instance=ExtResource( 4 )]
+[node name="Player" parent="." instance=ExtResource( 2 )]
[node name="Camera2D" type="Camera2D" parent="Player"]
current = true
limit_left = 0
limit_top = 0
-limit_right = 2304
-limit_bottom = 576
+limit_right = 512
+limit_bottom = 288
drag_margin_h_enabled = true
drag_margin_v_enabled = true
-editor_draw_limits = true
-editor_draw_drag_margin = true
__meta__ = {
"_edit_bone_": true
}
@@ -28,14 +27,15 @@ rect = Rect2( 0, 0, 24, 24 )
[node name="ParallaxBackground" type="ParallaxBackground" parent="."]
[node name="ParallaxLayer" type="ParallaxLayer" parent="ParallaxBackground"]
-motion_scale = Vector2( 0.2, 1 )
+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( 1 )
+texture = ExtResource( 4 )
centered = false
[node name="Map" type="Node2D" parent="."]
-position = Vector2( 0, 18 )
-[node name="level01" parent="Map" instance=ExtResource( 3 )]
+[node name="Prototype" parent="Map" instance=ExtResource( 3 )]
+script = ExtResource( 1 )
diff --git a/godot/levels/level01.tmx b/godot/levels/level01.tmx
deleted file mode 100644
index 9bc5967..0000000
--- a/godot/levels/level01.tmx
+++ /dev/null
@@ -1,112 +0,0 @@
-
-
diff --git a/godot/parallax/clouds.tmx b/godot/parallax/clouds.tmx
index 59fcd96..5eb1130 100644
--- a/godot/parallax/clouds.tmx
+++ b/godot/parallax/clouds.tmx
@@ -2,31 +2,8 @@
diff --git a/godot/parallax/hills.tmx b/godot/parallax/hills.tmx
index bf732ab..5373dbb 100644
--- a/godot/parallax/hills.tmx
+++ b/godot/parallax/hills.tmx
@@ -2,31 +2,8 @@
diff --git a/godot/parallax/mountains.tmx b/godot/parallax/mountains.tmx
index e963695..968553e 100644
--- a/godot/parallax/mountains.tmx
+++ b/godot/parallax/mountains.tmx
@@ -2,31 +2,8 @@
diff --git a/godot/parallax/snow.tmx b/godot/parallax/snow.tmx
index b35f59d..adabf88 100644
--- a/godot/parallax/snow.tmx
+++ b/godot/parallax/snow.tmx
@@ -2,31 +2,8 @@
diff --git a/godot/project.godot b/godot/project.godot
index e1b9eb4..52b2be8 100644
--- a/godot/project.godot
+++ b/godot/project.godot
@@ -53,6 +53,18 @@ texture={
"stream": false,
"svg/scale": 1.0
}
+vnen.tiled_importer={
+"add_background": true,
+"collision_layer": 2,
+"collision_mask": 0,
+"custom_properties": true,
+"embed_internal_images": false,
+"image_flags": 7,
+"post_import_script": "",
+"save_tiled_properties": false,
+"tile_metadata": false,
+"uv_clip": true
+}
[input]
@@ -81,8 +93,8 @@ right={
[layer_names]
-2d_physics/layer_1="Tiles"
-2d_physics/layer_2="Player"
+2d_physics/layer_1="Player"
+2d_physics/layer_2="Tiles"
[physics]
diff --git a/godot/tilesets/backgrounds.tsx b/godot/tilesets/backgrounds.tsx
index 1635d01..5e4097e 100644
--- a/godot/tilesets/backgrounds.tsx
+++ b/godot/tilesets/backgrounds.tsx
@@ -1,4 +1,5 @@
+
diff --git a/godot/tilesets/tiles.tsx b/godot/tilesets/tiles.tsx
index 7eb103a..547a5ff 100644
--- a/godot/tilesets/tiles.tsx
+++ b/godot/tilesets/tiles.tsx
@@ -1,5 +1,6 @@
+
@@ -21,11 +22,56 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -46,11 +92,48 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -91,6 +174,12 @@
+
+
+
+
+
+
@@ -111,6 +200,17 @@
+
+
+
+
+
+
+
+
+
+
+
@@ -131,6 +231,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -156,6 +288,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -176,6 +329,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -196,4 +369,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Main.cpp b/src/Main.cpp
index 387ff6e..4f91c0c 100644
--- a/src/Main.cpp
+++ b/src/Main.cpp
@@ -9,6 +9,7 @@ void Main::_register_methods()
{
register_method("_ready", &Main::_ready);
register_method("_physics_process", &Main::_physics_process);
+ register_property>("level", &Main::set_level, &Main::get_level, NULL, GODOT_METHOD_RPC_MODE_DISABLED, GODOT_PROPERTY_USAGE_DEFAULT, GODOT_PROPERTY_HINT_RESOURCE_TYPE, String("PackedScene"));
register_property("full_screen", &Main::set_full_screen, &Main::get_full_screen, main::full_screen);
register_property("window_size", &Main::set_window_size, &Main::get_window_size, main::window_size);
register_property("launch_screen", &Main::set_launch_screen, &Main::get_launch_screen, main::launch_screen);
@@ -45,6 +46,11 @@ void Main::_ready()
_os->get_screen_position(get_launch_screen()) + _os->get_screen_size() * 0.5 - _os->get_window_size() * 0.5
);
}
+
+ if (level != NULL)
+ {
+ add_child(level->instance());
+ }
}
void Main::_physics_process(float delta)
@@ -55,6 +61,16 @@ void Main::_physics_process(float delta)
}
}
+void Main::set_level(Ref level)
+{
+ this->level = level;
+}
+
+Ref Main::get_level()
+{
+ return this->level;
+}
+
void Main::set_full_screen(bool full_screen)
{
this->full_screen = full_screen;
diff --git a/src/Main.h b/src/Main.h
index 4d86783..d89c5c9 100644
--- a/src/Main.h
+++ b/src/Main.h
@@ -5,6 +5,8 @@
#include
#include
#include
+#include
+#include
/**
* @brief This is the godot namespace for all the code included in the library.
@@ -57,6 +59,11 @@ namespace godot
*/
Input *_input;
+ /**
+ * @brief The first level to load
+ *
+ */
+ Ref level;
/**
* @brief If the window is full screen or not.
*
@@ -116,6 +123,20 @@ namespace godot
*/
void _physics_process(float delta);
+ /**
+ * @brief Set the level object.
+ *
+ * @param[in] level The new level to load when starting.
+ */
+ void set_level(Ref level);
+
+ /**
+ * @brief Get the level object.
+ *
+ * @return Ref The level scene to load.
+ */
+ Ref get_level();
+
/**
* @brief Set the full screen object.
*
diff --git a/src/state_machine/State.cpp b/src/state_machine/State.cpp
index 29efa48..2763449 100644
--- a/src/state_machine/State.cpp
+++ b/src/state_machine/State.cpp
@@ -25,12 +25,12 @@ void State::_init()
void State::_state_enter(const String state, const Array args)
{
- WARN_PRINT("State " + state + " is missing its _state_enter method!");
+ WARN_PRINT("State " + get_state_machine()->get_current_state() + " is missing its _state_enter method!");
}
void State::_state_exit(const String state, const Array args)
{
- WARN_PRINT("State " + state + " is missing its _state_exit method!");
+ WARN_PRINT("State " + get_state_machine()->get_current_state() + " is missing its _state_exit method!");
}
void State::set_parent(Node *parent)
diff --git a/src/state_machine/StateMachine.cpp b/src/state_machine/StateMachine.cpp
index 4370842..73b1f9d 100644
--- a/src/state_machine/StateMachine.cpp
+++ b/src/state_machine/StateMachine.cpp
@@ -34,7 +34,15 @@ void StateMachine::_ready()
connect("tree_entered", this, "_on_StateMachine_tree_entered");
connect("tree_exiting", this, "_on_StateMachine_tree_exiting");
parent = get_parent();
- set_current_state(get_default_state());
+ add_states();
+ if (has(get_default_state()))
+ {
+ set_current_state(get_default_state());
+ }
+ else
+ {
+ WARN_PRINT("The selected default state " + get_default_state() + " doesn't exist!");
+ }
setup();
}
@@ -46,13 +54,13 @@ void StateMachine::setup()
{
if (children.size() > 0)
{
- WARN_PRINT("State machine doesn't have a default state set, using first child!");
+ WARN_PRINT("The state machine doesn't have a default state set, using first child!");
auto child = Object::cast_to(children[0].operator Object*());
set_current_state(child->get_name());
}
else
{
- ERR_PRINT("State machine doesn't have a default state set and has no child states!");
+ ERR_PRINT("The state machine doesn't have a default state set and has no child states!");
return;
}
}
@@ -60,7 +68,6 @@ void StateMachine::setup()
for (uint8_t i = 0; i < children.size(); i++)
{
auto child = Object::cast_to(children[i].operator Object*());
- add_state(child->get_name(), child);
child->call("set_state_machine", this);
@@ -72,7 +79,24 @@ void StateMachine::setup()
}
}
- this->call("_state_enter", get_current_state());
+ Node *state_node = Object::cast_to(this->states[get_current_state()]);
+ if (state_node->has_method("_state_enter"))
+ {
+ this->call("_state_enter", get_current_state());
+ }
+ else {
+ WARN_PRINT("The state " + get_current_state() + " doesn't have a _state_enter method!");
+ }
+}
+
+void StateMachine::add_states()
+{
+ auto children = get_children();
+ for (uint8_t i = 0; i < children.size(); i++)
+ {
+ auto child = Object::cast_to(children[i].operator Object*());
+ add_state(child->get_name(), child);
+ }
}
void StateMachine::add_state(const String state, Node *child)
@@ -111,8 +135,31 @@ void StateMachine::change(const String state, const Array &args)
return this->restart(state, args);
}
+ if (!has(state))
+ {
+ WARN_PRINT("The state " + state + " does not exist, called from state " + get_current_state() + "!");
+ return;
+ }
+
auto previous_state = get_current_state();
- auto exiting = this->call("_state_exit", state, args);
+
+ Variant exiting;
+ Node *state_node = Object::cast_to(this->states[previous_state]);
+ if (state_node)
+ {
+ if (state_node->has_method("_state_exit"))
+ {
+ exiting = this->call("_state_exit", state, args);
+ }
+ else
+ {
+ WARN_PRINT("The state " + get_current_state() + " doesn't have a _state_exit method!");
+ }
+ }
+ else
+ {
+ ERR_PRINT("Could not get current state node for " + get_current_state() + "!");
+ }
if (get_current_state() != "")
{
@@ -132,7 +179,23 @@ void StateMachine::change(const String state, const Array &args)
auto child = Object::cast_to(states[get_current_state()].operator Object*());
this->add_child(child);
- this->call("_state_enter", previous_state, args);
+ state_node = Object::cast_to(this->states[get_current_state()]);
+ if (state_node)
+ {
+ if (state_node->has_method("_state_enter"))
+ {
+ this->call("_state_enter", previous_state, args);
+ }
+ else
+ {
+ WARN_PRINT("The state " + get_current_state() + " doesn't have a _state_enter method!");
+ }
+ }
+ else
+ {
+ ERR_PRINT("Could not get current state node for " + get_current_state() + "!");
+ }
+
this->emit_signal("state_entered", get_current_state());
if (debug)
{
@@ -143,11 +206,23 @@ void StateMachine::change(const String state, const Array &args)
Variant StateMachine::call(const String method, const Array &args)
{
auto node = Object::cast_to(states[get_current_state()].operator Object*());
- if (node != nullptr)
+ if (node)
{
- return node->call(method, args);
+ if (node->has_method(method))
+ {
+ return node->call(method, args);
+ }
+ else
+ {
+ WARN_PRINT("The state " + get_current_state() + " doesn't contain the method " + method + "!");
+ return Variant();
+ }
+ }
+ else
+ {
+ ERR_PRINT("Could not get current state node for " + get_current_state() + "!");
+ return Variant();
}
- return Variant();
}
Variant StateMachine::_call(const String method, const Array &args)
@@ -196,7 +271,7 @@ void StateMachine::_on_StateMachine_tree_exiting()
for (uint8_t i = 0; i < keys.size(); i++)
{
auto child = Object::cast_to(states[keys[i]].operator Object*());
- if (child != nullptr)
+ if (child)
{
auto children = get_children();
if (!children.has(child))
@@ -204,5 +279,10 @@ void StateMachine::_on_StateMachine_tree_exiting()
this->add_child(child);
}
}
+ else
+ {
+ ERR_PRINT("Could not get child node!");
+ return;
+ }
}
}
diff --git a/src/state_machine/StateMachine.h b/src/state_machine/StateMachine.h
index 02789ba..0fdb8d7 100644
--- a/src/state_machine/StateMachine.h
+++ b/src/state_machine/StateMachine.h
@@ -43,6 +43,12 @@ namespace godot
*/
Dictionary states;
+ /**
+ * @brief This adds all nodes of the states machine as states in the machine.
+ *
+ */
+ void add_states();
+
/**
* @brief This adds a state to the list of states in the state machine.
*
@@ -51,6 +57,13 @@ namespace godot
*/
void add_state(const String state, Node *child);
+ /**
+ * @brief Set the current state object.
+ *
+ * @param[in] current_state The current state that is running.
+ */
+ void set_current_state(const String current_state);
+
public:
/**
* @brief This method registers classes with Godot.
@@ -157,6 +170,13 @@ namespace godot
*/
String get_default_state();
+ /**
+ * @brief Get the current state object.
+ *
+ * @return String The current running state.
+ */
+ String get_current_state();
+
/**
* @brief Set the debug object.
*
@@ -172,20 +192,6 @@ namespace godot
*/
bool get_debug();
- /**
- * @brief Set the current state object.
- *
- * @param[in] current_state The current state that is running.
- */
- void set_current_state(const String current_state);
-
- /**
- * @brief Get the current state object.
- *
- * @return String The current running state.
- */
- String get_current_state();
-
/**
* @brief This method is called when the signal tree_entered is emitted.
*