ADD: bears can shoot at player.
parent
92f660e43e
commit
751fe607bd
|
@ -25,6 +25,9 @@ func to_falling():
|
|||
m_state = preload("res://Actor/Falling.gd").new()
|
||||
m_state.this = self
|
||||
|
||||
func is_dead():
|
||||
return m_state.state_name == 'Dead'
|
||||
|
||||
func to_dead():
|
||||
m_state = preload("res://Actor/Dead.gd").new()
|
||||
m_state.this = self
|
||||
|
|
|
@ -1,7 +1,21 @@
|
|||
extends Node2D
|
||||
|
||||
var m_world = null
|
||||
var m_target = null
|
||||
var m_shoot_time = 2.0
|
||||
var m_shoot_timer = 0.0
|
||||
|
||||
func _ready():
|
||||
$Actor/Sprite2D.modulate = Color.RED
|
||||
|
||||
func _process(_delta):
|
||||
pass
|
||||
func _process(delta):
|
||||
if m_target and $Actor.is_normal() and not m_target.get_node('Actor').is_dead():
|
||||
if m_shoot_timer >= m_shoot_time:
|
||||
var to_target = m_target.get_node('Actor').global_position - $Actor.global_position
|
||||
var dir = to_target.normalized()
|
||||
var dist = to_target.length()
|
||||
m_world.throw_bomb($Actor.global_position, dir, dist)
|
||||
m_shoot_timer = 0.0
|
||||
m_shoot_timer += delta
|
||||
|
||||
|
||||
|
|
|
@ -15,11 +15,12 @@ func _ready():
|
|||
func _process(_delta):
|
||||
pass
|
||||
|
||||
func throw_at(pos: Vector2, dir: Vector2):
|
||||
func throw_at(pos: Vector2, dir: Vector2, dist: float):
|
||||
self.position = pos
|
||||
m_origin = pos
|
||||
m_dir = dir
|
||||
m_state = self._moving
|
||||
m_dist = dist
|
||||
|
||||
func _physics_process(delta):
|
||||
if (m_origin - self.position).length_squared() >= m_dist * m_dist:
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
extends Node2D
|
||||
|
||||
func _ready():
|
||||
pass
|
||||
$Bear.m_target = $Player
|
||||
$Bear.m_world = self
|
||||
|
||||
func _process(_delta):
|
||||
if Input.is_action_just_pressed("ui_accept"):
|
||||
throw_bomb(Vector2(512, 256), Vector2(0, 1))
|
||||
|
||||
if is_outside($Player/Actor) and $Player/Actor.is_normal():
|
||||
$Player/Actor.to_falling()
|
||||
|
||||
|
@ -20,10 +18,10 @@ func is_outside(actor):
|
|||
return tile.get_custom_data('is_void')
|
||||
|
||||
|
||||
func throw_bomb(from: Vector2, dir: Vector2):
|
||||
func throw_bomb(from: Vector2, dir: Vector2, dist: float):
|
||||
var bomb = preload("res://Molotov/molotov.tscn").instantiate()
|
||||
bomb.on_explode.connect(_on_bomb_explode)
|
||||
bomb.throw_at(from, dir)
|
||||
bomb.throw_at(from, dir, dist)
|
||||
add_child(bomb)
|
||||
|
||||
func _on_bomb_explode(bomb):
|
||||
|
|
Loading…
Reference in New Issue