added pipes and interact blocks

This commit is contained in:
Jonas Braus
2024-07-28 20:39:02 +02:00
parent 083c1b98ec
commit f9fdbb4612
11 changed files with 469 additions and 17 deletions
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

+34
View File
@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dth47lmb44qk8"
path="res://.godot/imported/items.png-47d902c7b073dc8ecbdcf38de461db0f.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/items.png"
dest_files=["res://.godot/imported/items.png-47d902c7b073dc8ecbdcf38de461db0f.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
+46
View File
@@ -0,0 +1,46 @@
[gd_scene load_steps=7 format=3 uid="uid://b6piduuvusiix"]
[ext_resource type="Texture2D" uid="uid://chrld8oybp4me" path="res://assets/bg-1-1.png" id="1_4h0ce"]
[ext_resource type="Script" path="res://scripts/destroyblock.gd" id="1_a8383"]
[sub_resource type="AtlasTexture" id="AtlasTexture_nbg0j"]
atlas = ExtResource("1_4h0ce")
region = Rect2(320, 144, 16, 16)
[sub_resource type="SpriteFrames" id="SpriteFrames_r70hc"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_nbg0j")
}],
"loop": true,
"name": &"default",
"speed": 5.0
}]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_i07jg"]
size = Vector2(16, 16)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_r8vfl"]
size = Vector2(8, 1)
[node name="destroyblock" type="RigidBody2D"]
gravity_scale = 0.0
script = ExtResource("1_a8383")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
position = Vector2(8, -8)
sprite_frames = SubResource("SpriteFrames_r70hc")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(8, -8)
shape = SubResource("RectangleShape2D_i07jg")
[node name="activate" type="Area2D" parent="."]
collision_mask = 2
[node name="CollisionShape2D" type="CollisionShape2D" parent="activate"]
position = Vector2(8, 0.5)
shape = SubResource("RectangleShape2D_r8vfl")
[connection signal="body_entered" from="activate" to="." method="_on_activate_body_entered"]
+73
View File
@@ -0,0 +1,73 @@
[gd_scene load_steps=10 format=3 uid="uid://d25ukpt8ot8xv"]
[ext_resource type="Script" path="res://scripts/itemblock.gd" id="2_fn5hi"]
[ext_resource type="Texture2D" uid="uid://dth47lmb44qk8" path="res://assets/items.png" id="2_t1ko6"]
[sub_resource type="AtlasTexture" id="AtlasTexture_lo6hv"]
atlas = ExtResource("2_t1ko6")
region = Rect2(4, 4, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_ghd0r"]
atlas = ExtResource("2_t1ko6")
region = Rect2(34, 4, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_5py80"]
atlas = ExtResource("2_t1ko6")
region = Rect2(64, 4, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_4m3oc"]
atlas = ExtResource("2_t1ko6")
region = Rect2(4, 4, 16, 16)
[sub_resource type="SpriteFrames" id="SpriteFrames_r54gk"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_lo6hv")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_ghd0r")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_5py80")
}],
"loop": false,
"name": &"destroy",
"speed": 10.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_4m3oc")
}],
"loop": true,
"name": &"idle",
"speed": 5.0
}]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_4kmo0"]
size = Vector2(16, 16)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_enc16"]
size = Vector2(8, 1)
[node name="itemblock" type="RigidBody2D"]
gravity_scale = 0.0
script = ExtResource("2_fn5hi")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
position = Vector2(8, -8)
sprite_frames = SubResource("SpriteFrames_r54gk")
animation = &"destroy"
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(8, -8)
shape = SubResource("RectangleShape2D_4kmo0")
[node name="activate" type="Area2D" parent="."]
collision_mask = 2
[node name="CollisionShape2D" type="CollisionShape2D" parent="activate"]
position = Vector2(8, 0.5)
shape = SubResource("RectangleShape2D_enc16")
[connection signal="body_entered" from="activate" to="." method="_on_activate_body_entered"]
+155 -14
View File
File diff suppressed because one or more lines are too long
+14
View File
@@ -0,0 +1,14 @@
[gd_scene load_steps=3 format=3 uid="uid://be832pldgbeyk"]
[ext_resource type="Script" path="res://scripts/pipe.gd" id="1_akqs5"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_5w6v5"]
size = Vector2(30, 1)
[node name="pipe" type="Area2D"]
collision_layer = 4
script = ExtResource("1_akqs5")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(16, -0.5)
shape = SubResource("RectangleShape2D_5w6v5")
+60 -1
View File
@@ -1,4 +1,4 @@
[gd_scene load_steps=11 format=3 uid="uid://dk1aby88pygtr"]
[gd_scene load_steps=13 format=3 uid="uid://dk1aby88pygtr"]
[ext_resource type="Script" path="res://scripts/player.gd" id="1_lm7ix"]
[ext_resource type="Texture2D" uid="uid://dhw3lpuskbvku" path="res://assets/mario-luigi-4.png" id="1_w3chr"]
@@ -72,10 +72,33 @@ animations = [{
radius = 6.0
height = 16.0
[sub_resource type="RectangleShape2D" id="RectangleShape2D_sqgi2"]
size = Vector2(8, 1)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_okc7h"]
size = Vector2(1, 2)
[node name="player" type="CharacterBody2D"]
position = Vector2(0, -10)
collision_layer = 2
script = ExtResource("1_lm7ix")
[node name="Camera2D" type="Camera2D" parent="."]
position = Vector2(35, 0)
zoom = Vector2(3, 3)
limit_left = -160
limit_bottom = 32
position_smoothing_enabled = true
[node name="ColorRect" type="ColorRect" parent="Camera2D"]
visible = false
z_index = 10
offset_left = -3995.0
offset_top = -1678.0
offset_right = 3965.0
offset_bottom = 1594.0
color = Color(0, 0, 0, 1)
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
position = Vector2(0, 2)
sprite_frames = SubResource("SpriteFrames_l5s58")
@@ -84,3 +107,39 @@ animation = &"jump"
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, 2)
shape = SubResource("CapsuleShape2D_4sl4a")
[node name="pipedetector_ground" type="Area2D" parent="."]
collision_mask = 4
[node name="CollisionShape2D" type="CollisionShape2D" parent="pipedetector_ground"]
position = Vector2(0, 10.5)
shape = SubResource("RectangleShape2D_sqgi2")
[node name="pipedetector_right" type="Area2D" parent="."]
collision_mask = 4
[node name="CollisionShape2D" type="CollisionShape2D" parent="pipedetector_right"]
position = Vector2(6.5, -2)
shape = SubResource("RectangleShape2D_okc7h")
[node name="pipedetector_left" type="Area2D" parent="."]
position = Vector2(-13, -4)
collision_mask = 4
[node name="CollisionShape2D" type="CollisionShape2D" parent="pipedetector_left"]
position = Vector2(6.5, 2)
shape = SubResource("RectangleShape2D_okc7h")
[node name="pipe_timer" type="Timer" parent="."]
wait_time = 2.0
one_shot = true
[node name="pipe_timer_half" type="Timer" parent="."]
one_shot = true
[connection signal="area_entered" from="pipedetector_ground" to="." method="_on_pipedetector_area_entered"]
[connection signal="area_exited" from="pipedetector_ground" to="." method="_on_pipedetector_area_exited"]
[connection signal="area_entered" from="pipedetector_right" to="." method="_on_pipedetector_right_area_entered"]
[connection signal="area_exited" from="pipedetector_right" to="." method="_on_pipedetector_right_area_exited"]
[connection signal="timeout" from="pipe_timer" to="." method="_on_pipe_timer_timeout"]
[connection signal="timeout" from="pipe_timer_half" to="." method="_on_pipe_timer_half_timeout"]
+9
View File
@@ -0,0 +1,9 @@
extends RigidBody2D
@onready var animated_sprite_2d = $AnimatedSprite2D
func _ready():
animated_sprite_2d.play("default")
func _on_activate_body_entered(body):
queue_free()
+14
View File
@@ -0,0 +1,14 @@
extends RigidBody2D
@onready var animated_sprite_2d = $AnimatedSprite2D
var destroyed = false
func _ready():
animated_sprite_2d.play("idle")#
func _on_activate_body_entered(body):
if destroyed:
return
destroyed = true
animated_sprite_2d.play("destroy")
+6
View File
@@ -0,0 +1,6 @@
extends Area2D
@export var target: Vector2
func get_target():
return target
+58 -2
View File
@@ -1,13 +1,42 @@
extends CharacterBody2D
@onready var animated_sprite_2d = $AnimatedSprite2D
@onready var camera_2d = $Camera2D
@onready var color_rect = $Camera2D/ColorRect
@onready var pipe_timer = $pipe_timer
@onready var pipe_timer_half = $pipe_timer_half
const SPEED = 130.0
const JUMP_VELOCITY = -350.0
const JUMP_VELOCITY = -360.0
var on_pipe = false
var right_pipe = false
var left_pipe = false
var pipe = null
var pipe_target = null
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
var on_pause = false
func _ready():
color_rect.visible = false
func _process(delta):
# set camera
if position.y <= 32:
camera_2d.limit_bottom = 32
camera_2d.limit_top = -1000000
else:
camera_2d.limit_bottom = 272
camera_2d.limit_top = 32
# check pipe
if on_pipe and Input.is_action_just_pressed("crawl") and is_on_floor() or right_pipe and Input.is_action_pressed("move_right"):
color_rect.visible = true
pipe_timer.start()
pipe_timer_half.start()
pipe_target = pipe.get_target()
func _physics_process(delta):
# Add the gravity.
@@ -15,12 +44,15 @@ func _physics_process(delta):
velocity.y += gravity * delta
# Handle jump.
if Input.is_action_just_pressed("jump") and is_on_floor():
if not on_pause and Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
# get input
var direction = Input.get_axis("move_left", "move_right")
if on_pause:
direction = 0
# face direction
if direction < 0:
animated_sprite_2d.flip_h = true
@@ -42,3 +74,27 @@ func _physics_process(delta):
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
func _on_pipedetector_area_entered(area):
on_pipe = true
pipe = area
func _on_pipedetector_area_exited(area):
on_pipe = false
func _on_pipedetector_right_area_entered(area):
right_pipe = true
pipe = area
func _on_pipedetector_right_area_exited(area):
right_pipe = false
func _on_pipe_timer_timeout():
on_pause = false
color_rect.visible = false
func _on_pipe_timer_half_timeout():
position = pipe_target