Skip to content

Commit

Permalink
Fixed #8
Browse files Browse the repository at this point in the history
Now the player also uses the same logic, no events are set to "interact" action by default, they are set during tutorial_screen.tscn
  • Loading branch information
henriiquecampos committed Mar 6, 2018
1 parent 4af42ab commit 665885f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 60 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
*.sample
*.oggstr
export_presets.cfg
*.pck
*.pck
export_presets.cfg
101 changes: 47 additions & 54 deletions actors/player/bard/bard.gd
Original file line number Diff line number Diff line change
@@ -1,73 +1,27 @@
extends "res://actors/player/player_character.gd"

const PITCHES = [1.0, 1.25, 1.50]
var object = null
const NOTE = preload("res://interface/note_duration/note.tscn")
var note = null
enum KEYS{Z, X, C}
var key = 0
var check = false

signal played_note(pitch, duration)

func _ready():
connect("played_note", get_tree().get_nodes_in_group("staff")[0], "add_note")
func _process(delta):
#Start the interaction if it can, then check for which pitch the
#player is trying to use in the interaction
if Input.is_action_just_pressed("interact") and current_state != JUMP:
can_move = false
$Animator.play("flute")
var pitch = 0.0
note = NOTE.instance()
note.position += Vector2(32, -150)
if Input.is_key_pressed(KEY_Z):
note.set_modulate(note.COLORS[Z])
pitch = 1.0
key = Z
elif Input.is_key_pressed(KEY_X):
note.set_modulate(note.COLORS[X])
pitch = 1.25
key = X
elif Input.is_key_pressed(KEY_C):
note.set_modulate(note.COLORS[C])
pitch = 1.50
key = C
add_child(note)
interact(pitch)
if object != null:
check = check_pitch(pitch, object.pitch)
if !check:
miss()
object.miss()

if Input.is_action_just_released("interact"):
can_move = true
if note == null:
return
var pitch = key
var duration = note.duration
note.finished()
note = null

if object != null:
if check_duration(duration, object.note_duration) and check:
success()
object.success()
emit_signal("played_note", pitch, duration)
elif check:
miss()
object.miss()
object = null
else:
resume()

func interact(p):
#Access the pitch effect and modify it based on the pitch the player
#is using in the interaction
var bus = AudioServer.get_bus_index($Flute.get_bus())
var fx = AudioServer.get_bus_effect(bus, 0)
fx.set_pitch_scale(p)
fx.set_pitch_scale(PITCHES[p])
$Flute.play()
if object != null:
check = check_pitch(PITCHES[p], object.pitch)
if !check:
# miss()
object.miss()

func resume():
#Returns the character to it's rest/idle position and re-enable its
Expand Down Expand Up @@ -101,4 +55,43 @@ func check_duration(player, other):
if player == other:
return(true)
else:
return(false)
return(false)

func _input(event):
if !(event is InputEventKey):
return
var p = 0

for e in InputMap.get_action_list("interact"):
if e.as_text() == event.as_text():
p = (InputMap.get_action_list("interact").find(e))

if event.is_action_pressed("interact") and current_state != JUMP:
can_move = false
$Animator.play("flute")
interact(p)
note = NOTE.instance()
note.position += Vector2(32, -150)
add_child(note)
note.set_modulate(note.COLORS[p])

elif event.is_action_released("interact"):
$Flute.stop()
can_move = true
if note == null:
return
var duration = note.duration
note.finished()
note = null

if object != null:
if check_duration(duration, object.note_duration) and check:
success()
object.success()
emit_signal("played_note", p, duration)
else:
miss()
object.miss()
else:
resume()

1 change: 1 addition & 0 deletions interface/staff/staff.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ extends HBoxContainer
const COLORS = [Color("bc5fd3"), Color("8d5fd3"), Color("37c871")]
const DURATIONS = [preload("res://interface/note_duration/16.png"),
preload("res://interface/note_duration/8.png"), preload("res://interface/note_duration/4.png")]

func add_note(pitch, duration):
var t = TextureRect.new()
if duration == 16:
Expand Down
5 changes: 1 addition & 4 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ timers/tooltip_delay_sec=0.5

[input]

interact=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":90,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":88,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":67,"unicode":0,"echo":false,"script":null)
]
interact=[ ]
walk_left=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"unicode":0,"echo":false,"script":null)
]
walk_right=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"unicode":0,"echo":false,"script":null)
Expand Down
2 changes: 1 addition & 1 deletion screens/tutorial_screen/tutorial_screen.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ use_filter = true
font_data = ExtResource( 18 )
_sections_unfolded = [ "Extra Spacing", "Font", "Settings" ]
[node name="Tutorial" index="0" instance=ExtResource( 1 )]
[node name="Tutorial" instance=ExtResource( 1 )]
script = ExtResource( 2 )
next_scene = "res://levels/level_01/level_01.tscn"
Expand Down

0 comments on commit 665885f

Please sign in to comment.