Example #1
0
 /// <summary>
 /// Loads the content of the class
 /// </summary>
 protected override void LoadContent()
 {
     spriteBatch = new SpriteBatch(GraphicsDevice);
     imageAlien = game.Content.Load<Texture2D>(img);
     al = new Alien(imageAlien.Width, imageAlien.Height, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, x, y, pts);
     base.LoadContent();
 }
Example #2
0
 public virtual void visitAlien(Alien a, CollisionPair p)
 {
     Debug.Assert(false, "Shouldn't have been called");
 }
Example #3
0
 public override void visitAlien(Alien a, CollisionPair p)
 {
     p.notify(a, this);
 }
Example #4
0
        void UpdateState()
        {
            // aktualizujeme výstřely
            UpdateShots(shots);
            UpdateShots(alienShots);

            // aktualizujeme vetřelci
            for (int row = 0; row < alienRows; row++)
            {
                for (int col = 0; col < alienCols; col++)
                {
                    if (aliens[row][col] == null)
                    {
                        continue;
                    }

                    Alien alien = aliens[row][col];

                    if (alien.shooted > 0)
                    {
                        alien.shooted--;

                        if (alien.shooted == 0)
                        {
                            alien = null;
                        }
                    }

                    aliens[row][col] = alien;
                }
            }

            // aktualizujeme zbraň
            if (gunShooted > 0)
            {
                gunShooted--;
            }

            gun.x += gun.dx;
            gun.x  = Math.Max(gunWidth / 2, gun.x);
            gun.x  = Math.Min(gameWidth - gunWidth / 2, gun.x);
            gun.dx = gun.dx - Math.Sign(gun.dx);

            // aktualizujeme ufo
            if (ufo != null)
            {
                if (ufo.shooted > 0)
                {
                    ufo.shooted--;

                    if (ufo.shooted == 0)
                    {
                        ufo = null;
                    }
                }
                else
                {
                    ufo.x++;

                    if (ufo.x >= gameWidth - ufoWidth)
                    {
                        ufo = null;
                    }
                }
            }
        }
Example #5
0
        // zpracování křížení výstřely
        void HitProcessing()
        {
            // zasah do vetřelce
            for (int i = alienRows - 1; i >= 0; i--)
            {
                for (int j = 0; j < alienCols; j++)
                {
                    Alien alien = aliens[i][j];

                    if (alien == null)
                    {
                        continue;
                    }

                    int[,] cells = alien.state ? aliensCells[alien.index] : aliensCells2[alien.index];

                    for (int k = 0; k < shots.Count; k++)
                    {
                        if (CheckHit(shots[k].x, shots[k].y, shots[k].cells, alien.x, alien.y, cells))
                        {
                            alien.shooted = 10;
                            scores       += alien.score;

                            gameTime -= deltaTime;

                            if (gameTime < endTime)
                            {
                                gameTime = endTime;
                            }

                            aliens[i][j] = alien;

                            shots.RemoveAt(k);
                            break;
                        }
                    }
                }
            }

            if (ufo != null)
            {
                for (int i = 0; i < shots.Count; i++)
                {
                    if (CheckHit(shots[i].x, shots[i].y, shots[i].cells, ufo.x, ufo.y, ufoCells))
                    {
                        scores     += ufoScores; // body za zasah do UFO
                        ufo.shooted = 20;

                        shots.RemoveAt(i);
                        break;
                    }
                }
            }

            // zpracování zasáhu do bunkru
            for (int i = 0; i < bunkersCount; i++)
            {
                Bunker bunker = bunkers[i];

                for (int j = alienShots.Count - 1; j >= 0; j--)
                {
                    if (CheckHit(alienShots[j].x, alienShots[j].y, alienShots[j].cells, bunker.x, bunker.y, bunker.cells))
                    {
                        ShotBunker(ref bunker, alienShots[j]);
                        alienShots.RemoveAt(j);

                        bunkers[i] = bunker;
                    }
                }

                for (int j = shots.Count - 1; j >= 0; j--)
                {
                    if (CheckHit(shots[j].x, shots[j].y, shots[j].cells, bunker.x, bunker.y, bunker.cells))
                    {
                        ShotBunker(ref bunker, shots[j]);
                        shots.RemoveAt(j);

                        bunkers[i] = bunker;
                    }
                }
            }

            // zpracování zasahu dvou výstřelu
            for (int i = shots.Count - 1; i >= 0; i--)
            {
                for (int j = alienShots.Count - 1; j >= 0; j--)
                {
                    if (CheckHit(shots[i].x, shots[i].y, shots[i].cells, alienShots[j].x, alienShots[j].y, alienShots[j].cells))
                    {
                        shots.RemoveAt(i);
                        alienShots.RemoveAt(j);
                        break;
                    }
                }
            }

            // zpracování zasáhu do zbraňe
            for (int i = alienShots.Count - 1; i >= 0; i--)
            {
                if (CheckHit(alienShots[i].x, alienShots[i].y, alienShots[i].cells, gun.x - gunWidth / 2, gun.y, gunCells))
                {
                    lifes--;
                    gunShooted = 20;
                    alienShots.RemoveAt(i);
                }
            }
        }
Example #6
0
        /// <summary>
        /// Creates the spriteBatch and the alien.
        /// </summary>
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            alien = new Alien(positionX, positionY, imageAlien.Width,
                              imageAlien.Height, GraphicsDevice.Viewport.Width,
                              GraphicsDevice.Viewport.Height);
            base.LoadContent();
        }
 public virtual void VisitAlien(Alien a)
 {
     // no differed to subcass
     Debug.WriteLine("Visit by Alien not implemented");
     Debug.Assert(false);
 }
Example #8
0
 public override void visitAlien(Alien a, CollisionPair p)
 {
     p.collision((GameObject)this.child, a);
 }
Example #9
0
 public void SetRight(Alien alien)
 {
     rightMostAlien = alien;
 }
Example #10
0
 public void SetLeft(Alien alien)
 {
     leftMostAlien = alien;
 }