Skip to content

Commit

Permalink
Cut marks (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrodreamer authored Mar 28, 2021
1 parent 3d2fe8f commit 6891753
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 27 deletions.
Binary file modified game/BeepCube_Cut.material
Binary file not shown.
3 changes: 2 additions & 1 deletion game/BeepCube_Cut.shader
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
shader_type spatial;

varying vec3 object_pos;
uniform sampler2D viewport;

void vertex() {
object_pos = VERTEX * 2.0 + vec3(0.5);
Expand All @@ -11,6 +12,6 @@ void fragment() {

float u = min(min(a.x, a.y), a.z);
u = smoothstep(u, 0.05, 1.0);
ALBEDO = vec3(0.0);
ALBEDO = texture(viewport,UV).rgb;
EMISSION = vec3(u);
}
6 changes: 3 additions & 3 deletions game/BeepSaberMainMenu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ func _load_playlists():

if (!_playlists):
vr.log_error("No songs found in " + bspath);
for b in $SongsMenu/Songs.get_children():
b.queue_free()
$SongsMenu.clear()
return false;

if (_playlists.size() == 0):
Expand Down Expand Up @@ -109,12 +108,13 @@ func _set_cur_playlist(pl):
if current_id.size() > 0:
_select_song(current_id[0])

var default_song_icon = preload("res://game/data/beepsaber_logo.png")
func _wire_song_dat(dat):
var current_song_data = {
id=dat,
info=_load_song_info(_song_path(dat))
}
$SongsMenu.add_item("%s - %s" % [current_song_data.info._songAuthorName, current_song_data.info._songName])
$SongsMenu.add_item("%s - %s" % [current_song_data.info._songAuthorName, current_song_data.info._songName],default_song_icon)
$SongsMenu.set_item_metadata($SongsMenu.get_item_count()-1,current_song_data)

func _song_path(dat):
Expand Down
1 change: 1 addition & 0 deletions game/BeepSaber_Game.gd
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ func update_saber_colors():
right_saber.type = 1;
#also updates map colors
$event_driver.update_colors()
$StandingGround.update_colors(COLOR_LEFT,COLOR_RIGHT)

func disable_events(disabled):
$event_driver.disabled = disabled
Expand Down
25 changes: 3 additions & 22 deletions game/BeepSaber_Game.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[gd_scene load_steps=27 format=2]
[gd_scene load_steps=25 format=2]

[ext_resource path="res://game/BeepCube_Cut.material" type="Material" id=1]
[ext_resource path="res://game/floor.tscn" type="PackedScene" id=1]
[ext_resource path="res://OQ_Toolkit/OQ_UI2D/OQ_UI2DLabel.tscn" type="PackedScene" id=2]
[ext_resource path="res://OQ_Toolkit/OQ_UI2D/OQ_UI2DCanvas.tscn" type="PackedScene" id=3]
[ext_resource path="res://OQ_Toolkit/OQ_ARVROrigin.tscn" type="PackedScene" id=4]
Expand Down Expand Up @@ -34,11 +34,6 @@ glow_blend_mode = 0
[sub_resource type="SphereShape" id=2]
radius = 0.07

[sub_resource type="BoxShape" id=3]

[sub_resource type="PlaneMesh" id=4]
size = Vector2( 0.5, 0.5 )

[node name="BeepSaber" type="Spatial"]
script = ExtResource( 9 )

Expand Down Expand Up @@ -82,21 +77,7 @@ ui_raycast_visible_button = -1

[node name="Track" type="Spatial" parent="."]

[node name="StandingGround" type="StaticBody" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1 )
collision_layer = 8
collision_mask = 8

[node name="CollisionShape" type="CollisionShape" parent="StandingGround"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0 )
shape = SubResource( 3 )

[node name="Spatial" type="Spatial" parent="StandingGround"]
transform = Transform( 4, 0, 0, 0, 1, 0, 0, 0, 4, 0, 0, 0 )

[node name="MeshInstance" type="MeshInstance" parent="StandingGround/Spatial"]
mesh = SubResource( 4 )
material/0 = ExtResource( 1 )
[node name="StandingGround" parent="." instance=ExtResource( 1 )]

[node name="event_driver" parent="." instance=ExtResource( 13 )]
game = NodePath("..")
Expand Down
9 changes: 9 additions & 0 deletions game/LightSaber.gd
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ func _process(delta):
last_pos.insert(0,pos)
while last_pos.size() > max_pos:
last_pos.remove(last_pos.size()-1)

#check floor collision for burn mark
$RayCast.force_raycast_update()
if $RayCast.is_colliding():
var raycoli = $RayCast.get_collider()
if raycoli in get_tree().get_nodes_in_group("floor"):
var colipoint = $RayCast.get_collision_point()
raycoli.burn_mark(colipoint,type)

else:
imm_geo.clear()

Expand Down
4 changes: 4 additions & 0 deletions game/LightSaber.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,7 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.0508851, 0 )

[node name="tip" type="Position3D" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.26252, 0 )

[node name="RayCast" type="RayCast" parent="."]
cast_to = Vector3( 0, 1.26, 0 )
collision_mask = 8
2 changes: 1 addition & 1 deletion game/Wall/Wall.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ height = 3
depth = 16

[node name="WallMeshOrientation" type="Spatial" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, -8 )
transform = Transform( 1, 0, 0, 0, 0.999999, 0, 0, 0, 1, 0, 1.5, -8 )

[node name="WallMesh" type="MeshInstance" parent="WallMeshOrientation"]
material_override = ExtResource( 3 )
Expand Down
56 changes: 56 additions & 0 deletions game/floor.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
extends StaticBody


#func _process(delta):
# burn_mark()

var last_position = [Vector2(0,-50),Vector2(0,-50)]

var C_LEFT = Color()
var C_RIGHT = Color()

func update_colors(COLOR_LEFT,COLOR_RIGHT):
C_LEFT = COLOR_LEFT
C_RIGHT = COLOR_RIGHT
$Viewport/ColorRect/burn_l.modulate = C_LEFT*6
$Viewport/ColorRect/burn_r.modulate = C_RIGHT*6

var is_out = [0,0]
func burn_mark(position=Vector3(0,0,-50),type=0):
var burn_mark_sprite
var burn_mark_sprite_long
if type == 0:
burn_mark_sprite = $Viewport/ColorRect/burn_l
burn_mark_sprite_long = $Viewport/ColorRect/burn_l/sprite
elif type == 1:
burn_mark_sprite = $Viewport/ColorRect/burn_r
burn_mark_sprite_long = $Viewport/ColorRect/burn_r/sprite
else:
return
var was_out = !burn_mark_sprite.visible
burn_mark_sprite.visible = true
is_out[type] = 0

var newpos = Vector2(
(position.x+1)*256,
position.z*256
)

burn_mark_sprite.position = newpos

burn_mark_sprite.rotation = newpos.angle_to_point(last_position[type])
burn_mark_sprite.rotation_degrees += 180
var dist = last_position[type].distance_to(newpos)
if dist > 12 and not was_out:
burn_mark_sprite_long.rect_size.x = dist+12
else:
burn_mark_sprite_long.rect_size.x = 24

last_position[type] = newpos

func _process(delta):
if is_out[0] == 1:
$Viewport/ColorRect/burn_l.visible = false
if is_out[1] == 1:
$Viewport/ColorRect/burn_r.visible = false
is_out = [1,1]
99 changes: 99 additions & 0 deletions game/floor.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
[gd_scene load_steps=9 format=2]

[ext_resource path="res://game/BeepCube_Cut.material" type="Material" id=1]
[ext_resource path="res://game/floor.gd" type="Script" id=3]

[sub_resource type="BoxShape" id=1]

[sub_resource type="PlaneMesh" id=2]
size = Vector2( 0.5, 0.5 )

[sub_resource type="ViewportTexture" id=3]
viewport_path = NodePath("Viewport")

[sub_resource type="SpatialMaterial" id=4]
resource_local_to_scene = true
flags_unshaded = true
albedo_texture = SubResource( 3 )

[sub_resource type="CanvasItemMaterial" id=6]
blend_mode = 1

[sub_resource type="StyleBoxFlat" id=5]
bg_color = Color( 1, 1, 1, 1 )
border_width_left = 8
border_width_top = 8
border_width_right = 8
border_width_bottom = 8
border_color = Color( 0, 0, 0, 1 )
border_blend = true
corner_radius_top_left = 11
corner_radius_top_right = 11
corner_radius_bottom_right = 11
corner_radius_bottom_left = 11
corner_detail = 6

[node name="StandingGround" type="StaticBody" groups=[
"floor",
]]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1 )
collision_layer = 8
collision_mask = 8
script = ExtResource( 3 )

[node name="CollisionShape" type="CollisionShape" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0 )
shape = SubResource( 1 )

[node name="Spatial" type="Spatial" parent="."]
transform = Transform( 4, 0, 0, 0, 1, 0, 0, 0, 4, 0, 0, 0 )

[node name="MeshInstance" type="MeshInstance" parent="Spatial"]
mesh = SubResource( 2 )
material/0 = ExtResource( 1 )

[node name="MeshInstance2" type="MeshInstance" parent="Spatial"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.001, 0 )
mesh = SubResource( 2 )
material/0 = SubResource( 4 )

[node name="Viewport" type="Viewport" parent="."]
size = Vector2( 512, 512 )
render_target_v_flip = true
render_target_clear_mode = 1

[node name="ColorRect" type="ColorRect" parent="Viewport"]
margin_right = 512.0
margin_bottom = 512.0
color = Color( 0, 0, 0, 0.027451 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="burn_l" type="Node2D" parent="Viewport/ColorRect"]
position = Vector2( -64, -64 )

[node name="sprite" type="Panel" parent="Viewport/ColorRect/burn_l"]
material = SubResource( 6 )
margin_left = -12.0
margin_top = -12.0
margin_right = 12.0
margin_bottom = 12.0
custom_styles/panel = SubResource( 5 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="burn_r" type="Node2D" parent="Viewport/ColorRect"]
position = Vector2( -64, -64 )

[node name="sprite" type="Panel" parent="Viewport/ColorRect/burn_r"]
material = SubResource( 6 )
margin_left = -12.0
margin_top = -12.0
margin_right = 12.0
margin_bottom = 12.0
custom_styles/panel = SubResource( 5 )
__meta__ = {
"_edit_use_anchors_": false
}

0 comments on commit 6891753

Please sign in to comment.