forked from andreyratz/block
Code cleanup
Cleaned up various things in the code to make it easier for the next person
This commit is contained in:
57
TedsNotepad.txt
Normal file
57
TedsNotepad.txt
Normal 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)
|
||||
@@ -1,46 +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 changeDirection(normal: Vector2):
|
||||
print("direction:", direction)
|
||||
# direction = direction.bounce(normal)
|
||||
direction = normal
|
||||
#direction = newDirection
|
||||
#direction = direction.bounce(perp_line)
|
||||
rotation = direction.angle()
|
||||
print("direction:", direction)
|
||||
|
||||
func bounce(normal: Vector2):
|
||||
direction = direction.bounce(normal)
|
||||
rotation = 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)
|
||||
|
||||
@@ -13,20 +13,15 @@ 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
|
||||
@@ -42,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()
|
||||
@@ -64,7 +57,6 @@ func _process(delta: float) -> void:
|
||||
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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
56
todoList
56
todoList
@@ -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)
|
||||
Reference in New Issue
Block a user