]>
Commit | Line | Data |
---|---|---|
097781e6 BB |
1 | using System; |
2 | using System.Collections.Generic; | |
3 | using System.Linq; | |
4 | using System.Text; | |
5 | using Microsoft.Xna.Framework; | |
6 | ||
7 | namespace SuperPolarity | |
8 | { | |
9 | class BasicGenerator | |
10 | { | |
11 | public enum Ships : byte { Ship, Scout, Battlecruiser }; | |
12 | ||
13 | protected Ships ShipType; | |
14 | protected SuperPolarity Game; | |
15 | protected int ScoreThreshold; | |
16 | protected int Rate; | |
17 | protected int CurrentTime; | |
18 | protected Random Randomizer; | |
19 | protected Vector2 Position; | |
20 | ||
21 | public void Initialize(SuperPolarity game, Vector2 position, Ships shipType, int rate, int scoreThreshold) | |
22 | { | |
23 | Game = game; | |
24 | ShipType = shipType; | |
25 | ScoreThreshold = scoreThreshold; | |
26 | Rate = rate; | |
27 | Randomizer = new Random(); | |
28 | Position = position; | |
b587e9d8 | 29 | CurrentTime = rate; |
097781e6 BB |
30 | } |
31 | ||
32 | public void Update(GameTime gameTime) | |
33 | { | |
b587e9d8 BB |
34 | if (ActorManager.CountBaddies() > 50) |
35 | { | |
36 | return; | |
37 | } | |
38 | ||
39 | if (Game.Player.Score >= ScoreThreshold) | |
097781e6 BB |
40 | { |
41 | CurrentTime = CurrentTime + gameTime.ElapsedGameTime.Milliseconds; | |
42 | ||
43 | if (CurrentTime >= Rate) | |
44 | { | |
45 | CurrentTime = 0; | |
46 | Spawn(); | |
47 | } | |
48 | } | |
49 | } | |
50 | ||
51 | protected void Spawn() | |
52 | { | |
53 | var polarity = Ship.Polarity.Positive; | |
54 | ||
55 | if (Randomizer.Next(2) == 1) | |
56 | { | |
57 | polarity = Ship.Polarity.Negative; | |
58 | } | |
59 | ||
60 | if (ShipType == Ships.Ship) | |
61 | { | |
b587e9d8 | 62 | Renderer.CheckIn(ActorFactory.CreateShip(polarity, Position)); |
097781e6 BB |
63 | } |
64 | ||
65 | if (ShipType == Ships.Scout) | |
66 | { | |
b587e9d8 | 67 | Renderer.CheckIn(ActorFactory.CreateScout(polarity, Position)); |
097781e6 BB |
68 | } |
69 | ||
70 | if (ShipType == Ships.Battlecruiser) | |
71 | { | |
b587e9d8 | 72 | Renderer.CheckIn(ActorFactory.CreateCruiser(polarity, Position)); |
097781e6 BB |
73 | } |
74 | ||
75 | } | |
76 | } | |
77 | } |