4 game objects, working characterbody, basic impulses
This commit is contained in:
parent
4439abfdf7
commit
b18a0fafde
@ -11,5 +11,12 @@ config_version=5
|
|||||||
[application]
|
[application]
|
||||||
|
|
||||||
config/name="FabiGame"
|
config/name="FabiGame"
|
||||||
|
run/main_scene="res://scenes/game.tscn"
|
||||||
config/features=PackedStringArray("4.3", "Forward Plus")
|
config/features=PackedStringArray("4.3", "Forward Plus")
|
||||||
config/icon="res://icon.svg"
|
config/icon="res://icon.svg"
|
||||||
|
|
||||||
|
[file_customization]
|
||||||
|
|
||||||
|
folder_colors={
|
||||||
|
"res://scripts/": "green"
|
||||||
|
}
|
||||||
|
13
fabigame/scenes/box.tscn
Normal file
13
fabigame/scenes/box.tscn
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
[gd_scene load_steps=2 format=3 uid="uid://bw3gps1njvtgr"]
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ddwss"]
|
||||||
|
size = Vector2(26, 26)
|
||||||
|
|
||||||
|
[node name="RigidBody2D" type="RigidBody2D" groups=["box"]]
|
||||||
|
position = Vector2(411, 384)
|
||||||
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
|
rotation = -0.802465
|
||||||
|
shape = SubResource("RectangleShape2D_ddwss")
|
||||||
|
debug_color = Color(0.848428, 0.374869, 0, 0.42)
|
65
fabigame/scenes/game.tscn
Normal file
65
fabigame/scenes/game.tscn
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
[gd_scene load_steps=8 format=3 uid="uid://ciko2h5jj1a3k"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://scripts/dudecontroller.gd" id="1_2426f"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://bw3gps1njvtgr" path="res://scenes/box.tscn" id="1_mg5q5"]
|
||||||
|
[ext_resource type="Script" path="res://scripts/trigger.gd" id="2_a7w16"]
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_fuiwd"]
|
||||||
|
size = Vector2(142, 10)
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_iice4"]
|
||||||
|
radius = 6.32456
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_lbd3t"]
|
||||||
|
size = Vector2(20, 4.47115)
|
||||||
|
|
||||||
|
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_vdfbk"]
|
||||||
|
|
||||||
|
[node name="Game" type="Node2D"]
|
||||||
|
|
||||||
|
[node name="Platform" type="StaticBody2D" parent="."]
|
||||||
|
position = Vector2(394, 460)
|
||||||
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Platform"]
|
||||||
|
scale = Vector2(1.02381, 1.00385)
|
||||||
|
shape = SubResource("RectangleShape2D_fuiwd")
|
||||||
|
|
||||||
|
[node name="CharacterBody2D" type="CharacterBody2D" parent="."]
|
||||||
|
position = Vector2(380, 429)
|
||||||
|
script = ExtResource("1_2426f")
|
||||||
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
|
||||||
|
shape = SubResource("CircleShape2D_iice4")
|
||||||
|
debug_color = Color(0.598404, 0.370441, 1, 0.42)
|
||||||
|
|
||||||
|
[node name="Area2D" type="Area2D" parent="."]
|
||||||
|
position = Vector2(392, 535)
|
||||||
|
scale = Vector2(24.2, 4.16)
|
||||||
|
script = ExtResource("2_a7w16")
|
||||||
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||||
|
position = Vector2(0, -7.76443)
|
||||||
|
scale = Vector2(1, 1)
|
||||||
|
shape = SubResource("RectangleShape2D_lbd3t")
|
||||||
|
debug_color = Color(0.31865, 0.625237, 0, 0.42)
|
||||||
|
|
||||||
|
[node name="RigidBody2D" parent="." instance=ExtResource("1_mg5q5")]
|
||||||
|
position = Vector2(432, 417)
|
||||||
|
|
||||||
|
[node name="RigidBody2D2" parent="." instance=ExtResource("1_mg5q5")]
|
||||||
|
position = Vector2(405, 385)
|
||||||
|
|
||||||
|
[node name="RigidBody2D3" parent="." instance=ExtResource("1_mg5q5")]
|
||||||
|
position = Vector2(422, 344)
|
||||||
|
|
||||||
|
[node name="StaticBody2D" type="StaticBody2D" parent="."]
|
||||||
|
position = Vector2(352, 535)
|
||||||
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"]
|
||||||
|
shape = SubResource("WorldBoundaryShape2D_vdfbk")
|
||||||
|
|
||||||
|
[connection signal="body_entered" from="Area2D" to="Area2D" method="_on_body_entered"]
|
31
fabigame/scripts/dudecontroller.gd
Normal file
31
fabigame/scripts/dudecontroller.gd
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
extends CharacterBody2D
|
||||||
|
|
||||||
|
|
||||||
|
const SPEED = 300.0
|
||||||
|
const JUMP_VELOCITY = -400.0
|
||||||
|
const BUMP_FORCE = 50
|
||||||
|
|
||||||
|
|
||||||
|
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() * BUMP_FORCE)
|
22
fabigame/scripts/trigger.gd
Normal file
22
fabigame/scripts/trigger.gd
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
extends Area2D
|
||||||
|
var BoxCount = 0
|
||||||
|
var MaxBoxes = 3
|
||||||
|
|
||||||
|
|
||||||
|
# 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("Triggered!")
|
||||||
|
if body.is_in_group("box"):
|
||||||
|
print("box hitted")
|
||||||
|
BoxCount +=1
|
||||||
|
if BoxCount >= MaxBoxes:
|
||||||
|
print("WINNER DING DING DING")
|
Loading…
Reference in New Issue
Block a user