Compare commits

...

2 Commits

Author SHA1 Message Date
Ervan Lefevre b2244386f3 🍻 You can now climb walls & ceilings 2 years ago
Ervan Lefevre 50fb9e9496 A rising level now kills the player 2 years ago
  1. BIN
      assets/placeholders/map.png
  2. 34
      assets/placeholders/map.png.import
  3. 80
      nodes/player/player.gd
  4. 6
      nodes/player/player.tscn
  5. 31
      scenes/poc.tscn
  6. 16
      scripts/gameplay/rising_level.gd
  7. 8
      scripts/ia/fsm.gd

Binary file not shown.

After

Width:  |  Height:  |  Size: 491 KiB

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://ccqiabs4p3ryl"
path="res://.godot/imported/map.png-2da3fc7424b1263a875c0fcdadfc0bc5.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/placeholders/map.png"
dest_files=["res://.godot/imported/map.png-2da3fc7424b1263a875c0fcdadfc0bc5.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

@ -1,28 +1,40 @@
extends CharacterBody2D
class_name Player
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
const SPEED = 100.0
const JUMP_VELOCITY = 200.0
const STATES= [
"spawn",
"idle",
"walk",
"climb",
"jump",
"die"
]
var use_gravity = {
"climb": false,
"die": false,
"idle": true,
"jump": true,
"spawn": true,
"walk": true
}
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
func _ready():
$fsm.set_states(STATES)
add_to_group("player")
func _enter_spawn():
$fsm.set_next_state("idle")
func on_enter_idle_state():
velocity.x = 0.0
pass
func idle_state(_delta):
var direction = Input.get_axis("ui_left", "ui_right")
@ -35,31 +47,81 @@ func idle_state(_delta):
func walk_state(_delta):
var direction = Input.get_axis("ui_left", "ui_right")
if direction:
if direction != 0:
velocity.x = direction * SPEED
else:
velocity.x = 0
$fsm.set_next_state("idle")
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
$fsm.set_next_state("jump")
# detect collision with wall or ceiling to enter climb state
if is_on_wall() or is_on_ceiling():
velocity.y = 0
$fsm.set_next_state("climb")
func on_enter_jump_state():
velocity.y = JUMP_VELOCITY
if is_on_floor():
velocity.y = -JUMP_VELOCITY
func jump_state(_delta):
var direction = Input.get_axis("ui_left", "ui_right")
velocity.x = move_toward(velocity.x, direction * SPEED, SPEED)
if(direction):
velocity.x = move_toward(velocity.x, direction * SPEED, SPEED)
if is_on_floor():
if direction:
$fsm.set_next_state("walk")
else:
velocity.x = 0
$fsm.set_next_state("idle")
if is_on_wall() or 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("ui_up", "ui_down")
velocity = Vector2(0, direction * SPEED)
if is_on_ceiling():
var direction = Input.get_axis("ui_left", "ui_right")
velocity = Vector2(direction * SPEED, 0)
if Input.is_action_just_pressed("ui_accept") and is_on_wall():
var wall_position = get_slide_collision(0).get_normal().x
var jump_normal = Vector2(wall_position, -0.5).normalized()
velocity = jump_normal * JUMP_VELOCITY
$fsm.set_next_state("jump")
if is_on_ceiling() && Input.is_action_just_pressed("ui_down"):
velocity.y = 0
$fsm.set_next_state("idle")
if !is_on_wall() && !is_on_ceiling():
$fsm.set_next_state("idle")
func after_state(delta):
if $fsm.current_state in ["idle", "walk"]:
move_and_slide()
move_and_slide()
if not is_on_floor():
if use_gravity[$fsm.current_state] == true:
velocity.y += gravity * delta
func die():
$fsm.set_next_state("die")
func on_enter_die_state():
velocity = Vector2(0, -500)
$shape.disabled = true
# $AnimationPlayer.play("die")

@ -6,7 +6,7 @@
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_w17ly"]
radius = 7.9984
height = 31.9936
height = 24.0
[node name="player" type="CharacterBody2D"]
script = ExtResource("1_exx2i")
@ -19,9 +19,9 @@ root = NodePath("..")
texture = ExtResource("1_s33dc")
[node name="shape" type="CollisionShape2D" parent="."]
rotation = 1.55081
rotation = 1.5708
shape = SubResource("CapsuleShape2D_w17ly")
metadata/_edit_group_ = true
[node name="camera" type="Camera2D" parent="."]
zoom = Vector2(2, 2)
zoom = Vector2(4, 4)

File diff suppressed because one or more lines are too long

@ -0,0 +1,16 @@
extends Area2D
class_name RisingLevel
@export var RISING_SPEED = 30
func _ready():
body_entered.connect(_body_entered)
func _physics_process(delta):
$shape.position.y -= RISING_SPEED * delta
self.position = self.position
func _body_entered(body):
if body.is_in_group("player"):
body.die()

@ -36,10 +36,12 @@ func _transition():
previous_state = current_state
current_state = next_state
next_state = null
print(self.name + " transitioning to " + current_state)
var on_exit_state_method = "on_exit_" + current_state + "_state"
if on_exit_state_method in root:
root.call(on_exit_state_method)
if previous_state:
var on_exit_state_method = "on_exit_" + previous_state + "_state"
if on_exit_state_method in root:
root.call(on_exit_state_method)
var on_enter_state_method = "on_enter_" + current_state + "_state"
if on_enter_state_method in root:

Loading…
Cancel
Save