source: 2010/23/hniemi/ShootEmUp/ShootEmUp/Weapons.cs @ 955

Revision 955, 5.9 KB checked in by hniemi, 13 years ago (diff)

Vihollisalus lisätty, Hudia paranneltu

Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using Jypeli;
6using Jypeli.ScreenObjects;
7using Jypeli.Assets;
8
9namespace ShootEmUp
10{
11    /// <summary>
12    /// Säilyttää aseita ja aluksia varten tagissa tietoa
13    /// </summary>
14    struct LisaData
15    {
16        public int Damage;
17        public string Tyyppi;
18        public bool Rajahtaa;
19    }
20
21    /// <summary>
22    /// Sädease
23    /// Ampuu sinisen säteen
24    /// </summary>
25    class Beam : Weapon
26    {
27        private Image ammus;
28        public int Damage { get; set; }
29        public int Level { get; private set; }
30        public CollisionHandler BeamCollision { get; set; }
31
32
33        public Beam(double width, double height)
34            : base(width, height)
35        {
36            Level = 1;
37            Color = Color.Blue;
38            Damage = 20;
39            this.AddedToGame += LisaaAV;
40            this.TimeBetweenUse = (new TimeSpan(0, 0, 0, 0, 5));
41            this.IsVisible = false;
42        }
43
44        /// <summary>
45        /// Lisää kuvan ja äänen aseeseen
46        /// </summary>
47        private void LisaaAV()
48        {
49            //AttackSound = Game.LoadSoundEffect("pum");
50            ammus = Game.LoadImage("sade");
51        }
52
53        protected override void OnUse()
54        {
55            OnShoot();
56        }
57
58        protected override PhysicsObject OnShoot()
59        {
60
61            PhysicsObject projectile = new PhysicsObject(Level * 35, Level * 5);
62
63            LisaData ammus;
64            ammus.Damage = 3;
65            ammus.Rajahtaa = false;
66            ammus.Tyyppi = "oma";
67            projectile.Tag = ammus;
68
69            projectile.Image = this.ammus;
70            projectile.Position = this.Position;
71            projectile.Color = this.Color;
72            projectile.IgnoresExplosions = true;
73            projectile.IgnoresCollisionResponse = true;
74            SetCollisionHandler(projectile, BeamCollision);
75            ShootProjectile(projectile, 3000 + (Math.Sin(Game.Time.SinceStartOfGame.Milliseconds) * 100));
76
77            return projectile;
78        }
79    }
80
81    /// <summary>
82    /// Ohjus-ase
83    /// Ampuu räjähtävän ohjuksen
84    /// </summary>
85    class Missile : Weapon
86    {
87        private Image ammus;
88        public int Level { get; private set; }
89        public CollisionHandler MissileCollision { get; set; }
90        public int Damage { get; set; }
91
92        public Missile(double width, double height)
93            : base(width, height)
94        {
95            Level = 1;
96            Damage = 20;
97            this.IsVisible = false;
98            this.TimeBetweenUse = (new TimeSpan(0,0,0,0,300));
99            Color = Color.Blue;
100            this.AddedToGame += LisaaAV;
101            LisaData ase;
102            ase.Damage = 20;
103            ase.Rajahtaa = true;
104            ase.Tyyppi = "oma";
105            this.Tag = ase;
106        }
107
108        /// <summary>
109        /// Lisää äänen ja kuvan aseeseen
110        /// </summary>
111        private void LisaaAV()
112        {
113            //AttackSound = Game.LoadSoundEffect("pum");
114            ammus = Game.LoadImage("ohjus");
115        }
116
117        protected override void OnUse()
118        {
119            OnShoot();
120        }
121
122        protected override PhysicsObject OnShoot()
123        {
124           
125            if (!this.IsDestroyed())
126            {
127                PhysicsObject projectile = new PhysicsObject(Level * 30, Level * 15);
128                projectile.Shape = Shapes.Triangle;
129                projectile.Position = this.Position;
130                projectile.Color = this.Color;
131                projectile.Image = this.ammus;
132                SetCollisionHandler(projectile, MissileCollision);
133                ShootProjectile(projectile, 1000);
134                projectile.IgnoresExplosions = true;
135                projectile.IgnoresCollisionResponse = true;
136
137                projectile.Tag = this.Tag;
138
139                return projectile;
140            }
141            return null;
142        }
143    }
144
145    /// <summary>
146    /// Photon-ase
147    /// Ampuu pallon
148    /// </summary>
149    class Photon : Weapon
150    {
151        private Image ammus;
152        public int Level { get; private set; }
153        public CollisionHandler PhotonCollision { get; set; }
154        public int Damage { get; set; }
155
156        public Photon(double width, double height): base(width, height)
157        {
158            Level = 1;
159            Damage = 20;
160            this.TimeBetweenUse = (new TimeSpan(0,0,0,0,150));
161            Color = Color.Blue;
162            this.AddedToGame += LisaaAani;
163            this.IsVisible = false;
164
165            //Tagi
166            LisaData ase;
167            ase.Damage = 20;
168            ase.Rajahtaa = false;
169            ase.Tyyppi = "oma";
170            this.Tag = ase;
171        }
172
173        /// <summary>
174        /// Lisää äänen
175        /// </summary>
176        private void LisaaAani()
177        {
178            //AttackSound = Game.LoadSoundEffect("pum");
179            ammus = Game.LoadImage("photon");
180        }
181
182        protected override void OnUse()
183        {
184            OnShoot();
185        }
186
187        protected override PhysicsObject OnShoot()
188        {
189
190            if (!this.IsDestroyed())
191            {
192                PhysicsObject projectile = new PhysicsObject(Level * 15, Level * 15);
193                projectile.Shape = Shapes.Circle;
194                projectile.Position = this.Position;
195                projectile.Color = this.Color;
196                projectile.Image = this.ammus;
197                SetCollisionHandler(projectile, PhotonCollision);
198                ShootProjectile(projectile, 2000);
199                projectile.IgnoresExplosions = true;
200                projectile.IgnoresCollisionResponse = true;
201
202                projectile.Tag = this.Tag;
203                return projectile;
204            }
205            return null;
206        }
207    }
208}
Note: See TracBrowser for help on using the repository browser.