Skip to content

Commit

Permalink
Show selected block
Browse files Browse the repository at this point in the history
  • Loading branch information
Janorico committed May 25, 2023
1 parent f3a20c3 commit 57af2d1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
19 changes: 18 additions & 1 deletion scenes/game/player.tscn
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=8 format=2]

[ext_resource path="res://scripts/game/Player.gd" type="Script" id=1]
[ext_resource path="res://scripts/game/Crosshair.gd" type="Script" id=2]
[ext_resource path="res://assets/crosshair.png" type="Texture" id=3]
[ext_resource path="res://assets/TextureAtlas.dds" type="Texture" id=4]

[sub_resource type="AtlasTexture" id=3]
atlas = ExtResource( 4 )
region = Rect2( 16, 0, 16, 16 )

[sub_resource type="CapsuleMesh" id=1]
radius = 0.5
Expand All @@ -14,6 +19,7 @@ radius = 0.5

[node name="Player" type="KinematicBody"]
script = ExtResource( 1 )
selected_block_texture = SubResource( 3 )

[node name="MeshInstance" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0, 0 )
Expand Down Expand Up @@ -50,3 +56,14 @@ script = ExtResource( 2 )
margin_right = 40.0
margin_bottom = 14.0
text = "Block: "

[node name="SelectedBlock" type="TextureRect" parent="CameraBase/Camera"]
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = -128.0
margin_top = -128.0
rect_min_size = Vector2( 128, 128 )
texture = SubResource( 3 )
stretch_mode = 1
8 changes: 8 additions & 0 deletions scripts/game/Player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ onready var initial_rotation: Vector3 = rotation_degrees
var Chunk = load("res://scripts/game/Chunk.gd")
var selected_block = Chunk.block_types.keys()[0]
var selected_block_index = 0
export var selected_block_texture: AtlasTexture

var camera_x_rotation = 0

Expand Down Expand Up @@ -79,6 +80,13 @@ func _physics_process(delta):
if selected_block_index >= Chunk.block_types.keys().size():
selected_block_index -= Chunk.block_types.keys().size()
selected_block = Chunk.block_types.keys()[selected_block_index]
var block = Chunk.block_types[selected_block]
if block.has(Chunk.Side.left):
selected_block_texture.region.position = block[Chunk.Side.left] * 16
elif block.has(Chunk.Side.only):
selected_block_texture.region.position = block[Chunk.Side.only] * 16
else:
selected_block_texture.region.position = Vector2(-16, -16)

var power_multipler = (Input.get_action_strength("run") + 1)
if Input.is_action_just_pressed("jump") and is_on_floor() and not fly:
Expand Down

0 comments on commit 57af2d1

Please sign in to comment.