Skip to content

Commit

Permalink
Added Main mechanic
Browse files Browse the repository at this point in the history
geegaz committed Jul 11, 2020
1 parent dafa884 commit fcc6b25
Showing 17 changed files with 419 additions and 13 deletions.
Binary file added Assets/Sprites/key_place.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -2,15 +2,15 @@

importer="texture"
type="StreamTexture"
path="res://.import/left_right.png-df80b7a0a745c4c84e399c40174d4644.stex"
path="res://.import/key_place.png-e324c29181a7859765d8fa2ffc549cbc.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Assets/Sprites/left_right.png"
dest_files=[ "res://.import/left_right.png-df80b7a0a745c4c84e399c40174d4644.stex" ]
source_file="res://Assets/Sprites/key_place.png"
dest_files=[ "res://.import/key_place.png-e324c29181a7859765d8fa2ffc549cbc.stex" ]

[params]

Binary file added Assets/Sprites/left.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 Assets/Sprites/left.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/left.png-3d705574e28ed47072146d7976ecd186.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Assets/Sprites/left.png"
dest_files=[ "res://.import/left.png-3d705574e28ed47072146d7976ecd186.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0
Binary file removed Assets/Sprites/left_right.png
Binary file not shown.
Binary file added Assets/Sprites/right.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 Assets/Sprites/right.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/right.png-428ee97e53a186622ceca4ca45829464.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Assets/Sprites/right.png"
dest_files=[ "res://.import/right.png-428ee97e53a186622ceca4ca45829464.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0
Binary file modified Assets/Sprites/spacebar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Sprites/spacebar_place.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 Assets/Sprites/spacebar_place.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/spacebar_place.png-fe3bf660459fca32c599d720b1f7fe3e.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Assets/Sprites/spacebar_place.png"
dest_files=[ "res://.import/spacebar_place.png-fe3bf660459fca32c599d720b1f7fe3e.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0
39 changes: 39 additions & 0 deletions Scenes/Objects/ControlJump.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[gd_scene load_steps=5 format=2]

[ext_resource path="res://Scripts/ControlBlock.gd" type="Script" id=1]
[ext_resource path="res://Assets/Sprites/spacebar.png" type="Texture" id=2]

[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 32, 8 )

[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 32, 8 )

[node name="ControlJump" type="KinematicBody2D"]
script = ExtResource( 1 )

[node name="Collider" type="CollisionShape2D" parent="."]
shape = SubResource( 1 )
disabled = true

[node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 2 )
vframes = 4

[node name="Control" type="Control" parent="."]
margin_left = -32.0
margin_top = -8.0
margin_right = 32.0
margin_bottom = 8.0
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Area2D" type="Area2D" parent="."]
monitorable = false

[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
shape = SubResource( 2 )
[connection signal="gui_input" from="Control" to="." method="_on_Control_gui_input"]
[connection signal="mouse_entered" from="Control" to="." method="_on_Control_mouse_entered"]
[connection signal="mouse_exited" from="Control" to="." method="_on_Control_mouse_exited"]
40 changes: 40 additions & 0 deletions Scenes/Objects/ControlLeft.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[gd_scene load_steps=5 format=2]

[ext_resource path="res://Scripts/ControlBlock.gd" type="Script" id=1]
[ext_resource path="res://Assets/Sprites/left.png" type="Texture" id=2]

[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 8, 8 )

[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 8, 8 )

[node name="ControlLeft" type="KinematicBody2D"]
script = ExtResource( 1 )
control_type = 1

[node name="Collider" type="CollisionShape2D" parent="."]
shape = SubResource( 1 )
disabled = true

[node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 2 )
vframes = 4

[node name="Control" type="Control" parent="."]
margin_left = -8.0
margin_top = -8.0
margin_right = 8.0
margin_bottom = 8.0
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Area2D" type="Area2D" parent="."]
monitorable = false

[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
shape = SubResource( 2 )
[connection signal="gui_input" from="Control" to="." method="_on_Control_gui_input"]
[connection signal="mouse_entered" from="Control" to="." method="_on_Control_mouse_entered"]
[connection signal="mouse_exited" from="Control" to="." method="_on_Control_mouse_exited"]
40 changes: 40 additions & 0 deletions Scenes/Objects/ControlRight.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[gd_scene load_steps=5 format=2]

[ext_resource path="res://Scripts/ControlBlock.gd" type="Script" id=1]
[ext_resource path="res://Assets/Sprites/right.png" type="Texture" id=2]

[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 8, 8 )

[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 8, 8 )

[node name="ControlRight" type="KinematicBody2D"]
script = ExtResource( 1 )
control_type = 2

[node name="Collider" type="CollisionShape2D" parent="."]
shape = SubResource( 1 )
disabled = true

[node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 2 )
vframes = 4

[node name="Control" type="Control" parent="."]
margin_left = -8.0
margin_top = -8.0
margin_right = 8.0
margin_bottom = 8.0
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Area2D" type="Area2D" parent="."]
monitorable = false

[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
shape = SubResource( 2 )
[connection signal="gui_input" from="Control" to="." method="_on_Control_gui_input"]
[connection signal="mouse_entered" from="Control" to="." method="_on_Control_mouse_entered"]
[connection signal="mouse_exited" from="Control" to="." method="_on_Control_mouse_exited"]
2 changes: 1 addition & 1 deletion Scenes/Player.tscn
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 12, 12 )

[node name="KinematicBody2D" type="KinematicBody2D"]
[node name="Player" type="KinematicBody2D"]
script = ExtResource( 1 )

[node name="Collider" type="CollisionShape2D" parent="."]
52 changes: 43 additions & 9 deletions Scenes/World.tscn
Original file line number Diff line number Diff line change
@@ -1,23 +1,57 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=9 format=2]

[ext_resource path="res://Assets/Tilesets/terrain_solid.tres" type="TileSet" id=1]
[ext_resource path="res://Scenes/Player.tscn" type="PackedScene" id=2]
[ext_resource path="res://Assets/Sprites/spacebar.png" type="Texture" id=3]
[ext_resource path="res://Scenes/Objects/ControlJump.tscn" type="PackedScene" id=3]
[ext_resource path="res://Scripts/World.gd" type="Script" id=4]
[ext_resource path="res://Assets/Sprites/spacebar_place.png" type="Texture" id=5]
[ext_resource path="res://Assets/Sprites/key_place.png" type="Texture" id=6]
[ext_resource path="res://Scenes/Objects/ControlRight.tscn" type="PackedScene" id=7]
[ext_resource path="res://Scenes/Objects/ControlLeft.tscn" type="PackedScene" id=8]

[node name="Node2D" type="Node2D"]
script = ExtResource( 4 )

[node name="TileMap" type="TileMap" parent="."]
tile_set = ExtResource( 1 )
cell_size = Vector2( 16, 16 )
format = 1
tile_data = PoolIntArray( 0, 0, 1, 1, 0, 196610, 2, 0, 196610, 3, 0, 196610, 4, 0, 196610, 5, 0, 196610, 6, 0, 196610, 7, 0, 196610, 8, 0, 196610, 9, 0, 196610, 10, 0, 196610, 11, 0, 196610, 12, 0, 196610, 13, 0, 196610, 14, 0, 196610, 15, 0, 196610, 16, 0, 196610, 17, 0, 196610, 18, 0, 196610, 19, 0, 3, 65536, 0, 65536, 65555, 0, 65536, 131072, 0, 65536, 131091, 0, 65536, 196608, 0, 65536, 196627, 0, 65536, 262144, 0, 65536, 262163, 0, 65536, 327680, 0, 65536, 327699, 0, 65536, 393216, 0, 65536, 393235, 0, 65536, 458752, 0, 65536, 458771, 0, 65536, 524288, 0, 65536, 524307, 0, 65536, 589824, 0, 65536, 589843, 0, 65536, 655360, 0, 65537, 655361, 0, 2, 655362, 0, 2, 655363, 0, 2, 655364, 0, 2, 655365, 0, 2, 655366, 0, 2, 655367, 0, 2, 655368, 0, 2, 655369, 0, 2, 655370, 0, 2, 655371, 0, 2, 655372, 0, 2, 655373, 0, 2, 655374, 0, 2, 655375, 0, 2, 655376, 0, 2, 655377, 0, 2, 655378, 0, 2, 655379, 0, 65539, 720896, 0, 131073, 720897, 0, 131074, 720898, 0, 131074, 720899, 0, 131074, 720900, 0, 131074, 720901, 0, 131074, 720902, 0, 131074, 720903, 0, 131074, 720904, 0, 131074, 720905, 0, 131074, 720906, 0, 131074, 720907, 0, 131074, 720908, 0, 131074, 720909, 0, 131074, 720910, 0, 131074, 720911, 0, 131074, 720912, 0, 131074, 720913, 0, 131074, 720914, 0, 131074, 720915, 0, 131075 )

[node name="KinematicBody2D" parent="TileMap" instance=ExtResource( 2 )]
position = Vector2( 48, 120 )
[node name="ScreenPos" type="CanvasLayer" parent="."]

[node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="ControlJumpPos" type="Position2D" parent="ScreenPos"]
position = Vector2( 184, 168 )

[node name="Sprite" type="Sprite" parent="CanvasLayer"]
position = Vector2( 160, 168 )
texture = ExtResource( 3 )
vframes = 4
[node name="Sprite" type="Sprite" parent="ScreenPos/ControlJumpPos"]
texture = ExtResource( 5 )

[node name="ControlLeftPos" type="Position2D" parent="ScreenPos"]
position = Vector2( 136, 168 )

[node name="Sprite" type="Sprite" parent="ScreenPos/ControlLeftPos"]
texture = ExtResource( 6 )

[node name="ControlRightPos" type="Position2D" parent="ScreenPos"]
position = Vector2( 112, 168 )

[node name="Sprite" type="Sprite" parent="ScreenPos/ControlRightPos"]
texture = ExtResource( 6 )

[node name="ControlJump" parent="ScreenPos" instance=ExtResource( 3 )]
position = Vector2( 184, 168 )

[node name="ControlLeft" parent="ScreenPos" instance=ExtResource( 8 )]
position = Vector2( 112, 168 )

[node name="ControlRight" parent="ScreenPos" instance=ExtResource( 7 )]
position = Vector2( 136, 168 )

[node name="Player" parent="." instance=ExtResource( 2 )]
position = Vector2( 52, 136 )
[connection signal="place_in_world" from="ScreenPos/ControlJump" to="." method="_on_Control_place_in_world"]
[connection signal="retrieve_from_world" from="ScreenPos/ControlJump" to="." method="_on_Control_retrieve_from_world"]
[connection signal="place_in_world" from="ScreenPos/ControlLeft" to="." method="_on_Control_place_in_world"]
[connection signal="retrieve_from_world" from="ScreenPos/ControlLeft" to="." method="_on_Control_retrieve_from_world"]
[connection signal="place_in_world" from="ScreenPos/ControlRight" to="." method="_on_Control_place_in_world"]
[connection signal="retrieve_from_world" from="ScreenPos/ControlRight" to="." method="_on_Control_retrieve_from_world"]
106 changes: 106 additions & 0 deletions Scripts/ControlBlock.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
extends KinematicBody2D

signal start_drag
signal stop_drag
signal place_in_world(node)
signal retrieve_from_world(node)

enum Controls {JUMP, LEFT, RIGHT}
export(Controls) var control_type

enum {NORMAL, HOVER, PRESSED, PRESSED_HOVER}

var hover = false
var dragged = false

var valid_pos = true
var in_world = false

var control_action: String

var ControlSprite: Sprite
var Collider: CollisionShape2D

# Called when the node enters the scene tree for the first time.
func _ready():
ControlSprite = $Sprite
Collider = $Collider

connect("start_drag", self, "_on_start_drag")
connect("stop_drag", self, "_on_stop_drag")

match control_type:
Controls.JUMP:
control_action = "ui_select"
Controls.LEFT:
control_action = "ui_left"
Controls.RIGHT:
control_action = "ui_right"

func _process(delta):

if Input.is_action_pressed(control_action) or dragged or in_world:
if hover:
ControlSprite.frame = PRESSED_HOVER
else:
ControlSprite.frame = PRESSED
else:
if hover:
ControlSprite.frame = HOVER
else:
ControlSprite.frame = NORMAL

if not valid_pos:
ControlSprite.modulate = Color(1.0,1.0,1.0,0.5)
else:
ControlSprite.modulate = Color.white

func _physics_process(delta):
valid_pos = true
if dragged:
position = get_global_mouse_position()
if $Area2D.get_overlapping_bodies().size() > 0:
valid_pos = false

func _on_start_drag():
if not in_world:
dragged = true
Collider.disabled = true
emit_signal("place_in_world", self)
position = get_global_mouse_position()
else:
in_world = false
Collider.disabled = true
emit_signal("retrieve_from_world", self)

func _on_stop_drag():
if dragged:
dragged = false
if valid_pos:
in_world = true
Collider.disabled = false
else:
in_world = false
Collider.disabled = true
emit_signal("retrieve_from_world", self)

func _on_Control_mouse_entered():
hover = true

func _on_Control_mouse_exited():
hover = false

func _on_Control_gui_input(event):
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT and event.pressed:
emit_signal("start_drag")

func _input(event):
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT and !event.pressed:
emit_signal("stop_drag")


func _on_VisibilityNotifier2D_screen_exited():
if in_world:
emit_signal("retrieve_from_world", self)
45 changes: 45 additions & 0 deletions Scripts/World.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
extends Node2D

enum Controls {JUMP, LEFT, RIGHT}

var Player: KinematicBody2D

# Called when the node enters the scene tree for the first time.
func _ready():
Player = $Player

func _process(delta):
pass

func reparent(child: Node, new_parent: Node):
var old_parent = child.get_parent()
old_parent.remove_child(child)
new_parent.add_child(child)

func _on_Control_place_in_world(node):

print("place")
print(node)
print(node.get_parent())
reparent(node, self)
match node.control_type:
Controls.JUMP:
Player.jump_control = false
Controls.LEFT:
Player.left_control = false
Controls.RIGHT:
Player.right_control = false

func _on_Control_retrieve_from_world(node):

print("retrieve")
print(node)
print(node.get_parent())
reparent(node, $ScreenPos)
match node.control_type:
Controls.JUMP:
Player.jump_control = true
Controls.LEFT:
Player.left_control = true
Controls.RIGHT:
Player.right_control = true

0 comments on commit fcc6b25

Please sign in to comment.