/// <summary>
 /// Create an alive object
 /// </summary>
 /// <param name="team">the team of the game object</param>
 /// <param name="coords">the position of the game object</param>
 /// <param name="drawable">the image to draw</param>
 /// <param name="soundHandler">the song container</param>
 /// <param name="life">the life of the imageObject</param>
 public AliveObject(Team team, Vector2D coords, Drawable drawable, SoundHandler soundHandler, int life) :
     base(team, coords, drawable)
 {
     Coords      -= new Vector2D(ImageDimentions.X / 2, 0);
     SoundHandler = GameException.RequireNonNull(soundHandler);
     Life         = (int)GameException.RequirePositive(life);
 }
Beispiel #2
0
 /// <summary>
 /// Stop a the playlist
 /// </summary>
 public void StopPlaylist()
 {
     foreach (MediaPlayer songs in GameException.RequireNonNull(Songs))
     {
         songs.Stop();
     }
 }
Beispiel #3
0
        /// <summary>
        /// Play the playlist
        /// </summary>
        public void PlayPlaylist()
        {
            StopPlaylist();

            if (GameException.RequireNonNull(Songs).Count != 0)
            {
                Songs[0].Play();
            }
        }
Beispiel #4
0
 /// <summary>
 /// Draw the current image into the graphics
 /// </summary>
 /// <param name="graphics">the graphics</param>
 /// <param name="destination">top left position represented in pixels</param>
 public override void Draw(Graphics graphics, Vector2D destination)
 {
     GameException.RequireNonNull(destination);
     graphics.DrawImage(
         Image,
         new Rectangle(
             (int)destination.X,
             (int)destination.Y,
             Width,
             Height
             )
         );
 }
Beispiel #5
0
        /// <summary>
        /// An gameObjet can is in collision with a projectile if
        /// the projectile meet a non transparent pixel of the DrawableObject
        /// </summary>
        /// <param name="projectile">projectile</param>
        /// <returns>Is the projectile in a non transparent pixel of the DrawableObject?</returns>
        public override bool CanCollision(ProjectileObject projectile)
        {
            GameException.RequireNonNull(projectile);

            if (Team == projectile.Team || !projectile.IsAlive())
            {
                return(false);
            }

            Rectangle intersect = Vector2D.Intersect(Coords, ImageDimentions, projectile.Coords, projectile.ImageDimentions);

            if (intersect.IsEmpty)
            {
                return(false);
            }

            return(IteratePixels(projectile, (x, y) => 0 < Drawable.Image.GetPixel(x, y).A));
        }
        /// <summary>
        /// Create shooter object
        /// </summary>
        /// <param name="src">initial position of the ennemy</param>
        /// <param name="dst">destination to reach before horizontal movement</param>
        /// <param name="drawable">image to draw</param>
        /// <param name="missileImage">projectile image to draw</param>
        /// <param name="speed">move speed in pixels</param>
        /// <param name="speedDecalage">move acceleration in pixels when the direction changes</param>
        /// <param name="shootPercentage">percentage to shoot by second between 0 and 100</param>
        /// <param name="life">life of the imageObject</param>
        public EnnemyObject(Vector2D src, Vector2D dst, Drawable drawable, Drawable missileImage, double speed,
                            double speedDecalage, int shootPercentage, int life) :
            base(Team.ENNEMY, GameException.RequireNonNull(src), drawable, ENNEMY_SOUNDS, speed, speedDecalage, life)
        {
            DestinationCoords = GameException.RequireNonNull(dst);
            MissileImage      = missileImage;
            ShootPercentage   = (int)GameException.RequirePositive(shootPercentage);

            // Every seconds, ...
            Timer = new Timer {
                Interval = 1000
            };

            // ..., the ennemy can try a shoot
            Timer.Elapsed += (object sender, ElapsedEventArgs e) => {
                TimeToShoot = true;
                Timer.Stop();
            };
        }
        /// <summary>
        /// Draw the current image into the graphics
        /// </summary>
        /// <param name="graphics">the graphics</param>
        /// <param name="destination">top left position represented in pixels</param>
        public override void Draw(Graphics graphics, Vector2D destination)
        {
            GameException.RequireNonNull(destination);
            graphics.DrawImage(
                Image,
                new Rectangle(
                    (int)destination.X, (int)destination.Y,
                    Width, Height
                    ),
                new Rectangle(
                    (int)Indexes.X * Width, (int)Indexes.Y * Height,
                    Width, Height
                    ),
                GraphicsUnit.Pixel
                );

            if (i++ % 10 == 0)
            {
                Next();
            }
        }
Beispiel #8
0
 /// <summary>
 /// Allow to a game object to be draw
 /// </summary>
 /// <param name="team">team of the game object</param>
 /// <param name="coords">coordinates of the gameObject</param>
 /// <param name="drawable">image to draw</param>
 public DrawableObject(Team team, Vector2D coords, View.Display.Images.Drawable drawable) : base(team, coords)
 {
     Drawable        = GameException.RequireNonNull(drawable);
     ImageDimentions = new Vector2D(drawable.Width, drawable.Height);
 }
Beispiel #9
0
 /// <summary>
 /// Return true if the gameObject is above of imageObject
 /// </summary>
 /// <param name="imageObject">the imageObject to compare</param>
 /// <returns>True if the gameObject is above of imageObject </returns>
 public bool IsAbove(DrawableObject imageObject)
 {
     return(Coords.Y < GameException.RequireNonNull(imageObject).Coords.Y);
 }
Beispiel #10
0
 /// <summary>
 /// Stop a SFX
 /// </summary>
 public void StopSFX(string url)
 {
     GameException.RequireNonNull(SFXDict)[url].Stop();
 }
Beispiel #11
0
 /// <summary>
 /// Play a sound
 /// </summary>
 public void PlaySFX(string url)
 {
     GameException.RequireNonNull(SFXDict)[url].Play();
 }
Beispiel #12
0
 /// <summary>
 /// Create a Drawable, ready to be drawed
 /// </summary>
 /// <param name="image">the first image that we have to draw</param>
 /// <param name="width">the width of the image</param>
 /// <param name="height">the height of the image</param>
 protected Drawable(Bitmap image, int width, int height)
 {
     Image  = GameException.RequireNonNull(image);
     Width  = (int)GameException.RequirePositive(width);
     Height = (int)GameException.RequirePositive(height);
 }