Beispiel #1
0
 public GameCharacter(Game game, World world, Vector2 position, Vector2 size, SpriteAnimation animation, BodyType bodyType)
     : base(game, world, position, size, animation, bodyType)
 {
     // Don't allow characters to rotate
     this.body.FixedRotation = true;
     this.jumpState = 0;
 }
Beispiel #2
0
        public GamePlayer(Game game, World world, Vector2 position, Vector2 size, SpriteAnimation animation, PlayerIndex playerIndex)
            : base(game, world, position, size, animation, BodyType.Dynamic)
        {
            this.playerIndex = playerIndex;

            this.game = (Limak) game;
        }
Beispiel #3
0
 public GameEnemy(Game game, World world, Vector2 position, Vector2 size, SpriteAnimation animation)
     : base(game, world, position, size, animation, BodyType.Dynamic)
 {
     changeDirection = false;
     timer = new System.Timers.Timer();
     timer.Elapsed += new ElapsedEventHandler(OnTimeEvent);
     Random random = new Random();
     timer.Interval = random.Next(200, 1000);
     base.moveForce = new Vector2(random.Next(100, 500), 0);
     timer.Enabled = true;
 }
Beispiel #4
0
        /// <summary>
        /// Base class for interactive game objects.
        /// </summary>
        /// <param name="game"></param>
        /// <param name="position"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="animation"></param>
        public GameObject(Game game, World world, Vector2 position, Vector2 size, SpriteAnimation animation, BodyType bodyType)
            : base(game)
        {
            this.animation = animation;

            this.Direction = GameObjectDirection.RIGHT;

            this.size = size;

            this.body = FarseerPhysics.Factories.BodyFactory.CreateRectangle(world, size.X, size.Y, 1.5f);
            this.body.BodyType = bodyType;
            this.body.Friction = 1.0f;
            this.body.Restitution = 0.01f;
            //this.body.LinearDamping = 3.0f;
            //this.body.AngularDamping = 3.0f;
            this.body.Inertia = 5.0f;
            this.body.Position = position;
        }
Beispiel #5
0
        // This is called whenever gameState = Playing (when you enter the actually game)
        public void GameLoading()
        {
            timeBegin = DateTime.Now;

            // Setup the map
            this.map = new Map(this, "level.txt");

            this.Components.Add(this.map);

            // Setup misc graphics
            font = this.Content.Load<SpriteFont>("SpriteFont1");

            //Background
            Texture2D level1 = this.Content.Load<Texture2D>("bg_level2");
            myBackground.Load( this.GraphicsDevice, level1);

            //Assign characters to players
            switch ( gameState.getCurrentCharacter1() )
            {
                case State.SralState:
                    player1T = this.Content.Load<Texture2D>("spriteSheetCharacter1");
                    break;
                case State.LimakState:
                    player1T = this.Content.Load<Texture2D>("spriteSheetCharacter2");
                    break;
                case State.NuduaState:
                    player1T = this.Content.Load<Texture2D>("spriteSheetCharacter3");
                    break;
                case State.DHState:
                    player1T = this.Content.Load<Texture2D>("spriteSheetCharacter4");
                    break;
                case State.BokajState:
                    player1T = this.Content.Load<Texture2D>("spriteSheetCharacter5");
                    break;
                default:
                    break;
            }
            switch (gameState.getCurrentCharacter2())
            {
                case State.SralState:
                    player2T = this.Content.Load<Texture2D>("spriteSheetCharacter1");
                    break;
                case State.LimakState:
                    player2T = this.Content.Load<Texture2D>("spriteSheetCharacter2");
                    break;
                case State.NuduaState:
                    player2T = this.Content.Load<Texture2D>("spriteSheetCharacter3");
                    break;
                case State.DHState:
                    player2T = this.Content.Load<Texture2D>("spriteSheetCharacter4");
                    break;
                case State.BokajState:
                    player2T = this.Content.Load<Texture2D>("spriteSheetCharacter5");
                    break;
                default:
                    break;
            }

            //Set players animation
            player1Animation = new SpriteAnimation(player1T, 120, 120, 4, 6);
            player1Animation.AnimationDelay = 200;
            player2Animation = new SpriteAnimation(player2T, 120, 120, 4, 6);
            player2Animation.AnimationDelay = 200;

            //Create players
            players = new List<GamePlayer>();

            player1 = new GamePlayer(
                this,
                this.world,
                new Vector2(2.0f, 0.0f), // position (meter)
                new Vector2(2.0f, 2.0f), // size (meter)
                player1Animation,
                PlayerIndex.One
            );
            player2 = new GamePlayer(
                this,
                this.world,
                new Vector2(1.0f, 0.0f), // position (meter)
                new Vector2(2.0f, 2.0f), // size (meter)
                player2Animation,
                PlayerIndex.Two
            );

            //Add camera man
            m_CameraMan = new DoubleTrackingCameraMan(this, new Camera(), player1, player2);
            this.Components.Add(m_CameraMan);

            //Add players
            this.Components.Add(player1);
            this.Components.Add(player2);
            this.players.Add(player1);
            this.players.Add(player2);

            // Bind players to characterInput
            this.character1Controller.BindCharacter(player1);
            this.character2Controller.BindCharacter(player2);

            //Collision detection
            foreach (GamePlayer player in this.players) {
                player.getFixture().OnCollision += player.CollisionWithEnemy;
                player.getFixture().OnCollision += player.PickUpCoin;
                player.getFixture().OnCollision += player.PlayerPlayerCollision;
                player.getFixture().OnCollision += player.CollisionWithGround;
                player.getFixture().OnCollision += player.PlayerFinish;
            }
        }
Beispiel #6
0
 public GameCoin(Game game, World world, Vector2 position, Vector2 size, SpriteAnimation animation)
     : base(game, world, position, size, animation, BodyType.Static)
 {
 }
Beispiel #7
0
        //returning certain properties that other classes might need.
        private void createEnemies(Game game)
        {
            Texture2D enemyTexture = game.Content.Load<Texture2D>("enemy");
            Vector2 size = new Vector2(2, 2);

            for (int i = 0; i < level.getEnemyPos.Count; i++)
            {
                SpriteAnimation enemyAnimation = new SpriteAnimation(enemyTexture, (int)Convert.ToPixels(size.X), (int)Convert.ToPixels(size.Y), 4, 7);
                enemyAnimation.AnimationDelay = 400;
                GameEnemy enemy = new GameEnemy(
                    ((Limak)game),
                    ((Limak)game).world,
                    level.getEnemyPos[i], // position (meter)
                    size, // size (meter)
                    enemyAnimation

                );
                //Console.WriteLine("i:" + level.getEnemyPos[i].X + "  j:" + level.getEnemyPos[i].Y) ;
                ((Limak)game).addGameObject(enemy);
            }
        }