-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhoton.cs
More file actions
101 lines (84 loc) · 3.59 KB
/
Photon.cs
File metadata and controls
101 lines (84 loc) · 3.59 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Drawing;
using System.Media;
using AsteroidsGdiApp.Core;
namespace AsteroidsGdiApp.GameObjects
{
public class Photon : IGameObject
{
private float _maxDistance;
private float _distanceTraveled = Constants.MaxEnemyBulletDistance + 1;
protected Sprite _bulletSprite = new Sprite();
protected Point _location = new Point(0, 0);
private PhotonTimeManager _photonTimeManager;
public void Fire(Point startLocation, double direction, float maxDistance, PhotonTimeManager photoTimeManager)
{
_photonTimeManager = photoTimeManager;
if(!EnoughTimeHasPassed())
return;
_maxDistance = maxDistance;
_distanceTraveled = 0;
_bulletSprite = new Sprite();
SoundPlayer player = new SoundPlayer();
System.IO.Stream str = Properties.Resources.mySoundFile;
System.Media.SoundPlayer snd = new System.Media.SoundPlayer(@"C:\Users\keife\Downloads\Backup-20200818T045439Z-001\Backup\GameObjects\380gunshotsinglemikekoenig.wav");
snd.Play();
_bulletSprite.Polygon = new[]
{
new Point(startLocation.X, startLocation.Y),
new Point(startLocation.X+1, startLocation.Y+1),
new Point(startLocation.X, startLocation.Y)
};
_bulletSprite.Speed = Constants.BulletSpeed;
_bulletSprite.TravelDirectionInDegrees = direction;
_location = startLocation;
_photonTimeManager.SetFired();
}
private bool EnoughTimeHasPassed()
{
return _photonTimeManager.EnoughTimeHasPassed();
}
public Point Location
{
get { return _location; }
}
public bool IsActive
{
get
{
return _distanceTraveled < _maxDistance;
}
}
public void Update()
{
if (_bulletSprite != null && IsActive)
{
double radians = _bulletSprite.TravelDirectionInDegrees.DegreesToRadians();
_location.X += (int)(_bulletSprite.Speed * Math.Cos(radians));
_location.Y += (int)(_bulletSprite.Speed * Math.Sin(radians));
if (_location.X < 0)
_location.X = Constants.CanvasWidth;
if (_location.X > Constants.CanvasWidth)
_location.X = 0;
if (_location.Y < 0)
_location.Y = Constants.CanvasWidth;
if (_location.Y > Constants.CanvasWidth)
_location.Y = 0;
_distanceTraveled += _bulletSprite.Speed;
}
}
public virtual void Draw(Graphics graphics)
{
if(_bulletSprite != null && IsActive)
{
_bulletSprite.Polygon = new Point[] { new Point(-1 + _location.X, -1 + _location.Y), new Point(-1 + _location.X, 1 + _location.Y), new Point(1 + _location.X, _location.Y), new Point(-1 + _location.X, -1 + _location.Y) };
Point[] clone = _bulletSprite.Polygon.ClonePolygon();
graphics.DrawPolygon(Pens.White, clone);
}
}
public void SetInactive()
{
_distanceTraveled = _maxDistance + 1;
}
}
}