static body, rigid body, character body, area2d, gamecontroller, custom signal
This commit is contained in:
parent
66f92e9d59
commit
e771dd5a61
@ -11,5 +11,12 @@ config_version=5
|
|||||||
[application]
|
[application]
|
||||||
|
|
||||||
config/name="JuneGame"
|
config/name="JuneGame"
|
||||||
|
run/main_scene="uid://dc4obqdsdq81h"
|
||||||
config/features=PackedStringArray("4.4", "Forward Plus")
|
config/features=PackedStringArray("4.4", "Forward Plus")
|
||||||
config/icon="res://icon.svg"
|
config/icon="res://icon.svg"
|
||||||
|
|
||||||
|
[file_customization]
|
||||||
|
|
||||||
|
folder_colors={
|
||||||
|
"res://scenes/": "orange"
|
||||||
|
}
|
||||||
|
29
scenes/character_body_2d.gd
Normal file
29
scenes/character_body_2d.gd
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
extends CharacterBody2D
|
||||||
|
|
||||||
|
|
||||||
|
const SPEED = 300.0
|
||||||
|
const JUMP_VELOCITY = -400.0
|
||||||
|
|
||||||
|
|
||||||
|
func _physics_process(delta: float) -> void:
|
||||||
|
# Add the gravity.
|
||||||
|
if not is_on_floor():
|
||||||
|
velocity += get_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()
|
||||||
|
for i in get_slide_collision_count():
|
||||||
|
var c = get_slide_collision(i)
|
||||||
|
if c.get_collider() is RigidBody2D:
|
||||||
|
c.get_collider().apply_central_impulse(-c.get_normal() * 100 )
|
1
scenes/character_body_2d.gd.uid
Normal file
1
scenes/character_body_2d.gd.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://dmyw2bn6gnbbv
|
11
scenes/crate.tscn
Normal file
11
scenes/crate.tscn
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
[gd_scene load_steps=2 format=3 uid="uid://dm0s1wei11x43"]
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_uwrxv"]
|
||||||
|
|
||||||
|
[node name="RigidBody2D3" type="RigidBody2D"]
|
||||||
|
rotation = 1.00826
|
||||||
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
|
shape = SubResource("RectangleShape2D_uwrxv")
|
||||||
|
debug_color = Color(0.869503, 0.340519, 0.233585, 0.42)
|
49
scenes/game.tscn
Normal file
49
scenes/game.tscn
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
[gd_scene load_steps=7 format=3 uid="uid://dc4obqdsdq81h"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://dflv3rb4v8c0r" path="res://scripts/gamecontroller.gd" id="1_lnu2h"]
|
||||||
|
[ext_resource type="Script" uid="uid://dmyw2bn6gnbbv" path="res://scenes/character_body_2d.gd" id="1_uwrxv"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://dm0s1wei11x43" path="res://scenes/crate.tscn" id="3_lbhrr"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://bu03yhhfncspe" path="res://scenes/trigger.tscn" id="4_iywne"]
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_8cj0n"]
|
||||||
|
size = Vector2(60, 20)
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_8cj0n"]
|
||||||
|
|
||||||
|
[node name="Game" type="Node2D"]
|
||||||
|
script = ExtResource("1_lnu2h")
|
||||||
|
|
||||||
|
[node name="StaticBody2D" type="StaticBody2D" parent="."]
|
||||||
|
position = Vector2(570, 369)
|
||||||
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"]
|
||||||
|
shape = SubResource("RectangleShape2D_8cj0n")
|
||||||
|
|
||||||
|
[node name="CharacterBody2D" type="CharacterBody2D" parent="."]
|
||||||
|
position = Vector2(568, 344)
|
||||||
|
script = ExtResource("1_uwrxv")
|
||||||
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
|
||||||
|
shape = SubResource("CircleShape2D_8cj0n")
|
||||||
|
debug_color = Color(0.365399, 0.613218, 0.181601, 0.42)
|
||||||
|
|
||||||
|
[node name="RigidBody2D3" parent="." instance=ExtResource("3_lbhrr")]
|
||||||
|
position = Vector2(551, 270)
|
||||||
|
|
||||||
|
[node name="Area2D" parent="." instance=ExtResource("4_iywne")]
|
||||||
|
position = Vector2(519, 453)
|
||||||
|
|
||||||
|
[node name="Area2D2" parent="." instance=ExtResource("4_iywne")]
|
||||||
|
position = Vector2(653, 461)
|
||||||
|
effect = "powerup"
|
||||||
|
|
||||||
|
[node name="RigidBody2D4" parent="." instance=ExtResource("3_lbhrr")]
|
||||||
|
position = Vector2(570, 193)
|
||||||
|
|
||||||
|
[node name="RigidBody2D5" parent="." instance=ExtResource("3_lbhrr")]
|
||||||
|
position = Vector2(589, 256)
|
||||||
|
|
||||||
|
[connection signal="areatrigger" from="Area2D" to="." method="_on_areatrigger"]
|
||||||
|
[connection signal="areatrigger" from="Area2D2" to="." method="_on_areatrigger"]
|
16
scenes/trigger.tscn
Normal file
16
scenes/trigger.tscn
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
[gd_scene load_steps=3 format=3 uid="uid://bu03yhhfncspe"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://ixnbwhm0ptg5" path="res://scripts/trigger.gd" id="1_du5ex"]
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_uwrxv"]
|
||||||
|
radius = 52.0384
|
||||||
|
|
||||||
|
[node name="Area2D" type="Area2D"]
|
||||||
|
script = ExtResource("1_du5ex")
|
||||||
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
|
shape = SubResource("CircleShape2D_uwrxv")
|
||||||
|
debug_color = Color(0.634268, 0.371171, 0.94535, 0.42)
|
||||||
|
|
||||||
|
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
21
scripts/gamecontroller.gd
Normal file
21
scripts/gamecontroller.gd
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
extends Node2D
|
||||||
|
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready() -> void:
|
||||||
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
|
||||||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
func _on_areatrigger(effect, body) -> void:
|
||||||
|
print("Game controller knows about trigger")
|
||||||
|
if effect == "destroy":
|
||||||
|
print("Destroy this thing")
|
||||||
|
body.queue_free()
|
||||||
|
|
||||||
|
if effect == "powerup":
|
||||||
|
print("power up the player")
|
1
scripts/gamecontroller.gd.uid
Normal file
1
scripts/gamecontroller.gd.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://dflv3rb4v8c0r
|
19
scripts/trigger.gd
Normal file
19
scripts/trigger.gd
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
extends Area2D
|
||||||
|
|
||||||
|
@export var effect = "destroy"
|
||||||
|
|
||||||
|
signal areatrigger(effect, Object)
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready() -> void:
|
||||||
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
|
||||||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
func _on_body_entered(body: Node2D) -> void:
|
||||||
|
print("Trigger entered")
|
||||||
|
#broadcast to controller
|
||||||
|
areatrigger.emit(effect, body)
|
1
scripts/trigger.gd.uid
Normal file
1
scripts/trigger.gd.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://ixnbwhm0ptg5
|
Loading…
Reference in New Issue
Block a user