4.8 Jump Pad
This commit is contained in:
parent
6cbcbe743c
commit
24fc7c2a82
4 changed files with 123 additions and 3 deletions
96
scenes/jump_pad.tscn
Normal file
96
scenes/jump_pad.tscn
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
[gd_scene load_steps=14 format=3 uid="uid://dfrcbemxybvbj"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/jump_pad.gd" id="1_kafhd"]
|
||||
[ext_resource type="Texture2D" uid="uid://2su0kid2txul" path="res://assets/textures/other/Idle.png" id="2_1m2vt"]
|
||||
[ext_resource type="Texture2D" uid="uid://cyy3gs64gm38x" path="res://assets/textures/other/Jump (28x28).png" id="3_vi0gn"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_pekj0"]
|
||||
size = Vector2(20, 4)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_xbhp4"]
|
||||
atlas = ExtResource("3_vi0gn")
|
||||
region = Rect2(0, 0, 28, 28)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_h5mcm"]
|
||||
atlas = ExtResource("3_vi0gn")
|
||||
region = Rect2(28, 0, 28, 28)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_dpm0s"]
|
||||
atlas = ExtResource("3_vi0gn")
|
||||
region = Rect2(56, 0, 28, 28)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_t5et8"]
|
||||
atlas = ExtResource("3_vi0gn")
|
||||
region = Rect2(84, 0, 28, 28)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_w8iil"]
|
||||
atlas = ExtResource("3_vi0gn")
|
||||
region = Rect2(112, 0, 28, 28)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_5w5io"]
|
||||
atlas = ExtResource("3_vi0gn")
|
||||
region = Rect2(140, 0, 28, 28)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_qjntm"]
|
||||
atlas = ExtResource("3_vi0gn")
|
||||
region = Rect2(168, 0, 28, 28)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_6oce2"]
|
||||
atlas = ExtResource("3_vi0gn")
|
||||
region = Rect2(196, 0, 28, 28)
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_fsh0p"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("2_1m2vt")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"idle",
|
||||
"speed": 20.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_xbhp4")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_h5mcm")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_dpm0s")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_t5et8")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_w8iil")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_5w5io")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_qjntm")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_6oce2")
|
||||
}],
|
||||
"loop": false,
|
||||
"name": &"jump",
|
||||
"speed": 20.0
|
||||
}]
|
||||
|
||||
[node name="JumpPad" type="Area2D"]
|
||||
collision_mask = 2
|
||||
script = ExtResource("1_kafhd")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(0, -10)
|
||||
shape = SubResource("RectangleShape2D_pekj0")
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||
position = Vector2(0, -14)
|
||||
sprite_frames = SubResource("SpriteFrames_fsh0p")
|
||||
animation = &"jump"
|
||||
autoplay = "idle"
|
||||
|
||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
[gd_scene load_steps=10 format=3 uid="uid://cchf5vmjp6ahj"]
|
||||
[gd_scene load_steps=11 format=3 uid="uid://cchf5vmjp6ahj"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/level.gd" id="1_84g5v"]
|
||||
[ext_resource type="PackedScene" uid="uid://c7y3ileam1twx" path="res://scenes/player.tscn" id="2_d65cs"]
|
||||
[ext_resource type="PackedScene" uid="uid://dfrcbemxybvbj" path="res://scenes/jump_pad.tscn" id="3_vhvgl"]
|
||||
|
||||
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_mvbjk"]
|
||||
|
||||
|
|
@ -58,4 +59,11 @@ texture = SubResource("GradientTexture1D_y3q5v")
|
|||
[node name="StartPosition" type="Marker2D" parent="."]
|
||||
position = Vector2(309, 135)
|
||||
|
||||
[node name="JumpPad" parent="." instance=ExtResource("3_vhvgl")]
|
||||
position = Vector2(338, 194)
|
||||
|
||||
[node name="JumpPad2" parent="." instance=ExtResource("3_vhvgl")]
|
||||
position = Vector2(140, 194)
|
||||
jump_force = 500
|
||||
|
||||
[connection signal="body_entered" from="Deathzone" to="." method="_on_death_zone_body_entered"]
|
||||
|
|
|
|||
11
scripts/jump_pad.gd
Normal file
11
scripts/jump_pad.gd
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
extends Area2D
|
||||
|
||||
@export var jump_force = 400
|
||||
|
||||
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
if body is Player:
|
||||
animated_sprite_2d.play("jump")
|
||||
body.jump(jump_force)
|
||||
pass # Replace with function body.
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
extends CharacterBody2D
|
||||
class_name Player
|
||||
|
||||
|
||||
@export var speed = 300.0
|
||||
@export var jump_velocity = 400.0
|
||||
@export var jump_force = 400.0
|
||||
|
||||
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
|
||||
|
||||
|
|
@ -14,7 +15,7 @@ func _physics_process(delta: float) -> void:
|
|||
|
||||
# Handle jump.
|
||||
if Input.is_action_just_pressed("jump") and is_on_floor():
|
||||
velocity.y = -jump_velocity
|
||||
jump(jump_force)
|
||||
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
var direction := Input.get_axis("move_left", "move_right")
|
||||
|
|
@ -39,3 +40,7 @@ func play_animations(direction: float):
|
|||
else:
|
||||
animated_sprite_2d.play("fall")
|
||||
pass
|
||||
|
||||
|
||||
func jump(jump_force: float):
|
||||
velocity.y = -jump_force
|
||||
|
|
|
|||
Loading…
Reference in a new issue