10 Commits

Author SHA1 Message Date
9ff7fee53c Merge branch 'Visual-overhaul' 2026-03-10 21:14:05 -07:00
cd4f527ab1 Code cleanup
Cleaned up various things in the code to make it easier for the next person
2026-03-10 18:26:21 -07:00
2c1c865e3d Added Creature
Added the creature from Mika's art and also implemented the animations as well
2026-03-09 18:57:18 -07:00
743899be33 Improved outline preservation
Did basically anti aliasing but for the sake of making the outlines more clear.

It worked but I'm gonna continue to noodle on this solution in the future

Also incidentally fixed a minor visual glitch with the projectile directions after bounce
2026-03-09 00:43:54 -07:00
6dd20aff97 merged changes to main, didn't test thoroughly just skimmed hopefully it works :P 2026-03-08 19:48:00 -07:00
894f77e3cd Cleanup
Cleaning up the messy sections of my code and making the debug console output easier to read
2026-03-04 13:11:51 -08:00
bbda9768a2 Fixed projectile rotation
Fixed minor visual glitch where projectiles wouldn't be at the correct rotation after being deflected
2026-03-03 17:04:12 -08:00
4e127b091c Merge pull request 'enemy+wraparound' (#2) from enemy+wraparound into main
Reviewed-on: #2
2026-02-16 23:49:24 -08:00
d3eac34147 Merge pull request 'added mouse look and added a depressed elmo png for later' (#1) from Mouse-Look into main
Reviewed-on: #1
2026-02-16 23:47:46 -08:00
a93f163b85 Added a basic monk enemy that always looks at the player
Also added a feature so it will wrap around if the player gets too far
2026-02-16 20:09:20 -08:00
16 changed files with 414 additions and 198 deletions

57
TedsNotepad.txt Normal file
View File

@@ -0,0 +1,57 @@
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)

Binary file not shown.

After

Width:  |  Height:  |  Size: 247 KiB

View File

@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c8c6fh1jtdd0i"
path="res://.godot/imported/Creature2Spritesheet.png-e2e0ef81f527506d5f444ce2e43b5c24.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Assets/GameplayArt/Creature2Spritesheet.png"
dest_files=["res://.godot/imported/Creature2Spritesheet.png-e2e0ef81f527506d5f444ce2e43b5c24.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View File

@@ -6,6 +6,7 @@ uniform sampler2D screen_texture : hint_screen_texture, filter_nearest;
uniform float pixel_size = 256.0; // This now represents the "Height" resolution
uniform float color_levels : hint_range(2.0, 256.0) = 2.0;
uniform float PXwidth = 640;
uniform float PXheight = 360;

View File

@@ -4,46 +4,67 @@ shader_type canvas_item;
uniform sampler2D screen_texture : hint_screen_texture, filter_nearest;
uniform sampler2D palette_texture : filter_nearest;
uniform int palette_size = 16;
uniform float pixel_size = 256.0; // This now represents the "Height" resolution
uniform float pixel_size = 256.0;
uniform float color_levels : hint_range(2.0, 256.0) = 2.0;
uniform float black_bias : hint_range(0.0, 1.0) = 1.0; // Lower = stronger preference for black
uniform float outline_sensitivity : hint_range(0.0, 1.0) = 0.25; // Higher = grabs more grey
uniform float PXwidth = 640;
uniform float PXheight = 360;
uniform vec2 target_resolution = vec2(640.0, 360.0);
void fragment() {
float aspect_ratio = SCREEN_PIXEL_SIZE.y / SCREEN_PIXEL_SIZE.x;
vec2 uv = SCREEN_UV;
uv.x = round(uv.x * pixel_size * aspect_ratio) / (pixel_size * aspect_ratio);
uv.y = round(uv.y * pixel_size) / pixel_size;
vec2 uv = floor(SCREEN_UV * target_resolution) / target_resolution;
vec2 v_pixel_size = 1.0 / target_resolution;
vec2 offset = v_pixel_size * 0.5;
// 3. Sample and Posterize
vec4 rgba = texture(screen_texture, uv);
// check center and 4 small offsets to see if black is nearby
vec3 col0 = texture(screen_texture, uv).rgb;
vec3 col1 = texture(screen_texture, uv + vec2(offset.x, 0.0)).rgb;
vec3 col2 = texture(screen_texture, uv - vec2(offset.x, 0.0)).rgb;
vec3 col3 = texture(screen_texture, uv + vec2(0.0, offset.y)).rgb;
vec3 col4 = texture(screen_texture, uv - vec2(0.0, offset.y)).rgb;
// Calculate the darkest brightness among the 5 samples
float b0 = dot(col0, vec3(0.299, 0.587, 0.114));
float b1 = dot(col1, vec3(0.299, 0.587, 0.114));
float b2 = dot(col2, vec3(0.299, 0.587, 0.114));
float b3 = dot(col3, vec3(0.299, 0.587, 0.114));
float b4 = dot(col4, vec3(0.299, 0.587, 0.114));
float min_brightness = min(b0, min(b1, min(b2, min(b3, b4))));
vec3 final_rgb;
// 2. The "Outline Guard"
// If ANY sampled pixel in this area is dark, force it to black immediately
if (min_brightness < outline_sensitivity) {
final_rgb = vec3(0.0, 0.0, 0.0);
} else {
// 3. Normal Palette Snapping
vec3 rgba = col0; // Use center sample for normal colors
float best_dist = 10.0;
vec3 best_color = rgba.rgb;
///*
// test posteriser instead of the for loop:
float levels = 8.0; // Number of color steps per channel
rgba.rgb = floor(rgba.rgb * levels) / levels;
COLOR = vec4(rgba.rgb, 1.0);
//*/
vec3 best_color = rgba;
//*
// Palette snapping logic
for (int i = 0; i < palette_size; i++) {
float x_coord = (float(i) + 0.5) / float(palette_size);
vec3 p_color = texture(palette_texture, vec2(x_coord, 0.5)).rgb;
float dist = distance(rgba.rgb, p_color);
float dist = distance(rgba, p_color);
/*
// Apply bias in the loop as a secondary safety measure
if (length(p_color) < 0.1) {
dist *= black_bias;
}
//*/
if (dist < best_dist) {
best_dist = dist;
best_color = p_color;
}
}
//*/
COLOR = vec4(best_color, 1.0);
final_rgb = best_color;
}
COLOR = vec4(final_rgb, 1.0);
}
void vertex() {

View File

@@ -0,0 +1,89 @@
[gd_scene format=3 uid="uid://cja4ibeplpuvg"]
[ext_resource type="PackedScene" uid="uid://db1oeukux1376" path="res://Scenes/Enemy1.tscn" id="1_1lo65"]
[ext_resource type="Texture2D" uid="uid://c8c6fh1jtdd0i" path="res://Assets/GameplayArt/Creature2Spritesheet.png" id="2_wvt7r"]
[sub_resource type="AtlasTexture" id="AtlasTexture_uldxc"]
atlas = ExtResource("2_wvt7r")
region = Rect2(0, 0, 1002, 1002)
[sub_resource type="AtlasTexture" id="AtlasTexture_hm5n8"]
atlas = ExtResource("2_wvt7r")
region = Rect2(1002, 0, 1002, 1002)
[sub_resource type="SpriteFrames" id="SpriteFrames_r1616"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_uldxc")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_hm5n8")
}],
"loop": true,
"name": &"default",
"speed": 1.0
}]
[sub_resource type="CircleShape2D" id="CircleShape2D_sli80"]
radius = 18.0
[sub_resource type="Animation" id="Animation_uldxc"]
resource_name = "Wiggle"
length = 2.0
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 1),
"transitions": PackedFloat32Array(1, 1),
"update": 1,
"values": [0, 1]
}
[sub_resource type="Animation" id="Animation_wvt7r"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [0]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_hm5n8"]
_data = {
&"Idle": SubResource("Animation_uldxc"),
&"RESET": SubResource("Animation_wvt7r")
}
[node name="Enemy1" unique_id=1765361359 instance=ExtResource("1_1lo65")]
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." index="0" unique_id=769003556]
visible = false
rotation = -1.5707964
scale = Vector2(0.3, 0.3)
sprite_frames = SubResource("SpriteFrames_r1616")
frame = 1
frame_progress = 0.7216727
[node name="Sprite2D" parent="." index="1" unique_id=93765061]
position = Vector2(0, 0)
rotation = -1.5707964
texture = ExtResource("2_wvt7r")
hframes = 2
[node name="CollisionShape2D" parent="." index="2" unique_id=1856443411]
shape = SubResource("CircleShape2D_sli80")
[node name="AnimationPlayer" type="AnimationPlayer" parent="." index="4" unique_id=525993328]
libraries/ = SubResource("AnimationLibrary_hm5n8")

View File

@@ -0,0 +1,88 @@
[gd_scene format=3 uid="uid://cja4ibeplpuvg"]
[ext_resource type="PackedScene" uid="uid://db1oeukux1376" path="res://Scenes/Enemy1.tscn" id="1_1lo65"]
[ext_resource type="Texture2D" uid="uid://c8c6fh1jtdd0i" path="res://Assets/GameplayArt/Creature2Spritesheet.png" id="2_wvt7r"]
[sub_resource type="AtlasTexture" id="AtlasTexture_uldxc"]
atlas = ExtResource("2_wvt7r")
region = Rect2(0, 0, 1002, 1002)
[sub_resource type="AtlasTexture" id="AtlasTexture_hm5n8"]
atlas = ExtResource("2_wvt7r")
region = Rect2(1002, 0, 1002, 1002)
[sub_resource type="SpriteFrames" id="SpriteFrames_r1616"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_uldxc")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_hm5n8")
}],
"loop": true,
"name": &"default",
"speed": 1.0
}]
[sub_resource type="CircleShape2D" id="CircleShape2D_sli80"]
radius = 18.0
[sub_resource type="Animation" id="Animation_uldxc"]
resource_name = "Wiggle"
length = 2.0
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 1),
"transitions": PackedFloat32Array(1, 1),
"update": 1,
"values": [0, 1]
}
[sub_resource type="Animation" id="Animation_wvt7r"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [1]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_hm5n8"]
_data = {
&"Idle": SubResource("Animation_uldxc"),
&"RESET": SubResource("Animation_wvt7r")
}
[node name="Enemy1" unique_id=1765361359 instance=ExtResource("1_1lo65")]
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." index="0" unique_id=769003556]
visible = false
rotation = -1.5707964
scale = Vector2(0.3, 0.3)
sprite_frames = SubResource("SpriteFrames_r1616")
frame = 1
frame_progress = 0.7216727
[node name="Sprite2D" parent="." index="1" unique_id=93765061]
texture = ExtResource("2_wvt7r")
hframes = 2
frame = 1
[node name="CollisionShape2D" parent="." index="2" unique_id=1856443411]
shape = SubResource("CircleShape2D_sli80")
[node name="AnimationPlayer" type="AnimationPlayer" parent="." index="4" unique_id=525993328]
libraries/ = SubResource("AnimationLibrary_hm5n8")

View File

@@ -16,6 +16,7 @@ scale = Vector2(0.3, 0.3)
texture = ExtResource("1_g6sln")
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1856443411]
visible = false
scale = Vector2(6, 6)
shape = SubResource("CapsuleShape2D_g6sln")

11
block/Scenes/MapTest.tscn Normal file
View 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)

View File

@@ -1,49 +1,24 @@
extends Node2D
const isDebugLineOn: bool = false
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()
#look_at(player.global_position)
# pass
# direction of the player
direction = (player.global_position - global_position).normalized()
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:
position += direction * speed * delta
#position += playerDirection * speed * delta
look_at(player.global_position)
#look_at(direction)#
func get_facing_direction():
# Get the direction vector based on the node's current rotation
var direction_vector: Vector2 = Vector2.from_angle(rotation)
return direction_vector
func changeTrajectory(direction_vector: Vector2):
rotation = rad_to_deg(atan2(direction_vector.y, direction_vector.x))
func changeDirection(normal: Vector2):
print("direction:", direction)
# direction = direction.bounce(normal)
direction = normal
#direction = newDirection
#direction = direction.bounce(perp_line)
rotation = rad_to_deg(direction.angle())
print("direction:", direction)
rotation = direction.angle()
func bounce(normal: Vector2):
direction = direction.bounce(normal)
rotation = rad_to_deg(direction.angle())
#debug functions
var debug_normal: Vector2 = Vector2.ZERO
func _draw():
if isDebugLineOn:
draw_line(Vector2(1,0) * 1000, debug_normal * 50, Color.RED, 2.0)

View File

@@ -3,6 +3,7 @@
[ext_resource type="PackedScene" uid="uid://du7hapc7kscm6" path="res://Scenes/game.tscn" id="1_i0wgn"]
[ext_resource type="Shader" uid="uid://dyr1qs8xwscgm" path="res://Assets/Shaders/ShaderTest.gdshader" id="2_exucn"]
[ext_resource type="Texture2D" uid="uid://djar02rjgqabs" path="res://Assets/GameplayArt/Black.png" id="2_ipaa6"]
[ext_resource type="PackedScene" uid="uid://cja4ibeplpuvg" path="res://Scenes/Creature_2.tscn" id="3_meac5"]
[ext_resource type="Texture2D" uid="uid://b4xxaewt8vfbl" path="res://Assets/GameplayArt/PallateV1.png" id="4_vet50"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_exucn"]
@@ -11,8 +12,9 @@ shader_parameter/palette_texture = ExtResource("4_vet50")
shader_parameter/palette_size = 16
shader_parameter/pixel_size = 256.0
shader_parameter/color_levels = 8.0
shader_parameter/PXwidth = 640.0
shader_parameter/PXheight = 360.0
shader_parameter/black_bias = 0.6
shader_parameter/outline_sensitivity = 0.25
shader_parameter/target_resolution = Vector2(640, 360)
[node name="ShaderTest" type="Node2D" unique_id=1126703629]
@@ -21,10 +23,14 @@ shader_parameter/PXheight = 360.0
[node name="Sprite2D" parent="Game/ArenaGameManager/MapArena/Parallax2D" parent_id_path=PackedInt32Array(850692785, 1024187604, 194007747, 598922861) index="0" unique_id=1318408175]
texture = ExtResource("2_ipaa6")
[node name="Enemy2" parent="Game" unique_id=1765361359 instance=ExtResource("3_meac5")]
position = Vector2(258, 363)
[node name="CanvasLayer" type="CanvasLayer" parent="." unique_id=298300130]
layer = 10
[node name="ColorRect" type="ColorRect" parent="CanvasLayer" unique_id=570744568]
texture_filter = 2
material = SubResource("ShaderMaterial_exucn")
anchors_preset = 15
anchor_right = 1.0

View File

@@ -13,23 +13,21 @@ enum States
const max_distance = 750
const SPEED = 300.0
var is_enemy_chase: bool
#
var health = 100
var health_max = 100
var health_min = 0
var attack_dammage = 10
var dir: Vector2
var knockback = 200
var current_state = States.IDLE
@onready var player: CharacterBody2D = get_tree().get_first_node_in_group("player")
@onready var _animation_player = $AnimationPlayer
@export var Projectile: PackedScene
var anim_player
func _on_timer_timeout() -> void:
$DirectionTimer.wait_time = chose([1,2,3])
if current_state != States.CHASE:
@@ -39,8 +37,6 @@ func _on_timer_timeout() -> void:
# newProjectile.global_rotation=global_rotation
get_tree().current_scene.add_child(newProjectile)
func chose(array):
array.shuffle()
return array.front()
@@ -49,41 +45,21 @@ func wraparound():
var direction = global_position.direction_to(player.global_position)
global_position += direction * max_distance*2
func _ready() -> void:
if has_node("AnimationPlayer"):
anim_player = get_node_or_null("AnimationPlayer")
var list = anim_player.get_animation_list()
print(list) # Outputs something like ["idle", "walk", "default"]
func _process(delta: float) -> void:
if has_node("AnimationPlayer"):
anim_player = get_node_or_null("AnimationPlayer")
if anim_player.has_animation("Idle"):
anim_player.play("Idle")
look_at(player.global_position)
#print(player.global_position)
var distance = global_position.distance_to(player.global_position)
if distance > max_distance:
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()
"""

View File

@@ -1,10 +1,8 @@
extends CharacterBody2D
const SPEED = 300.0
func _process(_delta: float) -> void:
func _process(delta: float) -> void:
var dirX := Input.get_axis("move_left", "move_right")
var dirY := Input.get_axis("move_up", "move_down")
@@ -17,7 +15,8 @@ func _process(_delta: float) -> void:
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())
rotation += angle_to_mouse# + deg_to_rad(90) #+90 to makes top of image face mouse, not side
# mouse control no longer requires this 90 degree compensation
# var angle_to_mouse = get_angle_to(get_global_mouse_position())
# rotation += angle_to_mouse + deg_to_rad(90)

View File

@@ -14,11 +14,12 @@ script = ExtResource("1_cvnsp")
[node name="Body" type="Sprite2D" parent="." unique_id=719417979]
rotation = -1.5707964
scale = Vector2(0.114894986, 0.11449075)
scale = Vector2(0.115, 0.115)
texture = ExtResource("2_vgqql")
[node name="BodyColision" type="CollisionShape2D" parent="." unique_id=1477808378]
scale = Vector2(4.2653956, 4.2653956)
visible = false
scale = Vector2(3.5, 3.5)
shape = SubResource("CircleShape2D_v0iea")
[node name="Shield" type="Sprite2D" parent="." unique_id=212386399]
@@ -27,6 +28,7 @@ scale = Vector2(0.15, 0.15)
texture = ExtResource("3_6t5aa")
[node name="ShieldColision" type="CollisionShape2D" parent="." unique_id=948717563]
visible = false
position = Vector2(50, 0)
scale = Vector2(2.5, 6)
shape = SubResource("RectangleShape2D_6t5aa")
@@ -37,6 +39,7 @@ collision_mask = 2
script = ExtResource("4_vgqql")
[node name="ShieldHitboxCol" type="CollisionShape2D" parent="ShieldHitbox" unique_id=1829894325]
visible = false
position = Vector2(50, 0)
scale = Vector2(2.5, 6)
shape = SubResource("RectangleShape2D_6t5aa")

View File

@@ -1,45 +1,36 @@
extends Area2D
var debug_normal: Vector2 = Vector2.ZERO
var bounceTrajectory: Vector2
# Toggles debugger console output
const isVerbose: bool = false
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
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):
if area.is_in_group("Projectiles"):
draw_line(Vector2(400,900), debug_normal * 50, Color.RED, 2.0) # normal
print("projectile has hit player shield")
#gets the proper velocity
var projectile_velocity = area.get_parent().get_facing_direction()
print("projectile speed......................", projectile_velocity)
# gets parent node because parent is what's moving, not the child area node
var parent = area.get_parent()
readout("Event: Projectile has hit player shield")
var projectile_dir = Vector2.from_angle(parent.rotation)
vec2Readout("Projectile Dir", projectile_dir)
var shield_normal = global_transform.x.normalized()
#var bounceTrajectory: Vector2 = projectile_velocity.bounce(shield_normal)
bounceTrajectory = projectile_velocity.bounce(shield_normal)
print("Shield Normal: ", shield_normal)
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)
#if area.has_method("bounce"):
# area.bounce(bounceTrajectory)
vec2Readout("Shield Normal: ", shield_normal)
if parent.has_method("changeDirection"):
var bounce_dir = projectile_dir.bounce(shield_normal)
parent.changeDirection(bounce_dir)
# makes debug output cleaner when printing Vector2
func vec2str(vec: Vector2) -> String:
var x_str = String.num(vec.x, 2)
var y_str = String.num(vec.y, 2)
if not x_str.begins_with("-"): x_str = " " + x_str
if not y_str.begins_with("-"): y_str = " " + y_str
return "(%s, %s)" % [x_str, y_str]
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta: float) -> void:
# pass
func vec2Readout(label: String, vec: Vector2):
if isVerbose:
print("Readout: ", label, vec2str(vec))
func readout(str: String):
if isVerbose:
print(str)

View File

@@ -2,12 +2,15 @@ So that we can keep track of what things need to be done
Using godot version 4.6
- Get sprites for basic characters, and background
- collisions
- projectiles
- attack types?
- Get sprites for and background
- projectile damage
- enemy attack types
- enemy behaviors
Done
- WASD movement
- projectiles launching
- projectiles bouncing
- Get sprites for basic characters,
Current imported assests:
@@ -15,9 +18,6 @@ https://screamingbrainstudios.itch.io/tiny-texture-pack
x1*x2+y1*y2
along normal speedx*sp
@@ -27,45 +27,3 @@ 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)