Compare commits
6 Commits
Visual-ove
...
6dd20aff97
| Author | SHA1 | Date | |
|---|---|---|---|
| 6dd20aff97 | |||
| 894f77e3cd | |||
| bbda9768a2 | |||
| 4e127b091c | |||
| d3eac34147 | |||
| a93f163b85 |
11
block/Scenes/MapTest.tscn
Normal file
11
block/Scenes/MapTest.tscn
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
[gd_scene format=3 uid="uid://d3m22yqoyvo4t"]
|
||||||
|
|
||||||
|
[ext_resource type="PackedScene" uid="uid://b448mpav6ek52" path="res://Scenes/arena_game_manager.tscn" id="1_0tjoe"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://db1oeukux1376" path="res://Scenes/Enemy1.tscn" id="2_pddb8"]
|
||||||
|
|
||||||
|
[node name="MapTest" type="Node2D" unique_id=2115555896]
|
||||||
|
|
||||||
|
[node name="ArenaGameManager" parent="." unique_id=1024187604 instance=ExtResource("1_0tjoe")]
|
||||||
|
|
||||||
|
[node name="Enemy1" parent="." unique_id=1765361359 instance=ExtResource("2_pddb8")]
|
||||||
|
position = Vector2(379, 168)
|
||||||
@@ -5,45 +5,22 @@ const speed = 200
|
|||||||
var direction = Vector2.RIGHT
|
var direction = Vector2.RIGHT
|
||||||
#var debug_normal: Vector2 = Vector2.ZERO
|
#var debug_normal: Vector2 = Vector2.ZERO
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
#direction = (player.global_position - global_position).normalized()
|
|
||||||
#look_at(player.global_position)
|
|
||||||
# pass
|
|
||||||
direction = (player.global_position - global_position).normalized()
|
direction = (player.global_position - global_position).normalized()
|
||||||
global_rotation=direction.angle()
|
global_rotation=direction.angle()
|
||||||
#direction= global_position.direction_to(player.global_position)
|
|
||||||
#direction = Vector2.RIGHT.rotated(rotation+ get_angle_to(playerDirection))
|
|
||||||
|
|
||||||
func _draw():
|
|
||||||
pass
|
|
||||||
# draw_line(Vector2(1,0) * 1000, debug_normal * 50, Color.RED, 2.0)
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
position += direction * speed * delta
|
position += direction * speed * delta
|
||||||
#position += playerDirection * speed * delta
|
|
||||||
look_at(player.global_position)
|
|
||||||
|
|
||||||
#look_at(direction)#
|
|
||||||
|
|
||||||
func get_facing_direction():
|
func get_facing_direction():
|
||||||
# Get the direction vector based on the node's current rotation
|
var direction_vector = Vector2.from_angle(rotation)
|
||||||
var direction_vector: Vector2 = Vector2.from_angle(rotation)
|
|
||||||
return direction_vector
|
return direction_vector
|
||||||
|
|
||||||
func changeTrajectory(direction_vector: Vector2):
|
|
||||||
rotation = rad_to_deg(atan2(direction_vector.y, direction_vector.x))
|
|
||||||
|
|
||||||
func changeDirection(normal: Vector2):
|
func changeDirection(normal: Vector2):
|
||||||
print("direction:", direction)
|
|
||||||
# direction = direction.bounce(normal)
|
|
||||||
direction = normal
|
direction = normal
|
||||||
#direction = newDirection
|
rotation = direction.angle()
|
||||||
#direction = direction.bounce(perp_line)
|
|
||||||
rotation = rad_to_deg(direction.angle())
|
|
||||||
print("direction:", direction)
|
|
||||||
|
|
||||||
func bounce(normal: Vector2):
|
# Debug function
|
||||||
direction = direction.bounce(normal)
|
func _draw():
|
||||||
rotation = rad_to_deg(direction.angle())
|
# draw_line(Vector2(1,0) * 1000, debug_normal * 50, Color.RED, 2.0)
|
||||||
|
pass
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ enum States
|
|||||||
const max_distance = 750
|
const max_distance = 750
|
||||||
const SPEED = 300.0
|
const SPEED = 300.0
|
||||||
var is_enemy_chase: bool
|
var is_enemy_chase: bool
|
||||||
#
|
|
||||||
var health = 100
|
var health = 100
|
||||||
var health_max = 100
|
var health_max = 100
|
||||||
var health_min = 0
|
var health_min = 0
|
||||||
@@ -24,9 +24,6 @@ var dir: Vector2
|
|||||||
var knockback = 200
|
var knockback = 200
|
||||||
var current_state = States.IDLE
|
var current_state = States.IDLE
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@onready var player: CharacterBody2D = get_tree().get_first_node_in_group("player")
|
@onready var player: CharacterBody2D = get_tree().get_first_node_in_group("player")
|
||||||
@export var Projectile: PackedScene
|
@export var Projectile: PackedScene
|
||||||
|
|
||||||
@@ -38,8 +35,6 @@ func _on_timer_timeout() -> void:
|
|||||||
newProjectile.global_position=global_position
|
newProjectile.global_position=global_position
|
||||||
# newProjectile.global_rotation=global_rotation
|
# newProjectile.global_rotation=global_rotation
|
||||||
get_tree().current_scene.add_child(newProjectile)
|
get_tree().current_scene.add_child(newProjectile)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func chose(array):
|
func chose(array):
|
||||||
array.shuffle()
|
array.shuffle()
|
||||||
@@ -48,10 +43,6 @@ func chose(array):
|
|||||||
func wraparound():
|
func wraparound():
|
||||||
var direction = global_position.direction_to(player.global_position)
|
var direction = global_position.direction_to(player.global_position)
|
||||||
global_position += direction * max_distance*2
|
global_position += direction * max_distance*2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
look_at(player.global_position)
|
look_at(player.global_position)
|
||||||
@@ -61,29 +52,3 @@ func _process(delta: float) -> void:
|
|||||||
wraparound()
|
wraparound()
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
if (global_position.x-player.global_position.x)>600:#player to the right
|
|
||||||
global_position.x=player.global_position.x-600#move right
|
|
||||||
elif(global_position.x-player.global_position.x)<-600:#player to the left
|
|
||||||
global_position.x=player.global_position.x+600#move left
|
|
||||||
|
|
||||||
if (global_position.y-player.global_position.y)>600:#player to the up
|
|
||||||
global_position.y=player.global_position.y-600#move up
|
|
||||||
elif(global_position.y-player.global_position.y)<-600:#player to the down
|
|
||||||
global_position.y=player.global_position.y+600#move down
|
|
||||||
"""
|
|
||||||
"""
|
|
||||||
func _physics_process(delta: float) -> void:
|
|
||||||
# Add the gravity.
|
|
||||||
if not is_on_floor():
|
|
||||||
velocity += get_gravity() * delta
|
|
||||||
# Get the input direction and handle the movement/deceleration.
|
|
||||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
|
||||||
var direction := Input.get_axis("ui_left", "ui_right")
|
|
||||||
if direction:
|
|
||||||
velocity.x = direction * SPEED
|
|
||||||
else:
|
|
||||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
|
||||||
|
|
||||||
move_and_slide()
|
|
||||||
"""
|
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ func _process(_delta: float) -> void:
|
|||||||
|
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
|
|
||||||
# look_at(get_global_mouse_position()) # uncompensated mouse control
|
look_at(get_global_mouse_position())
|
||||||
|
|
||||||
var angle_to_mouse = get_angle_to(get_global_mouse_position())
|
#OLD: used when player shield direction aigned 90 deg off from front
|
||||||
rotation += angle_to_mouse# + deg_to_rad(90) #+90 to makes top of image face mouse, not side
|
# var angle_to_mouse = get_angle_to(get_global_mouse_position())
|
||||||
|
# rotation += angle_to_mouse# + deg_to_rad(90) #+90 to makes top of image face mouse, not side
|
||||||
|
|||||||
@@ -1,45 +1,32 @@
|
|||||||
extends Area2D
|
extends Area2D
|
||||||
|
|
||||||
var debug_normal: Vector2 = Vector2.ZERO
|
var debug_normal: Vector2 = Vector2.ZERO
|
||||||
var bounceTrajectory: Vector2
|
|
||||||
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
area_entered.connect(_on_area_entered)
|
area_entered.connect(_on_area_entered)
|
||||||
print("READY!")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func _draw():
|
|
||||||
# pass
|
|
||||||
draw_line(bounceTrajectory *1000, debug_normal * 50, Color.RED, 2.0) # normal
|
|
||||||
# draw_line(Vector2(400,900), debug_normal * 50, Color.RED, 2.0) # normal
|
|
||||||
# draw_line(Vector2.ZERO, debug_bounce * 50, Color.GREEN, 2.0) # bounce direction
|
|
||||||
# draw_line(Vector2.ZERO, debug_incoming * 50, Color.BLUE, 2.0) # incoming projectile
|
|
||||||
|
|
||||||
|
|
||||||
func _on_area_entered(area):
|
func _on_area_entered(area):
|
||||||
if area.is_in_group("Projectiles"):
|
if area.is_in_group("Projectiles"):
|
||||||
draw_line(Vector2(400,900), debug_normal * 50, Color.RED, 2.0) # normal
|
print("Event: Projectile hit shield")
|
||||||
|
|
||||||
print("projectile has hit player shield")
|
|
||||||
#gets the proper velocity
|
|
||||||
var projectile_velocity = area.get_parent().get_facing_direction()
|
|
||||||
print("projectile speed......................", projectile_velocity)
|
|
||||||
var shield_normal = global_transform.x.normalized()
|
var shield_normal = global_transform.x.normalized()
|
||||||
#var bounceTrajectory: Vector2 = projectile_velocity.bounce(shield_normal)
|
print("Readout: Shield normal: ", Vec2str(shield_normal))
|
||||||
bounceTrajectory = projectile_velocity.bounce(shield_normal)
|
# Gets the direction from the parent Node2D NOT the Area2d component
|
||||||
print("Shield Normal: ", shield_normal)
|
var projectile_velocity = area.get_parent().get_facing_direction()
|
||||||
|
print("Readout: Projectile dir: ", Vec2str(projectile_velocity))
|
||||||
|
var bounceTrajectory = projectile_velocity.bounce(shield_normal)
|
||||||
|
print("Readout: Bounce dir: ", Vec2str(bounceTrajectory))
|
||||||
if area.get_parent().has_method("changeDirection"):
|
if area.get_parent().has_method("changeDirection"):
|
||||||
draw_line(bounceTrajectory, debug_normal * 50, Color.RED, 2.0)
|
|
||||||
# area.changeDirection(bounceTrajectory)
|
|
||||||
# area.get_parent().changeTrajectory(bounceTrajectory)
|
|
||||||
area.get_parent().changeDirection(bounceTrajectory)
|
area.get_parent().changeDirection(bounceTrajectory)
|
||||||
#if area.has_method("bounce"):
|
|
||||||
# area.bounce(bounceTrajectory)
|
|
||||||
|
|
||||||
|
# Debug functions
|
||||||
|
func _draw():
|
||||||
|
# draw_line(Vector2(1,0) * 1000, debug_normal * 50, Color.RED, 2.0) # normal
|
||||||
|
pass
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Makes the string a bit easier to read in debug console
|
||||||
#func _process(delta: float) -> void:
|
func Vec2str(vec: Vector2) -> String:
|
||||||
# pass
|
var x_sign = " " if vec.x >= 0 else ""
|
||||||
|
var y_sign = " " if vec.y >= 0 else ""
|
||||||
|
|
||||||
|
return "(%s%.2f, %s%.2f)" % [x_sign, vec.x, y_sign, vec.y]
|
||||||
|
|||||||
Reference in New Issue
Block a user