level now detects (in a very rudimentary way, by checking every frame) whether all blocks have been broken

This commit is contained in:
2024-07-23 20:53:55 +02:00
parent eeffba61b6
commit 9ae0d04136
6 changed files with 40 additions and 75 deletions
+8 -19
View File
@@ -3,18 +3,18 @@ extends CharacterBody2D
@export var speed: float = 5
@export var strength: int = 1
const _speed_mult: float = 20
var _direction: Vector2 = Vector2(-1.0, -0.5)
var _velocity: Vector2
const _speed_mult: float = 5000
var _direction: Vector2
var _velocity: Vector2
var deg: float
func _ready():
_velocity.x = 400#speed * _speed_mult * _direction.x * delta
_velocity.y = 450#speed * _speed_mult * _direction.y * delta
_direction = Vector2.UP.rotated(deg_to_rad(randf_range(0.0, 360.0)))
func _physics_process(delta):
_velocity.x = speed * _speed_mult * _direction.x * delta
_velocity.y = speed * _speed_mult * _direction.y * delta
var collide = move_and_collide(_velocity * delta)
if collide:
@@ -23,22 +23,11 @@ func _physics_process(delta):
_invert_x()
if (deg >= 135 and deg < 225) or deg < 45 or deg >= 315:
_invert_y()
print(collide.get_collider())
if collide.get_collider().get_parent() is Block:
print(true)
collide.get_collider().get_parent().take_damage(strength)
func _invert_x():
_velocity.x *= -1
_direction.x *= -1
func _invert_y():
_velocity.y *= -1
func has_collided():
pass
#if $Raycasts/North.is_colliding() or $Raycasts/South.is_colliding():
#_invert_y()
#print("y")
#if $Raycasts/West.is_colliding() or $Raycasts/East.is_colliding():
#_invert_x()
#print("x")
_direction.y *= -1
+4 -44
View File
@@ -1,55 +1,15 @@
[gd_scene load_steps=8 format=3 uid="uid://sl3jbnopo0yh"]
[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)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_qicwc"]
size = Vector2(46, 2)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ugdte"]
size = Vector2(46, 2)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_2tu06"]
size = Vector2(2, 46)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_0vqpn"]
size = Vector2(2, 46)
[sub_resource type="CircleShape2D" id="CircleShape2D_gj21y"]
radius = 25.0
[node name="Ball" instance=ExtResource("1_ffml1")]
collision_mask = 14
[node name="CollisionShape2D" type="CollisionShape2D" parent="." index="0"]
shape = SubResource("RectangleShape2D_isusp")
shape = SubResource("CircleShape2D_gj21y")
[node name="Sprite2D" type="Sprite2D" parent="." index="1"]
texture = ExtResource("2_4dnuc")
[node name="Raycasts" type="Node2D" parent="." index="2"]
visible = false
[node name="North" type="ShapeCast2D" parent="Raycasts" index="0"]
shape = SubResource("RectangleShape2D_qicwc")
target_position = Vector2(0, -25)
collision_mask = 10
collide_with_areas = true
[node name="South" type="ShapeCast2D" parent="Raycasts" index="1"]
shape = SubResource("RectangleShape2D_ugdte")
target_position = Vector2(0, 25)
collision_mask = 10
collide_with_areas = true
[node name="West" type="ShapeCast2D" parent="Raycasts" index="2"]
shape = SubResource("RectangleShape2D_2tu06")
target_position = Vector2(-25, 0)
collision_mask = 10
collide_with_areas = true
[node name="East" type="ShapeCast2D" parent="Raycasts" index="3"]
shape = SubResource("RectangleShape2D_0vqpn")
target_position = Vector2(25, 0)
collision_mask = 10
collide_with_areas = true
+14
View File
@@ -0,0 +1,14 @@
extends Node2D
var _current_level = 1
var ball_scene = preload("res://balls/basic/ball_basic.tscn")
func _on_button_pressed():
var new_ball = ball_scene.instantiate()
new_ball.global_position = $GameContent/BallSpawn.global_position
$GameContent/Balls.add_child(new_ball)
func _physics_process(delta):
if $GameContent/Blocks.get_children().size() == 0:
_current_level += 1
print("DONE")
+13 -2
View File
@@ -1,9 +1,9 @@
[gd_scene load_steps=11 format=3 uid="uid://bmscox3qtwvs2"]
[ext_resource type="Script" path="res://scenes/level.gd" id="1_3qps3"]
[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="PackedScene" uid="uid://c1i1fp3xbp6ly" path="res://blocks/block.tscn" id="7_7fnx3"]
@@ -23,6 +23,7 @@ normal = Vector2(-1, 0)
distance = -750.0
[node name="Level" type="Node2D"]
script = ExtResource("1_3qps3")
[node name="Camera2D" type="Camera2D" parent="."]
position = Vector2(960, 540)
@@ -52,13 +53,18 @@ theme_override_font_sizes/font_size = 64
text = "BREAKOUT"
horizontal_alignment = 1
[node name="Button" type="Button" parent="GUI"]
layout_mode = 2
theme_override_fonts/font = ExtResource("2_musvo")
theme_override_font_sizes/font_size = 50
text = "ADD BALL"
[node name="GameContent" type="Node2D" parent="."]
[node name="WorldBoundary" type="StaticBody2D" parent="GameContent"]
position = Vector2(1140, 540)
collision_layer = 2
collision_mask = 4
script = ExtResource("3_w4mye")
[node name="Top" parent="GameContent/WorldBoundary" instance=ExtResource("4_455ct")]
shape = SubResource("WorldBoundaryShape2D_ybmo2")
@@ -118,3 +124,8 @@ position = Vector2(1603, 907)
[node name="Block12" parent="GameContent/Blocks" instance=ExtResource("7_7fnx3")]
position = Vector2(1635, 293)
[node name="BallSpawn" type="Node2D" parent="GameContent"]
position = Vector2(1140, 540)
[connection signal="pressed" from="GUI/Button" to="." method="_on_button_pressed"]
+1
View File
@@ -3,6 +3,7 @@ extends Control
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
randomize()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
-10
View File
@@ -1,10 +0,0 @@
extends StaticBody2D
#func _on_ball_shape_entered(body_rid, body, body_shape_index, local_shape_index):
#print("FUCK YES")
#body.has_collided()
#match self.shape_owner_get_owner(local_shape_index).boundary_invert_axis:
#0: # x
#body.invert_x()
#1: # y
#body.invert_y()