Compare commits

..

5 Commits

Author SHA1 Message Date
da8f257636 Cube & Scoring Logic Part 2
Offset :
0-15 basically center (ln 42)
and anything else is left right

alignment:
0.8-1 good cut
0  basically perpendicular
-1 opposite to cut direction
2025-07-04 14:18:07 +03:00
4ebfb16ca7 Cube & Scoring Logic Part 1 2025-07-04 13:50:16 +03:00
efccbfc52b new startup options 2025-07-02 00:00:25 +03:00
23d5530610 Merge branch 'main' of https://kevinblog.sytes.net/Code/Kevin/2D-Beatsaber-game 2025-07-01 22:50:52 +03:00
ac4e016200 Expo easing function + welcome screen 2025-07-01 22:50:47 +03:00
16 changed files with 209 additions and 56 deletions

58
game/Objects/Cube.gd Normal file
View File

@@ -0,0 +1,58 @@
extends Area2D
@export var cubeHeight = 364
@export var cursor_path: NodePath
@onready var cursor = get_node(cursor_path)
@onready var mesh_instance: MeshInstance2D = $MeshInstance2D
@onready var line = $Vector/Line2D
@onready var shape: CollisionShape2D = $HitBox
@onready var red_line = $Vector/CursorVector
@onready var green_line = $Vector/Top
@onready var pink_line = $Vector/Mid
var cube_top_center: Vector2
var CorrectHit = false
var TopScore = 0
var MidScore = 0
var BotScore = 0
@onready var area_direction
@onready var body_direction
var sliced = false
func _ready():
pass
func _on_area_entered(area: Area2D) -> void:
if area.name != "Cursor":
return
area_direction = -area.global_transform.y.normalized()
body_direction = -self.global_transform.y.normalized()
var local_pos = to_local(area.global_position)
var side_offset = local_pos.y
var alignment = area_direction.dot(body_direction)
if abs(side_offset) < 15:
print("Hit near center Slice Side offset:", round(side_offset) ," ", alignment)
elif side_offset < 0:
print("Hit to the LEFT Side, offset:", side_offset, " ", alignment)
else:
print("Hit to the RIGHT Side, offset:", side_offset, " ", alignment)
if alignment > 0.8:
print("Consider Good Cut")
func get_closest_point_on_line(line_origin: Vector2, line_dir: Vector2, point: Vector2) -> Vector2:
# Projects point onto the infinite line defined by (line_origin, line_dir)
var v = point - line_origin
var d = v.dot(line_dir)
return line_origin + line_dir * d

View File

@@ -1,16 +1,40 @@
[gd_scene load_steps=4 format=3 uid="uid://ctcv7rr8w3fnf"] [gd_scene load_steps=5 format=3 uid="uid://ctcv7rr8w3fnf"]
[ext_resource type="Texture2D" uid="uid://2nxh3mui3ia7" path="res://Textures/svg/Cube.svg" id="1_k3834"] [ext_resource type="Texture2D" uid="uid://2nxh3mui3ia7" path="res://Textures/svg/Cube.svg" id="1_k3834"]
[ext_resource type="Script" uid="uid://cu1ss1gvex68v" path="res://Objects/SelfSlicer.gd" id="1_m4rrt"] [ext_resource type="Script" uid="uid://cu1ss1gvex68v" path="res://Objects/Cube.gd" id="1_m4rrt"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ae35o"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_ae35o"]
size = Vector2(68, 68) size = Vector2(68, 68)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_m4rrt"]
size = Vector2(26.5, 68)
[node name="Node2D" type="Area2D"] [node name="Node2D" type="Area2D"]
script = ExtResource("1_m4rrt") script = ExtResource("1_m4rrt")
[node name="Sprite2D" type="Sprite2D" parent="."] [node name="Sprite2D" type="Sprite2D" parent="."]
scale = Vector2(0.5, 0.5)
texture = ExtResource("1_k3834") texture = ExtResource("1_k3834")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="HitBox" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_ae35o") shape = SubResource("RectangleShape2D_ae35o")
[node name="Area2D" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
position = Vector2(-21.25, 0)
shape = SubResource("RectangleShape2D_m4rrt")
debug_color = Color(0.988715, 0, 0.298839, 0.42)
[node name="Vector" type="Node2D" parent="."]
[node name="CursorVector" type="Line2D" parent="Vector"]
[node name="Mid" type="Line2D" parent="Vector"]
default_color = Color(0, 0.952941, 0, 1)
[node name="Top" type="Line2D" parent="Vector"]
position = Vector2(-32, 0)
default_color = Color(1, 0, 0, 1)
[connection signal="area_entered" from="." to="." method="_on_area_entered"]

View File

@@ -4,13 +4,14 @@
[ext_resource type="Texture2D" uid="uid://d0hckoql2xnbq" path="res://Textures/svg/Cursor.svg" id="2_r0du0"] [ext_resource type="Texture2D" uid="uid://d0hckoql2xnbq" path="res://Textures/svg/Cursor.svg" id="2_r0du0"]
[sub_resource type="CircleShape2D" id="CircleShape2D_v75j3"] [sub_resource type="CircleShape2D" id="CircleShape2D_v75j3"]
radius = 19.0263 radius = 28.0
[node name="Cursor" type="Area2D"] [node name="Cursor" type="Area2D"]
script = ExtResource("1_uu6xs") script = ExtResource("1_uu6xs")
ShowMouse = true ShowMouse = true
[node name="CursorTexture" type="Sprite2D" parent="."] [node name="CursorTexture" type="Sprite2D" parent="."]
scale = Vector2(0.5, 0.5)
texture = ExtResource("2_r0du0") texture = ExtResource("2_r0du0")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]

View File

@@ -1,12 +0,0 @@
extends Area2D
class_name SelfSlicer
@export var cursor_path: NodePath
@onready var cursor = get_node(cursor_path)
@onready var mesh_instance: MeshInstance2D = $MeshInstance2D
var sliced = false
func _ready():
pass

View File

@@ -1,6 +1,9 @@
[gd_scene format=3 uid="uid://57px5totoewp"] [gd_scene load_steps=2 format=3 uid="uid://57px5totoewp"]
[ext_resource type="Script" uid="uid://mgj6wd25jrsn" path="res://Scripts/WelcomeScreen/welcome_screen.gd" id="1_5gy0r"]
[node name="WelcomeScreen" type="CanvasLayer"] [node name="WelcomeScreen" type="CanvasLayer"]
script = ExtResource("1_5gy0r")
[node name="ColorRect" type="ColorRect" parent="."] [node name="ColorRect" type="ColorRect" parent="."]
anchors_preset = 15 anchors_preset = 15

View File

@@ -1,11 +1,13 @@
extends Area2D extends Area2D
@onready var Cursor = $Cursor @onready var Cursor = $Cursor
@onready var MouseOn = true
@export var ShowMouse = false @export var ShowMouse = false
var old_mouse_pos = Vector2.ZERO var old_mouse_pos = Vector2.ZERO
var mouse_velocity = Vector2.ZERO var mouse_velocity = Vector2.ZERO
@export var vector_length = 100 @export var vector_length = 360
@export var vector_width = 5 @export var vector_width = 5
var line_2d : Line2D var line_2d : Line2D
var is_touchingCube = false var is_touchingCube = false
var collision_normal = Vector2.ZERO var collision_normal = Vector2.ZERO
@@ -39,30 +41,32 @@ func _ready() -> void:
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void: func _process(delta: float) -> void:
if is_touchingCube: if is_touchingCube:
draw_vector() # draw_vector()
pass
else: else:
line_2d.clear_points() line_2d.clear_points()
if MouseOn:
var current_mouse_pos = get_viewport().get_mouse_position()
var current_mouse_pos = get_viewport().get_mouse_position() mouse_velocity = current_mouse_pos - old_mouse_pos
mouse_velocity = current_mouse_pos - old_mouse_pos if mouse_velocity.length_squared()>0.1:
rotation = lerp_angle(rotation, mouse_velocity.angle(), 80 * delta)
if mouse_velocity.length_squared()>0.1:
rotation = lerp_angle(rotation, mouse_velocity.angle(), 80 * delta)
var direction_to_mouse = (current_mouse_pos - global_position).normalized() var direction_to_mouse = (current_mouse_pos - global_position).normalized()
global_position = current_mouse_pos global_position = current_mouse_pos
old_mouse_pos = current_mouse_pos old_mouse_pos = current_mouse_pos
pass pass
func _on_area_entered(area: Area2D) -> void: func _on_area_entered(area: Area2D) -> void:
print("AAAA " + str(area.name)) # print("AAAA " + str(area.name))
if area.name == "Node2D": if area.name == "Node2D":
#freeze cursor on touch block
MouseOn = true
is_touchingCube = true is_touchingCube = true
draw_vector() draw_vector()
@@ -92,5 +96,5 @@ func draw_vector():
line_2d.add_point(start_point,1) line_2d.add_point(start_point,1)
line_2d.add_point(end_point,2) line_2d.add_point(end_point,2)
print("Draws the vector\nStart %s\nEnd: %s\nDirection %s" % [start_point, end_point, vector_direction]) #print("Draws the vector\nStart %s\nEnd: %s\nDirection %s" % [start_point, end_point, vector_direction])
pass pass

View File

@@ -0,0 +1,18 @@
extends Node2D
@export var UseNativeDisplaySize = false
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
if UseNativeDisplaySize:
print("Using Native Display 0 Size : " + str(DisplayServer.screen_get_size(0)))
get_viewport().size = DisplayServer.screen_get_size(0)
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass

View File

@@ -0,0 +1 @@
uid://chbq0wiah2mov

View File

@@ -0,0 +1,43 @@
extends CanvasLayer
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
update_progress_bar(80)
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func update_progress_bar(value: float):
var start_value = $ProgressBar.value
var percent = 0
while percent < 100:
var ease = expo_ease_in_out(start_value, value, percent)
$ProgressBar.value = ease
percent += 1
await get_tree().create_timer(0.05).timeout
func expo_ease_in_out(start: float, end: float, percent: int) -> float:
var t: float = clamp(float(percent) / 100.0, 0, 1.0)
var change: float = end - start
if t == 0:
return start
if t == 1.0:
return end
if t < 0.5:
return change / 2 * pow(2, 20 * t - 10) + start
else:
return change / 2 * (-pow(2, -20 * t + 10) + 2) + start

View File

@@ -0,0 +1 @@
uid://mgj6wd25jrsn

View File

@@ -32,6 +32,6 @@ process/hdr_as_srgb=false
process/hdr_clamp_exposure=false process/hdr_clamp_exposure=false
process/size_limit=0 process/size_limit=0
detect_3d/compress_to=1 detect_3d/compress_to=1
svg/scale=1.0 svg/scale=2.0
editor/scale_with_editor_scale=false editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false editor/convert_colors_with_editor_theme=false

View File

@@ -32,6 +32,6 @@ process/hdr_as_srgb=false
process/hdr_clamp_exposure=false process/hdr_clamp_exposure=false
process/size_limit=0 process/size_limit=0
detect_3d/compress_to=1 detect_3d/compress_to=1
svg/scale=1.0 svg/scale=2.0
editor/scale_with_editor_scale=false editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false editor/convert_colors_with_editor_theme=false

View File

@@ -17,5 +17,6 @@ config/icon="res://icon.svg"
[display] [display]
window/stretch/mode="viewport"
window/stretch/aspect="expand" window/stretch/aspect="expand"
window/vsync/vsync_mode=0 window/vsync/vsync_mode=0

View File

@@ -1,13 +1,30 @@
[gd_scene load_steps=4 format=3 uid="uid://dc02h0h7ooucv"] [gd_scene load_steps=5 format=3 uid="uid://dc02h0h7ooucv"]
[ext_resource type="Script" uid="uid://hfccs84dimkv" path="res://test_ground.gd" id="1_85h15"] [ext_resource type="Script" uid="uid://hfccs84dimkv" path="res://test_ground.gd" id="1_85h15"]
[ext_resource type="Script" uid="uid://chbq0wiah2mov" path="res://Scripts/StartupOptions.gd" id="1_fhsvb"]
[ext_resource type="PackedScene" uid="uid://c42ny2e8vbhhc" path="res://Objects/Cursor.tscn" id="1_rkps0"] [ext_resource type="PackedScene" uid="uid://c42ny2e8vbhhc" path="res://Objects/Cursor.tscn" id="1_rkps0"]
[ext_resource type="PackedScene" uid="uid://ctcv7rr8w3fnf" path="res://Objects/Cube.tscn" id="3_66313"] [ext_resource type="PackedScene" uid="uid://ctcv7rr8w3fnf" path="res://Objects/Cube.tscn" id="3_66313"]
[node name="Screen" type="CanvasLayer"] [node name="Screen" type="Node2D"]
script = ExtResource("1_fhsvb")
UseNativeDisplaySize = true
[node name="Node2D" parent="." instance=ExtResource("3_66313")]
position = Vector2(409, 323)
scale = Vector2(3.385, 3.385)
cursor_path = NodePath("../Cursor")
[node name="Node2D2" parent="." instance=ExtResource("3_66313")]
position = Vector2(625, 528)
rotation = 0.60511
[node name="Cursor" parent="." instance=ExtResource("1_rkps0")]
position = Vector2(162, 227)
[node name="CanvasLayer" type="CanvasLayer" parent="."]
script = ExtResource("1_85h15") script = ExtResource("1_85h15")
[node name="VBoxContainer" type="VBoxContainer" parent="."] [node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer"]
anchors_preset = 2 anchors_preset = 2
anchor_top = 1.0 anchor_top = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
@@ -15,35 +32,27 @@ offset_top = -131.0
offset_right = 134.0 offset_right = 134.0
grow_vertical = 0 grow_vertical = 0
size_flags_vertical = 8 size_flags_vertical = 8
metadata/_edit_use_anchors_ = true
[node name="Label" type="Label" parent="VBoxContainer"] [node name="Label" type="Label" parent="CanvasLayer/VBoxContainer"]
layout_mode = 2 layout_mode = 2
text = "Info?" text = "Info?"
[node name="Fps" type="Label" parent="VBoxContainer"] [node name="Resolution" type="Label" parent="CanvasLayer/VBoxContainer"]
layout_mode = 2
text = "Info?"
[node name="Fps" type="Label" parent="CanvasLayer/VBoxContainer"]
layout_mode = 2 layout_mode = 2
text = "FPS : " text = "FPS : "
[node name="Frametime" type="Label" parent="VBoxContainer"] [node name="Frametime" type="Label" parent="CanvasLayer/VBoxContainer"]
layout_mode = 2 layout_mode = 2
text = "FrameTimeMCS :" text = "FrameTimeMCS :"
[node name="PT" type="Label" parent="VBoxContainer"] [node name="PT" type="Label" parent="CanvasLayer/VBoxContainer"]
layout_mode = 2 layout_mode = 2
text = "Procces Time: " text = "Procces Time: "
[node name="VideoMemory" type="Label" parent="VBoxContainer"] [node name="VideoMemory" type="Label" parent="CanvasLayer/VBoxContainer"]
layout_mode = 2 layout_mode = 2
text = "Video Mem:" text = "Video Mem:"
[node name="Node2D" parent="." instance=ExtResource("3_66313")]
position = Vector2(409, 323)
cursor_path = NodePath("../Cursor")
[node name="Node2D2" parent="." instance=ExtResource("3_66313")]
position = Vector2(615, 531)
rotation = 0.60511
[node name="Cursor" parent="." instance=ExtResource("1_rkps0")]
position = Vector2(263, 291)

View File

@@ -8,8 +8,10 @@ func _ready() -> void:
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void: func _process(delta: float) -> void:
$VBoxContainer/Resolution.text = "Resolution: %s" % get_viewport().size
$VBoxContainer/Fps.text = "FPS: %s" % Performance.get_monitor(Performance.TIME_FPS) $VBoxContainer/Fps.text = "FPS: %s" % Performance.get_monitor(Performance.TIME_FPS)
$VBoxContainer/Frametime.text = "FrameTime: %s" % snapped(Engine.get_physics_interpolation_fraction(), 0.000001) $VBoxContainer/Frametime.text = "FrameTime: %s" % snapped(Engine.get_physics_interpolation_fraction(), 0.000001)
$VBoxContainer/PT.text = "Process time: %s ms" % snapped(Performance.get_monitor(Performance.TIME_PROCESS)*1000, 0.001) $VBoxContainer/PT.text = "Process time: %s ms" % snapped(Performance.get_monitor(Performance.TIME_PROCESS)*1000, 0.001)
$VBoxContainer/VideoMemory.text ="Video memory Used: %s MB" % snapped(Performance.get_monitor(Performance.RENDER_VIDEO_MEM_USED)/1024**2, 0.001) $VBoxContainer/VideoMemory.text ="Video memory Used: %s MB" % snapped(Performance.get_monitor(Performance.RENDER_VIDEO_MEM_USED)/1024**2, 0.001)
pass pass