added a basic ball that properly inverts velocity when colliding with a world boundary. my balls are getting stuck on each other tho
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://d2r0ip6xy3a2"]
|
||||
|
||||
[ext_resource type="Script" path="res://balls/ball.gd" id="1_ija2k"]
|
||||
|
||||
[node name="Ball" type="CharacterBody2D"]
|
||||
motion_mode = 1
|
||||
floor_stop_on_slope = false
|
||||
script = ExtResource("1_ija2k")
|
||||
@@ -0,0 +1,17 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
@export var speed: float = 5
|
||||
const _speed_mult: float = 200
|
||||
var _direction: Vector2 = Vector2(1.0, 0.5)
|
||||
|
||||
func _physics_process(delta):
|
||||
velocity.x = speed * _speed_mult * _direction.x
|
||||
velocity.y = speed * _speed_mult * _direction.y
|
||||
|
||||
move_and_slide()
|
||||
|
||||
func invert_x():
|
||||
_direction.x *= -1
|
||||
|
||||
func invert_y():
|
||||
_direction.y *= -1
|
||||
@@ -0,0 +1,8 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://d2r0ip6xy3a2"]
|
||||
|
||||
[ext_resource type="Script" path="res://balls/ball.gd" id="1_ija2k"]
|
||||
|
||||
[node name="Ball" type="CharacterBody2D"]
|
||||
motion_mode = 1
|
||||
floor_stop_on_slope = false
|
||||
script = ExtResource("1_ija2k")
|
||||
@@ -0,0 +1,15 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://sl3jbnopo0yh"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://d2r0ip6xy3a2" path="res://balls/ball.tscn" id="1_ffml1"]
|
||||
[ext_resource type="Texture2D" uid="uid://cxi0fqy5sajh5" path="res://balls/basic/basic.webp" id="2_4dnuc"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_isusp"]
|
||||
size = Vector2(50, 50)
|
||||
|
||||
[node name="Ball" instance=ExtResource("1_ffml1")]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." index="0"]
|
||||
shape = SubResource("RectangleShape2D_isusp")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="." index="1"]
|
||||
texture = ExtResource("2_4dnuc")
|
||||
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
@@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://cxi0fqy5sajh5"
|
||||
path="res://.godot/imported/basic.webp-a129d05a6653f0c702726e8f6c206488.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://balls/basic/basic.webp"
|
||||
dest_files=["res://.godot/imported/basic.webp-a129d05a6653f0c702726e8f6c206488.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
|
||||
@@ -0,0 +1,10 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://cbygje4vi2rkv"]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/boundary.gd" id="1_dkemt"]
|
||||
|
||||
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_dxkod"]
|
||||
|
||||
[node name="Boundary" type="CollisionShape2D"]
|
||||
shape = SubResource("WorldBoundaryShape2D_dxkod")
|
||||
debug_color = Color(0.878431, 0, 0.415686, 0.419608)
|
||||
script = ExtResource("1_dkemt")
|
||||
@@ -0,0 +1,3 @@
|
||||
extends CollisionShape2D
|
||||
|
||||
@export_enum("x", "y") var boundary_invert_axis = 1
|
||||
+151
-10
@@ -1,19 +1,160 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://bmscox3qtwvs2"]
|
||||
[gd_scene load_steps=11 format=3 uid="uid://bmscox3qtwvs2"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://c7wvhwsys1ll4" path="res://resources/backgrounds/levelbg.webp" id="1_7ct6t"]
|
||||
[ext_resource type="FontFile" uid="uid://dxgnofummhosw" path="res://fonts/play_bold.ttf" id="2_musvo"]
|
||||
[ext_resource type="PackedScene" uid="uid://sl3jbnopo0yh" path="res://balls/basic/ball_basic.tscn" id="3_14yi2"]
|
||||
[ext_resource type="Script" path="res://scenes/world_boundary.gd" id="3_w4mye"]
|
||||
[ext_resource type="PackedScene" uid="uid://cbygje4vi2rkv" path="res://boundaries/world_boundary.tscn" id="4_455ct"]
|
||||
[ext_resource type="Script" path="res://scenes/boundary.gd" id="4_r1kkq"]
|
||||
|
||||
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_ybmo2"]
|
||||
normal = Vector2(0, 1)
|
||||
distance = -510.0
|
||||
|
||||
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_k0bca"]
|
||||
distance = -510.0
|
||||
|
||||
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_4nfnd"]
|
||||
normal = Vector2(1, 0)
|
||||
distance = -750.0
|
||||
|
||||
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_ktw6h"]
|
||||
normal = Vector2(-1, 0)
|
||||
distance = -750.0
|
||||
|
||||
[node name="Level" type="Node2D"]
|
||||
|
||||
[node name="GUI" type="Control" parent="."]
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
|
||||
[node name="PlayArea" type="Camera2D" parent="."]
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
position = Vector2(960, 540)
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="."]
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
offset_right = 1920.0
|
||||
offset_bottom = 1080.0
|
||||
texture = ExtResource("1_7ct6t")
|
||||
|
||||
[node name="GUI" type="VBoxContainer" parent="."]
|
||||
offset_left = 20.0
|
||||
offset_top = 20.0
|
||||
offset_right = 360.0
|
||||
offset_bottom = 1060.0
|
||||
|
||||
[node name="Title0" type="Label" parent="GUI"]
|
||||
layout_mode = 2
|
||||
theme_override_fonts/font = ExtResource("2_musvo")
|
||||
theme_override_font_sizes/font_size = 154
|
||||
text = "IDLE"
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="Title1" type="Label" parent="GUI"]
|
||||
layout_mode = 2
|
||||
theme_override_fonts/font = ExtResource("2_musvo")
|
||||
theme_override_font_sizes/font_size = 64
|
||||
text = "BREAKOUT"
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="GameContent" type="Node2D" parent="."]
|
||||
|
||||
[node name="WorldBoundary" type="Area2D" parent="GameContent"]
|
||||
position = Vector2(1140, 540)
|
||||
script = ExtResource("3_w4mye")
|
||||
|
||||
[node name="Top" parent="GameContent/WorldBoundary" instance=ExtResource("4_455ct")]
|
||||
shape = SubResource("WorldBoundaryShape2D_ybmo2")
|
||||
|
||||
[node name="Bottom" parent="GameContent/WorldBoundary" instance=ExtResource("4_455ct")]
|
||||
shape = SubResource("WorldBoundaryShape2D_k0bca")
|
||||
|
||||
[node name="Left" parent="GameContent/WorldBoundary" instance=ExtResource("4_455ct")]
|
||||
shape = SubResource("WorldBoundaryShape2D_4nfnd")
|
||||
boundary_invert_axis = 0
|
||||
|
||||
[node name="Right" type="CollisionShape2D" parent="GameContent/WorldBoundary"]
|
||||
shape = SubResource("WorldBoundaryShape2D_ktw6h")
|
||||
debug_color = Color(0.878431, 0, 0.415686, 0.419608)
|
||||
script = ExtResource("4_r1kkq")
|
||||
boundary_invert_axis = 0
|
||||
|
||||
[node name="Balls" type="Node2D" parent="GameContent"]
|
||||
|
||||
[node name="Ball" parent="GameContent/Balls" instance=ExtResource("3_14yi2")]
|
||||
position = Vector2(687, 534)
|
||||
motion_mode = 0
|
||||
floor_stop_on_slope = true
|
||||
|
||||
[node name="Ball2" parent="GameContent/Balls" instance=ExtResource("3_14yi2")]
|
||||
position = Vector2(971, 920)
|
||||
motion_mode = 0
|
||||
floor_stop_on_slope = true
|
||||
|
||||
[node name="Ball3" parent="GameContent/Balls" instance=ExtResource("3_14yi2")]
|
||||
position = Vector2(1641, 958)
|
||||
motion_mode = 0
|
||||
floor_stop_on_slope = true
|
||||
|
||||
[node name="Ball4" parent="GameContent/Balls" instance=ExtResource("3_14yi2")]
|
||||
position = Vector2(482, 986)
|
||||
motion_mode = 0
|
||||
floor_stop_on_slope = true
|
||||
|
||||
[node name="Ball5" parent="GameContent/Balls" instance=ExtResource("3_14yi2")]
|
||||
position = Vector2(899, 280)
|
||||
motion_mode = 0
|
||||
floor_stop_on_slope = true
|
||||
|
||||
[node name="Ball6" parent="GameContent/Balls" instance=ExtResource("3_14yi2")]
|
||||
position = Vector2(1427, 577)
|
||||
motion_mode = 0
|
||||
floor_stop_on_slope = true
|
||||
|
||||
[node name="Ball7" parent="GameContent/Balls" instance=ExtResource("3_14yi2")]
|
||||
position = Vector2(1330, 823)
|
||||
motion_mode = 0
|
||||
floor_stop_on_slope = true
|
||||
|
||||
[node name="Ball8" parent="GameContent/Balls" instance=ExtResource("3_14yi2")]
|
||||
position = Vector2(1544, 413)
|
||||
motion_mode = 0
|
||||
floor_stop_on_slope = true
|
||||
|
||||
[node name="Ball9" parent="GameContent/Balls" instance=ExtResource("3_14yi2")]
|
||||
position = Vector2(1646, 179)
|
||||
motion_mode = 0
|
||||
floor_stop_on_slope = true
|
||||
|
||||
[node name="Ball10" parent="GameContent/Balls" instance=ExtResource("3_14yi2")]
|
||||
position = Vector2(1666, 660)
|
||||
motion_mode = 0
|
||||
floor_stop_on_slope = true
|
||||
|
||||
[node name="Ball11" parent="GameContent/Balls" instance=ExtResource("3_14yi2")]
|
||||
position = Vector2(516, 671)
|
||||
motion_mode = 0
|
||||
floor_stop_on_slope = true
|
||||
|
||||
[node name="Ball12" parent="GameContent/Balls" instance=ExtResource("3_14yi2")]
|
||||
position = Vector2(553, 174)
|
||||
motion_mode = 0
|
||||
floor_stop_on_slope = true
|
||||
|
||||
[node name="Ball13" parent="GameContent/Balls" instance=ExtResource("3_14yi2")]
|
||||
position = Vector2(1303, 479)
|
||||
motion_mode = 0
|
||||
floor_stop_on_slope = true
|
||||
|
||||
[node name="Ball14" parent="GameContent/Balls" instance=ExtResource("3_14yi2")]
|
||||
position = Vector2(943, 726)
|
||||
motion_mode = 0
|
||||
floor_stop_on_slope = true
|
||||
|
||||
[node name="Ball15" parent="GameContent/Balls" instance=ExtResource("3_14yi2")]
|
||||
position = Vector2(1363, 282)
|
||||
motion_mode = 0
|
||||
floor_stop_on_slope = true
|
||||
|
||||
[node name="Ball16" parent="GameContent/Balls" instance=ExtResource("3_14yi2")]
|
||||
position = Vector2(1135, 158)
|
||||
motion_mode = 0
|
||||
floor_stop_on_slope = true
|
||||
|
||||
[connection signal="body_entered" from="GameContent/WorldBoundary" to="GameContent/WorldBoundary" method="_on_ball_entered"]
|
||||
[connection signal="body_shape_entered" from="GameContent/WorldBoundary" to="GameContent/WorldBoundary" method="_on_ball_shape_entered"]
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
extends Area2D
|
||||
|
||||
func _on_ball_shape_entered(body_rid, body, body_shape_index, local_shape_index):
|
||||
print("FUCK YES")
|
||||
match self.shape_owner_get_owner(local_shape_index).boundary_invert_axis:
|
||||
0: # x
|
||||
body.invert_x()
|
||||
1: # y
|
||||
body.invert_y()
|
||||
Reference in New Issue
Block a user