Esempio n. 1
0
        public override void OnScreenCreate()
        {
            Title         = new TextDisplay(0, 0, "BRME", 30, new RGBColor(255, 105, 24));
            Title.X       = DrawHelper.CenteredToScreenWidth(Title.Width);
            Title.Y       = 20;
            Title.Outline = true;

            PlayButton   = new TextButton("Play", 30);
            PlayButton.X = DrawHelper.CenteredToScreenWidth(PlayButton.Width);
            PlayButton.Y = DrawHelper.CenteredToScreenHeight(PlayButton.Height);
            PlayButton.Y = 700;
            PlayButton.TextDisplay.Outline = true;
            PlayButton.AddEventListener(Event.CLICKLEFT, OnPlay);
            PlayButton.AddEventListener(Event.MOUSEOVER, OnPlayButtonOver);
            PlayButton.AddEventListener(Event.MOUSEOUT, OnPlayButtonOut);

            Background = new FilledRectangle(AssetLibrary.Images["titleScreenBackGround"])
            {
                X = 0,
                Y = 0
            };

            Background.AddChild(Title);
            Background.AddChild(PlayButton);

            NetworkClient.SendPacket(new ClientResponse()
            {
                From    = "GetUnlockedCharacters",
                Result  = 0,
                Content = ""
            });
        }
Esempio n. 2
0
    public override void OnAwake()
    {
        CreateBackground();

        _physicsContainer = PhysicsContainer.NewEmpty(Vector2.up * -30f);
        AddChild(_physicsContainer);

        var field = CinchSprite.NewFromImage("Cinch2D/Field", 512);

        field.Width  = ViewportWidth;
        field.Height = 1f;

        //create a physics body for the field, same size as the CinchSprite
        var fieldBody = BodyFactory.CreateRectangle(_physicsContainer.World, field.Width, field.Height, 1);

        //as soon as we set the fieldBody as field's PhysicsBody, field will take its position and rotation from fieldBody after every frame
        field.PhysicsBody = fieldBody;
        //align it with the bottom of the screen
        //setting physics body position will update sprite's position on next frame
        fieldBody.Position = new Vector2(0, 0 - ViewportHeight / 2 + field.Height / 2f);
        //set the field as static so it uses less CPU
        fieldBody.IsStatic = true;
        //make it a wee bit bouncy
        fieldBody.Restitution = .5f;
        _physicsContainer.AddChild(field);

        //create a soccer ball to roll around
        var ball = CinchSprite.NewFromImage("Cinch2D/SoccerBall", 256);

        _ballBody          = BodyFactory.CreateCircle(_physicsContainer.World, .5f, 1f);
        ball.PhysicsBody   = _ballBody;
        _ballBody.BodyType = BodyType.Dynamic;
        //drop it on the right side of the screen
        _ballBody.Position = new Vector2(ViewportWidth / 2 - 1, 0);

        //we add all physics objects to the same parent.
        //Adding a physics object as a child of another physics object (like a wheel as a child of a car), will produce super-bad results.
        //you can still add non-physics objects to different containers, like a mud splat as a child of the ball
        _physicsContainer.AddChild(ball);

        var player1 = CreatePlayer();
        var player2 = CreatePlayer();

        _physicsContainer.AddChild(player1);
        _physicsContainer.AddChild(player2);

        player1.Y = player2.Y = 0 - ViewportHeight / 2 + field.Height + player1.Height / 2;
        player1.X = 0 - ViewportWidth / 2 + 1;
        player2.X = ViewportWidth / 2 - 1;
        player1.PhysicsBody.OnCollision += BallHitPlayer1;
        player2.PhysicsBody.OnCollision += BallHitPlayer2;

        _debugDrawButton      = Library.New <TextButton>("DebugDrawToggle");
        _debugDrawButton.Text = "Debug: Off";
        AddChild(_debugDrawButton);
        _debugDrawButton.Y = 0 + ViewportHeight / 2 - _debugDrawButton.Height;
        //toggle debug draw when pressed
        _debugDrawButton.AddEventListener <MouseEvent>(MouseEvent.MOUSE_UP, ToggleDebugDraw);
    }
Esempio n. 3
0
    public override void OnAwake()
    {
        CreateBackground();

        _physicsContainer = PhysicsContainer.NewEmpty(Vector2.up * -30f);
        AddChild(_physicsContainer);

        var field = CinchSprite.NewFromImage("Cinch2D/Field", 512);
        field.Width = ViewportWidth;
        field.Height = 1f;

        //create a physics body for the field, same size as the CinchSprite
        var fieldBody = BodyFactory.CreateRectangle(_physicsContainer.World, field.Width, field.Height, 1);

        //as soon as we set the fieldBody as field's PhysicsBody, field will take its position and rotation from fieldBody after every frame
        field.PhysicsBody = fieldBody;
        //align it with the bottom of the screen
        //setting physics body position will update sprite's position on next frame
        fieldBody.Position = new Vector2(0, 0 - ViewportHeight/2 + field.Height/2f);
        //set the field as static so it uses less CPU
        fieldBody.IsStatic = true;
        //make it a wee bit bouncy
        fieldBody.Restitution = .5f;
        _physicsContainer.AddChild(field);

        //create a soccer ball to roll around
        var ball = CinchSprite.NewFromImage("Cinch2D/SoccerBall", 256);
        _ballBody = BodyFactory.CreateCircle(_physicsContainer.World, .5f, 1f);
        ball.PhysicsBody = _ballBody;
        _ballBody.BodyType = BodyType.Dynamic;
        //drop it on the right side of the screen
        _ballBody.Position = new Vector2(ViewportWidth/2 - 1, 0);

        //we add all physics objects to the same parent.
        //Adding a physics object as a child of another physics object (like a wheel as a child of a car), will produce super-bad results.
        //you can still add non-physics objects to different containers, like a mud splat as a child of the ball
        _physicsContainer.AddChild(ball);

        var player1 = CreatePlayer();
        var player2 = CreatePlayer();
        _physicsContainer.AddChild(player1);
        _physicsContainer.AddChild(player2);

        player1.Y = player2.Y = 0 - ViewportHeight/2 + field.Height + player1.Height/2;
        player1.X = 0 - ViewportWidth/2 + 1;
        player2.X = ViewportWidth/2 - 1;
        player1.PhysicsBody.OnCollision += BallHitPlayer1;
        player2.PhysicsBody.OnCollision += BallHitPlayer2;

        _debugDrawButton = Library.New<TextButton>("DebugDrawToggle");
        _debugDrawButton.Text = "Debug: Off";
        AddChild(_debugDrawButton);
        _debugDrawButton.Y = 0 + ViewportHeight / 2 - _debugDrawButton.Height;
        //toggle debug draw when pressed
        _debugDrawButton.AddEventListener<MouseEvent>(MouseEvent.MOUSE_UP, ToggleDebugDraw);
    }