コード例 #1
0
        public Player()
        {
            //load the player's sprite
            var tex1 = new TextureInfo(new Texture2D("/Application/data/tiles/machinegun_fire.png", false)
                                       , new Vector2i(14, 1));

            tex1.Texture.SetFilter(TextureFilterMode.Disabled);
            playerBodySprite             = new SpriteTile();
            playerBodySprite.TextureInfo = tex1;
            playerBodySprite.TileIndex2D = new Vector2i(0, 0);
            //playerBodySprite.BlendMode = BlendMode.None; //testing only


            //set up scale,position ect

            playerBodySprite.CenterSprite(new Vector2(0.2f, 0.1f));

            playerBodySprite.Pivot = new Vector2(0.08f, 0.0f);

            playerBodySprite.Scale = new Vector2(0.75f, 1.5f);

            this.AddChild(playerBodySprite);

            //Position = new Vector2 (MapManager.Instance.currentMap.width/2.0f, MapManager.Instance.currentMap.height/2.0f);

            var list = MapManager.Instance.currentMap.returnTilesOfType(MapTile.Types.floor);

            Position = list[Support.random.Next(0, list.Count - 1)].position;

            //get the local bounds of the sprite
            bounds = new Bounds2();
            playerBodySprite.GetlContentLocalBounds(ref bounds);
            bounds = new Bounds2(bounds.Min * 0.5f, bounds.Max * 0.5f);
        }
コード例 #2
0
        public new bool HasCollidedWithPlayer(SpriteUV player)         //Check if the a sprite has hit a part of the maze
        {
            if (tileIndex > 5 && tileIndex < 15)
            {
                laserOn = true;
            }
            else
            {
                laserOn = false;
            }

            Bounds2 playerBounds = player.GetlContentLocalBounds();

            player.GetContentWorldBounds(ref playerBounds);             //Get sprite bounds (player bounds)

            Bounds2 laserBounds = sprite.GetlContentLocalBounds();

            sprite.GetContentWorldBounds(ref laserBounds);             //Get all of the maze bounds

            laserBounds.Max = laserBounds.Max - 15.0f;
            laserBounds.Min = laserBounds.Min + 15.0f;

            if (playerBounds.Overlaps(laserBounds) && laserOn)
            {
                return(true);
            }

            return(false);
        }
コード例 #3
0
        public bool HasCollidedWithPlayer(SpriteUV player)         //Check if the a sprite has hit a part of the maze
        {
            if (collected == false)
            {
                Bounds2 playerBounds = player.GetlContentLocalBounds();
                player.GetContentWorldBounds(ref playerBounds);                 //Get sprite bounds (player bounds)

                Bounds2 spriteBounds = sprite.GetlContentLocalBounds();
                sprite.GetContentWorldBounds(ref spriteBounds);                 //Get all of the maze bounds

                if (playerBounds.Overlaps(spriteBounds))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #4
0
        public new bool HasCollidedWithPlayer(SpriteUV player)         //Check if the a sprite has hit a part of the maze
        {
            Bounds2 playerBounds = player.GetlContentLocalBounds();

            player.GetContentWorldBounds(ref playerBounds);             //Get sprite bounds (player bounds)

            Bounds2 holeBounds = sprite.GetlContentLocalBounds();

            sprite.GetContentWorldBounds(ref holeBounds);             //Get all of the maze bounds

            holeBounds.Max = holeBounds.Max - 15.0f;
            holeBounds.Min = holeBounds.Min + 15.0f;

            if (playerBounds.Overlaps(holeBounds))
            {
                return(true);
            }

            return(false);
        }
コード例 #5
0
ファイル: BasicEnemy.cs プロジェクト: gambiting/VitaShooter
        public BasicEnemy(Vector2 pos, TextureInfo tex)
        {
            Position = pos;

            sprite             = new SpriteTile();
            sprite.TextureInfo = tex;
            sprite.Position    = pos;
            sprite.TileIndex2D = new Vector2i(0, 0);
            sprite.CenterSprite(new Vector2(0.4f, 0.5f));
            sprite.Scale = new Vector2(2.0f, 2.0f);

            //set up the random vector
            randomMovement = Support.rand.NextVector2(-0.01f, 0.01f);

            //update the animation frames
            sprite.Schedule((dt) => {
                if (FrameCount % 2 == 0)
                {
                    //if attacking,use all animation frames
                    if (attacking)
                    {
                        //deal damage to the player
                        if (FrameCount % damageDelay == 0)
                        {
                            Player.Instance.Health -= damage;
                        }

                        animationFrame = (animationFrame + 1) % 25;
                    }
                    else
                    {
                        //if not,then use first three animation frames
                        animationFrame = (animationFrame + 1) % 4;
                    }
                    //assign the correct tileindex
                    sprite.TileIndex1D = animationFrame;

                    //if close to the player,then follow,otherwise move randomly
                    if (Player.Instance.Position.Distance(sprite.Position) < 6.0f &&
                        Collisions.checkLineOfSight(this, Player.Instance))
                    {
                        isMovingRandomly = false;
                        step             = (Player.Instance.Position - sprite.Position).Normalize() / 15.0f;

                        //check if should be attacking
                        if (Collisions.checkCollisionBetweenEntities(this, Player.Instance))
                        {
                            //check if is not attacking already
                            if (attacking == false)
                            {
                                attacking = true;
                                //manualy skip the frames
                                animationFrame = 4;
                            }
                        }
                        else
                        {
                            //make sure that attacking is set to false
                            attacking = false;
                        }
                    }
                    else
                    {
                        //player is not within range, move randomly
                        isMovingRandomly = true;
                        step             = randomMovement;
                    }
                }

                //advance the position by the given Vector2 step
                sprite.Position += step;

                //only move when not attacking
                if (!attacking)
                {
                    //collision detection on the X axis

                    //create a vector 2 containing a proposed change to the position
                    Vector2 proposedChange = new Vector2(step.X, 0.0f) * speedModifier;
                    //temporary game entity to contain the entity the enemy might have collided with
                    GameEntity tempEntity;

                    //check wall collisions and then collisions with other enemies
                    if (!Collisions.checkWallsCollisions(this, MapManager.Instance.currentMap, ref proposedChange) && !Collisions.efficientCollisionsCheck(this, proposedChange, out tempEntity))
                    {
                        //no collision, so we can change the position
                        Position += proposedChange / speedModifier;
                    }
                    else if (isMovingRandomly)
                    {
                        //collided with something,but if the enemy should be moving randomly, then let it move
                        randomMovement.X = -randomMovement.X;
                    }


                    //collision detection on the Y axis

                    proposedChange = new Vector2(0.0f, step.Y) * speedModifier;
                    if (!Collisions.checkWallsCollisions(this, MapManager.Instance.currentMap, ref proposedChange) && !Collisions.efficientCollisionsCheck(this, proposedChange, out tempEntity))
                    {
                        Position += proposedChange / speedModifier;
                    }
                    else if (isMovingRandomly)
                    {
                        randomMovement.Y = -randomMovement.Y;
                    }


                    //position changed, so we need to remove the entity from the QuadTree and add again
                    //this is because the entity might be in the wrong place in the QuadTree and removing and re-adding is the only way to fix that
                    Game.Instance.quadTree.removeEntity(this);
                    Game.Instance.quadTree.insert(this);
                }



                //rotate the sprite to face the direction of walking
                var angleInRadians = -FMath.Atan2(step.X, step.Y);
                sprite.Rotation    = new Vector2(FMath.Cos(angleInRadians), FMath.Sin(angleInRadians));

                //correct for the fact that the sprite is rotated in the texture file
                sprite.Rotation = sprite.Rotation.Rotate(90.0f);
            }, -1);

            //create a shadow texture - temporarily disabled
            //SpriteUV shadow = new SpriteUV(new TextureInfo(Bullet.fireTexture));
            //shadow.CenterSprite(new Vector2(0.5f,0.5f));
            //shadow.Color = Sce.PlayStation.HighLevel.GameEngine2D.Base.Math.SetAlpha(Colors.Black,0.5f);


            //calculate the bounds for the entire sprite
            bounds = new Bounds2();
            sprite.GetlContentLocalBounds(ref bounds);

            bounds = new Bounds2(bounds.Min * 0.5f, bounds.Max * 0.5f);
        }