summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assets/world/ground_tileset.asepritebin0 -> 641 bytes
-rw-r--r--assets/world/ground_tileset.pngbin0 -> 547 bytes
-rw-r--r--src/entities/actors/snake/scenes/Head.tscn20
-rw-r--r--src/entities/actors/snake/scripts/dash_state.gd25
-rw-r--r--src/entities/actors/snake/scripts/generic_segment.gd2
-rw-r--r--src/entities/actors/snake/scripts/head.gd61
-rw-r--r--src/entities/actors/snake/scripts/jump_state.gd27
-rw-r--r--src/entities/actors/snake/scripts/normal_state.gd28
-rw-r--r--src/entities/actors/snake/scripts/slow_state.gd27
-rw-r--r--src/entities/actors/snake/scripts/state_machine.gd72
-rw-r--r--src/event.gd9
-rw-r--r--src/global.gd17
-rw-r--r--src/project.godot21
-rw-r--r--src/tools/score_manager/scripts/score_manager.gd2
-rw-r--r--src/tools/world_generator/scenes/WorldGenerator.tscn136
-rw-r--r--src/tools/world_generator/scripts/walker_head.gd19
-rw-r--r--src/tools/world_generator/scripts/walker_unit.gd6
-rw-r--r--src/tools/world_generator/scripts/world_generator.gd6
-rw-r--r--src/tools/world_generator/sprites/ground_tileset.pngbin0 -> 547 bytes
-rw-r--r--src/tools/world_generator/sprites/ground_tileset.png.import35
20 files changed, 450 insertions, 63 deletions
diff --git a/assets/world/ground_tileset.aseprite b/assets/world/ground_tileset.aseprite
new file mode 100644
index 0000000..cd81af5
--- /dev/null
+++ b/assets/world/ground_tileset.aseprite
Binary files differ
diff --git a/assets/world/ground_tileset.png b/assets/world/ground_tileset.png
new file mode 100644
index 0000000..cd9d696
--- /dev/null
+++ b/assets/world/ground_tileset.png
Binary files differ
diff --git a/src/entities/actors/snake/scenes/Head.tscn b/src/entities/actors/snake/scenes/Head.tscn
index a08197b..d69cbf8 100644
--- a/src/entities/actors/snake/scenes/Head.tscn
+++ b/src/entities/actors/snake/scenes/Head.tscn
@@ -1,8 +1,12 @@
-[gd_scene load_steps=10 format=2]
+[gd_scene load_steps=14 format=2]
[ext_resource path="res://entities/actors/snake/sprites/head.png" type="Texture" id=1]
[ext_resource path="res://entities/actors/snake/scripts/head.gd" type="Script" id=2]
[ext_resource path="res://entities/actors/snake/sprites/tongue.png" type="Texture" id=3]
+[ext_resource path="res://entities/actors/snake/scripts/state_machine.gd" type="Script" id=4]
+[ext_resource path="res://entities/actors/snake/scripts/normal_state.gd" type="Script" id=5]
+[ext_resource path="res://entities/actors/snake/scripts/dash_state.gd" type="Script" id=6]
+[ext_resource path="res://entities/actors/snake/scripts/slow_state.gd" type="Script" id=7]
[sub_resource type="AtlasTexture" id=2]
atlas = ExtResource( 3 )
@@ -35,6 +39,20 @@ radius = 2.0
collision_mask = 262
script = ExtResource( 2 )
+[node name="StateMachine" type="Node" parent="."]
+script = ExtResource( 4 )
+
+[node name="NormalState" type="Node" parent="StateMachine"]
+script = ExtResource( 5 )
+
+[node name="DashState" type="Node" parent="StateMachine"]
+script = ExtResource( 6 )
+
+[node name="SlowState" type="Node" parent="StateMachine"]
+script = ExtResource( 7 )
+
+[node name="JumpState" type="Node" parent="StateMachine"]
+
[node name="Tongue" type="AnimatedSprite" parent="."]
position = Vector2( 0, -5 )
frames = SubResource( 6 )
diff --git a/src/entities/actors/snake/scripts/dash_state.gd b/src/entities/actors/snake/scripts/dash_state.gd
new file mode 100644
index 0000000..3eb0bdf
--- /dev/null
+++ b/src/entities/actors/snake/scripts/dash_state.gd
@@ -0,0 +1,25 @@
+extends Node
+
+var fsm: StateMachine
+
+
+func enter():
+ if fsm.DEBUG:
+ print("Got inside %s." % name)
+ Event.emit_signal("snake_started_dash")
+ Global.SNAKE_SPEED = Global.SNAKE_DASH_SPEED
+ yield(get_tree().create_timer(Global.SNAKE_DASH_TIME), "timeout")
+ exit()
+
+
+func exit():
+ Event.emit_signal("snake_finished_dash")
+ Global.SNAKE_SPEED = Global.SNAKE_SPEED_BACKUP
+ fsm.back()
+
+
+func physics_process(delta: float) -> void:
+ fsm.player.velocity = fsm.player.direction * Global.SNAKE_SPEED
+ fsm.player.velocity = fsm.player.move_and_slide(fsm.player.velocity)
+
+ fsm.slow_down_on_collisions(Global.SNAKE_DASH_SPEED)
diff --git a/src/entities/actors/snake/scripts/generic_segment.gd b/src/entities/actors/snake/scripts/generic_segment.gd
index d0bb944..a1a930a 100644
--- a/src/entities/actors/snake/scripts/generic_segment.gd
+++ b/src/entities/actors/snake/scripts/generic_segment.gd
@@ -21,4 +21,4 @@ func _on_body_entered(body: Node) -> void:
func _on_snake_rotated() -> void:
# this is just random, i need to offset a tiny bit whenever the snake rotates
# so that the first body segmetn doesn't catch up with the head
- offset -= Global.SNAKE_SPEED * pow(get_physics_process_delta_time(), 2) \ No newline at end of file
+ offset -= 0.75 * Global.SNAKE_SPEED * pow(get_physics_process_delta_time(), 2) \ No newline at end of file
diff --git a/src/entities/actors/snake/scripts/head.gd b/src/entities/actors/snake/scripts/head.gd
index 8747910..e6824a7 100644
--- a/src/entities/actors/snake/scripts/head.gd
+++ b/src/entities/actors/snake/scripts/head.gd
@@ -9,49 +9,30 @@ onready var tongue_sprite: AnimatedSprite = $Tongue
var _initial_speed: float = Global.SNAKE_SPEED
var velocity: Vector2 = Vector2.ZERO
-var _direction: Vector2 = Vector2.UP
+var direction: Vector2 = Vector2.UP
var _time_elapsed: float = 0.0
+var can_dash: bool = true
+var can_slow: bool = true
+var can_jump: bool = true
+
func _ready() -> void:
Event.connect("food_eaten", self, "_on_food_eaten")
+ Event.connect("snake_started_dash", self, "_on_snake_started_dash")
+ Event.connect("snake_started_slow", self, "_on_snake_started_slow")
+ Event.connect("snake_started_jump", self, "_on_snake_started_jump")
tongue_sprite.visible = false
-func _physics_process(delta: float) -> void:
- if Input.is_action_pressed("move_left"):
- _rotate_to(LEFT)
- if Input.is_action_pressed("move_right"):
- _rotate_to(RIGHT)
-
- velocity = _direction * Global.SNAKE_SPEED
-
- # not sure if needed, worked wonders when using a Node2D instead of KB2D
- velocity = move_and_slide(velocity)
-
- # slow down on collisions, so it isn't as unfair
- if get_last_slide_collision():
- var speed: float = velocity.length()
- Global.SNAKE_SPEED = speed
- else:
- Global.SNAKE_SPEED = Global.SNAKE_SPEED_BACKUP
-
- # handle slow speeds
- if Global.SNAKE_SPEED <= Global.SNAKE_SPEED_BACKUP / 4.0:
- Global.SNAKE_SPEED = Global.SNAKE_SPEED_BACKUP
- Event.emit_signal("game_over")
-
- _handle_time_elapsed(delta)
-
-
-func _rotate_to(direction: int) -> void:
- rotate(deg2rad(direction * Global.SNAKE_ROT_SPEED * get_physics_process_delta_time()))
- _direction = _direction.rotated(deg2rad(direction * Global.SNAKE_ROT_SPEED * get_physics_process_delta_time()))
+func rotate_to(_direction: int) -> void:
+ rotate(deg2rad(_direction * Global.SNAKE_ROT_SPEED * get_physics_process_delta_time()))
+ direction = direction.rotated(deg2rad(_direction * Global.SNAKE_ROT_SPEED * get_physics_process_delta_time()))
Event.emit_signal("snake_rotated")
# using a timer is not recommended for < 0.01
-func _handle_time_elapsed(delta: float) -> void:
+func handle_time_elapsed(delta: float) -> void:
if _time_elapsed >= Global.SNAKE_POSITION_UPDATE_INTERVAL:
Event.emit_signal("snake_path_new_point", global_position)
_time_elapsed = 0.0
@@ -65,3 +46,21 @@ func _on_food_eaten(properties: Dictionary) -> void:
yield(tongue_sprite, "animation_finished")
tongue_sprite.stop()
tongue_sprite.frame = 0
+
+
+func _on_snake_started_dash() -> void:
+ can_dash = false
+ yield(get_tree().create_timer(Global.SNAKE_DASH_COOLDOWN), "timeout")
+ can_dash = true
+
+
+func _on_snake_started_slow() -> void:
+ can_slow = false
+ yield(get_tree().create_timer(Global.SNAKE_SLOW_COOLDOWN), "timeout")
+ can_slow = true
+
+
+func _on_snake_started_jump() -> void:
+ can_jump = false
+ yield(get_tree().create_timer(Global.SNAKE_JUMP_COOLDOWN), "timeout")
+ can_jump = true
diff --git a/src/entities/actors/snake/scripts/jump_state.gd b/src/entities/actors/snake/scripts/jump_state.gd
new file mode 100644
index 0000000..396ceb4
--- /dev/null
+++ b/src/entities/actors/snake/scripts/jump_state.gd
@@ -0,0 +1,27 @@
+extends Node
+
+var fsm: StateMachine
+
+
+func enter():
+ if fsm.DEBUG:
+ print("Got inside %s." % name)
+ Event.emit_signal("snake_started_dash")
+ Global.SNAKE_SPEED = Global.SNAKE_DASH_SPEED
+ yield(get_tree().create_timer(Global.SNAKE_DASH_TIME), "timeout")
+ exit()
+
+
+func exit():
+ Event.emit_signal("snake_finished_dash")
+ Global.SNAKE_SPEED = Global.SNAKE_SPEED_BACKUP
+ fsm.back()
+
+
+func physics_process(delta: float) -> float:
+ fsm.player.velocity = fsm.player.direction * Global.SNAKE_SPEED
+ fsm.player.velocity = fsm.player.move_and_slide(fsm.player.velocity)
+
+ fsm.slow_down_on_collisions(Global.SNAKE_DASH_SPEED)
+
+ return delta
diff --git a/src/entities/actors/snake/scripts/normal_state.gd b/src/entities/actors/snake/scripts/normal_state.gd
new file mode 100644
index 0000000..11981a3
--- /dev/null
+++ b/src/entities/actors/snake/scripts/normal_state.gd
@@ -0,0 +1,28 @@
+extends Node
+
+var fsm: StateMachine
+
+
+func enter():
+ if fsm.DEBUG:
+ print("Got inside %s." % name)
+
+
+func exit(next_state):
+ fsm.change_to(next_state)
+
+
+func physics_process(delta: float) -> void:
+ fsm.player.velocity = fsm.player.direction * Global.SNAKE_SPEED
+ fsm.player.velocity = fsm.player.move_and_slide(fsm.player.velocity)
+
+ fsm.slow_down_on_collisions(Global.SNAKE_SPEED_BACKUP)
+
+
+func input(event: InputEvent) -> void:
+ if fsm.player.can_dash and event.is_action_pressed("dash"):
+ exit("DashState")
+ if fsm.player.can_slow and event.is_action_pressed("slow"):
+ exit("SlowState")
+ # if fsm.player.can_jump and event.is_action_pressed("jump"):
+ # exit("JumpState")
diff --git a/src/entities/actors/snake/scripts/slow_state.gd b/src/entities/actors/snake/scripts/slow_state.gd
new file mode 100644
index 0000000..8d54bfb
--- /dev/null
+++ b/src/entities/actors/snake/scripts/slow_state.gd
@@ -0,0 +1,27 @@
+extends Node
+
+var fsm: StateMachine
+
+
+func enter():
+ if fsm.DEBUG:
+ print("Got inside %s." % name)
+ Event.emit_signal("snake_started_slow")
+ Global.SNAKE_SPEED = Global.SNAKE_SLOW_SPEED
+ yield(get_tree().create_timer(Global.SNAKE_SLOW_TIME), "timeout")
+ exit()
+
+
+func exit():
+ Event.emit_signal("snake_finished_dash")
+ Global.SNAKE_SPEED = Global.SNAKE_SPEED_BACKUP
+ fsm.back()
+
+
+func physics_process(delta: float) -> float:
+ fsm.player.velocity = fsm.player.direction * Global.SNAKE_SPEED
+ fsm.player.velocity = fsm.player.move_and_slide(fsm.player.velocity)
+
+ fsm.slow_down_on_collisions(Global.SNAKE_SLOW_SPEED)
+
+ return delta
diff --git a/src/entities/actors/snake/scripts/state_machine.gd b/src/entities/actors/snake/scripts/state_machine.gd
new file mode 100644
index 0000000..b63f272
--- /dev/null
+++ b/src/entities/actors/snake/scripts/state_machine.gd
@@ -0,0 +1,72 @@
+class_name StateMachine
+extends Node
+
+const DEBUG: bool = false
+
+var player: KinematicBody2D
+var state: Node
+var history: Array = []
+
+
+func _ready() -> void:
+ player = get_parent()
+ state = get_child(0)
+ _enter_state()
+
+
+func change_to(new_state: String) -> void:
+ history.append(state.name)
+ state = get_node(new_state)
+ _enter_state()
+
+
+func back() -> void:
+ if history.size() > 0:
+ state = get_node(history.pop_back())
+ _enter_state()
+
+
+func _enter_state() -> void:
+ if DEBUG:
+ print("Entering state %s" % state.name)
+ state.fsm = self
+ state.enter()
+
+
+# routing game loop functions
+func _process(delta: float) -> void:
+ if state.has_method("process"):
+ state.process(delta)
+
+
+func _physics_process(delta: float) -> void:
+ if Input.is_action_pressed("move_left"):
+ player.rotate_to(player.LEFT)
+ if Input.is_action_pressed("move_right"):
+ player.rotate_to(player.RIGHT)
+
+ # state specific code, move_and_slide is called here
+ if state.has_method("physics_process"):
+ state.physics_process(delta)
+
+ handle_slow_speeds()
+
+ player.handle_time_elapsed(delta)
+
+
+func slow_down_on_collisions(speed_backup: float):
+ if player.get_last_slide_collision():
+ Global.SNAKE_SPEED = player.velocity.length()
+ else:
+ Global.SNAKE_SPEED = speed_backup
+
+
+func handle_slow_speeds() -> void:
+ if Global.SNAKE_SPEED <= Global.SNAKE_SPEED_BACKUP / 4.0:
+ Global.SNAKE_SPEED = Global.SNAKE_SPEED_BACKUP
+ Event.emit_signal("game_over")
+
+
+func _input(event: InputEvent) -> void:
+ if state.has_method("input"):
+ state.input(event)
diff --git a/src/event.gd b/src/event.gd
index 6c817c8..6ef812c 100644
--- a/src/event.gd
+++ b/src/event.gd
@@ -14,6 +14,15 @@ signal snake_segment_body_entered(body)
signal snake_rotated
signal snake_growth_progress(progress)
+signal snake_started_dash
+signal snake_finished_dash
+
+signal snake_started_slow
+signal snake_finished_slow
+
+signal snake_started_jump
+signal snake_finished_jump
+
signal food_placing_new_food(special, type)
signal food_placed_new_food(properties)
signal food_eaten(properties)
diff --git a/src/global.gd b/src/global.gd
index 112f16c..fc188d8 100644
--- a/src/global.gd
+++ b/src/global.gd
@@ -3,8 +3,9 @@ extends Node
var GAME_NODE: PackedScene = preload("res://Game.tscn")
var GAME_SCALE: float = 2.0
var TILE_SIZE: int = 16
-var WORLD_TILE_PATH: int = 0
-var WORLD_TILE_WALL: int = 1
+var GROUND_TILE_AMOUNT: int = 8
+# var WORLD_TILE_PATH: int = 0
+# var WORLD_TILE_WALL: int = 1
var SNAKE_INITIAL_SEGMENTS: int = 1
var SNAKE_SPEED: float = 50.0
@@ -14,6 +15,18 @@ var SNAKE_POSITION_UPDATE_INTERVAL: float = 0.001
# this usually corresponds to the sprite size
var SNAKE_SEGMENT_SIZE: float = 6.0
+var SNAKE_DASH_SPEED: float = SNAKE_SPEED * 2.0
+var SNAKE_DASH_TIME: float = 1.0
+var SNAKE_DASH_COOLDOWN: float = 4.0
+
+var SNAKE_SLOW_SPEED: float = SNAKE_SPEED / 2.0
+var SNAKE_SLOW_TIME: float = 1.0
+var SNAKE_SLOW_COOLDOWN: float = 4.0
+
+var SNAKE_JUMP_SPEED: float = SNAKE_SPEED * 1.5
+var SNAKE_JUMP_TIME: float = 0.5
+var SNAKE_JUMP_COOLDOWN: float = 4.0
+
var POINTS_TO_GROW: int = 10
# percentage of the available tiles
diff --git a/src/project.godot b/src/project.godot
index 7ad8041..4b8f008 100644
--- a/src/project.godot
+++ b/src/project.godot
@@ -65,6 +65,11 @@ _global_script_classes=[ {
"path": "res://entities/actors/snake/scripts/snake.gd"
}, {
"base": "Node",
+"class": "StateMachine",
+"language": "GDScript",
+"path": "res://entities/actors/snake/scripts/state_machine.gd"
+}, {
+"base": "Node",
"class": "Stats",
"language": "GDScript",
"path": "res://stats.gd"
@@ -81,6 +86,7 @@ _global_script_class_icons={
"ProgressionLabel": "",
"ScoreLabel": "",
"Snake": "",
+"StateMachine": "",
"Stats": ""
}
@@ -175,6 +181,21 @@ debug={
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":80,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
]
}
+dash={
+"deadzone": 0.5,
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
+ ]
+}
+slow={
+"deadzone": 0.5,
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
+ ]
+}
+jump={
+"deadzone": 0.5,
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
+ ]
+}
[layer_names]
diff --git a/src/tools/score_manager/scripts/score_manager.gd b/src/tools/score_manager/scripts/score_manager.gd
index 492ceb5..95fcfce 100644
--- a/src/tools/score_manager/scripts/score_manager.gd
+++ b/src/tools/score_manager/scripts/score_manager.gd
@@ -49,7 +49,7 @@ func _process_points(points: int) -> int:
func _spawn_added_score_text(points: int, location: Vector2) -> void:
var label: ScoreLabel = SCORE_LABEL.instance()
add_child(label)
- label.set_properties(points, Color.red, location)
+ label.set_properties(points, Color.aquamarine, location)
func _spawn_added_segment_text(amount: int) -> void:
diff --git a/src/tools/world_generator/scenes/WorldGenerator.tscn b/src/tools/world_generator/scenes/WorldGenerator.tscn
index 824d298..c098207 100644
--- a/src/tools/world_generator/scenes/WorldGenerator.tscn
+++ b/src/tools/world_generator/scenes/WorldGenerator.tscn
@@ -1,16 +1,13 @@
-[gd_scene load_steps=8 format=2]
+[gd_scene load_steps=9 format=2]
-[ext_resource path="res://tools/world_generator/sprites/white.png" type="Texture" id=1]
+[ext_resource path="res://tools/world_generator/sprites/ground_tileset.png" type="Texture" id=1]
[ext_resource path="res://tools/world_generator/sprites/black.png" type="Texture" id=2]
[ext_resource path="res://tools/world_generator/scenes/WalkerUnit.tscn" type="PackedScene" id=3]
[ext_resource path="res://tools/world_generator/scenes/WalkerHead.tscn" type="PackedScene" id=4]
[ext_resource path="res://tools/world_generator/scripts/world_generator.gd" type="Script" id=5]
-[sub_resource type="ConvexPolygonShape2D" id=2]
-points = PoolVector2Array( 16, 16, 0, 16, 0, 0, 16, 0 )
-
[sub_resource type="TileSet" id=1]
-0/name = "white.png 0"
+0/name = "ground_tileset.png 0"
0/texture = ExtResource( 1 )
0/tex_offset = Vector2( 0, 0 )
0/modulate = Color( 1, 1, 1, 1 )
@@ -24,39 +21,148 @@ points = PoolVector2Array( 16, 16, 0, 16, 0, 0, 16, 0 )
0/shape_one_way_margin = 0.0
0/shapes = [ ]
0/z_index = 0
-1/name = "black.png 1"
-1/texture = ExtResource( 2 )
+1/name = "ground_tileset.png 1"
+1/texture = ExtResource( 1 )
1/tex_offset = Vector2( 0, 0 )
1/modulate = Color( 1, 1, 1, 1 )
-1/region = Rect2( 0, 0, 16, 16 )
+1/region = Rect2( 16, 0, 16, 16 )
1/tile_mode = 0
1/occluder_offset = Vector2( 0, 0 )
1/navigation_offset = Vector2( 0, 0 )
1/shape_offset = Vector2( 0, 0 )
1/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
-1/shape = SubResource( 2 )
1/shape_one_way = false
-1/shape_one_way_margin = 1.0
-1/shapes = [ {
+1/shape_one_way_margin = 0.0
+1/shapes = [ ]
+1/z_index = 0
+2/name = "ground_tileset.png 2"
+2/texture = ExtResource( 1 )
+2/tex_offset = Vector2( 0, 0 )
+2/modulate = Color( 1, 1, 1, 1 )
+2/region = Rect2( 32, 0, 16, 16 )
+2/tile_mode = 0
+2/occluder_offset = Vector2( 0, 0 )
+2/navigation_offset = Vector2( 0, 0 )
+2/shape_offset = Vector2( 0, 0 )
+2/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
+2/shape_one_way = false
+2/shape_one_way_margin = 0.0
+2/shapes = [ ]
+2/z_index = 0
+3/name = "ground_tileset.png 3"
+3/texture = ExtResource( 1 )
+3/tex_offset = Vector2( 0, 0 )
+3/modulate = Color( 1, 1, 1, 1 )
+3/region = Rect2( 48, 0, 16, 16 )
+3/tile_mode = 0
+3/occluder_offset = Vector2( 0, 0 )
+3/navigation_offset = Vector2( 0, 0 )
+3/shape_offset = Vector2( 0, 0 )
+3/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
+3/shape_one_way = false
+3/shape_one_way_margin = 0.0
+3/shapes = [ ]
+3/z_index = 0
+4/name = "ground_tileset.png 4"
+4/texture = ExtResource( 1 )
+4/tex_offset = Vector2( 0, 0 )
+4/modulate = Color( 1, 1, 1, 1 )
+4/region = Rect2( 0, 16, 16, 16 )
+4/tile_mode = 0
+4/occluder_offset = Vector2( 0, 0 )
+4/navigation_offset = Vector2( 0, 0 )
+4/shape_offset = Vector2( 0, 0 )
+4/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
+4/shape_one_way = false
+4/shape_one_way_margin = 0.0
+4/shapes = [ ]
+4/z_index = 0
+5/name = "ground_tileset.png 5"
+5/texture = ExtResource( 1 )
+5/tex_offset = Vector2( 0, 0 )
+5/modulate = Color( 1, 1, 1, 1 )
+5/region = Rect2( 16, 16, 16, 16 )
+5/tile_mode = 0
+5/occluder_offset = Vector2( 0, 0 )
+5/navigation_offset = Vector2( 0, 0 )
+5/shape_offset = Vector2( 0, 0 )
+5/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
+5/shape_one_way = false
+5/shape_one_way_margin = 0.0
+5/shapes = [ ]
+5/z_index = 0
+6/name = "ground_tileset.png 6"
+6/texture = ExtResource( 1 )
+6/tex_offset = Vector2( 0, 0 )
+6/modulate = Color( 1, 1, 1, 1 )
+6/region = Rect2( 32, 16, 16, 16 )
+6/tile_mode = 0
+6/occluder_offset = Vector2( 0, 0 )
+6/navigation_offset = Vector2( 0, 0 )
+6/shape_offset = Vector2( 0, 0 )
+6/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
+6/shape_one_way = false
+6/shape_one_way_margin = 0.0
+6/shapes = [ ]
+6/z_index = 0
+7/name = "ground_tileset.png 7"
+7/texture = ExtResource( 1 )
+7/tex_offset = Vector2( 0, 0 )
+7/modulate = Color( 1, 1, 1, 1 )
+7/region = Rect2( 48, 16, 16, 16 )
+7/tile_mode = 0
+7/occluder_offset = Vector2( 0, 0 )
+7/navigation_offset = Vector2( 0, 0 )
+7/shape_offset = Vector2( 0, 0 )
+7/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
+7/shape_one_way = false
+7/shape_one_way_margin = 0.0
+7/shapes = [ ]
+7/z_index = 0
+
+[sub_resource type="ConvexPolygonShape2D" id=2]
+points = PoolVector2Array( 16, 16, 0, 16, 0, 0, 16, 0 )
+
+[sub_resource type="TileSet" id=3]
+0/name = "black.png 0"
+0/texture = ExtResource( 2 )
+0/tex_offset = Vector2( 0, 0 )
+0/modulate = Color( 1, 1, 1, 1 )
+0/region = Rect2( 0, 0, 16, 16 )
+0/tile_mode = 0
+0/occluder_offset = Vector2( 0, 0 )
+0/navigation_offset = Vector2( 0, 0 )
+0/shape_offset = Vector2( 0, 0 )
+0/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
+0/shape = SubResource( 2 )
+0/shape_one_way = false
+0/shape_one_way_margin = 1.0
+0/shapes = [ {
"autotile_coord": Vector2( 0, 0 ),
"one_way": false,
"one_way_margin": 1.0,
"shape": SubResource( 2 ),
"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
} ]
-1/z_index = 0
+0/z_index = 0
[node name="WorldGenerator" type="Node2D"]
script = ExtResource( 5 )
-[node name="TileMap" type="TileMap" parent="."]
+[node name="GroundTileMap" type="TileMap" parent="."]
tile_set = SubResource( 1 )
cell_size = Vector2( 16, 16 )
cell_quadrant_size = 4
format = 1
+[node name="WallTileMap" type="TileMap" parent="."]
+tile_set = SubResource( 3 )
+cell_size = Vector2( 16, 16 )
+format = 1
+
[node name="WalkerHead" parent="." instance=ExtResource( 4 )]
-TILEMAP_NP = NodePath("../TileMap")
+GROUND_TILEMAP_NP = NodePath("../GroundTileMap")
+WALL_TILEMAP_NP = NodePath("../WallTileMap")
WALKER_UNIT_NP = ExtResource( 3 )
[node name="Camera" type="Camera2D" parent="."]
diff --git a/src/tools/world_generator/scripts/walker_head.gd b/src/tools/world_generator/scripts/walker_head.gd
index 2ad9650..8bc5c4b 100644
--- a/src/tools/world_generator/scripts/walker_head.gd
+++ b/src/tools/world_generator/scripts/walker_head.gd
@@ -1,11 +1,13 @@
extends Node2D
-export(NodePath) var TILEMAP_NP: NodePath
+export(NodePath) var GROUND_TILEMAP_NP: NodePath
+export(NodePath) var WALL_TILEMAP_NP: NodePath
export(PackedScene) var WALKER_UNIT_NP: PackedScene
export(int, 4, 100, 1) var STARTING_UNIT_COUNT: int = 6
export(int, 2, 10, 1) var INITIAL_SAFE_ZONE_SIZE: int = 2
-onready var tilemap: TileMap = get_node(TILEMAP_NP)
+onready var ground_tilemap: TileMap = get_node(GROUND_TILEMAP_NP)
+onready var wall_tilemap: TileMap = get_node(WALL_TILEMAP_NP)
var max_x: int = 0
var max_y: int = 0
@@ -36,7 +38,11 @@ func _place_safe_zone() -> void:
var size: int = INITIAL_SAFE_ZONE_SIZE
for i in range(-size, size):
for j in range(-size, size):
- tilemap.set_cell(i, j, Global.WORLD_TILE_PATH)
+ ground_tilemap.set_cell(i, j, get_random_tile())
+
+
+func get_random_tile() -> int:
+ return randi() % Global.GROUND_TILE_AMOUNT
func _spawn_walker_units() -> void:
@@ -55,17 +61,18 @@ func _spawn_walker_unit(spawn_position: Vector2) -> void:
func _fill_empty_space() -> void:
var locations: Array = _get_empty_cells_location()
for location in locations:
- tilemap.set_cellv(location, Global.WORLD_TILE_WALL)
+ # doesn't matter which index is set, as long as its form the wall tilemap
+ wall_tilemap.set_cellv(location, 0)
func _get_empty_cells_location() -> Array:
var locations: Array = []
- var rect: Rect2 = tilemap.get_used_rect()
+ var rect: Rect2 = ground_tilemap.get_used_rect()
var margin: int = map_margin
for x in range(-margin, rect.size.x + margin):
for y in range (-margin, rect.size.y + margin):
var location: Vector2 = Vector2(rect.position.x + x, rect.position.y + y)
- if tilemap.get_cell(int(location.x), int(location.y)) == TileMap.INVALID_CELL:
+ if ground_tilemap.get_cell(int(location.x), int(location.y)) == TileMap.INVALID_CELL:
locations.append(location)
return locations
diff --git a/src/tools/world_generator/scripts/walker_unit.gd b/src/tools/world_generator/scripts/walker_unit.gd
index cfa8f91..3107367 100644
--- a/src/tools/world_generator/scripts/walker_unit.gd
+++ b/src/tools/world_generator/scripts/walker_unit.gd
@@ -30,7 +30,7 @@ var walk_straight_length: float
func start(id: int) -> void:
Event.emit_signal("world_gen_walker_started", id)
_walker_head = get_parent()
- _tilemap = _walker_head.tilemap
+ _tilemap = _walker_head.ground_tilemap
_randomize_stats()
var path_steps: Array = _get_path_steps()
@@ -70,11 +70,11 @@ func _set_path_tiles(path_steps: Array) -> bool:
# get initial tile location
var location: Vector2 = get_parent().global_position * Global.TILE_SIZE
var move_direction: Vector2
- _set_tile(location, 0)
+ _set_tile(location, _walker_head.get_random_tile())
for step in path_steps:
move_direction = direction[step]
location += move_direction * Global.TILE_SIZE
- _set_tile(location, Global.WORLD_TILE_PATH)
+ _set_tile(location, _walker_head.get_random_tile())
if randf() < birth_chance and not given_birth:
Event.emit_signal("world_gen_spawn_walker_unit", location)
diff --git a/src/tools/world_generator/scripts/world_generator.gd b/src/tools/world_generator/scripts/world_generator.gd
index 5de84ea..cbc5dd5 100644
--- a/src/tools/world_generator/scripts/world_generator.gd
+++ b/src/tools/world_generator/scripts/world_generator.gd
@@ -1,16 +1,16 @@
extends Node2D
-onready var tilemap: TileMap = $TileMap
+onready var ground_tilemap: TileMap = $GroundTileMap
onready var walker_head: Node2D = $WalkerHead
func get_valid_map_coords() -> Array:
var safe_area: Array = walker_head.get_cells_around()
- var cells_used: Array = tilemap.get_used_cells_by_id(Global.WORLD_TILE_PATH)
+ var cells_used: Array = ground_tilemap.get_used_cells()
for location in safe_area:
cells_used.erase(location)
return cells_used
func get_centered_world_position(location: Vector2) -> Vector2:
- return tilemap.map_to_world(location) + Vector2.ONE * Global.TILE_SIZE / 2.0
+ return ground_tilemap.map_to_world(location) + Vector2.ONE * Global.TILE_SIZE / 2.0
diff --git a/src/tools/world_generator/sprites/ground_tileset.png b/src/tools/world_generator/sprites/ground_tileset.png
new file mode 100644
index 0000000..cd9d696
--- /dev/null
+++ b/src/tools/world_generator/sprites/ground_tileset.png
Binary files differ
diff --git a/src/tools/world_generator/sprites/ground_tileset.png.import b/src/tools/world_generator/sprites/ground_tileset.png.import
new file mode 100644
index 0000000..28db0d2
--- /dev/null
+++ b/src/tools/world_generator/sprites/ground_tileset.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/ground_tileset.png-7a8766cf1f87b69a9c1b072401597bed.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://tools/world_generator/sprites/ground_tileset.png"
+dest_files=[ "res://.import/ground_tileset.png-7a8766cf1f87b69a9c1b072401597bed.stex" ]
+
+[params]
+
+compress/mode=0
+compress/lossy_quality=0.7
+compress/hdr_mode=0
+compress/bptc_ldr=0
+compress/normal_map=0
+flags/repeat=0
+flags/filter=false
+flags/mipmaps=false
+flags/anisotropic=false
+flags/srgb=2
+process/fix_alpha_border=false
+process/premult_alpha=false
+process/HDR_as_SRGB=false
+process/invert_color=false
+process/normal_map_invert_y=false
+stream=false
+size_limit=0
+detect_3d=false
+svg/scale=1.0