From 14538d486de312af41ce012836861468b8fb7897 Mon Sep 17 00:00:00 2001 From: David Luevano Alvarado Date: Sun, 5 Jun 2022 14:09:41 -0600 Subject: finish all necessary for playability --- src/entities/actors/snake/scenes/Head.tscn | 4 +++- src/entities/actors/snake/scripts/dash_state.gd | 1 + src/entities/actors/snake/scripts/head.gd | 14 +++++++++++--- src/entities/actors/snake/scripts/jump_state.gd | 18 ++++++++++-------- src/entities/actors/snake/scripts/normal_state.gd | 5 +++-- src/entities/actors/snake/scripts/slow_state.gd | 1 + src/entities/actors/snake/scripts/state_machine.gd | 13 +++++++------ src/entities/food/scripts/food.gd | 3 ++- src/entities/food/scripts/food_basic.gd | 4 +++- src/entities/food/scripts/food_manager.gd | 7 +++++-- src/entities/food/scripts/food_special.gd | 4 +--- 11 files changed, 47 insertions(+), 27 deletions(-) (limited to 'src/entities') diff --git a/src/entities/actors/snake/scenes/Head.tscn b/src/entities/actors/snake/scenes/Head.tscn index d69cbf8..b9180c3 100644 --- a/src/entities/actors/snake/scenes/Head.tscn +++ b/src/entities/actors/snake/scenes/Head.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=14 format=2] +[gd_scene load_steps=15 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] @@ -7,6 +7,7 @@ [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] +[ext_resource path="res://entities/actors/snake/scripts/jump_state.gd" type="Script" id=8] [sub_resource type="AtlasTexture" id=2] atlas = ExtResource( 3 ) @@ -52,6 +53,7 @@ script = ExtResource( 6 ) script = ExtResource( 7 ) [node name="JumpState" type="Node" parent="StateMachine"] +script = ExtResource( 8 ) [node name="Tongue" type="AnimatedSprite" parent="."] position = Vector2( 0, -5 ) diff --git a/src/entities/actors/snake/scripts/dash_state.gd b/src/entities/actors/snake/scripts/dash_state.gd index 3eb0bdf..a23b241 100644 --- a/src/entities/actors/snake/scripts/dash_state.gd +++ b/src/entities/actors/snake/scripts/dash_state.gd @@ -19,6 +19,7 @@ func exit(): func physics_process(delta: float) -> void: + fsm.rotate_on_input() fsm.player.velocity = fsm.player.direction * Global.SNAKE_SPEED fsm.player.velocity = fsm.player.move_and_slide(fsm.player.velocity) diff --git a/src/entities/actors/snake/scripts/head.gd b/src/entities/actors/snake/scripts/head.gd index e6824a7..2853d00 100644 --- a/src/entities/actors/snake/scripts/head.gd +++ b/src/entities/actors/snake/scripts/head.gd @@ -12,9 +12,11 @@ var velocity: Vector2 = Vector2.ZERO 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 +var stats: Stats = SaveData.get_stats() + +var can_dash: bool = false +var can_slow: bool = false +var can_jump: bool = false func _ready() -> void: @@ -22,6 +24,12 @@ func _ready() -> void: 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") + + print(stats.get_stats()) + can_dash = stats.trait_dash + can_slow = stats.trait_slow + can_jump = stats.trait_jump + tongue_sprite.visible = false diff --git a/src/entities/actors/snake/scripts/jump_state.gd b/src/entities/actors/snake/scripts/jump_state.gd index 396ceb4..329b426 100644 --- a/src/entities/actors/snake/scripts/jump_state.gd +++ b/src/entities/actors/snake/scripts/jump_state.gd @@ -6,22 +6,24 @@ 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") + Event.emit_signal("snake_started_jump") + fsm.player.set_collision_mask_bit(1, false) + fsm.player.set_collision_mask_bit(2, false) + Global.SNAKE_SPEED = Global.SNAKE_JUMP_SPEED + yield(get_tree().create_timer(Global.SNAKE_JUMP_TIME), "timeout") exit() func exit(): - Event.emit_signal("snake_finished_dash") + fsm.player.set_collision_mask_bit(1, true) + fsm.player.set_collision_mask_bit(2, true) Global.SNAKE_SPEED = Global.SNAKE_SPEED_BACKUP + Event.emit_signal("snake_finished_jump") fsm.back() -func physics_process(delta: float) -> float: +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) - - return delta + fsm.slow_down_on_collisions(Global.SNAKE_JUMP_SPEED) diff --git a/src/entities/actors/snake/scripts/normal_state.gd b/src/entities/actors/snake/scripts/normal_state.gd index 11981a3..1a9c1b1 100644 --- a/src/entities/actors/snake/scripts/normal_state.gd +++ b/src/entities/actors/snake/scripts/normal_state.gd @@ -13,6 +13,7 @@ func exit(next_state): func physics_process(delta: float) -> void: + fsm.rotate_on_input() fsm.player.velocity = fsm.player.direction * Global.SNAKE_SPEED fsm.player.velocity = fsm.player.move_and_slide(fsm.player.velocity) @@ -24,5 +25,5 @@ func input(event: InputEvent) -> void: 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") + 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 index 8d54bfb..3a2c94b 100644 --- a/src/entities/actors/snake/scripts/slow_state.gd +++ b/src/entities/actors/snake/scripts/slow_state.gd @@ -19,6 +19,7 @@ func exit(): func physics_process(delta: float) -> float: + fsm.rotate_on_input() fsm.player.velocity = fsm.player.direction * Global.SNAKE_SPEED fsm.player.velocity = fsm.player.move_and_slide(fsm.player.velocity) diff --git a/src/entities/actors/snake/scripts/state_machine.gd b/src/entities/actors/snake/scripts/state_machine.gd index b63f272..93e76b9 100644 --- a/src/entities/actors/snake/scripts/state_machine.gd +++ b/src/entities/actors/snake/scripts/state_machine.gd @@ -40,20 +40,21 @@ func _process(delta: float) -> void: 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 rotate_on_input() -> 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) + + func slow_down_on_collisions(speed_backup: float): if player.get_last_slide_collision(): Global.SNAKE_SPEED = player.velocity.length() diff --git a/src/entities/food/scripts/food.gd b/src/entities/food/scripts/food.gd index 386f0e5..e4bbc21 100644 --- a/src/entities/food/scripts/food.gd +++ b/src/entities/food/scripts/food.gd @@ -21,7 +21,7 @@ func update_texture() -> void: _sprite.texture = texture[properties["type"]] -func set_properties(pos: Vector2, loc: Vector2, special: bool, type: int, points: int=1, ttl: float = -1.0) -> void: +func set_properties(pos: Vector2, loc: Vector2, special: bool, type: int, points: int=1, special_points: int=1, ttl: float = -1.0) -> void: properties["global_position"] = pos global_position = pos properties["location"] = loc @@ -29,6 +29,7 @@ func set_properties(pos: Vector2, loc: Vector2, special: bool, type: int, points properties["type"] = type properties["points"] = points + properties["special_points"] = special_points properties["ttl"] = ttl if properties["ttl"] != -1.0: timer.wait_time = properties["ttl"] diff --git a/src/entities/food/scripts/food_basic.gd b/src/entities/food/scripts/food_basic.gd index 8090cdc..cfeec18 100644 --- a/src/entities/food/scripts/food_basic.gd +++ b/src/entities/food/scripts/food_basic.gd @@ -3,10 +3,12 @@ extends Food enum Type { APPLE, - BANANA + BANANA, + RAT } func _ready(): texture[Type.APPLE] = preload("res://entities/food/sprites/apple.png") texture[Type.BANANA] = preload("res://entities/food/sprites/banana.png") + texture[Type.RAT] = preload("res://entities/food/sprites/rat.png") diff --git a/src/entities/food/scripts/food_manager.gd b/src/entities/food/scripts/food_manager.gd index a605f9e..e6c7248 100644 --- a/src/entities/food/scripts/food_manager.gd +++ b/src/entities/food/scripts/food_manager.gd @@ -41,7 +41,10 @@ func _place_new_basic_food() -> void: var loc: Vector2 = pos_loc[1] # need to set the position first, else it will spawn on the middle and the moved - food.set_properties(pos, loc, false, type) + if type == FoodBasic.Type.RAT: + food.set_properties(pos, loc, false, type, Global.POINTS_TO_GROW / 2) + else: + food.set_properties(pos, loc, false, type) add_child(food) food.update_texture() current_basic_food.append(loc) @@ -57,7 +60,7 @@ func _place_new_special_food() -> void: var loc: Vector2 = pos_loc[1] # need to set the position first, else it will spawn on the middle and the moved - food.set_properties(pos, loc, true, type, Global.POINTS_TO_GROW) + food.set_properties(pos, loc, true, type, Global.POINTS_TO_GROW, Global.POINTS_TO_GROW / Global.POINTS_TO_GROW) add_child(food) food.update_texture() current_special_food.append(loc) diff --git a/src/entities/food/scripts/food_special.gd b/src/entities/food/scripts/food_special.gd index c2fde78..45d0c56 100644 --- a/src/entities/food/scripts/food_special.gd +++ b/src/entities/food/scripts/food_special.gd @@ -3,9 +3,8 @@ extends Food enum Type { BUNNY, - FROG, TURTLE, - RAT + FROG } @@ -13,4 +12,3 @@ func _ready(): texture[Type.BUNNY] = preload("res://entities/food/sprites/bunny.png") texture[Type.FROG] = preload("res://entities/food/sprites/frog.png") texture[Type.TURTLE] = preload("res://entities/food/sprites/turtle.png") - texture[Type.RAT] = preload("res://entities/food/sprites/rat.png") -- cgit v1.2.3-70-g09d2