Compare commits
3 Commits
f0fcf0dcb3
...
stage/mole
| Author | SHA1 | Date | |
|---|---|---|---|
| f4e5d13cf8 | |||
| 0af538ff3f | |||
| c20985ac91 |
@@ -23,8 +23,6 @@ var healthPoints: int = 100
|
||||
var isAlive: bool = true
|
||||
@onready var invulnerable_cooldown_timer: Timer = $InvulnerableCooldownTimer
|
||||
var hasiframes: bool = false # only used for iframe after collision for now
|
||||
var target = Vector2.ZERO # either vector2 or Node2D
|
||||
var updating_target: bool = false
|
||||
|
||||
func _ready() -> void:
|
||||
var screen_size = get_viewport_rect().size
|
||||
@@ -37,33 +35,14 @@ func _ready() -> void:
|
||||
sprite.play("default")
|
||||
|
||||
|
||||
func _input(event):
|
||||
# TODO: only does clicks/taps; accept mouse drags
|
||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
|
||||
target = get_global_mouse_position()
|
||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
|
||||
if event.pressed:
|
||||
# start tracking
|
||||
target = get_global_mouse_position()
|
||||
updating_target = true
|
||||
else:
|
||||
# stop tracking
|
||||
updating_target = false
|
||||
|
||||
if updating_target and event is InputEventMouseMotion:
|
||||
target = get_global_mouse_position()
|
||||
func set_target(target) -> void:
|
||||
$Input.target = target
|
||||
|
||||
func _physics_process(delta):
|
||||
var pos
|
||||
if typeof(target) == TYPE_VECTOR2:
|
||||
pos = target
|
||||
elif "position" in target:
|
||||
pos = target.position
|
||||
else:
|
||||
return
|
||||
var dir: Vector2 = position.direction_to(pos)
|
||||
var target_pos = $Input.get_target_position()
|
||||
var dir: Vector2 = position.direction_to(target_pos)
|
||||
|
||||
if position.distance_to(pos) > 2:
|
||||
if position.distance_to(target_pos) > 2:
|
||||
self.desired_rotation = atan2(dir.y, dir.x)
|
||||
move_and_collide(speed * dir * delta)
|
||||
position = GameManager.get_boundaried_position(position)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
[ext_resource type="Texture2D" uid="uid://du1lb4nr47kvl" path="res://molecular/assets/player-sprite-attacking.png" id="2_rq1v6"]
|
||||
[ext_resource type="Texture2D" uid="uid://bsd1qtw50esai" path="res://molecular/assets/player-sprite-attacking2.png" id="3_xiwfn"]
|
||||
[ext_resource type="Texture2D" uid="uid://cd0iv6hsi3fad" path="res://molecular/assets/player-sprite.png" id="4_rq1v6"]
|
||||
[ext_resource type="Script" uid="uid://dehus7ao5xv2l" path="res://molecular/player_input.gd" id="5_xiwfn"]
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_onrkg"]
|
||||
animations = [{
|
||||
@@ -49,6 +50,9 @@ animation = &"attacking"
|
||||
rotation = -1.5732701
|
||||
shape = SubResource("CapsuleShape2D_4flbx")
|
||||
|
||||
[node name="Input" type="Node" parent="." unique_id=2043215647]
|
||||
script = ExtResource("5_xiwfn")
|
||||
|
||||
[node name="AttackArea" type="Area2D" parent="." unique_id=187975387]
|
||||
position = Vector2(0, 56)
|
||||
rotation = -1.5732701
|
||||
|
||||
@@ -92,7 +92,7 @@ tile_set = SubResource("TileSet_ojt85")
|
||||
position = Vector2(112, 64)
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="player" unique_id=1614218911]
|
||||
zoom = Vector2(5, 5)
|
||||
zoom = Vector2(3, 3)
|
||||
limit_enabled = false
|
||||
limit_left = 0
|
||||
limit_top = 0
|
||||
|
||||
29
evolve-die-repeat/molecular/player_input.gd
Normal file
29
evolve-die-repeat/molecular/player_input.gd
Normal file
@@ -0,0 +1,29 @@
|
||||
extends Node
|
||||
|
||||
|
||||
var target = Vector2.ZERO # should be either Vector2 or Node2D
|
||||
var updating: bool = false
|
||||
var holding_lmb: bool = false
|
||||
|
||||
func _input(event):
|
||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
|
||||
if event.pressed:
|
||||
# start tracking
|
||||
target = owner.get_global_mouse_position()
|
||||
updating = true
|
||||
else:
|
||||
# stop tracking
|
||||
updating = false
|
||||
|
||||
func _process(delta):
|
||||
if typeof(target) == TYPE_VECTOR2 and updating:
|
||||
target = owner.get_global_mouse_position()
|
||||
|
||||
func get_target_position() -> Vector2:
|
||||
if typeof(target) == TYPE_VECTOR2 or typeof(target) == TYPE_VECTOR3:
|
||||
return target
|
||||
elif "position" in target:
|
||||
return target.position
|
||||
else:
|
||||
return Vector2.ZERO
|
||||
target = Vector2.ZERO # reset target to a Vector2
|
||||
1
evolve-die-repeat/molecular/player_input.gd.uid
Normal file
1
evolve-die-repeat/molecular/player_input.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dehus7ao5xv2l
|
||||
@@ -69,9 +69,3 @@ func _on_sight_body_entered(body: Node2D) -> void:
|
||||
|
||||
func _on_attack_cooldown_timer_timeout() -> void:
|
||||
can_attack = true
|
||||
|
||||
|
||||
func _on_collision_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
|
||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
|
||||
if player:
|
||||
player.target = self.collision
|
||||
|
||||
@@ -42,9 +42,3 @@ func become_injured() -> void:
|
||||
func _on_sight_body_entered(body: Node2D) -> void:
|
||||
if body.is_in_group("predator") or (health < maxHealth and body.is_in_group("player")):
|
||||
fsm.transition_to_next_state(fsm.States.FLEEING, {"threat": body})
|
||||
|
||||
|
||||
func _on_collision_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
|
||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
|
||||
if player:
|
||||
player.target = self.collision
|
||||
|
||||
@@ -37,3 +37,8 @@ func play_sprite(anim: String) -> void:
|
||||
self.sprite.play(anim)
|
||||
if "wrapper" in self:
|
||||
self.wrapper.play_sprite(anim)
|
||||
|
||||
func _on_collision_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
|
||||
if player:
|
||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
|
||||
player.set_target(self.collision)
|
||||
|
||||
Reference in New Issue
Block a user