Beispiel #1
0
 protected override void onPickup(Player player)
 {
     // player.gunEquipped = new BasicGun(2, new LinearLocationEquation(-Math.PI / 2, 1),
     //                GraphicsLoader.getGraphicsLoader().getTexture("bullet"), 500, TEAM.FRIENDLY);
     // player.gunEquipped.GunShotHandler += BHGame.Canvas.OnGunShot;
     //FIXME:
     player.gunEquipped = new Gun(1, GraphicsLoader.getGraphicsLoader().getBulletTexture(),
                                  BulletFactoryFactory.make("surround"), TEAM.FRIENDLY);
     player.gunEquipped.GunShotHandler += BHGame.Canvas.OnGunShot;
 }
Beispiel #2
0
        public Tuple <GameDirector, Canvas, CollisionManager> makeGame(GraphicsDevice graphicsDevice, Controller controller)
        {
            xmlParser        = new XMLParser("test.xml");
            director         = new GameDirector();
            canvas           = new Canvas(new SpriteBatch(graphicsDevice));
            collisionManager = new CollisionManager();
            try
            {
                graphicsLoader = GraphicsLoader.makeGraphicsLoader(graphicsDevice);
            }
            catch (ArgumentException)
            {
                graphicsLoader = GraphicsLoader.getGraphicsLoader();
            }
            EnemyFactory enemyFactory = new EnemyFactory();

            xmlParser.Parse();
            List <Encounter> encounters = xmlParser.getEncounterList();
            int lastTime = 0;

            foreach (var encounter in encounters)
            {
                EncounterEvent encounterEvent = new EncounterEvent(collisionManager, canvas, encounter, director);
                lastTime = encounter.timeInMS;
                director.addEvent(encounter.timeInMS, encounterEvent);
            }


            SCREEN_WIDTH  = graphicsDevice.Viewport.Bounds.Width;
            SCREEN_HEIGHT = graphicsDevice.Viewport.Bounds.Height;


            int     offset    = 50;
            Vector2 topMiddle = new Vector2(SCREEN_WIDTH / 2 - offset, -100);
            Vector2 topLeft   = new Vector2(SCREEN_WIDTH / 4 - offset, -100);
            Vector2 topRight  = new Vector2(3 * SCREEN_WIDTH / 4 - offset, -100);

            // sin.healthbar = new HealthBar(sin.Location, new Vector2(8, 0), 85, 90, sin.Health);

            Player player = MakePlayer(controller);

            player.invulnerable = hasCheatMode;
            director.addEvent(0, new PlayerEnter(canvas, player));
            player.DeathEvent += canvas.OnPlayerDeath;

            //director.addEvent(0, new PlayerEnter(canvas, player));

            return(new Tuple <GameDirector, Canvas, CollisionManager>(director, canvas, collisionManager));
        }
Beispiel #3
0
        private Player MakePlayer(Controller controller)
        {
            Texture2D playerTexture = graphicsLoader.getTexture("player");
            Texture2D heartTexture  = graphicsLoader.getTexture("heart");
            // Texture2D playerTexture = null;
            Player player = new Player(canvas, playerTexture, new Vector2(SCREEN_WIDTH / 2 - playerTexture.Width / 2, 300), controller, heartTexture);

            player.SetSize(72, 100);
            player.gunEquipped = new Gun(.7F, GraphicsLoader.getGraphicsLoader().getTexture("player-bullet"),
                                         BulletFactoryFactory.make("basic"), TEAM.FRIENDLY, -Math.PI / 2);
            player.PropertyChanged            += canvas.OnWeaponChange;
            player.gunEquipped.GunShotHandler += canvas.OnGunShot;
            player.Hitbox = new CollidingCircle(player.Location, new Vector2(player.Rect.Width / 2, player.Rect.Height / 2), 15);
            collisionManager.addToTeam(player, TEAM.FRIENDLY);
            return(player);
        }
Beispiel #4
0
        public Player(Canvas canvas, Texture2D texture, Vector2 startLocation, Controller controller, Texture2D heart_texture) : base(texture, startLocation)
        {
            //invulnerable = true;
            this.respawnLocation = startLocation;
            this.canvas          = canvas;
            InputControl.AssignPlayer(this);
            // gunEquipped = new BasicGun(1, new LinearLocationEquation(-Math.PI / 2, 1),
            //     GraphicsLoader.getGraphicsLoader().getTexture("bullet"), 500, TEAM.FRIENDLY);

            // gunEquipped = new BasicGun(1, new LinearLocationEquation(-Math.PI / 2, 1), GraphicsLoader.getGraphicsLoader().getBulletTexture(), 1000, true);

            healthPoints = 5;      //player lives

            MakeHearts(heart_texture);
            AddHearts(healthPoints);
            gunEquipped = new Gun(1, GraphicsLoader.getGraphicsLoader().getTexture("player-bullet"), BulletFactoryFactory.make("basic"), TEAM.FRIENDLY, -Math.PI / 2);

            subscribeToController(controller);
        }
Beispiel #5
0
        private Enemy makeEnemy(string textureName, int health, Path path, string gunType, float delay, double scale = 1)
        {
            Texture2D texture = GraphicsLoader.getGraphicsLoader().getTexture(textureName);
            Enemy     enemy;

            try
            {
                enemy = new Enemy(texture, path, health, BulletFactoryFactory.make(gunType), delay);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error loading gun " + gunType);
                Console.WriteLine(e.Message);
                enemy = new Enemy(texture, path, health);
            }
            Gun gun = gunFactory.makeGun(gunType);

            enemy.Hitbox = HitboxRepo.getHitboxRepo().getHitbox(textureName).Copy();
            enemy.Scale(scale);
            enemy.healthbar = new HealthBar(enemy.Location, new Vector2(8, 0), enemy.Rect.Width, 10, enemy.Health);


            return(enemy);
        }
Beispiel #6
0
        public Tuple <GameDirector, Canvas, CollisionManager> makeGame(GraphicsDevice graphicsDevice, Controller controller)
        {
            xmlParser        = new XMLParser("test.xml");
            director         = new GameDirector();
            canvas           = new Canvas(new SpriteBatch(graphicsDevice));
            collisionManager = new CollisionManager();

            Hitbox top    = new CollidingRectangle(new Vector2(-50, -450), Vector2.Zero, graphicsDevice.Viewport.Width + 100, 50);
            Hitbox bottom = new CollidingRectangle(new Vector2(-50, graphicsDevice.Viewport.Height + 50), Vector2.Zero, graphicsDevice.Viewport.Width + 100, 50);
            Hitbox left   = new CollidingRectangle(new Vector2(-100, -450), Vector2.Zero, 50, graphicsDevice.Viewport.Height + 500);
            Hitbox right  = new CollidingRectangle(new Vector2(graphicsDevice.Viewport.Width + 50, -450), Vector2.Zero, 50, graphicsDevice.Viewport.Height + 500);

            BoundingObject bTop    = new BoundingObject(null, Vector2.Zero, canvas);
            BoundingObject bBottom = new BoundingObject(null, Vector2.Zero, canvas);
            BoundingObject bLeft   = new BoundingObject(null, Vector2.Zero, canvas);
            BoundingObject bRight  = new BoundingObject(null, Vector2.Zero, canvas);

            bTop.Hitbox    = top;
            bBottom.Hitbox = bottom;
            bLeft.Hitbox   = left;
            bRight.Hitbox  = right;

            collisionManager.addToTeam(bTop, TEAM.UNASSIGNED);
            collisionManager.addToTeam(bBottom, TEAM.UNASSIGNED);
            collisionManager.addToTeam(bLeft, TEAM.UNASSIGNED);
            collisionManager.addToTeam(bRight, TEAM.UNASSIGNED);

            try
            {
                graphicsLoader = GraphicsLoader.makeGraphicsLoader(graphicsDevice);
            }
            catch (ArgumentException)
            {
                graphicsLoader = GraphicsLoader.getGraphicsLoader();
            }
            EnemyFactory enemyFactory = new EnemyFactory();

            xmlParser.Parse();
            List <Encounter> encounters = xmlParser.getEncounterList();

            foreach (var encounter in encounters)
            {
                EncounterEvent encounterEvent = new EncounterEvent(collisionManager, canvas, encounter, director);
                //Console.WriteLine(encounter.timeInMS);
                director.addEvent(encounter.timeInMS, encounterEvent);
            }


            SCREEN_WIDTH  = graphicsDevice.Viewport.Bounds.Width;
            SCREEN_HEIGHT = graphicsDevice.Viewport.Bounds.Height;


            int     offset    = 50;
            Vector2 topMiddle = new Vector2(SCREEN_WIDTH / 2 - offset, -100);
            Vector2 topLeft   = new Vector2(SCREEN_WIDTH / 4 - offset, -100);
            Vector2 topRight  = new Vector2(3 * SCREEN_WIDTH / 4 - offset, -100);

            // sin.healthbar = new HealthBar(sin.Location, new Vector2(8, 0), 85, 90, sin.Health);

            Player player = MakePlayer(controller);

            player.invulnerable = hasCheatMode;
            director.addEvent(0, new PlayerEnter(canvas, player));
            player.DeathEvent += canvas.OnPlayerDeath;

            return(new Tuple <GameDirector, Canvas, CollisionManager>(director, canvas, collisionManager));
        }