Jypeli  9
The simple game programming library
ShootingPlatformCharacter.cs
Siirry tämän tiedoston dokumentaatioon.
1 using Jypeli;
2 using System;
3 
8 {
9  public ShootingPlatformCharacter(double width, double height) : base(width, height)
10  {
12  }
13 
14  public ShootingPlatformCharacter(double width, double height, Shape shape) : base(width, height, shape)
15  {
17  }
18 
19  private TimeSpan _timeBetweenShots = TimeSpan.FromSeconds(1.0);
20 
24  public TimeSpan TimeBetweenShots
25  {
26  get { return _timeBetweenShots; }
27  set
28  {
29  _timeBetweenShots = value;
30  if (timer != null)
31  timer.Interval = value.TotalSeconds;
32  }
33  }
34 
38  public GameObject Target { get; set; }
39 
44  public double MaximumShootingDistance { get; set; } = double.MaxValue;
45 
46  private Timer timer;
47 
48  public override void Destroy()
49  {
50  base.Destroy();
52  }
53 
55  {
56  if (timer != null)
57  timer.Stop();
58 
60  }
61 
62  private void Shoot()
63  {
64  if (Weapon == null || Target == null || IsDestroyed || !IsAddedToGame ||
65  Target.IsDestroyed || !Target.IsAddedToGame)
66  return;
67 
68  Vector distanceVector = Target.AbsolutePosition - AbsolutePosition;
69 
70  if (distanceVector.Magnitude > MaximumShootingDistance)
71  return;
72 
73  Weapon.Shoot();
74  }
75 
76  public override void Update(Time time)
77  {
78  if (Weapon == null || Target == null || Target.IsDestroyed || !Target.IsAddedToGame)
79  return;
80 
81  Vector distanceVector = Target.AbsolutePosition - AbsolutePosition;
82 
83  if (distanceVector.Magnitude > MaximumShootingDistance)
84  return;
85 
86  Weapon.Angle = distanceVector.Angle;
87 
88  base.Update(time);
89  }
90 }
PlatformCharacter
Tasohyppelypelin hahmo. Voi liikkua ja hyppiä. Lisäksi sillä voi olla ase.
Definition: PlatformCharacter.cs:17
ShootingPlatformCharacter.ShootingPlatformCharacter
ShootingPlatformCharacter(double width, double height)
Definition: ShootingPlatformCharacter.cs:9
Jypeli
Definition: Automobile.cs:5
ShootingPlatformCharacter.TimeBetweenShots
TimeSpan TimeBetweenShots
Aika, joka kuluu ennen kuin hahmo ampuu.
Definition: ShootingPlatformCharacter.cs:25
ShootingPlatformCharacter._timeBetweenShots
TimeSpan _timeBetweenShots
Definition: ShootingPlatformCharacter.cs:19
ShootingPlatformCharacter.Target
GameObject Target
Kohde, jota hahmo ampuu.
Definition: ShootingPlatformCharacter.cs:38
Jypeli.Shape
Kuvio.
Definition: Shapes.cs:47
ShootingPlatformCharacter.timer
Timer timer
Definition: ShootingPlatformCharacter.cs:46
PlatformCharacter.Weapon
Weapon Weapon
Hahmolla oleva ase.
Definition: PlatformCharacter.cs:155
Jypeli.GameObject.IsAddedToGame
bool IsAddedToGame
Onko olio lisätty peliin.
Definition: GameConnection.cs:8
ShootingPlatformCharacter.ShootingPlatformCharacter
ShootingPlatformCharacter(double width, double height, Shape shape)
Definition: ShootingPlatformCharacter.cs:14
ShootingPlatformCharacter.Update
override void Update(Time time)
Definition: ShootingPlatformCharacter.cs:76
ShootingPlatformCharacter.ShootingPlatformCharacter_AddedToGame
void ShootingPlatformCharacter_AddedToGame()
Definition: ShootingPlatformCharacter.cs:54
ShootingPlatformCharacter
Tasohyppelypelin hahmo, joka ampuu aseella automaattisesti määritellyin väliajoin.
Definition: ShootingPlatformCharacter.cs:8
ShootingPlatformCharacter.Destroy
override void Destroy()
Definition: ShootingPlatformCharacter.cs:48
Jypeli.Time
Sisältää tiedon ajasta, joka on kulunut pelin alusta ja viime päivityksestä.
Definition: Time.cs:14
Jypeli.Timer.Interval
double Interval
Aika sekunneissa, jonka välein TimeOut tapahtuu.
Definition: Timer.cs:87
Jypeli.Vector.Angle
Angle Angle
Kulma radiaaneina.
Definition: Vector.cs:346
Jypeli.Timer.Stop
void Stop()
Pysäyttää ajastimen ja nollaa sen tilan.
Definition: Timer.cs:292
ShootingPlatformCharacter.MaximumShootingDistance
double MaximumShootingDistance
Korkein etäisyys, jonka päästä hahmo ampuu. Jos hahmo on tätä kauempana kohteesta,...
Definition: ShootingPlatformCharacter.cs:44
Jypeli.Vector.Magnitude
double Magnitude
Vektorin pituus.
Definition: Vector.cs:319
Jypeli.Vector
2D-vektori.
Definition: Vector.cs:59
System
Definition: CFFauxAttributes.cs:29
Jypeli.Timer
Ajastin, joka voidaan asettaa laukaisemaan tapahtumia tietyin väliajoin.
Definition: Timer.cs:38
Jypeli.GameObject
Pelialueella liikkuva olio. Käytä fysiikkapeleissä PhysicsObject-olioita.
Definition: Appearance.cs:34
Jypeli.Timer.CreateAndStart
static Timer CreateAndStart(double interval, Action onTimeout)
Luo ja käynnistää uuden ajastimen tietyllä tapahtuma-aikavälillä sekä aliohjelmalla,...
Definition: Timer.cs:207
ShootingPlatformCharacter.Shoot
void Shoot()
Definition: ShootingPlatformCharacter.cs:62