online multiplayer chess game (note server currently down)
tweening movement
bendn 2022-04-26
parent 101ea07 · commit c930618
-rw-r--r--Piece.gd36
-rw-r--r--Piece.tscn2
-rw-r--r--World.tscn2
3 files changed, 34 insertions, 6 deletions
diff --git a/Piece.gd b/Piece.gd
index 6b7e6ac..966319a 100644
--- a/Piece.gd
+++ b/Piece.gd
@@ -9,6 +9,7 @@ var sprite
var black_holder
+onready var tween = $Tween
onready var colorrect = $ColorRect
onready var frame = $Frame
@@ -34,7 +35,17 @@ func clear_clicked(): # TODO: fix this shit
func move(newpos: Vector2): # dont use directly; use moveto
has_moved = true
- global_position = newpos * Globals.grid.piece_size
+ tween.interpolate_property(
+ self,
+ "global_position",
+ global_position,
+ newpos * Globals.grid.piece_size,
+ 0.5,
+ Tween.TRANS_BACK,
+ Tween.EASE_IN_OUT
+ )
+ tween.start()
+ # global_position = newpos * Globals.grid.piece_size
func moveto(position):
@@ -51,16 +62,33 @@ func pos_around(around_vector):
func all_dirs():
- return [Vector2.UP, Vector2.DOWN, Vector2.LEFT, Vector2.RIGHT, Vector2(1, 1), Vector2(1, -1), Vector2(-1, 1), Vector2(-1, -1)]
+ return [
+ Vector2.UP,
+ Vector2.DOWN,
+ Vector2.LEFT,
+ Vector2.RIGHT,
+ Vector2(1, 1),
+ Vector2(1, -1),
+ Vector2(-1, 1),
+ Vector2(-1, -1)
+ ]
func create_circles():
# for motion
match realname:
"pawn":
- var carry = [pos_around(Vector2.UP)] if has_moved else [pos_around(Vector2.UP), pos_around(Vector2.UP * 2)]
+ var carry = (
+ [pos_around(Vector2.UP)]
+ if has_moved
+ else [pos_around(Vector2.UP), pos_around(Vector2.UP * 2)]
+ )
if !white:
- carry = ([pos_around(Vector2.DOWN)] if has_moved else [pos_around(Vector2.DOWN), pos_around(Vector2.DOWN * 2)])
+ carry = (
+ [pos_around(Vector2.DOWN)]
+ if has_moved
+ else [pos_around(Vector2.DOWN), pos_around(Vector2.DOWN * 2)]
+ )
set_circle(carry)
# deal with the take logic
carry = []
diff --git a/Piece.tscn b/Piece.tscn
index 5fc374c..e310e84 100644
--- a/Piece.tscn
+++ b/Piece.tscn
@@ -21,3 +21,5 @@ texture = ExtResource( 2 )
visible = false
position = Vector2( 50, 50 )
texture = ExtResource( 3 )
+
+[node name="Tween" type="Tween" parent="."]
diff --git a/World.tscn b/World.tscn
index 3e33970..2a5f680 100644
--- a/World.tscn
+++ b/World.tscn
@@ -6,7 +6,5 @@
[node name="Grid" type="Node2D" parent="."]
script = ExtResource( 1 )
-board_color1 = Color( 0.870588, 0.890196, 0.901961, 1 )
-board_color2 = Color( 0.54902, 0.635294, 0.678431, 1 )
[node name="Background" type="Node2D" parent="Grid"]