Files
przygody-pana-cegly/scripts/components/beam_component.gd
Gabriel Kaszewski d84f7d1740 Csharp rewrite (#4)
* Implement BeamComponent in C# and enhance marketplace button functionality

* Add core game components including ConfigFileHandler, GameManager, SaveSystem, and UIManager

* cleanup

* Add new components: CanPickUpComponent, CollapsableComponent, DestroyableComponent, EffectInflictorComponent, StatusEffectComponent, and StatusEffectDataResource

* Add new components: EnemyDeathComponent, EnemyWaveTriggerComponent, and ExitDoorComponent

* Add new components: ExplosiveComponent, FadeAwayComponent, FireEffectComponent, FlipComponent, GravityMotionComponent, LaunchComponent, and update PlatformMovement with LastDirection property

* Add new components: HealComponent, HitComponent, HomingMissileMotionComponent, LeverComponent, and TriggerLeverComponent

* Refactor GameManager session state handling and add new components: CanBeLaunchedComponent, IceEffectComponent, JumpPadComponent, KillPlayerOutOfScreenComponent, KnockbackComponent, LifetimeComponent, MagneticSkillComponent, OutOfScreenComponent, PeriodicShootingComponent, PlayerDeathComponent, ProgressiveDamageComponent, ProjectileComponent, ProjectileInitComponent, RequirementComponent, ScoreComponent, ShipMovementComponent, ShipShooterComponent, and SideToSideMovementComponent

* Add new components: CannotStompComponent, SkillUnlockedComponent, SpaceshipEnterComponent, SpaceshipExitComponent, SpinComponent, StompDamageComponent, StraightMotionComponent, TerrainHitFx, TooltipComponent, TrailComponent, and UnlockOnRequirementComponent

* Add new components: BrickThrowComponent, BulletComponent, CageComponent, ChaseLevelComponent, CleanupComponent, and ThrowInputResource classes; implement game saving and loading logic in SaveSystem

* Add audio settings management and platform movement component

* Add ChargeProgressBar, Credits, and GameOverScreen components for UI management

* Add UID files for ConfigFileHandler, GameManager, SaveSystem, and UIManager components

* Add README.md file with game description and features; include project license and contribution guidelines

* Add Hud component for UI management; display health, coins, and lives

* Add MainMenu and Marketplace components; implement game management and skill unlocking features

* Add PauseMenu, SettingsMenu, and SkillButton components; enhance game management and UI functionality
2025-08-15 00:45:57 +02:00

65 lines
2.2 KiB
GDScript

# class_name BeamComponent
extends Node2D
@export var expansion_speed: float = 16.0
@export var max_length: float = 512.0
@export var direction: Vector2 = Vector2.DOWN
var current_length: float = 16.0
@export var root: Node2D
@export var sprite2d: Sprite2D
@export var collision_shape: CollisionShape2D
func _ready() -> void:
collision_shape.shape.extents = Vector2(current_length / 2.0, current_length / 2.0)
sprite2d.scale = Vector2(1, 1)
collision_shape.position = Vector2.ZERO
func _process(delta: float) -> void:
var new_length = current_length + expansion_speed * delta
if new_length > max_length:
new_length = max_length
if not check_for_obstacle(new_length):
expand_beam(new_length)
func expand_beam(new_length: float) -> void:
current_length = new_length
if direction == Vector2.UP:
sprite2d.scale.y = current_length / 16.0
sprite2d.position.y = -current_length / 2.0
collision_shape.shape.extents = Vector2(8.0, current_length / 2.0)
collision_shape.position.y = -current_length / 2.0
elif direction == Vector2.DOWN:
sprite2d.scale.y = current_length / 16.0
sprite2d.position.y = current_length / 2.0
collision_shape.shape.extents = Vector2(8.0, current_length / 2.0)
collision_shape.position.y = current_length / 2.0
elif direction == Vector2.LEFT:
sprite2d.scale.y = current_length / 16.0
sprite2d.position.x = -current_length / 2.0
collision_shape.shape.extents = Vector2(current_length / 2.0, 8.0)
collision_shape.position.x = -current_length / 2.0
elif direction == Vector2.RIGHT:
sprite2d.scale.y = current_length / 16.0
sprite2d.position.x = current_length / 2.0
collision_shape.shape.extents = Vector2(current_length / 2.0, 8.0)
collision_shape.position.x = current_length / 2.0
func check_for_obstacle(new_length: float) -> bool:
var space_state: PhysicsDirectSpaceState2D = get_world_2d().direct_space_state
var query_start: Vector2 = global_position
var query_end: Vector2 = global_position + direction * new_length
var query: PhysicsRayQueryParameters2D = PhysicsRayQueryParameters2D.create(query_start, query_end)
query.collide_with_areas = false
query.collide_with_bodies = true
var result: Dictionary = space_state.intersect_ray(query)
return result.size() > 0