コード例 #1
0
ファイル: WorldTest.cs プロジェクト: julius/pse_spacewar
        public void AddWorldObjectTest()
        {
            Planet planet1 = new Planet();
            WorldObject[] worldObjects = {planet1};

            World target = new World(worldObjects);
            WorldObject spaceship1 = new Spaceship();
            WorldObject spaceship2 = new Spaceship();
            WorldObject projectile = new Projectile();
            WorldObject explosion = new Explosion();
            WorldObject planet2 = new Planet();

            target.AddWorldObject(spaceship1);
            target.AddWorldObject(spaceship2);
            target.AddWorldObject(projectile);
            target.AddWorldObject(explosion);
            target.AddWorldObject(planet2);

            Assert.IsTrue((new List<WorldObject>(target.WorldObjects)).Contains(planet1));
            Assert.IsTrue((new List<WorldObject>(target.WorldObjects)).Contains(spaceship1));
            Assert.IsTrue((new List<WorldObject>(target.WorldObjects)).Contains(spaceship2));
            Assert.IsTrue((new List<WorldObject>(target.WorldObjects)).Contains(projectile));
            Assert.IsTrue((new List<WorldObject>(target.WorldObjects)).Contains(explosion));
            Assert.IsTrue((new List<WorldObject>(target.WorldObjects)).Contains(planet2));
        }
コード例 #2
0
        /// <summary>
        /// Constructor for Flint's Hat.
        /// </summary>
        /// <param name="parentScreen">The screen which this object is a part of.</param>
        /// <param name="spriteBatch">The sprite batch which handles drawing this object.</param>
        /// <param name="position">The initial position of this character.</param>
        public SpaceBoss(Screen gameScreen, World world, SpriteBatch spriteBatch, Vector2 position, Character owner)
            : base(world, spriteBatch, position)
        {
            mass = 1.0f;
            //Set the Hat's owner
            this.owner = owner;

            this.gameScreen = gameScreen;

            //Set up the Animation Map
            animationMap = new Dictionary<string, Animation>();

            //Set up the Hat's Animations
            SetUpAnimation();

            animationPlayer = new AnimationPlayer(spriteBatch, animationMap["Fall"]);

            currentState = "None";

            //Set the Hat's positon
            if (owner.Facing == SpriteEffects.FlipHorizontally)
            {
                Position = owner.Position + new Vector2(20, -29);
            }
            else
            {
                Position = owner.Position + new Vector2(-20, -30);
            }

            //Set the hat's velocity
            if (currentState.Contains("Fall"))
            {
                velocity = new Vector2(0, 0);
            }

            //Initializes the hat's hotspots.
            List<CollisionHotspot> hotspots = new List<CollisionHotspot>();
            hotspots.Add(new CollisionHotspot(this, new Vector2(-1, -10), HOTSPOT_TYPE.top));
            hotspots.Add(new CollisionHotspot(this, new Vector2(-7, 1), HOTSPOT_TYPE.left));
            hotspots.Add(new CollisionHotspot(this, new Vector2(5, 1), HOTSPOT_TYPE.right));
            hotspots.Add(new CollisionHotspot(this, new Vector2(-1, 12), HOTSPOT_TYPE.bottom));
            Hotspots = hotspots;

            this.world = world;
            world.AddWorldObject(this);
            //this.ParentScreen.Components.Add(this);
        }
コード例 #3
0
        /// <summary>
        /// Constructor for Flint's Hat.
        /// </summary>
        /// <param name="parentScreen">The screen which this object is a part of.</param>
        /// <param name="spriteBatch">The sprite batch which handles drawing this object.</param>
        /// <param name="position">The initial position of this character.</param>
        public FlintHat(Screen gameScreen, World world, SpriteBatch spriteBatch, Vector2 position, Character owner)
            : base(world, spriteBatch, position)
        {
            mass = 1.0f;
            //Set the Hat's owner
            this.owner = owner;

            this.gameScreen = gameScreen;

            //Set up the Animation Map
            animationMap = new Dictionary<string, Animation>();

            //Set up the Hat's Animations
            SetUpAnimation();

            //Set the current Animation
            currentAnimation = animationMap["Fall"];

            animationPlayer = new AnimationPlayer(spriteBatch, animationMap["Fall"]);

            currentState = "None";

            //Set the Hat's positon
            position = owner.Position + new Vector2(60, 0);

            //Set the hat's velocity
            velocity = new Vector2(0, 0);

            //Initializes the hat's hotspots.
            List<CollisionHotspot> hotspots = new List<CollisionHotspot>();
            hotspots.Add(new CollisionHotspot(this, new Vector2(-1, -10), HOTSPOT_TYPE.top));
            hotspots.Add(new CollisionHotspot(this, new Vector2(-7, 1), HOTSPOT_TYPE.left));
            hotspots.Add(new CollisionHotspot(this, new Vector2(5, 1), HOTSPOT_TYPE.right));
            hotspots.Add(new CollisionHotspot(this, new Vector2(-1, 12), HOTSPOT_TYPE.bottom));
            Hotspots = hotspots;

            this.world = world;
            world.AddWorldObject(this);
            //this.ParentScreen.Components.Add(this);
        }