aboutsummaryrefslogtreecommitdiff
path: root/SuperPolarity/BasicGenerator.cs
blob: fa4edeb21e6fead4e8bc957904cd22498f0ab028 (plain)
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace SuperPolarity
{
    class BasicGenerator
    {
        public enum Ships : byte { Ship, Scout, Battlecruiser };

        protected Ships ShipType;
        protected SuperPolarity Game;
        protected int ScoreThreshold;
        protected int Rate;
        protected int CurrentTime;
        protected Random Randomizer;
        protected Vector2 Position;

        public void Initialize(SuperPolarity game, Vector2 position, Ships shipType, int rate, int scoreThreshold)
        {
            Game = game;
            ShipType = shipType;
            ScoreThreshold = scoreThreshold;
            Rate = rate;
            Randomizer = new Random();
            Position = position;
            CurrentTime = rate;
        }

        public void Update(GameTime gameTime)
        {
            if (ActorManager.CountBaddies() > 50)
            {
                return;
            }

            if (Game.Player.Score >= ScoreThreshold)
            {
                CurrentTime = CurrentTime + gameTime.ElapsedGameTime.Milliseconds;

                if (CurrentTime >= Rate)
                {
                    CurrentTime = 0;
                    Spawn();
                }
            }
        }

        protected void Spawn()
        {
            var polarity = Ship.Polarity.Positive;

            if (Randomizer.Next(2) == 1)
            {
                polarity = Ship.Polarity.Negative;
            }

            if (ShipType == Ships.Ship)
            {
                Renderer.CheckIn(ActorFactory.CreateShip(polarity, Position));
            }

            if (ShipType == Ships.Scout)
            {
                Renderer.CheckIn(ActorFactory.CreateScout(polarity, Position));
            }

            if (ShipType == Ships.Battlecruiser)
            {
                Renderer.CheckIn(ActorFactory.CreateCruiser(polarity, Position));
            }

        }
    }
}