-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,22 @@ | ||
[gd_scene format=3 uid="uid://iaq32s2ve124"] | ||
[gd_scene load_steps=4 format=3 uid="uid://iaq32s2ve124"] | ||
|
||
[ext_resource type="Texture2D" uid="uid://dds1sdaxddjq" path="res://assets/circle.svg" id="1_7avmq"] | ||
[ext_resource type="Script" path="res://scenes/gameplay/trampoline/trampoline-manager.gd" id="2_x7po0"] | ||
|
||
[sub_resource type="CircleShape2D" id="CircleShape2D_bnr8y"] | ||
radius = 32.0 | ||
|
||
[node name="Main" type="Node2D"] | ||
|
||
[node name="RigidBody2D" type="RigidBody2D" parent="."] | ||
position = Vector2(174, 97) | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D"] | ||
shape = SubResource("CircleShape2D_bnr8y") | ||
|
||
[node name="Sprite2D" type="Sprite2D" parent="RigidBody2D"] | ||
scale = Vector2(0.5, 0.5) | ||
texture = ExtResource("1_7avmq") | ||
|
||
[node name="TrampolineManager" type="Node2D" parent="."] | ||
script = ExtResource("2_x7po0") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
extends CharacterBody2D | ||
|
||
|
||
const SPEED = 300.0 | ||
const JUMP_VELOCITY = -400.0 | ||
|
||
# Get the gravity from the project settings to be synced with RigidBody nodes. | ||
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity") | ||
|
||
|
||
func _physics_process(delta): | ||
# Add the gravity. | ||
if not is_on_floor(): | ||
velocity.y += gravity * delta | ||
|
||
# Handle jump. | ||
if Input.is_action_just_pressed("ui_accept") and is_on_floor(): | ||
velocity.y = JUMP_VELOCITY | ||
|
||
# Get the input direction and handle the movement/deceleration. | ||
# As good practice, you should replace UI actions with custom gameplay actions. | ||
var direction = Input.get_axis("ui_left", "ui_right") | ||
if direction: | ||
velocity.x = direction * SPEED | ||
else: | ||
velocity.x = move_toward(velocity.x, 0, SPEED) | ||
|
||
move_and_slide() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
extends Node2D | ||
|
||
const TRAMPOLINE = preload("res://scenes/gameplay/trampoline/trampoline.tscn") | ||
var current_trampoline | ||
|
||
func _input(event): | ||
if event is InputEventMouseButton: | ||
if event.pressed: | ||
current_trampoline = TRAMPOLINE.instantiate() | ||
get_tree().root.add_child(current_trampoline) | ||
current_trampoline.position = get_global_mouse_position() | ||
else: | ||
current_trampoline.stop_editing() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
extends StaticBody2D | ||
|
||
@onready var collision_shape_2d = $CollisionShape2D | ||
@onready var line_2d = $Line2D | ||
var is_editing := true | ||
|
||
func _ready(): | ||
var new_shape = SegmentShape2D.new() | ||
collision_shape_2d.set_shape(new_shape) | ||
|
||
func _process(delta): | ||
if is_editing: | ||
update_shape(get_global_mouse_position() - position) | ||
|
||
func update_shape(position: Vector2): | ||
collision_shape_2d.shape.set_b(position) | ||
line_2d.points[1] = position | ||
|
||
func stop_editing(): | ||
is_editing = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[gd_scene load_steps=3 format=3 uid="uid://bop0rlanl0dl"] | ||
|
||
[ext_resource type="Script" path="res://scenes/gameplay/trampoline/trampoline.gd" id="1_aj7n4"] | ||
|
||
[sub_resource type="SegmentShape2D" id="SegmentShape2D_qiy1v"] | ||
|
||
[node name="Trampoline" type="StaticBody2D"] | ||
script = ExtResource("1_aj7n4") | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] | ||
shape = SubResource("SegmentShape2D_qiy1v") | ||
|
||
[node name="Line2D" type="Line2D" parent="."] | ||
points = PackedVector2Array(0, 0, 0, 0) |