Compare commits

...

5 Commits

  1. 7
      nodes/npc/npc.gd
  2. 10
      nodes/npc_factory/npc_factory.tscn
  3. 33
      nodes/player/player.gd
  4. 1
      nodes/player/player.tscn
  5. 24
      scripts/gameplay/rising_level.gd

@ -6,7 +6,7 @@ const SPEED = 100
const MINIMUM_STATE_DURATION = 3
const STATES = ['panic', 'dead']
const QUEUE_FREE_DELAY = 30
const QUEUE_FREE_DELAY = 10
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
var direction = 0
@ -41,13 +41,14 @@ func dead_state(_delta):
velocity = Vector2(0, -rising_speed)
move_and_slide()
if $fsm.state_duration > QUEUE_FREE_DELAY:
queue_free()
func die(level_speed):
$fsm.set_next_state('dead')
rising_speed = level_speed
if $fsm.state_duration > QUEUE_FREE_DELAY:
queue_free()
func pick_new_direction():
direction = [1,-1][randi_range(0,1)] * SPEED

@ -1,9 +1,17 @@
[gd_scene load_steps=3 format=3 uid="uid://b2hu7kxvxvgc1"]
[gd_scene load_steps=4 format=3 uid="uid://b2hu7kxvxvgc1"]
[ext_resource type="Script" path="res://nodes/npc_factory/npc_factory.gd" id="1_p5cuf"]
[ext_resource type="PackedScene" uid="uid://dvx48q5ecyxjs" path="res://nodes/npc/npc.tscn" id="2_exj6u"]
[sub_resource type="CircleShape2D" id="CircleShape2D_nl4mj"]
[node name="npc_factory" type="Node2D"]
script = ExtResource("1_p5cuf")
NPC_SCENE = ExtResource("2_exj6u")
SPAWN_DELAY = 2.0
[node name="factory_death" type="Area2D" parent="." groups=["factory_death"]]
monitoring = false
[node name="CollisionShape2D" type="CollisionShape2D" parent="factory_death"]
shape = SubResource("CircleShape2D_nl4mj")

@ -93,24 +93,20 @@ func jump_state(_delta):
if(direction):
velocity.x = move_toward(velocity.x, direction * SPEED, SPEED)
if velocity.y > 0:
if is_on_floor():
if direction:
$fsm.set_next_state("walk")
else:
velocity.x = 0
$fsm.set_next_state("idle")
if is_on_wall() || (is_on_ceiling() and Input.is_action_pressed("player_up")):
$fsm.set_next_state("climb")
if is_on_floor():
if direction:
$fsm.set_next_state("walk")
else:
velocity.x = 0
$fsm.set_next_state("idle")
if is_on_wall() || (is_on_ceiling() ):
$fsm.set_next_state("climb")
func on_enter_climb_state():
sprite.modulate = Color(1, 0, 0)
velocity = Vector2(0, 0)
func on_exit_climb_state():
sprite.modulate = Color(1, 1, 1)
func climb_state(_delta):
if is_on_wall():
var direction = Input.get_axis("player_up", "player_down")
@ -178,10 +174,6 @@ func drop_obstacle():
grabbed_obstacle = null
func handle_sprite_orientation():
# rotates oriented_container to face
# the direction of the velocity
# if is_on_wall, rotated regarding velocity.y, with up by default
# if is_on_ceiling, rotated regarding velocity.x, with right by default
if is_on_wall_only():
if velocity.y != 0:
$oriented_container.rotation = PI/2 if (velocity.y > 0) else - PI / 2
@ -190,17 +182,21 @@ func handle_sprite_orientation():
var should_flip_with_wall_left = (wall_position > player_position) && (velocity.y > 0)
var should_flip_with_wall_right = (wall_position < player_position) && (velocity.y < 0)
sprite.flip_v = should_flip_with_wall_left || should_flip_with_wall_right
sprite.flip_h = false
elif is_on_ceiling():
elif is_on_ceiling_only():
if velocity.x != 0:
$oriented_container.rotation = PI if (velocity.x > 0) else -PI
sprite.flip_h = velocity.x > 0
else:
if velocity.x != 0:
$oriented_container.rotation = 0 if (velocity.x > 0) else PI
sprite.flip_v = velocity.x < 0
sprite.flip_h = false
func on_enter_swim_state():
sprite.modulate = Color(0, 0, 1)
gravity = WORLD_GRAVITY / 2
func swim_state(_delta):
@ -215,6 +211,7 @@ func swim_state(_delta):
die()
func on_exit_swim_state():
sprite.modulate = Color(1, 1, 1)
gravity = WORLD_GRAVITY
sprite.modulate = Color(1,1,1)

@ -5,7 +5,6 @@
[ext_resource type="Script" path="res://scripts/ia/fsm.gd" id="2_ix1o4"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_w17ly"]
radius = 7.9984
height = 24.0
[node name="player" type="CharacterBody2D"]

@ -2,23 +2,39 @@ extends Area2D
class_name RisingLevel
@export var RISING_SPEED = 30
const FORCE_CHECK_FREQUENCY = 5
var duration = 0
func _ready():
body_entered.connect(_body_entered)
area_entered.connect(_area_entered)
body_exited.connect(_body_exited)
func _physics_process(delta):
$shape.position.y -= RISING_SPEED * delta
self.position = self.position
duration += delta
if duration > FORCE_CHECK_FREQUENCY:
duration = 0
for body in get_overlapping_bodies():
process_body(body, true)
func _body_entered(body):
process_body(body, false)
func _area_entered(body):
if body.is_in_group("factory_death"):
body.get_parent().queue_free()
func _body_exited(body):
if body.is_in_group("player"):
body.unswim()
func process_body(body, force= false):
if force == false && body.is_in_group("player"):
body.swim()
if body.is_in_group("npc"):
body.die(RISING_SPEED)
func _body_exited(body):
if body.is_in_group("player"):
body.unswim()

Loading…
Cancel
Save