コード例 #1
0
ファイル: Environment.cs プロジェクト: koboldul/Cocos2DGame1
        public void HandleCollisionWithPlayer(Ball ball, Player player)
        {
            Vector2 v = ball.Velocity;

            if (ball.Position.X + ball.Size.X >= player.Position.X && ball.Position.Y < player.Position.Y)
                v = new Vector2(-ball.Velocity.X, ball.Velocity.Y);

            ball.Velocity = v;
        }
コード例 #2
0
ファイル: Environment.cs プロジェクト: koboldul/Cocos2DGame1
        public void HandleCollisionWithMargins(Ball ball)
        {
            Vector2 v = ball.Velocity;

            if (ball.Position.X <= MarginWidth + XOffset) v = new Vector2(-ball.Velocity.X, ball.Velocity.Y);

            if (ball.Position.X + ball.Size.X >= MarginWidth + XOffset + TerrainWidth) v = new Vector2(-ball.Velocity.X, ball.Velocity.Y);

            if (ball.Position.Y <= MarginWidth + YOffset) v = new Vector2(ball.Velocity.X, -ball.Velocity.Y);

            if (ball.Position.Y + ball.Size.Y > MarginWidth + YOffset + TerrainHeight) v = new Vector2(ball.Velocity.X, -ball.Velocity.Y);

            ball.Velocity = v;
        }
コード例 #3
0
ファイル: Football.cs プロジェクト: koboldul/Cocos2DGame1
        public Football()
        {
            _graphics = new GraphicsDeviceManager(this);
            _graphics.IsFullScreen = true;

            Content.RootDirectory = "Content";

            _environment = new GEnvironment();

            _ball = new Ball(_environment);

            _topTeam = new Team(PlayerType.Top, _environment);
            _bottomTeam = new Team(PlayerType.Bottom, _environment);

            _environment.RegisterEntity(_ball);

            // Frame rate is 30 fps by default for Windows Phone.
            TargetElapsedTime = TimeSpan.FromTicks(333333);

            // Pre-autoscale settings.
            _graphics.PreferredBackBufferWidth = 480;
            _graphics.PreferredBackBufferHeight = 800;
        }
コード例 #4
0
ファイル: Environment.cs プロジェクト: koboldul/Cocos2DGame1
 public void RegisterEntity(Entity entity)
 {
     if (entity is Ball)
     {
         _ball = entity as Ball;
     }
     if (entity is Player)
     {
         _players.Add(entity as Player);
     }
 }