online multiplayer chess game (note server currently down)
sfx+stalemate
| -rw-r--r-- | Grid.gd | 35 | ||||
| -rw-r--r-- | Piece.tscn | 12 | ||||
| -rw-r--r-- | Utils.gd | 3 | ||||
| -rw-r--r-- | pieces/King.gd | 2 | ||||
| -rw-r--r-- | pieces/Piece.gd | 4 | ||||
| -rw-r--r-- | project.godot | 10 | ||||
| -rw-r--r-- | sounds/Capture.ogg | 3 | ||||
| -rw-r--r-- | sounds/Capture.ogg.import | 15 | ||||
| -rw-r--r-- | sounds/Check.ogg | 3 | ||||
| -rw-r--r-- | sounds/Check.ogg.import | 15 | ||||
| -rw-r--r-- | sounds/Defeat.ogg | 3 | ||||
| -rw-r--r-- | sounds/Defeat.ogg.import | 15 | ||||
| -rw-r--r-- | sounds/Draw.ogg | 3 | ||||
| -rw-r--r-- | sounds/Draw.ogg.import | 15 | ||||
| -rw-r--r-- | sounds/Error.ogg | 3 | ||||
| -rw-r--r-- | sounds/Error.ogg.import | 15 | ||||
| -rw-r--r-- | sounds/Move.ogg | 3 | ||||
| -rw-r--r-- | sounds/Move.ogg.import | 15 | ||||
| -rw-r--r-- | sounds/SoundFX.gd | 25 | ||||
| -rw-r--r-- | sounds/SoundFX.tscn | 18 | ||||
| -rw-r--r-- | sounds/Victory.ogg | 3 | ||||
| -rw-r--r-- | sounds/Victory.ogg.import | 15 |
22 files changed, 216 insertions, 19 deletions
@@ -23,7 +23,7 @@ var last_clicked onready var piece_sets = walk_dir() -func _ready(): # TODO: add draws +func _ready(): # TODO: repetition draw Globals.grid = self # tell the globals that this is the grid init_board() # create the tile squares init_matrix() # create the pieces @@ -34,13 +34,23 @@ func _on_turn_over(): Globals.checking_piece = null # reset checking_piece Globals.in_check = false # reset in_check check_in_check(true) # check if in_check - if Globals.in_check and is_check_mate(): - var winner = "black" if Globals.turn else "white" - print(winner, " won the game in ", Globals.turns(winner), " turns!") - print("the board:") - print_matrix_pretty() - yield(get_tree().create_timer(5), "timeout") - get_tree().reload_current_scene() + if can_move(): + if Globals.in_check: + var winner = "black" if Globals.turn else "white" + print(winner, " won the game in ", Globals.turns(winner), " turns!") + print("the board:") + SoundFx.play("Victory") + print_matrix_pretty() + yield(get_tree().create_timer(5), "timeout") + get_tree().reload_current_scene() + SoundFx.play("Victory") + else: + print("stalemate") + SoundFx.play("Draw") + print_matrix_pretty() + yield(get_tree().create_timer(5), "timeout") + get_tree().reload_current_scene() + SoundFx.play("Victory") func check_in_check(prin = false): # check if in_check @@ -53,11 +63,12 @@ func check_in_check(prin = false): # check if in_check Globals.in_check = true # set in_check Globals.checking_piece = spot # set checking_piece print("check by " + spot.shortname) # print the check + SoundFx.play("Check") return true # stop at the first check found return false -func is_check_mate(): +func can_move(): for i in range(0, 8): # for each row for j in range(0, 8): # for each column var spot = matrix[i][j] # get the square @@ -113,7 +124,6 @@ func add_pieces(): # add the pieces add_bishops() add_queens() add_kings() - print_matrix_pretty() # print the matrix func add_pawns(): @@ -254,6 +264,11 @@ func clear_fx(): # clear the circles func _input(event): # input if event.is_action("debug"): # if debug print_matrix_pretty() # print the matrix + if event.is_action("kill"): + if last_clicked: + last_clicked.took() # kill the piece + last_clicked = null + clear_fx() # clear the circles func walk_dir(path = "res://assets"): # walk the directory, finding the asset packs @@ -6,7 +6,7 @@ [sub_resource type="Animation" id=1] resource_name = "Move" -length = 0.5 +length = 0.3 step = 0.05 tracks/0/type = "value" tracks/0/path = NodePath("Sprite:scale") @@ -15,7 +15,7 @@ tracks/0/loop_wrap = true tracks/0/imported = false tracks/0/enabled = true tracks/0/keys = { -"times": PoolRealArray( 0, 0.001, 0.25, 0.5 ), +"times": PoolRealArray( 0, 0.001, 0.15, 0.3 ), "transitions": PoolRealArray( 2, 1, 1, 0.5 ), "update": 0, "values": [ Vector2( 1, 1 ), Vector2( 1, 1 ), Vector2( 1.15, 1.15 ), Vector2( 1, 1 ) ] @@ -27,7 +27,7 @@ tracks/1/loop_wrap = true tracks/1/imported = false tracks/1/enabled = true tracks/1/keys = { -"times": PoolRealArray( 0, 0.5 ), +"times": PoolRealArray( 0, 0.3 ), "transitions": PoolRealArray( 1, 1 ), "update": 1, "values": [ 1, 0 ] @@ -50,7 +50,7 @@ tracks/0/keys = { [sub_resource type="Animation" id=2] resource_name = "Take" -length = 0.5 +length = 0.3 step = 0.05 tracks/0/type = "value" tracks/0/path = NodePath("Sprite:scale") @@ -59,7 +59,7 @@ tracks/0/loop_wrap = true tracks/0/imported = false tracks/0/enabled = true tracks/0/keys = { -"times": PoolRealArray( 0, 0.1, 0.15, 0.35, 0.5 ), +"times": PoolRealArray( 0, 0.05, 0.1, 0.2, 0.3 ), "transitions": PoolRealArray( 2, 1, 1, 1, 0.5 ), "update": 0, "values": [ Vector2( 1, 1 ), Vector2( 1.25, 1.25 ), Vector2( 1.35, 1.35 ), Vector2( 0.25, 0.25 ), Vector2( 0, 0 ) ] @@ -71,7 +71,7 @@ tracks/1/loop_wrap = true tracks/1/imported = false tracks/1/enabled = true tracks/1/keys = { -"times": PoolRealArray( 0.5 ), +"times": PoolRealArray( 0.3 ), "transitions": PoolRealArray( 1 ), "values": [ { "args": [ ], @@ -1,4 +1,5 @@ extends Node + func is_pawn(inode): - return inode is Pawn
\ No newline at end of file + return inode is Pawn diff --git a/pieces/King.gd b/pieces/King.gd index 1bd4487..c039f5b 100644 --- a/pieces/King.gd +++ b/pieces/King.gd @@ -55,7 +55,7 @@ func _ready(): func can_move(): # checks if you can legally move castle_check = false - var can = can_move() + var can = .can_move() castle_check = true return can diff --git a/pieces/Piece.gd b/pieces/Piece.gd index bb9604b..2d62ba3 100644 --- a/pieces/Piece.gd +++ b/pieces/Piece.gd @@ -43,7 +43,7 @@ func move(newpos: Vector2): # dont use directly; use moveto "global_position", global_position, newpos * Globals.grid.piece_size, - 0.5, + 0.3, Tween.TRANS_BACK, Tween.EASE_IN_OUT ) @@ -57,6 +57,7 @@ func moveto(position, real = true): if real: real_position = position move(position) + SoundFx.play("Move") has_moved = true @@ -174,6 +175,7 @@ func take(piece: Piece): func took(): # called when piece is taken + SoundFx.play("Capture") print(shortname, "was killed") Globals.grid.matrix[real_position.y][real_position.x] = null anim.play("Take") diff --git a/project.godot b/project.godot index 6da6899..0f71ef7 100644 --- a/project.godot +++ b/project.godot @@ -76,6 +76,7 @@ config/icon="res://icon.png" Globals="*res://Globals.gd" Events="*res://Events.gd" Utils="*res://Utils.gd" +SoundFx="*res://sounds/SoundFX.tscn" [debug] @@ -115,6 +116,10 @@ texture={ "stream": false, "svg/scale": 1.0 } +ogg_vorbis={ +"loop": false, +"loop_offset": 0 +} [input] @@ -123,6 +128,11 @@ debug={ "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":92,"physical_scancode":0,"unicode":0,"echo":false,"script":null) ] } +kill={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":75,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} [rendering] diff --git a/sounds/Capture.ogg b/sounds/Capture.ogg new file mode 100644 index 0000000..6bffeca --- /dev/null +++ b/sounds/Capture.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3d1352ded44d53e55d001f78bb043fe1288692fb882420ec17677997637762ed +size 5663 diff --git a/sounds/Capture.ogg.import b/sounds/Capture.ogg.import new file mode 100644 index 0000000..716081c --- /dev/null +++ b/sounds/Capture.ogg.import @@ -0,0 +1,15 @@ +[remap] + +importer="ogg_vorbis" +type="AudioStreamOGGVorbis" +path="res://.import/Capture.ogg-f2e17ec5719fd0451670492ce185e886.oggstr" + +[deps] + +source_file="res://sounds/Capture.ogg" +dest_files=[ "res://.import/Capture.ogg-f2e17ec5719fd0451670492ce185e886.oggstr" ] + +[params] + +loop=false +loop_offset=0 diff --git a/sounds/Check.ogg b/sounds/Check.ogg new file mode 100644 index 0000000..dde7eaf --- /dev/null +++ b/sounds/Check.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a9913ad35450c7d7941376d0ff95dc530394555727093f1bcb4da3e16b23ac66 +size 4421 diff --git a/sounds/Check.ogg.import b/sounds/Check.ogg.import new file mode 100644 index 0000000..4fd13e5 --- /dev/null +++ b/sounds/Check.ogg.import @@ -0,0 +1,15 @@ +[remap] + +importer="ogg_vorbis" +type="AudioStreamOGGVorbis" +path="res://.import/Check.ogg-bab7bb3cb78e4f201cee463128abbae1.oggstr" + +[deps] + +source_file="res://sounds/Check.ogg" +dest_files=[ "res://.import/Check.ogg-bab7bb3cb78e4f201cee463128abbae1.oggstr" ] + +[params] + +loop=false +loop_offset=0 diff --git a/sounds/Defeat.ogg b/sounds/Defeat.ogg new file mode 100644 index 0000000..e5ffd86 --- /dev/null +++ b/sounds/Defeat.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a0f8dec47f2698f62a769f84d79d4903c1475224cd9e40c53dc2fe5d2c0e7d5c +size 8883 diff --git a/sounds/Defeat.ogg.import b/sounds/Defeat.ogg.import new file mode 100644 index 0000000..63843f7 --- /dev/null +++ b/sounds/Defeat.ogg.import @@ -0,0 +1,15 @@ +[remap] + +importer="ogg_vorbis" +type="AudioStreamOGGVorbis" +path="res://.import/Defeat.ogg-a3453b9d2f260a588582234d5fa9ba76.oggstr" + +[deps] + +source_file="res://sounds/Defeat.ogg" +dest_files=[ "res://.import/Defeat.ogg-a3453b9d2f260a588582234d5fa9ba76.oggstr" ] + +[params] + +loop=false +loop_offset=0 diff --git a/sounds/Draw.ogg b/sounds/Draw.ogg new file mode 100644 index 0000000..e5ffd86 --- /dev/null +++ b/sounds/Draw.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a0f8dec47f2698f62a769f84d79d4903c1475224cd9e40c53dc2fe5d2c0e7d5c +size 8883 diff --git a/sounds/Draw.ogg.import b/sounds/Draw.ogg.import new file mode 100644 index 0000000..4aa00da --- /dev/null +++ b/sounds/Draw.ogg.import @@ -0,0 +1,15 @@ +[remap] + +importer="ogg_vorbis" +type="AudioStreamOGGVorbis" +path="res://.import/Draw.ogg-9c657519a42c1bcc6f5fc6b90af52d95.oggstr" + +[deps] + +source_file="res://sounds/Draw.ogg" +dest_files=[ "res://.import/Draw.ogg-9c657519a42c1bcc6f5fc6b90af52d95.oggstr" ] + +[params] + +loop=false +loop_offset=0 diff --git a/sounds/Error.ogg b/sounds/Error.ogg new file mode 100644 index 0000000..a3f9c76 --- /dev/null +++ b/sounds/Error.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:660ff42b5d4a945e27e72c44f469d37ef527cab0f2ee57a835e8446a665198de +size 4302 diff --git a/sounds/Error.ogg.import b/sounds/Error.ogg.import new file mode 100644 index 0000000..4784339 --- /dev/null +++ b/sounds/Error.ogg.import @@ -0,0 +1,15 @@ +[remap] + +importer="ogg_vorbis" +type="AudioStreamOGGVorbis" +path="res://.import/Error.ogg-9394d48b6a93d9c7ee647b7bb01118d0.oggstr" + +[deps] + +source_file="res://sounds/Error.ogg" +dest_files=[ "res://.import/Error.ogg-9394d48b6a93d9c7ee647b7bb01118d0.oggstr" ] + +[params] + +loop=false +loop_offset=0 diff --git a/sounds/Move.ogg b/sounds/Move.ogg new file mode 100644 index 0000000..bf1ea7a --- /dev/null +++ b/sounds/Move.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bef9236737f601790b1eb30a9eefc0c00de85804d4dfc9d2b51555b5e4b82f5c +size 5399 diff --git a/sounds/Move.ogg.import b/sounds/Move.ogg.import new file mode 100644 index 0000000..c792afb --- /dev/null +++ b/sounds/Move.ogg.import @@ -0,0 +1,15 @@ +[remap] + +importer="ogg_vorbis" +type="AudioStreamOGGVorbis" +path="res://.import/Move.ogg-43cc90e19874469411763fbdc6329567.oggstr" + +[deps] + +source_file="res://sounds/Move.ogg" +dest_files=[ "res://.import/Move.ogg-43cc90e19874469411763fbdc6329567.oggstr" ] + +[params] + +loop=false +loop_offset=0 diff --git a/sounds/SoundFX.gd b/sounds/SoundFX.gd new file mode 100644 index 0000000..8a15875 --- /dev/null +++ b/sounds/SoundFX.gd @@ -0,0 +1,25 @@ +extends Node + +const soundpath = "res://sounds/" + +var sounds = { + "Check": load(soundpath + "Check.ogg"), + "Error": load(soundpath + "Error.ogg"), + "Victory": load(soundpath + "Victory.ogg"), + "Defeat": load(soundpath + "Defeat.ogg"), + "Capture": load(soundpath + "Capture.ogg"), + "Draw": load(soundpath + "Draw.ogg"), + "Move": load(soundpath + "Move.ogg"), +} + +onready var sound_players = get_children() + +func play(sound_string, pitch_scale = 1, volume_db = 0): + for soundPlayer in sound_players: + if not soundPlayer.playing: + soundPlayer.pitch_scale = pitch_scale + soundPlayer.volume_db = volume_db + soundPlayer.stream = sounds[sound_string] + soundPlayer.play() + return + print("Too many sounds playing at once") diff --git a/sounds/SoundFX.tscn b/sounds/SoundFX.tscn new file mode 100644 index 0000000..ece5246 --- /dev/null +++ b/sounds/SoundFX.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://sounds/SoundFX.gd" type="Script" id=1] + +[node name="SoundFX" type="Node"] +script = ExtResource( 1 ) + +[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."] + +[node name="AudioStreamPlayer2" type="AudioStreamPlayer" parent="."] + +[node name="AudioStreamPlayer3" type="AudioStreamPlayer" parent="."] + +[node name="AudioStreamPlayer4" type="AudioStreamPlayer" parent="."] + +[node name="AudioStreamPlayer5" type="AudioStreamPlayer" parent="."] + +[node name="AudioStreamPlayer6" type="AudioStreamPlayer" parent="."] diff --git a/sounds/Victory.ogg b/sounds/Victory.ogg new file mode 100644 index 0000000..e5ffd86 --- /dev/null +++ b/sounds/Victory.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a0f8dec47f2698f62a769f84d79d4903c1475224cd9e40c53dc2fe5d2c0e7d5c +size 8883 diff --git a/sounds/Victory.ogg.import b/sounds/Victory.ogg.import new file mode 100644 index 0000000..9f3ece0 --- /dev/null +++ b/sounds/Victory.ogg.import @@ -0,0 +1,15 @@ +[remap] + +importer="ogg_vorbis" +type="AudioStreamOGGVorbis" +path="res://.import/Victory.ogg-ffe84c097dfb61848224cc932565dfd8.oggstr" + +[deps] + +source_file="res://sounds/Victory.ogg" +dest_files=[ "res://.import/Victory.ogg-ffe84c097dfb61848224cc932565dfd8.oggstr" ] + +[params] + +loop=false +loop_offset=0 |