Example #1
0
    public override void Begin()
    {
        // 1. Game style and size
        SetWindowSize(1024, 768);
        SmoothTextures = false; // false = use NN? scaling
        Mouse.IsCursorVisible = true;

        // 2. Level, OSD and others
        Gravity = new Vector(0, -1000);
        SetupLevel();
        CreateOSD();

        // 3. Cats
        player = CreateCat(Color.FromHexCode("DD7777"));
        // Other competitors
        for (int i = 0; i < 3 ; i++)
        {
            Timer.SingleShot(RandomGen.NextDouble(0.3, 3.0), AddNewRunnerCat);
        }
        Camera.Follow(player);

        // 4. Input devices
        Mouse.Listen(MouseButton.Left, ButtonState.Released, MouseClicked, "Jump a cat");
        Keyboard.Listen(Key.P, ButtonState.Pressed, Pause, "Pause/Unpause the game");
        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Exit game");
        Keyboard.Listen(Key.Right, ButtonState.Down, RunRight, "Walk/Run to right");
        Keyboard.Listen(Key.Left, ButtonState.Down, RunLeft, "Walk/Run to left");
        Keyboard.Listen(Key.Right, ButtonState.Released, Stopping, "Stop Walk/Run to right");
        Keyboard.Listen(Key.Left, ButtonState.Released, Stopping, "Stop Walk/Run to left");
        Keyboard.Listen(Key.Up, ButtonState.Pressed, PrepareToJump, "Prepare to jump! (longer you hold, bigger the jump)");
        Keyboard.Listen(Key.Up, ButtonState.Down, UpdateJumpMeter, "");
        Keyboard.Listen(Key.Up, ButtonState.Released, Jump, "Jump!");
        Keyboard.Listen(Key.Down, ButtonState.Pressed, Sit, "Sit down");

        // 5. Give directions
        guideLabel = new Label("Rescue your fellow cats\nby herding them\n(clicking them makes a cat jump).");
        guideLabel.Font = Font.DefaultLargeBold;
        guideLabel.TextColor = Color.White;
        Add(guideLabel);
        Timer.SingleShot(3, OnHideGuide);
    }
Example #2
0
    ClimbingPlatformCharacter CreateCat(Color catColor)
    {
        Converter<Color, Color> tiltTo = pixelColor =>
        {
            Color col = pixelColor;
            if (pixelColor.AlphaComponent > 128 && pixelColor != Color.Black && pixelColor != Color.White)
            {
                col = new Color(
                    (pixelColor.RedComponent + catColor.RedComponent) / 2,
                    (pixelColor.GreenComponent + catColor.GreenComponent) / 2,
                    (pixelColor.BlueComponent + catColor.BlueComponent) / 2);
            }
            return col;
        };
        Image coloredStandCatSkin = catStandSkin.Clone();
        coloredStandCatSkin.ApplyPixelOperation(tiltTo);
        Image coloredSitCatSkin = catSitSkin.Clone();
        coloredSitCatSkin.ApplyPixelOperation(tiltTo);
        Image coloredFlyCatSkin = catFlySkin.Clone();
        coloredFlyCatSkin.ApplyPixelOperation(tiltTo);
        Image coloredCatHangsSkin = catHangsSkin.Clone();
        coloredCatHangsSkin.ApplyPixelOperation(tiltTo);

        Image[] coloredCatRunSkins = new Image[catRunSkins.Length];
        for (int i = 0; i < catRunSkins.Length; i++)
        {
            coloredCatRunSkins[i] = catRunSkins[i].Clone();
            coloredCatRunSkins[i].ApplyPixelOperation(tiltTo);
        }

        Image[] coloredCatClimbSkins = new Image[catClimbSkins.Length];
        for (int i = 0; i < catClimbSkins.Length; i++)
        {
            coloredCatClimbSkins[i] = catClimbSkins[i].Clone();
            coloredCatClimbSkins[i].ApplyPixelOperation(tiltTo);
        }

        ClimbingPlatformCharacter cat = new ClimbingPlatformCharacter(79, 79);
        cat.Image = coloredStandCatSkin;
        cat.AnimIdle = coloredSitCatSkin;
        cat.AnimWalk = new Animation(coloredCatRunSkins);
        cat.AnimJump = coloredFlyCatSkin;
        cat.AnimHangs = coloredCatHangsSkin;
        cat.AnimClimb = new Animation(coloredCatClimbSkins);
        cat.Shape = Shape.FromImage(catHitBox);

        cat.Tag = "cat";

        //cat.Image = catSkin;
        //cat.CanMoveOnAir = false;
        cat.LinearDamping = AIR_FRICTION;
        Add(cat);

        AddCollisionHandler(cat, "roof", OnCatCollidesRoof);
        AddCollisionHandler(cat, "flag", OnCatCollidesFlag);

        return cat;
    }