Exemple #1
0
    public Ufo(FixedPointVector3 _pos, FixedPoint _diameter)
    {
        type = EntityType.Ufo;

        originPosition          = _pos;
        speed                   = Extensions.Range(0.5f, 1f);
        orbitRadius             = scale;
        asteroidDetectionRadius = _diameter * 5;

        health = 20;

        body = new CircleBody(originPosition, _diameter * (FixedPoint)0.5f, this);

        body.SetLayer(type);
        body.SetCollidesWith(EntityType.Asteroid, true);
        body.SetCollidesWith(EntityType.Blast, true);
        body.SetCollidesWith(EntityType.Placeholder, true);
        body.SetCollidesWith(EntityType.Ufo, true);

        //randomize rotations
        if (Random.value > 0.5f)
        {
            orbitSpeedPerSecond = -orbitSpeedPerSecond;
        }

        currentOrbitAngle = Extensions.Range(0, Mathf.PI * 2);

        behavior = new UfoBehavior(this);
    }
Exemple #2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            this.IsMouseVisible = true;

            var w = (float)graphics.PreferredBackBufferWidth;
            var h = (float)graphics.PreferredBackBufferHeight;

            CollisionEngine.Init(new Region(0, (float)w, 0, (float)h), 10);
            PE = new PhysicsEngine();


            var w0 = new VertWallBody(new Vector2(0, h / 2), h);
            var w1 = new VertWallBody(new Vector2(w, h / 2), h);

            var w2 = new HorizWallBody(new Vector2(w / 2, 0), w);
            var w3 = new HorizWallBody(new Vector2(w / 2, h), w);

            PE.MapBodies.Add(w0);
            PE.MapBodies.Add(w1);
            PE.MapBodies.Add(w2);
            PE.MapBodies.Add(w3);


            var c0 = new CircleBody(30, 300, new Vector2(600, h / 2));

            c0.Velocity = -1000 * Vector2.UnitX;
            PE.ActiveBodies.Add(c0);


            Random rand = new Random();

            int nx  = 40;
            int ny  = 30;
            var rad = 4f;
            var buf = 0f;
            var pos = new Vector2(w / 2 - nx * (2f * rad + buf) / 2f, h / 2 - ny * (2f * rad + buf) / 2f);

            for (int xi = 0; xi < nx; xi++)
            {
                for (int yi = 0; yi < ny; yi++)
                {
                    var cent = pos + new Vector2((2f * rad + buf) * xi, (2f * rad + buf) * yi);
                    var ball = new CircleBody(rad, rad, cent);
                    PE.ActiveBodies.Add(ball);
                }
            }



            base.Initialize();
        }
Exemple #3
0
    public Asteroid(FixedPointVector3 _pos, FixedPoint _scale)
    {
        position = _pos;
        scale    = _scale;
        speed    = Extensions.Range(1, 2);
        health   = 5;
        type     = EntityType.Asteroid;

        body = new CircleBody(position, scale * (FixedPoint)0.5f, this);

        body.SetLayer(type);
        body.SetCollidesWith(EntityType.Ufo, true);
        body.SetCollidesWith(EntityType.Asteroid, true);
        body.SetCollidesWith(EntityType.Blast, true);
        body.SetCollidesWith(EntityType.Placeholder, true);

        behavior = new  AsteroidBehavior(this);
    }