Initial repo

This commit is contained in:
zerothelootrat
2024-06-03 05:29:11 -04:00
commit 613fc89bab
33 changed files with 974 additions and 0 deletions

18
Scripts/enemy_laser.gd Normal file
View File

@@ -0,0 +1,18 @@
extends Area2D
var speed = 500
func _physics_process(delta):
global_position.y += speed * delta
if global_position.y > 1000:
queue_free()
#this is where i do stuff
func _on_area_entered(area):
if area is player:
area.take_damage(1)
queue_free()

42
Scripts/enemy_spawner.gd Normal file
View File

@@ -0,0 +1,42 @@
extends Node2D
signal scored()
var spawn_positions = null
var enemy = preload("res://Scenes/enemy_xwing.tscn")
func _ready():
randomize()
spawn_positions = $SpawnPositions.get_children()
func spawn_enemy():
var index = randi() % spawn_positions.size()
var enemy = enemy.instantiate()
enemy.global_position = spawn_positions[index].global_position
#connect error. unsure why.
#enemy.connect("enemy_died", get_tree().current_scene, "scored")
add_child(enemy)
#AI Generated code, doesn't work. connect error
#func spawn_enemy():
#var index = randi() % spawn_positions.size()
#var enemy_instance = enemy.instantiate()
#var world_node = get_node("res://Scenes/world.tscn")
#var world_script = world_node.get_script()
#enemy_instance.connect("enemy_died", world_script, 10)
#enemy_instance.global_position = spawn_positions[index].global_position
#add_child(enemy_instance)
func _on_spawn_timer_timeout():
spawn_enemy()
func enemy_died():
emit_signal("scored")
func missile_spawn():
print("Missile")

86
Scripts/enemy_xwing.gd Normal file
View File

@@ -0,0 +1,86 @@
extends Area2D
signal enemy_died()
@export var speed : int = 150
#position where the thing shoots from
@onready var marker = $Marker2D
#sensor location, central just for testing
@onready var ray1 = $RayCast2D
signal missile_spawn()
#health, duh.
var health = 3
#had to add for things that require sensors, going to require moving one for turrets maybe?
#for tutorial https://www.youtube.com/watch?v=V_gaCLbWqzk&ab_channel=KaanAlpar
func _ready():
ray1.exclude_parent = true
ray1.collide_with_areas = true
#setting variable if it can shoot used later.
var can_shoot = true
#testing for the raycast feature.
#func _process(delta):
#print(ray1.is_colliding())
#print(ray1.get_collider())
func _physics_process(delta):
#movement
global_position.y += speed * delta
#detecting player in area.
if ray1.is_colliding and ray1.get_collider() is player:
if can_shoot == true:
#shooting
fire_enemy_laser()
#starting firing timer so it cant just spam.
$Firing_timer.start()
can_shoot = false
func take_damage(damage):
health -= damage
if health <= 0:
$death_timer.start()
#$AnimatedSprite2D.play("death")
emit_signal("enemy_died")
get_tree().current_scene.scored()
power_up_check()
#print(str(get_tree().current_scene.player.global_position))
func fire_enemy_laser():
get_tree().current_scene.fire_enemy_laser(marker.global_position)
func power_up_check():
var index = randi() % 51
# 1 - 40 does nothing
# 40-48 spawns missiles
# 49 spawns nothing
# 50 spawns nothing
#1-39+ 40 does nothing.
if index <= 39:
pass
# if greater than or equal to 40, and less than or equal to 48 it spawns stuff
elif index >= 40 and index <= 48:
get_tree().current_scene.missile_spawn(marker.global_position)
#get_tree().current_scene.missile_spawn(marker.global_position)
func _on_area_entered(area):
if area is player:
area.take_damage(1)
func _on_death_timer_timeout():
queue_free() # Replace with function body.
func _on_firing_timer_timeout():
can_shoot = true

17
Scripts/missile.gd Normal file
View File

@@ -0,0 +1,17 @@
extends Area2D
var speed = 200
@onready var FirstStage = $CollisionShape2D
@onready var SecondStage = $CollisionPolygon2D
func _physics_process(delta):
global_position.y += -speed * delta
func _on_area_entered(area):
if area.is_in_group("enemies"):
FirstStage.disabled = true
SecondStage.disabled = false
area.take_damage(5)
queue_free()

26
Scripts/missile_pickup.gd Normal file
View File

@@ -0,0 +1,26 @@
extends Area2D
var speed = 200
func _ready():
$pickup_despawn.start()
#print("ready started")
func _physics_process(delta):
global_position.y += speed * delta
#asset clean up
if global_position.y > 980:
queue_free()
func _on_area_entered(area):
if area is player:
get_tree().current_scene.missile_container()
queue_free()
#timer might be redundant, remove later
func _on_pickup_despawn_timeout():
print("time out")
queue_free()

78
Scripts/player.gd Normal file
View File

@@ -0,0 +1,78 @@
extends Area2D
class_name player
#setting up signals
signal spawn_laser(location)
signal spawn_missile(location)
#loading the muzzle position on load
@onready var muzzle = $muzzle
#speed, health and direction, direction is for future animations vector sets up an Axis.
var speed = 250
var health = 3
var direction = "none"
var input_vector = Vector2()
var missile_total = 3
var missile_current = 3
#mostly movement stuff below, + some firing commands, check happens between every frame
func _physics_process(delta):
input_vector.x = 0
if Input.is_action_pressed("move_right"):
input_vector.x += 1
direction = "right"
if Input.is_action_pressed("move_left"):
input_vector.x -= 1
direction = "left"
input_vector.y = 0
if Input.is_action_pressed("move_forward"):
#print("fwd")
input_vector.y -= 1
if Input.is_action_pressed("move_back"):
input_vector.y += 1
global_position += input_vector * speed * delta
if Input.is_action_just_pressed("shoot"):
$AnimatedSprite2D.play("shoot")
shoot_laser()
#$AnimatedSprite2D.play("default")
#Missile launching signal
if Input.is_action_just_pressed("fire_missile"):
if missile_current > 0:
$AnimatedSprite2D.play("shoot")
shoot_missile()
missile_current -= 1
print(str(missile_current))
else:
print("No Missiles")
#if entering an area with enemy, DO damage.
func take_damage(damage):
health -= damage
get_tree().current_scene.player_health(health)
if health <= 0:
get_tree().current_scene.player_health(health)
queue_free()
#if entering an area with enemy = collision, does 1 damage
func _on_area_entered(area):
if area.is_in_group("enemies"):
area.take_damage(1)
#sends laser shoot command to worl + muzzle position
func shoot_laser():
emit_signal("spawn_laser",muzzle.global_position)
#sends missile launch command to world + muzzle position
func shoot_missile():
emit_signal("spawn_missile",muzzle.global_position)
func refil_missiles():
if missile_current < missile_total:
missile_current = missile_total
else:
pass