Пример #1
2
        private void MainForm_Load(object sender, EventArgs e)
        {
            theControl = new OpenTK.GLControl();
            theControl.Dock = DockStyle.Fill;
            Controls.Add(theControl);
            OpenTK.Graphics.GL.Viewport(0, 0, this.Width, this.Height);

            Program.mainFormWidth = this.Width;
            Program.mainFormHeight = this.Height;

            Program.theMixer = new Mixer();

            theGameWorld = new GameWorld();
            theRenderer = new Renderer(theGameWorld);

            theControl.MouseDown += MainForm_MouseDown;
            theControl.MouseUp += MainForm_MouseUp;
            theControl.KeyDown += MainForm_KeyDown;
            theControl.KeyUp += MainForm_KeyUp;

            theControl.MouseWheel += MainForm_MouseWheel;

            Application.Idle += appIdle;
            System.Threading.Thread t = new System.Threading.Thread(worldLoop);
            t.Name = "World tick loop";
            t.IsBackground = true;
            t.Start();
            Cursor.Hide();
        }
Пример #2
0
 public Renderer(GameWorld theWorld)
 {
     this.theWorld = theWorld;
     backgroundTexture = createTexture(Properties.Resources.Background);
     invertBackgroundTexture2 = createTexture(Properties.Resources.InvertedBackground2);
     invertBackgroundTexture = createTexture(Properties.Resources.InvertedBackground);
     pathTexture = createTexture(Properties.Resources.PathTexture);
     enemyTexture = createTexture(Properties.Resources.EnemySprite);
     flashTexture = createTexture(Properties.Resources.Flash);
     playerTexture = createTexture(Properties.Resources.Player);
 }
Пример #3
0
        public void tick(GameWorld w)
        {
            if (dead)
                return;
            this.rotation += this.rotSpeed;
            this.position += this.speed;
            if (enemy)
                this.speed += (w.currentPlayer.position - this.position).Normalized() * 0.003f;

            for (int i = 0; i < 3 * w.particleMultiplier(position); i++)
            {
                if (enemy)
                {
                    Particle pz = new Particle(this.position, new OpenTK.Vector2(((float)r.NextDouble() * 0.4f) - 0.2f, ((float)r.NextDouble() * 0.4f) - 0.2f), System.Drawing.Color.Cornsilk, 1.0f);
                    w.addParticle(pz);
                }
                else
                {
                    Particle pz = new Particle(this.position, new OpenTK.Vector2(((float)r.NextDouble() * 0.4f) - 0.2f, ((float)r.NextDouble() * 0.4f) - 0.2f), System.Drawing.Color.Azure, 1.0f);
                    w.addParticle(pz);
                }
            }
            if (w.currentPlayer.health > 0.0f)
            {
                if (enemy && (((this.position - w.currentPlayer.position).LengthFast < 3.0f) || ((w.currentPlayer.parent.position - position).Length < w.currentPlayer.parent.radius)))
                {
                    dead = true;
                    w.currentPlayer.hurting = 1.0f;
                    w.currentPlayer.health -= 8.0f + ((float)r.NextDouble() * 7.0f);

                    if(w.currentPlayer.health > 0.0f)
                        Program.theMixer.addSource(Properties.Resources.Hurtd, 1.0f / (((w.currentPlayer.position - position).Length / 10.0f) + 1.0f));
                    else
                        Program.theMixer.addSource(Properties.Resources.Death, 1.0f);

                    for (int i = 0; i < 30 * w.particleMultiplier(position); i++)
                    {
                        Particle pz = new Particle(this.position, new OpenTK.Vector2(((float)r.NextDouble() * 0.4f) - 0.2f, ((float)r.NextDouble() * 0.4f) - 0.2f), System.Drawing.Color.Blue, 1.0f);
                        w.addParticle(pz);
                    }
                    
                }
            }
            if (dead)
                return;
            foreach (Planet p in w.planets)
            {
                //this.speed += 0.05f * ((p.position - this.position).Normalized() / (((this.position - p.position).Length) + 1.0f)) * (float)(Math.Sqrt(p.radius / 2.0f));
                this.speed += 1.0f * ((p.position - this.position).Normalized() / (((this.position - p.position).LengthSquared) + 1.0f)) * (float)(Math.Sqrt(p.radius / 2.0f)+0.5f);

                if ((p.position - position).Length < p.radius)
                {
                    Program.theMixer.addSource(Properties.Resources.PingHit, 1.0f / (((w.currentPlayer.position - position).Length / 10.0f) + 1.0f));
                    dead = true;
                }
            }


            if (position.Length > 300.0f)
                dead = true;
        }
Пример #4
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;

        }