Compare commits
3 Commits
4e127b091c
...
Projectile
| Author | SHA1 | Date | |
|---|---|---|---|
| 894f77e3cd | |||
| bbda9768a2 | |||
| ebff6dfa3e |
@@ -1,12 +1,14 @@
|
|||||||
[gd_scene format=3 uid="uid://db1oeukux1376"]
|
[gd_scene format=3 uid="uid://db1oeukux1376"]
|
||||||
|
|
||||||
[ext_resource type="Texture2D" uid="uid://xg0mu5mtpcgo" path="res://Assets/PlaceHolders/BuffMonk.png" id="1_g6sln"]
|
[ext_resource type="Texture2D" uid="uid://xg0mu5mtpcgo" path="res://Assets/PlaceHolders/BuffMonk.png" id="1_g6sln"]
|
||||||
[ext_resource type="Script" uid="uid://dm8ytxk67ejef" path="res://Scenes/enemy_1.gd" id="1_s7od6"]
|
[ext_resource type="Script" uid="uid://d34snqiuscbv8" path="res://Scenes/enemy_1.gd" id="1_s7od6"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://b3ngjk0lkeemd" path="res://Scenes/Projectile_1.tscn" id="2_n3m8v"]
|
||||||
|
|
||||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_g6sln"]
|
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_g6sln"]
|
||||||
|
|
||||||
[node name="Enemy1" type="CharacterBody2D" unique_id=1765361359]
|
[node name="Enemy1" type="CharacterBody2D" unique_id=1765361359]
|
||||||
script = ExtResource("1_s7od6")
|
script = ExtResource("1_s7od6")
|
||||||
|
Projectile = ExtResource("2_n3m8v")
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=93765061]
|
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=93765061]
|
||||||
position = Vector2(22, -29)
|
position = Vector2(22, -29)
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
[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)
|
|
||||||
26
block/Scenes/Projectile_1.gd
Normal file
26
block/Scenes/Projectile_1.gd
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
extends Node2D
|
||||||
|
|
||||||
|
const speed = 200
|
||||||
|
@onready var player: CharacterBody2D = get_tree().get_first_node_in_group("player")
|
||||||
|
var direction = Vector2.RIGHT
|
||||||
|
#var debug_normal: Vector2 = Vector2.ZERO
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
direction = (player.global_position - global_position).normalized()
|
||||||
|
global_rotation=direction.angle()
|
||||||
|
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
position += direction * speed * delta
|
||||||
|
|
||||||
|
func get_facing_direction():
|
||||||
|
var direction_vector = Vector2.from_angle(rotation)
|
||||||
|
return direction_vector
|
||||||
|
|
||||||
|
func changeDirection(normal: Vector2):
|
||||||
|
direction = normal
|
||||||
|
rotation = direction.angle()
|
||||||
|
|
||||||
|
# Debug function
|
||||||
|
func _draw():
|
||||||
|
# draw_line(Vector2(1,0) * 1000, debug_normal * 50, Color.RED, 2.0)
|
||||||
|
pass
|
||||||
1
block/Scenes/Projectile_1.gd.uid
Normal file
1
block/Scenes/Projectile_1.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://bxqq5rcm0twuk
|
||||||
34
block/Scenes/Projectile_1.tscn
Normal file
34
block/Scenes/Projectile_1.tscn
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
[gd_scene format=3 uid="uid://b3ngjk0lkeemd"]
|
||||||
|
|
||||||
|
[ext_resource type="Texture2D" uid="uid://bsjn11wcewgya" path="res://Assets/PlaceHolders/Blob.png" id="1_1rre0"]
|
||||||
|
[ext_resource type="Script" uid="uid://bxqq5rcm0twuk" path="res://Scenes/Projectile_1.gd" id="1_lrei0"]
|
||||||
|
|
||||||
|
[sub_resource type="GDScript" id="GDScript_4ipem"]
|
||||||
|
script/source = "extends Area2D
|
||||||
|
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
#func _ready() -> void:
|
||||||
|
# pass # Replace with function body.
|
||||||
|
|
||||||
|
|
||||||
|
"
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_v0834"]
|
||||||
|
|
||||||
|
[node name="Projectile1" type="Node2D" unique_id=1531719161]
|
||||||
|
script = ExtResource("1_lrei0")
|
||||||
|
|
||||||
|
[node name="Area2D" type="Area2D" parent="." unique_id=1629546418 groups=["Projectiles"]]
|
||||||
|
collision_layer = 2
|
||||||
|
collision_mask = 2
|
||||||
|
script = SubResource("GDScript_4ipem")
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D" unique_id=286593893]
|
||||||
|
scale = Vector2(1.1, 1.1)
|
||||||
|
shape = SubResource("CircleShape2D_v0834")
|
||||||
|
|
||||||
|
[node name="Sprite2D" type="Sprite2D" parent="Area2D" unique_id=1983633174]
|
||||||
|
position = Vector2(-0.9999995, 1)
|
||||||
|
scale = Vector2(0.17, 0.17)
|
||||||
|
texture = ExtResource("1_1rre0")
|
||||||
@@ -24,15 +24,17 @@ 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
|
||||||
|
|
||||||
func _on_timer_timeout() -> void:
|
func _on_timer_timeout() -> void:
|
||||||
$DirectionTimer.wait_time = chose([1,2,3])
|
$DirectionTimer.wait_time = chose([1,2,3])
|
||||||
if current_state !=States.CHASE:
|
if current_state !=States.CHASE:
|
||||||
dir = chose([Vector2.RIGHT, Vector2.LEFT])
|
dir = chose([Vector2.RIGHT, Vector2.LEFT])
|
||||||
|
var newProjectile = Projectile.instantiate() as Node2D
|
||||||
|
newProjectile.global_position=global_position
|
||||||
|
# newProjectile.global_rotation=global_rotation
|
||||||
|
get_tree().current_scene.add_child(newProjectile)
|
||||||
|
|
||||||
func chose(array):
|
func chose(array):
|
||||||
array.shuffle()
|
array.shuffle()
|
||||||
@@ -41,39 +43,12 @@ 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)
|
||||||
print(player.global_position)
|
#print(player.global_position)
|
||||||
var distance = global_position.distance_to(player.global_position)
|
var distance = global_position.distance_to(player.global_position)
|
||||||
if distance>max_distance:
|
if distance>max_distance:
|
||||||
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()
|
|
||||||
"""
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
uid://dm8ytxk67ejef
|
uid://d34snqiuscbv8
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
[ext_resource type="Script" uid="uid://bah031ailk0ha" path="res://Scenes/player.gd" id="1_cvnsp"]
|
[ext_resource type="Script" uid="uid://bah031ailk0ha" path="res://Scenes/player.gd" id="1_cvnsp"]
|
||||||
[ext_resource type="Texture2D" uid="uid://g0m835iol4mp" path="res://Assets/PlaceHolders/Screenshot 2024-11-24 210808.png" id="1_v0iea"]
|
[ext_resource type="Texture2D" uid="uid://g0m835iol4mp" path="res://Assets/PlaceHolders/Screenshot 2024-11-24 210808.png" id="1_v0iea"]
|
||||||
[ext_resource type="Texture2D" uid="uid://bcmuqd6p3jhdw" path="res://Assets/PlaceHolders/Elmo.png" id="3_6t5aa"]
|
[ext_resource type="Texture2D" uid="uid://bcmuqd6p3jhdw" path="res://Assets/PlaceHolders/Elmo.png" id="3_6t5aa"]
|
||||||
|
[ext_resource type="Script" uid="uid://b7vgyn15fioeu" path="res://Scenes/shield_hitbox.gd" id="4_vgqql"]
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_v0iea"]
|
[sub_resource type="CircleShape2D" id="CircleShape2D_v0iea"]
|
||||||
|
|
||||||
@@ -20,13 +21,21 @@ scale = Vector2(4.2653956, 4.2653956)
|
|||||||
shape = SubResource("CircleShape2D_v0iea")
|
shape = SubResource("CircleShape2D_v0iea")
|
||||||
|
|
||||||
[node name="Shield" type="Sprite2D" parent="." unique_id=212386399]
|
[node name="Shield" type="Sprite2D" parent="." unique_id=212386399]
|
||||||
position = Vector2(0, -50)
|
position = Vector2(50, 0)
|
||||||
rotation = 1.5707964
|
|
||||||
scale = Vector2(0.15, 0.15)
|
scale = Vector2(0.15, 0.15)
|
||||||
texture = ExtResource("3_6t5aa")
|
texture = ExtResource("3_6t5aa")
|
||||||
|
|
||||||
[node name="ShieldColision" type="CollisionShape2D" parent="." unique_id=948717563]
|
[node name="ShieldColision" type="CollisionShape2D" parent="." unique_id=948717563]
|
||||||
position = Vector2(0, -50)
|
position = Vector2(50, 0)
|
||||||
rotation = 1.5707964
|
scale = Vector2(2.5, 6)
|
||||||
|
shape = SubResource("RectangleShape2D_6t5aa")
|
||||||
|
|
||||||
|
[node name="ShieldHitbox" type="Area2D" parent="." unique_id=2121529100]
|
||||||
|
collision_layer = 2
|
||||||
|
collision_mask = 2
|
||||||
|
script = ExtResource("4_vgqql")
|
||||||
|
|
||||||
|
[node name="ShieldHitboxCol" type="CollisionShape2D" parent="ShieldHitbox" unique_id=1829894325]
|
||||||
|
position = Vector2(50, 0)
|
||||||
scale = Vector2(2.5, 6)
|
scale = Vector2(2.5, 6)
|
||||||
shape = SubResource("RectangleShape2D_6t5aa")
|
shape = SubResource("RectangleShape2D_6t5aa")
|
||||||
|
|||||||
32
block/Scenes/shield_hitbox.gd
Normal file
32
block/Scenes/shield_hitbox.gd
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
extends Area2D
|
||||||
|
|
||||||
|
var debug_normal: Vector2 = Vector2.ZERO
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready() -> void:
|
||||||
|
area_entered.connect(_on_area_entered)
|
||||||
|
|
||||||
|
func _on_area_entered(area):
|
||||||
|
if area.is_in_group("Projectiles"):
|
||||||
|
print("Event: Projectile hit shield")
|
||||||
|
var shield_normal = global_transform.x.normalized()
|
||||||
|
print("Readout: Shield normal: ", Vec2str(shield_normal))
|
||||||
|
# Gets the direction from the parent Node2D NOT the Area2d component
|
||||||
|
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"):
|
||||||
|
area.get_parent().changeDirection(bounceTrajectory)
|
||||||
|
|
||||||
|
# Debug functions
|
||||||
|
func _draw():
|
||||||
|
# draw_line(Vector2(1,0) * 1000, debug_normal * 50, Color.RED, 2.0) # normal
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Makes the string a bit easier to read in debug console
|
||||||
|
func Vec2str(vec: Vector2) -> String:
|
||||||
|
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]
|
||||||
1
block/Scenes/shield_hitbox.gd.uid
Normal file
1
block/Scenes/shield_hitbox.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://b7vgyn15fioeu
|
||||||
@@ -18,6 +18,7 @@ config/icon="res://icon.svg"
|
|||||||
[global_group]
|
[global_group]
|
||||||
|
|
||||||
player="Making this for an easy reference to the player in the enemies code"
|
player="Making this for an easy reference to the player in the enemies code"
|
||||||
|
Projectiles="Tell if the object is a projectile or not"
|
||||||
|
|
||||||
[input]
|
[input]
|
||||||
|
|
||||||
|
|||||||
57
todoList
57
todoList
@@ -12,3 +12,60 @@ Done
|
|||||||
|
|
||||||
Current imported assests:
|
Current imported assests:
|
||||||
https://screamingbrainstudios.itch.io/tiny-texture-pack
|
https://screamingbrainstudios.itch.io/tiny-texture-pack
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
x1*x2+y1*y2
|
||||||
|
|
||||||
|
along normal speedx*sp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var proje_normal = global_transform.x.normalized()
|
||||||
|
#proje_normal.y = -proje_normal.y
|
||||||
|
print("Proje Normal: ", proje_normal)
|
||||||
|
var speed_perp: float = proje_normal.dot(normal)
|
||||||
|
var perp_line: Vector2 = Vector2(normal.y,-normal.x)
|
||||||
|
var speed_para: float = proje_normal.dot(perp_line)
|
||||||
|
print("speed perp: ", speed_perp)
|
||||||
|
print("speed para: ", speed_para)
|
||||||
|
# this is just to check my math
|
||||||
|
# should be aproximately 1 (there will be some bit depth precision errors)
|
||||||
|
print("speed hype: ", speed_para*speed_para + speed_perp*speed_perp)
|
||||||
|
|
||||||
|
var newDirection: Vector2 = Vector2(
|
||||||
|
(speed_perp * normal.x) + (speed_para * normal.y),
|
||||||
|
(speed_perp * normal.y) + (speed_para *-normal.x))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var projectile_velocity = area.get_parent().get_facing_direction()
|
||||||
|
print("projectile speed......................", projectile_velocity)
|
||||||
|
var shield_normal = global_transform.x.normalized()
|
||||||
|
print("Shield Normal: ", shield_normal)
|
||||||
|
#shield_normal.y = -shield_normal.y
|
||||||
|
# if abs(projectile_velocity.y)>abs(projectile_velocity.x):
|
||||||
|
# shield_normal = global_transform.y.normalized()
|
||||||
|
#shield_normal.y = -shield_normal.y
|
||||||
|
#shield_normal.x = -shield_normal.x
|
||||||
|
# var shield_perp = Vector2(shield_normal.y,-shield_normal.x)
|
||||||
|
# if area.has_method("bounce"):
|
||||||
|
# if projectile_velocity.dot(shield_perp) < 0:
|
||||||
|
# area.bounce(shield_normal)
|
||||||
|
if area.has_method("bounce"):
|
||||||
|
#if projectile_velocity.dot(shield_normal) < 0:
|
||||||
|
area.bounce(shield_normal)
|
||||||
Reference in New Issue
Block a user