added bow
This commit is contained in:
parent
5d01f40535
commit
2d3fc72ebe
50 changed files with 610 additions and 151 deletions
|
@ -7,8 +7,10 @@ onready var climb_ray = $ClimbRay
|
|||
onready var anims = $AnimationPlayer
|
||||
onready var sword_sprite = $SwordSprite
|
||||
onready var sword_hitbox = $SwordArea
|
||||
#Map
|
||||
onready var map = get_owner()
|
||||
##States
|
||||
enum State {IDLE,WALK,JUMP,FALL,STUNNED,CLIMB,SWORD}
|
||||
enum State {IDLE,WALK,JUMP,FALL,STUNNED,CLIMB,SWORD,SHOOT}
|
||||
var current_state = State.IDLE
|
||||
var axis = Vector2.ZERO
|
||||
##Physics
|
||||
|
@ -20,7 +22,9 @@ var jump_force = 150
|
|||
var current_ladder = null
|
||||
var can_doublejump = true
|
||||
var doublejump_force = 120
|
||||
|
||||
var arrowpos = Vector2(5,3)
|
||||
#Preload
|
||||
var pre_arrow = preload("res://objects/player/arrow_projectile.tscn")
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
|
@ -47,11 +51,14 @@ func _physics_process(delta):
|
|||
continue
|
||||
State.SWORD:
|
||||
_process_sword()
|
||||
continue
|
||||
State.SHOOT:
|
||||
_process_shoot()
|
||||
|
||||
#Gravity
|
||||
if current_state != State.CLIMB: velocity.y += gravity
|
||||
#Apply velocity
|
||||
move_and_slide(velocity,Vector2.UP)
|
||||
print(velocity.y)
|
||||
#Debug
|
||||
if Input.is_action_pressed("debug_move_player"):
|
||||
position = get_viewport().get_mouse_position()
|
||||
|
@ -89,6 +96,8 @@ func _process_idle_walk():
|
|||
Game.play_sound(Game.a_sword,Game.ac_jump)
|
||||
current_state = State.SWORD
|
||||
return
|
||||
#Goto Shoot
|
||||
check_shoot()
|
||||
|
||||
func _process_jump():
|
||||
jump_pressure += 1
|
||||
|
@ -99,6 +108,8 @@ func _process_jump():
|
|||
velocity.y = -jump_force / 4
|
||||
#velocity.y = 0
|
||||
current_state = State.FALL
|
||||
#Goto Shoot
|
||||
check_shoot()
|
||||
|
||||
func _process_fall():
|
||||
if anims.get_current_animation() != "doublejump": anims.play("jump")
|
||||
|
@ -109,8 +120,11 @@ func _process_fall():
|
|||
if is_on_floor():
|
||||
current_state = State.IDLE
|
||||
return
|
||||
#Goto Shoot
|
||||
check_shoot()
|
||||
|
||||
func _process_climb():
|
||||
can_doublejump = true
|
||||
#Graphics
|
||||
anims.play("climb")
|
||||
anims.set_speed_scale(abs(axis.y))
|
||||
|
@ -141,13 +155,25 @@ func _process_sword():
|
|||
sword_hitbox.position.x = sprite.scale.x * 10
|
||||
#Return to idle after animationplayer end anim signal
|
||||
|
||||
func _process_shoot():
|
||||
#Stop
|
||||
velocity.x = 0
|
||||
if anims.get_current_animation() == "shoot air":
|
||||
#Cancel air shoot animation when grounded
|
||||
if is_on_floor():
|
||||
current_state = State.IDLE
|
||||
return
|
||||
move(walk_speed,0,true)
|
||||
|
||||
func spawn_arrow():
|
||||
Game.play_sound(Game.a_shoot,Game.ac_jump)
|
||||
Game.instance_node(pre_arrow,global_position.x+(arrowpos.x*sprite.scale.x),global_position.y+arrowpos.y,map)
|
||||
|
||||
func check_jump():
|
||||
if Input.is_action_just_pressed("jump"):
|
||||
#Detach ladder
|
||||
if current_state == State.CLIMB:
|
||||
Game.ac_climb.set_stream(null)
|
||||
Game.ac_climb.set_stream(null) # stop climb sound
|
||||
position.x -= sprite.scale.x * 5
|
||||
anims.set_speed_scale(1)
|
||||
# Jump
|
||||
|
@ -166,6 +192,15 @@ func check_double_jump():
|
|||
velocity.y = -doublejump_force
|
||||
anims.play("doublejump")
|
||||
|
||||
func check_shoot():
|
||||
#Only Shoot if have arrows and there are no arrows onscreen
|
||||
if Input.is_action_just_pressed("shoot") && Game.arrows > 0 && get_tree().get_nodes_in_group("arrow").size() == 0:
|
||||
current_state = State.SHOOT
|
||||
if is_on_floor():
|
||||
anims.play("shoot grounded")
|
||||
else:
|
||||
anims.play("shoot air") #Shoot immediately in air
|
||||
|
||||
func move(hsp,vsp,flip:bool):
|
||||
velocity.x = hsp * axis.x
|
||||
#Flip
|
||||
|
@ -196,3 +231,15 @@ func _on_AnimationPlayer_animation_finished(anim_name):
|
|||
if anim_name == "stab":
|
||||
current_state = State.IDLE
|
||||
return
|
||||
#Return to idle after grounded shoot
|
||||
if anim_name == "shoot grounded":
|
||||
current_state = State.IDLE
|
||||
return
|
||||
#Return to fall or idle after air shoot
|
||||
if anim_name == "shoot air":
|
||||
if is_on_floor():
|
||||
current_state = State.IDLE
|
||||
return
|
||||
else:
|
||||
current_state = State.FALL
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue