Skip to content

Commit

Permalink
Adding sound effects, refactoring, making cards in hand nicely spread
Browse files Browse the repository at this point in the history
  • Loading branch information
grymmy committed Nov 22, 2024
1 parent 755da62 commit 28b2db1
Show file tree
Hide file tree
Showing 17 changed files with 129 additions and 35 deletions.
1 change: 1 addition & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Audio="*res://scripts/Audio.gd"

window/size/viewport_width=1920
window/size/viewport_height=1080
window/size/mode=3
window/size/initial_screen=1
window/stretch/mode="canvas_items"

Expand Down
15 changes: 9 additions & 6 deletions scenes/main.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=36 format=3 uid="uid://cjtnhugpl35ay"]
[gd_scene load_steps=37 format=3 uid="uid://cjtnhugpl35ay"]

[ext_resource type="Script" path="res://scripts/MouseHandler.gd" id="1_fysce"]
[ext_resource type="PackedScene" uid="uid://dhw27v0raxlxp" path="res://components/arrow.tscn" id="2_5cnle"]
Expand All @@ -16,6 +16,7 @@
[ext_resource type="Script" path="res://scripts/GraveyardController.gd" id="8_4bn74"]
[ext_resource type="Script" path="res://scripts/DragController.gd" id="9_slc2b"]
[ext_resource type="Script" path="res://scripts/DropArea.gd" id="10_w3wlf"]
[ext_resource type="Resource" uid="uid://d3f4j3k5ep0ew" path="res://sounds/defaults.tres" id="12_g1dgu"]
[ext_resource type="Script" path="res://scripts/CardDisplayController.gd" id="13_kk3ip"]
[ext_resource type="Texture2D" uid="uid://c1kuehp5fdmdr" path="res://art/counterspell_hackclub/Reference/bg1_big.png" id="16_sjurj"]
[ext_resource type="Texture2D" uid="uid://d7tnyehh7oxt" path="res://art/counterspell_hackclub/Reference/bg5.png" id="19_tm8m1"]
Expand Down Expand Up @@ -107,6 +108,7 @@ script = ExtResource("1_fysce")
game_logic = NodePath("../GameLogic")
battlefield_dropzone = NodePath("../Dropzones/Control/BattlefieldDropzone")
arrow_controller = NodePath("../Main Canvas/Arrow")
sound_resource = ExtResource("12_g1dgu")

[node name="Main Canvas" type="CanvasLayer" parent="."]

Expand Down Expand Up @@ -208,7 +210,7 @@ offset_bottom = 1074.0
mouse_filter = 2

[node name="Stars" type="Node2D" parent="Main Canvas"]
position = Vector2(501, 541)
position = Vector2(894, 541)
scale = Vector2(0.5, 0.5)

[node name="NinePatchRect" type="NinePatchRect" parent="Main Canvas/Stars"]
Expand Down Expand Up @@ -435,6 +437,7 @@ panel_done = NodePath("../Main Canvas/DonePanel")
button_done = NodePath("../Main Canvas/DonePanel/DoneButton")
panel_notification = NodePath("../Main Canvas/NotificationPanel")
richtext_notification_message = NodePath("../Main Canvas/NotificationPanel/RichTextLabel")
sound_resource = ExtResource("12_g1dgu")

[node name="Lights" type="Node3D" parent="."]
visible = false
Expand All @@ -458,7 +461,7 @@ controlled_by_me = true
graveyard = NodePath("../MyGraveyard")

[node name="MyHand" type="Node3D" parent="Card Groups/Mine" node_paths=PackedStringArray("graveyard")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.709553, -6.28475, 0)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.709553, -9.428, 0)
script = ExtResource("7_mqjt8")
controlled_by_me = true
graveyard = NodePath("../MyGraveyard")
Expand Down Expand Up @@ -487,7 +490,7 @@ script = ExtResource("2_rndq6")
graveyard = NodePath("../OpponentGraveyard")

[node name="OpponentHand" type="Node3D" parent="Card Groups/Opponent" node_paths=PackedStringArray("graveyard")]
transform = Transform3D(-1, 8.74228e-08, 0, -8.74228e-08, -1, 0, 0, 0, 1, 0.748875, 8.03919, 0)
transform = Transform3D(-1, 8.74228e-08, 0, -8.74228e-08, -1, 0, 0, 0, 1, 0.748875, 9.61394, 0)
script = ExtResource("7_mqjt8")
hidden_hand = true
graveyard = NodePath("../OpponentGraveyard")
Expand Down Expand Up @@ -588,11 +591,11 @@ texture = ExtResource("16_sjurj")
[node name="CanvasLayer" type="CanvasLayer" parent="."]

[node name="MyAvatar" parent="." node_paths=PackedStringArray("graveyard") instance=ExtResource("21_5rpq5")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -4.99695, 0)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2.63062, 4.05117)
graveyard = NodePath("../Card Groups/Mine/MyGraveyard")

[node name="OpponentAvatar" parent="." node_paths=PackedStringArray("graveyard") instance=ExtResource("21_5rpq5")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.87758, 0)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.12341, 4.38049)
graveyard = NodePath("../Card Groups/Opponent/OpponentGraveyard")

[connection signal="pressed" from="Main Canvas/AddCardButton" to="Card Groups/Mine/MyBattlefield" method="_on_add_card_button_pressed"]
Expand Down
1 change: 1 addition & 0 deletions scripts/Avatar.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var power : int = 0
var card_group_controller : Node = null
var hovered = false
@export var graveyard : Node = null # the graveyard associated w/ this card group controller
var type = Avatar

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
Expand Down
6 changes: 3 additions & 3 deletions scripts/GameLogic.gd
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ enum GameState {
@export var panel_notification : NodePath
@export var richtext_notification_message : NodePath
@onready var timer_finished_cb = connect("on_done_pressed", Callable(self, "_on_done_pressed"))
@export var sound_resource : Resource

var state : GameState = GameState.MY_TURN
var instance = null
Expand Down Expand Up @@ -63,7 +64,7 @@ func deal_cards():
var time_between_cards = 0.25
#await add_test_battlefield_cards(time_between_cards)

for i in 1:
for i in 7:
add_card(CardIndex.get_random_card(), my_hand)
add_card(CardIndex.get_random_card(), opponent_hand)
await get_tree().create_timer(time_between_cards).timeout
Expand Down Expand Up @@ -142,8 +143,7 @@ func reset_all_cards(card_group_controller):
card.heal()

func draw_card(hand, deck):
var sounds = ResourceLoader.load("res://sounds/defaults.tres").sounds
Audio.play(sounds.get("draw"))
Audio.play(sound_resource.sounds.get("draw"))
var card = deck.take_card(0)
if card == null:
print("NOTE - player tried to draw a card, failed to do so")
Expand Down
21 changes: 17 additions & 4 deletions scripts/HandController.gd
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
class_name HandController
extends "res://scripts/CardGroupController.gd"

@export var hidden_hand = false
var original_rotation : Basis
func _ready() -> void:
super._ready()
original_rotation = transform.basis

func _process(delta: float) -> void:
super._process(delta)
var rotation : float
rotation = float(get_cards_len())
#transform.basis = transform.basis.slerp(original_rotation.rotated(Vector3.FORWARD, deg_to_rad(rotation)), delta * 15.0)

func insert_card(card: Node3D, index: int, global_position: Vector3) -> void:
if !hidden_hand:
Audio.play(ResourceLoader.load("res://sounds/defaults.tres").sounds.get("enter_hand"))
super.insert_card(card, index, global_position)
card.show_power_toughness(!hidden_hand)

func get_desired_position(index: int) -> Vector3:
var num_cards = get_cards_len()
var desired_width = 4.0
var desired_width = pow(1.25, float(num_cards)) * 3
var width_per_card = float(desired_width) / float(num_cards)

if num_cards == 1:
return Vector3(0.75, 0, -0.01)

var absolute_x_offset = width_per_card * float(index)
var centered_x_offset = -(desired_width - width_per_card*2) / 2.0 + absolute_x_offset
return Vector3(centered_x_offset, 0, -0.01 * float(index))
return Vector3(centered_x_offset, 2, -0.01 * float(index))

func get_desired_rotation(index: int) -> Basis:
var num_cards = get_cards_len()
var spread_degrees = deg_to_rad(70)
var spread_degrees = deg_to_rad(float(num_cards) * 5)
var index_ratio = float(index) / (float(num_cards)-1)
var degs = spread_degrees * index_ratio
var rot = Basis.IDENTITY
Expand All @@ -31,7 +44,7 @@ func get_desired_rotation(index: int) -> Basis:
return rot

rot = rot.rotated(Vector3.FORWARD, degs - spread_degrees/2)
rot = rot.rotated(Vector3.UP, deg_to_rad(-0.1 * float(index)))
rot = rot.rotated(Vector3.UP, deg_to_rad(-0.01 * float(index)))

return rot

4 changes: 4 additions & 0 deletions scripts/MouseHandler.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var old_drop_point = null
@export var battlefield_dropzone : Node
const CardType = preload("res://scripts/CardController.gd").CardType
@export var arrow_controller : Control
@export var sound_resource : Resource

func get_drop_point(mouse_position:Vector2):
if battlefield_dropzone.hovered:
Expand Down Expand Up @@ -84,6 +85,8 @@ func handle_placement_mousemotion():

# Calculate intersection of ray with the plane
var intersect_pos = plane.intersects_ray(ray_origin, ray_direction)
if clicked_card.card_group_controller is HandController:
return
clicked_card.card_group_controller.position_override = intersect_pos

var drop_point = get_drop_point(battlefield_dropzone.get_global_mouse_position())
Expand Down Expand Up @@ -182,6 +185,7 @@ func on_placement_dropped(event, card: CardController):
card.card_group_controller.take(card)
var drop_index = drop_point.card_group_controller.current_drag_index
drop_point.card_group_controller.insert_card(card, drop_index, gp)
Audio.play(sound_resource.sounds.get("enter_play"))
else:
card.card_group_controller.take(card)
group_dragged_from.insert_card(card, 0, gp)
Expand Down
30 changes: 30 additions & 0 deletions shaders/avatar-mask.gdshader
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
shader_type canvas_item;

// Declare the screen texture
uniform sampler2D screen_texture : hint_screen_texture;

void fragment() {
// Sample the mask texture
vec4 mask_color = texture(TEXTURE, UV);

// Sample the screen texture (what's currently rendered beneath this shader)
vec4 screen_color = texture(screen_texture, SCREEN_UV);

// Choose your blend mode:
//COLOR = screen_color;
// Normal blending (just display the mask)
COLOR = mask_color;

// Additive blending
//COLOR = mask_color + screen_color;

// Subtractive blending
//COLOR = screen_color - mask_color;

// Multiplicative blending
if(mask_color.a != 1.0) {
COLOR = screen_color;
} else {
COLOR = screen_color * mask_color;
}
}
10 changes: 7 additions & 3 deletions sounds/defaults.tres
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[gd_resource type="Resource" load_steps=4 format=3 uid="uid://d3f4j3k5ep0ew"]
[gd_resource type="Resource" load_steps=6 format=3 uid="uid://d3f4j3k5ep0ew"]

[ext_resource type="AudioStream" uid="uid://cdt7b5s5buo81" path="res://sounds/hit.ogg" id="1_8b5rk"]
[ext_resource type="AudioStream" uid="uid://3nilbvu8p7s7" path="res://sounds/draw.mp3" id="2_kk36w"]
[ext_resource type="AudioStream" uid="uid://ddgw2ir3mmqr8" path="res://sounds/draw.ogg" id="2_sgs4j"]
[ext_resource type="AudioStream" uid="uid://bmbahxmv63kr4" path="res://sounds/plop.ogg" id="3_d8f2r"]
[ext_resource type="AudioStream" uid="uid://l72p4xa51evd" path="res://sounds/yoink.ogg" id="4_t4bwo"]

[sub_resource type="GDScript" id="GDScript_yrye7"]
script/source = "@export var sounds : Dictionary
Expand All @@ -10,6 +12,8 @@ script/source = "@export var sounds : Dictionary
[resource]
script = SubResource("GDScript_yrye7")
sounds = {
"draw": ExtResource("2_kk36w"),
"draw": ExtResource("2_sgs4j"),
"enter_hand": ExtResource("4_t4bwo"),
"enter_play": ExtResource("3_d8f2r"),
"hit": ExtResource("1_8b5rk")
}
Binary file removed sounds/draw.mp3
Binary file not shown.
19 changes: 0 additions & 19 deletions sounds/draw.mp3.import

This file was deleted.

Binary file added sounds/draw.ogg
Binary file not shown.
19 changes: 19 additions & 0 deletions sounds/draw.ogg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[remap]

importer="oggvorbisstr"
type="AudioStreamOggVorbis"
uid="uid://ddgw2ir3mmqr8"
path="res://.godot/imported/draw.ogg-f8371bc8f12c92fb5d70bd8495eb0e32.oggvorbisstr"

[deps]

source_file="res://sounds/draw.ogg"
dest_files=["res://.godot/imported/draw.ogg-f8371bc8f12c92fb5d70bd8495eb0e32.oggvorbisstr"]

[params]

loop=false
loop_offset=0
bpm=0
beat_count=0
bar_beats=4
Binary file modified sounds/hit.ogg
Binary file not shown.
Binary file added sounds/plop.ogg
Binary file not shown.
19 changes: 19 additions & 0 deletions sounds/plop.ogg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[remap]

importer="oggvorbisstr"
type="AudioStreamOggVorbis"
uid="uid://bmbahxmv63kr4"
path="res://.godot/imported/plop.ogg-63993b6765b5c7880e34f9d974582ae5.oggvorbisstr"

[deps]

source_file="res://sounds/plop.ogg"
dest_files=["res://.godot/imported/plop.ogg-63993b6765b5c7880e34f9d974582ae5.oggvorbisstr"]

[params]

loop=false
loop_offset=0
bpm=0
beat_count=0
bar_beats=4
Binary file added sounds/yoink.ogg
Binary file not shown.
19 changes: 19 additions & 0 deletions sounds/yoink.ogg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[remap]

importer="oggvorbisstr"
type="AudioStreamOggVorbis"
uid="uid://l72p4xa51evd"
path="res://.godot/imported/yoink.ogg-4945adf8eb20a40e9058c94afe5aaca3.oggvorbisstr"

[deps]

source_file="res://sounds/yoink.ogg"
dest_files=["res://.godot/imported/yoink.ogg-4945adf8eb20a40e9058c94afe5aaca3.oggvorbisstr"]

[params]

loop=false
loop_offset=0.0
bpm=0.0
beat_count=0
bar_beats=4

0 comments on commit 28b2db1

Please sign in to comment.