-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProjectile.cs
68 lines (56 loc) · 1.77 KB
/
Projectile.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
namespace Nitemare3D
{
public enum ProjectileType
{
Plasma,
Magic
}
public class Projectile : Entity, ISprite
{
static Animation[] animations = new Animation[]
{
new Animation(666, 2, 125), //plasma
new Animation(671, 3, 125) //magic
};
AnimationHandler anim = new AnimationHandler();
public int spriteIndex {get; set;}
public bool visible{get;set;} = true;
public Vec2 spritePosition{get;set;} = new Vec2();
public float yOffset{get;set;}
const float speed = 4;
ProjectileType type;
Vec2 direction;
public Projectile(Vec2 direction, ProjectileType type)
{
this.direction = direction;
this.type = type;
anim.LoadAnimation(animations[(int)type]);
Game.player.AddSprite(this);
hasCollision = false;
}
public override void Update()
{
anim.Update();
position += direction * speed * Time.dt;
spritePosition = position;
spriteIndex = anim.index;
bool delete = false;
foreach(var entity in entities)
{
if(entity.id == id || entity.id == Game.player.id){continue;}
if(entity.position.Rounded().Equals(position.Rounded()))
{
delete = entity.hasCollision;
entity.SendMessage("ShootPlasma");
return;
}
}
if(!Level.IsWalkable((int)position.X, (int)position.Y, this))
{
delete = true;
}
if(delete){Entity.Remove(this); visible = false;}
}
}
}