Exemple #1
0
        public void addProjectile(Projectile p)
        {
            lock (theProjectiles)
                theProjectiles.Add(p);

        }
Exemple #2
0
        public void tick(GameWorld w)
        {
            if (dead)
                return;

            position = position + speed;

            //deflect with planets
            foreach (Planet p in w.planets)
            {
                this.speed += ((p.position - this.position).Normalized() / (((this.position - p.position).LengthSquared) + 1.0f)) * (float)(Math.Sqrt(p.radius / 2.0f)) * 0.1f;

                //if ((p.position - position).Length < p.radius)
                //    dead = true;
            }

            //attracted towards player
            //if(this.position.Length > 50.0f)
                this.speed +=(w.currentPlayer.position - this.position).Normalized() *  0.001f;

            foreach (Projectile p in w.projectiles)
                if ((p.position - position).LengthFast < 7.0f && !p.enemy)
                {
                    for (int i = 0; i < 800 * w.particleMultiplier(position); i++)
                    {
                        Particle pz = new Particle(this.position, new OpenTK.Vector2(((float)r.NextDouble() * 0.8f) - 0.4f, ((float)r.NextDouble() * 0.8f) - 0.4f), System.Drawing.Color.White,5.0f);
                        w.addParticle(pz);
                    }

                    for (int i = 0; i < 2; i++)
                    {
                        Particle pz2 = new Particle(this.position, new OpenTK.Vector2(((float)r.NextDouble() * 0.04f) - 0.02f, ((float)r.NextDouble() * 0.4f) - 0.2f), System.Drawing.Color.White, 20.0f);
                        pz2.flash = true;
                        w.addParticle(pz2);
                    }

                    Program.theMixer.addSource(Properties.Resources.FakeExplosion, 1.0f / (((w.currentPlayer.position - position).Length / 50.0f) + 1.0f));

                    dead = true;
                    p.dead = true;
                }

            if (DateTime.Now.Subtract(lastShot).TotalMilliseconds > nextFireRate)
            {
                Program.theMixer.addSource(Properties.Resources.EnemyShoot, 1.0f / (((w.currentPlayer.position - position).Length / 10.0f) + 1.0f));

                OpenTK.Vector2 v = (this.position - w.currentPlayer.position).Normalized();

                v.X += (float)r.NextDouble() - (float)r.NextDouble();
                v.Y += (float)r.NextDouble() - (float)r.NextDouble();
                OpenTK.Vector2 vz = v * 0.1f;
                Projectile p = new Projectile(position, vz);
                p.enemy = true;
                w.addProjectile(p);
                lastShot = DateTime.Now;
                nextFireRate = fireRate + r.Next(200) - r.Next(200);


            }
            if (position.Length > 400.0f)
                position = position.Normalized() * 400.0f;

        }