65 lines
2.1 KiB
C#
65 lines
2.1 KiB
C#
|
using Godot;
|
||
|
using System;
|
||
|
|
||
|
public partial class lazer : StaticBody2D
|
||
|
{
|
||
|
//named lazer because Zs are cooler than Ss
|
||
|
//I just tweaked the ghost code, cause it works.
|
||
|
|
||
|
private Area2D probe; // probe to find the tile in the in the direction of the lazer's movement
|
||
|
public AnimatedSprite2D sprite; // animated sprite of lazer
|
||
|
private bool destroy; //if lazer should be destroyed
|
||
|
public int pause = 3; //timer for when processing needs to occur
|
||
|
//hmm this seems similar to the one from EvilEye... sure would make it easy to share this variable between them...
|
||
|
public int direction; //left-1 right-2 up-3 down-4
|
||
|
|
||
|
private void _on_probe_body_entered(Node2D body)
|
||
|
{
|
||
|
if (body.IsInGroup("Wall")) // if probe detects walls
|
||
|
{
|
||
|
destroy = true; //next update the lazer will be erased
|
||
|
}
|
||
|
if (body.IsInGroup("Obsticals") && !body.IsInGroup("Lazer") && !body.IsInGroup("Ghost")) // if probe detects non-lazer, non-ghost obsticals
|
||
|
{
|
||
|
destroy = true; //next update the lazer will be erased
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public override void _Ready() // on startup
|
||
|
{
|
||
|
// setting starting coditions for variables
|
||
|
probe = GetNode<Area2D>("Probe");
|
||
|
sprite = GetNode<AnimatedSprite2D>("LazerSprite");
|
||
|
//yeah. it's kinda obvious that everything the lazer can do is determined by the evil eye, huh.
|
||
|
switch (direction)
|
||
|
{
|
||
|
case 1: sprite.Rotation = 3.1416f; probe.Position = new Vector2(-20,0); break;
|
||
|
case 2: sprite.Rotation = 0; probe.Position = new Vector2(20,0); break;
|
||
|
case 3: sprite.Rotation = 4.712f; probe.Position = new Vector2(0,-20); break;
|
||
|
case 4: sprite.Rotation = 1.5708f; probe.Position = new Vector2(0,20); break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public override void _PhysicsProcess(double delta) // updates multipul times a frame so movment happens propperly
|
||
|
{
|
||
|
//finished tasks become functions
|
||
|
if (pause == 0)
|
||
|
{
|
||
|
//destruction happens before everything else
|
||
|
//think of it as a permanent break();
|
||
|
if(destroy == true)
|
||
|
{
|
||
|
QueueFree();
|
||
|
}
|
||
|
move();
|
||
|
pause = 3;
|
||
|
//no animations because the lazer gets synced by it's parent
|
||
|
}
|
||
|
}
|
||
|
public void move()
|
||
|
{
|
||
|
//just goes forwards really fast
|
||
|
GlobalPosition = probe.GlobalPosition; //player position changes to probe's position
|
||
|
}
|
||
|
}
|