コード例 #1
0
        /// <summary>
        /// Returns true if projectile is still alive
        /// </summary>
        /// <param name="gameTime"></param>
        /// <returns>True if projectile is still alive</returns>
        public bool Update(GameTime gameTime, Map map, ParticleTools particleTools)
        {
            offset += (float)gameTime.ElapsedGameTime.TotalMilliseconds * ProjectileSpeed;

            TileInfo.SideType    direction      = TileInfo.FromFacing(horizontalDirection, verticalDirection);
            Rectangle            rectangle      = CollisionRectangle;
            List <CollisionTile> collidingTiles = map.GetCollidingTiles(rectangle, direction);

            for (int i = 0; i < collidingTiles.Count; i++)
            {
                TileInfo.SideType side = TileInfo.OppositeSide(direction);
                GameUnit          perpendicularPosition = TileInfo.Vertical(side) ?
                                                          rectangle.Center.X : rectangle.Center.Y;
                GameUnit          leadingPosition  = rectangle.Side(direction);
                bool              shouldTestSlopes = true;
                TestCollisionInfo testInfo         = collidingTiles[i].TestCollision(side, perpendicularPosition,
                                                                                     leadingPosition, shouldTestSlopes);
                if (testInfo.isColliding)
                {
                    GameUnit collisionX;
                    if (TileInfo.Vertical(side))
                    {
                        collisionX = perpendicularPosition;
                    }
                    else
                    {
                        collisionX = testInfo.position;
                    }
                    GameUnit collisionY;
                    if (TileInfo.Vertical(side))
                    {
                        collisionY = testInfo.position;
                    }
                    else
                    {
                        collisionY = perpendicularPosition;
                    }
                    particleTools.FrontSystem.AddNewParticle(ProjectileWallParticle.Create(particleTools.Content,
                                                                                           collisionX - Units.HalfTile, collisionY - Units.HalfTile));
                    return(false);
                }
            }
            if (!alive)
            {
                return(false);
            }
            else if (offset >= ProjectileMaxOffsets[gunLevel - 1])
            {
                particleTools.FrontSystem.AddNewParticle(ProjectileStarParticle.Create(particleTools.Content, X, Y));
                return(false);
            }
            else
            {
                return(true);
            }
        }
コード例 #2
0
 public Projectile(Sprite sprite,
                   SpriteState.HorizontalFacing horizontalDirection, SpriteState.VerticalFacing verticalDirection,
                   GameUnit x, GameUnit y,
                   GunLevelUnit gunLevel, ParticleTools particleTools)
 {
     this.sprite = sprite;
     this.horizontalDirection = horizontalDirection;
     this.verticalDirection   = verticalDirection;
     this.x        = x;
     this.y        = y;
     this.gunLevel = gunLevel;
     offset        = 0;
     alive         = true;
     particleTools.FrontSystem.AddNewParticle(ProjectileStarParticle.Create(particleTools.Content, x, y));
 }