Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
manuq committed Jun 18, 2024
1 parent 80b227a commit 3ba3a92
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ func get_class():
return "SimpleCharacter"


static func get_base_class():
return "CharacterBody2D"


static func get_exposed_properties() -> Array[String]:
return ["position"]

Expand Down
20 changes: 16 additions & 4 deletions addons/block_code/ui/picker/picker.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,27 @@ signal block_picked(block: Block)


func bsd_selected(bsd: BlockScriptData):
var categories_to_add: Array[BlockCategory] = []

var custom_script = null
for class_dict in ProjectSettings.get_global_class_list():
prints("MANUQ", bsd.script_inherits)
if class_dict.class == bsd.script_inherits:
var script = load(class_dict.path)
if script.has_method("get_custom_blocks"):
init_picker(script.get_custom_blocks())
return
categories_to_add = script.get_custom_blocks()
custom_script = script
break

var parent_class: String
if custom_script:
parent_class = custom_script.get_base_class()
else: # Built in
parent_class = bsd.script_inherits

categories_to_add.append_array(CategoryFactory.get_inherited_categories(parent_class))

# Should be built-in class
init_picker(CategoryFactory.get_inherited_categories(bsd.script_inherits))
init_picker(categories_to_add)


func init_picker(extra_blocks: Array[BlockCategory] = []):
Expand Down
36 changes: 36 additions & 0 deletions pong_game/paddle.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@tool
class_name Paddle
extends CharacterBody2D


func get_class():
return "Paddle"

static func get_base_class():
return "CharacterBody2D"


static func get_exposed_properties() -> Array[String]:
return ["position"]


static func get_custom_blocks() -> Array[BlockCategory]:
var b: Block

# Movement
var movement_list: Array[Block] = []
b = CategoryFactory.BLOCKS["statement_block"].instantiate()
b.block_type = Types.BlockType.EXECUTE
b.block_format = "Move with player 1 buttons, speed {speed: INT}"
b.statement = 'velocity = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")*{speed}\n' + "move_and_slide()"
movement_list.append(b)

b = CategoryFactory.BLOCKS["statement_block"].instantiate()
b.block_type = Types.BlockType.EXECUTE
b.block_format = "Move with player 2 buttons, speed {speed: INT}"
b.statement = 'velocity = Input.get_vector("player_2_left", "player_2_right", "player_2_up", "player_2_down")*{speed}\n' + "move_and_slide()"
movement_list.append(b)

var movement_cat: BlockCategory = BlockCategory.new("Movement", movement_list, Color("4a86d5"))

return [movement_cat]
Binary file added pong_game/paddle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions pong_game/paddle.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://tplpgtnfeda0"
path="res://.godot/imported/paddle.png-2fbcaaf37bbbddd482a4ad5b20dde0a2.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://pong_game/paddle.png"
dest_files=["res://.godot/imported/paddle.png-2fbcaaf37bbbddd482a4ad5b20dde0a2.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
19 changes: 19 additions & 0 deletions pong_game/paddle.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[gd_scene load_steps=4 format=3 uid="uid://s7enbp56f256"]

[ext_resource type="Script" path="res://pong_game/paddle.gd" id="1_74lee"]
[ext_resource type="Texture2D" uid="uid://tplpgtnfeda0" path="res://pong_game/paddle.png" id="1_eucti"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_bbbjr"]
size = Vector2(128, 384)

[node name="Paddle" type="CharacterBody2D" groups=["paddles"]]
collision_mask = 68
motion_mode = 1
script = ExtResource("1_74lee")

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_bbbjr")

[node name="Sprite2D" type="Sprite2D" parent="."]
unique_name_in_owner = true
texture = ExtResource("1_eucti")
110 changes: 110 additions & 0 deletions pong_game/pong_game.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
[gd_scene load_steps=19 format=3 uid="uid://tf7b8c64ecc0"]

[ext_resource type="PackedScene" uid="uid://s7enbp56f256" path="res://pong_game/paddle.tscn" id="1_1k5k2"]
[ext_resource type="Script" path="res://addons/block_code/block_code_node/block_code.gd" id="3_6jaq8"]
[ext_resource type="Script" path="res://addons/block_code/ui/block_canvas/serialized_block_tree_node.gd" id="4_qtggh"]
[ext_resource type="Script" path="res://addons/block_code/ui/block_canvas/serialized_block.gd" id="5_wr38c"]
[ext_resource type="Script" path="res://addons/block_code/ui/block_canvas/serialized_block_tree_node_array.gd" id="6_ppdc3"]
[ext_resource type="Script" path="res://addons/block_code/block_script_data/block_script_data.gd" id="7_uuuue"]

[sub_resource type="Resource" id="Resource_3ils6"]
script = ExtResource("5_wr38c")
block_class = &"StatementBlock"
serialized_props = [["block_name", "statement_block"], ["label", "StatementBlock"], ["color", Color(0.290196, 0.52549, 0.835294, 1)], ["block_type", 2], ["position", Vector2(0, 0)], ["block_format", "Move with player 2 buttons, speed {speed: INT}"], ["statement", "velocity = Input.get_vector(\"player_2_left\", \"player_2_right\", \"player_2_up\", \"player_2_down\")*{speed}
move_and_slide()"], ["param_input_strings", {
"speed": "500"
}]]

[sub_resource type="Resource" id="Resource_qd5oi"]
script = ExtResource("4_qtggh")
serialized_block = SubResource("Resource_3ils6")
path_child_pairs = []

[sub_resource type="Resource" id="Resource_vjq0g"]
script = ExtResource("5_wr38c")
block_class = &"EntryBlock"
serialized_props = [["block_name", "process_block"], ["label", "EntryBlock"], ["color", Color(0.980392, 0.34902, 0.337255, 1)], ["block_type", 1], ["position", Vector2(53, 164)], ["block_format", "On Process"], ["statement", "func _process(delta):"], ["param_input_strings", {}]]

[sub_resource type="Resource" id="Resource_dkmie"]
script = ExtResource("4_qtggh")
serialized_block = SubResource("Resource_vjq0g")
path_child_pairs = [[NodePath("VBoxContainer/SnapPoint"), SubResource("Resource_qd5oi")]]

[sub_resource type="Resource" id="Resource_1q8dn"]
script = ExtResource("6_ppdc3")
array = Array[ExtResource("4_qtggh")]([SubResource("Resource_dkmie")])

[sub_resource type="Resource" id="Resource_t7nl4"]
script = ExtResource("7_uuuue")
script_inherits = "Paddle"
block_trees = SubResource("Resource_1q8dn")
generated_script = "extends Paddle
var VAR_DICT := {}
func _process(delta):
velocity = Input.get_vector(\"player_2_left\", \"player_2_right\", \"player_2_up\", \"player_2_down\")*500
move_and_slide()
"

[sub_resource type="Resource" id="Resource_xj1ks"]
script = ExtResource("5_wr38c")
block_class = &"StatementBlock"
serialized_props = [["block_name", "statement_block"], ["label", "StatementBlock"], ["color", Color(0.290196, 0.52549, 0.835294, 1)], ["block_type", 2], ["position", Vector2(0, 0)], ["block_format", "Move with player 1 buttons, speed {speed: INT}"], ["statement", "velocity = Input.get_vector(\"ui_left\", \"ui_right\", \"ui_up\", \"ui_down\")*{speed}
move_and_slide()"], ["param_input_strings", {
"speed": "500"
}]]

[sub_resource type="Resource" id="Resource_r1oo8"]
script = ExtResource("4_qtggh")
serialized_block = SubResource("Resource_xj1ks")
path_child_pairs = []

[sub_resource type="Resource" id="Resource_3hvmm"]
script = ExtResource("5_wr38c")
block_class = &"EntryBlock"
serialized_props = [["block_name", "process_block"], ["label", "EntryBlock"], ["color", Color(0.980392, 0.34902, 0.337255, 1)], ["block_type", 1], ["position", Vector2(90, 95)], ["block_format", "On Process"], ["statement", "func _process(delta):"], ["param_input_strings", {}]]

[sub_resource type="Resource" id="Resource_owydw"]
script = ExtResource("4_qtggh")
serialized_block = SubResource("Resource_3hvmm")
path_child_pairs = [[NodePath("VBoxContainer/SnapPoint"), SubResource("Resource_r1oo8")]]

[sub_resource type="Resource" id="Resource_4hv2q"]
script = ExtResource("6_ppdc3")
array = Array[ExtResource("4_qtggh")]([SubResource("Resource_owydw")])

[sub_resource type="Resource" id="Resource_52r02"]
script = ExtResource("7_uuuue")
script_inherits = "Paddle"
block_trees = SubResource("Resource_4hv2q")
generated_script = "extends Paddle
var VAR_DICT := {}
func _process(delta):
velocity = Input.get_vector(\"ui_left\", \"ui_right\", \"ui_up\", \"ui_down\")*500
move_and_slide()
"

[node name="Node2D" type="Node2D"]

[node name="Paddle" parent="." instance=ExtResource("1_1k5k2")]
modulate = Color(1, 0.653955, 0.477429, 1)
position = Vector2(326, 313)
scale = Vector2(0.603749, 0.603749)

[node name="BlockCode" type="Node" parent="Paddle"]
script = ExtResource("3_6jaq8")
bsd = SubResource("Resource_t7nl4")

[node name="Paddle2" parent="." instance=ExtResource("1_1k5k2")]
modulate = Color(0.681415, 0.928494, 0.956385, 1)
position = Vector2(875, 313)
scale = Vector2(0.603749, 0.603749)

[node name="BlockCode" type="Node" parent="Paddle2"]
script = ExtResource("3_6jaq8")
bsd = SubResource("Resource_52r02")
4 changes: 4 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ config/icon="res://icon.svg"

SignalManager="*res://addons/block_code/block_code_node/utilities/signal_manager.gd"

[debug]

gdscript/warnings/native_method_override=1

[editor_plugins]

enabled=PackedStringArray("res://addons/block_code/plugin.cfg", "res://addons/gut/plugin.cfg", "res://addons/plugin_refresher/plugin.cfg")
Expand Down

0 comments on commit 3ba3a92

Please sign in to comment.