Example #1
0
 public static float Align(Camera camera, float pos)
 {
     return(((int)(pos * camera.Zoom)) / camera.Zoom);
 }
Example #2
0
        public override void Create()
        {
            base.Create();

            GameScene.Scene = null;

            defaultZoom = (int)Math.Ceiling(Game.density * 2.5);
            while ((Game.Width / defaultZoom < MIN_WIDTH || Game.Height / defaultZoom < MIN_HEIGHT) && defaultZoom > 1)
            {
                defaultZoom--;
            }

            landscapeAvailable = Game.Height / defaultZoom >= MIN_WIDTH && Game.Width / defaultZoom >= MIN_HEIGHT;

            if (PixelDungeon.ScaleUp())
            {
                while ((Game.Width / (defaultZoom + 1) >= MIN_WIDTH && Game.Height / (defaultZoom + 1) >= MIN_HEIGHT))
                {
                    defaultZoom++;
                }
            }

            minZoom = 1;
            maxZoom = defaultZoom * 2;


            Camera.Reset(new PixelCamera(defaultZoom));

            float uiZoom = defaultZoom;

            uiCamera = Camera.CreateFullscreen(uiZoom);
            Camera.Add(uiCamera);

            if (font1x == null)
            {
                // 3x5 (6)
                font1x          = Font.ColorMarked(BitmapCache.Get(Assets.FONTS1X), Android.Graphics.Color.Argb(0x00, 0x00, 0x00, 0x00), Font.LatinFull);
                font1x.BaseLine = 6;
                font1x.tracking = -1;

                // 5x8 (10)
                font15x          = Font.ColorMarked(BitmapCache.Get(Assets.FONTS15X), 12, Android.Graphics.Color.Argb(0x00, 0x00, 0x00, 0x00), Font.LatinFull);
                font15x.BaseLine = 9;
                font15x.tracking = -1;

                // 6x10 (12)
                font2x          = Font.ColorMarked(BitmapCache.Get(Assets.FONTS2X), 14, Android.Graphics.Color.Argb(0x00, 0x00, 0x00, 0x00), Font.LatinFull);
                font2x.BaseLine = 11;
                font2x.tracking = -1;

                // 7x12 (15)
                font25x          = Font.ColorMarked(BitmapCache.Get(Assets.FONTS25X), 17, Android.Graphics.Color.Argb(0x00, 0x00, 0x00, 0x00), Font.LatinFull);
                font25x.BaseLine = 13;
                font25x.tracking = -1;

                // 9x15 (18)
                font3x          = Font.ColorMarked(BitmapCache.Get(Assets.FONTS3X), 22, Android.Graphics.Color.Argb(0x00, 0x00, 0x00, 0x00), Font.LatinFull);
                font3x.BaseLine = 17;
                font3x.tracking = -2;
            }

            Sample.Instance.Load(Assets.SND_CLICK, Assets.SND_BADGE, Assets.SND_GOLD);
        }
Example #3
0
        public override void Create()
        {
            base.Create();

            Music.Instance.Play(Assets.HAPPY, true);
            Music.Instance.Volume(1f);

            uiCamera.Visible = false;

            var w = pdsharp.noosa.Camera.Main.CameraWidth;
            var h = pdsharp.noosa.Camera.Main.CameraHeight;

            var archs = new Archs();

            archs.Reversed = true;
            archs.SetSize(w, h);
            Add(archs);

            var vx = Align((w - WIDTH) / 2);
            var vy = Align((h - HEIGHT) / 2);

            var s = pdsharp.noosa.Camera.Main.CameraToScreen(vx, vy);

            _viewport = new pdsharp.noosa.Camera(s.X, s.Y, WIDTH, HEIGHT, defaultZoom);
            pdsharp.noosa.Camera.Add(_viewport);

            var window = new Group();

            window.Camera = _viewport;
            Add(window);

            var dayTime = !Dungeon.NightMode;

            var sky = new Sky(dayTime);

            sky.Scale.Set(WIDTH, HEIGHT);
            window.Add(sky);

            if (!dayTime)
            {
                for (var i = 0; i < Nstars; i++)
                {
                    var size = pdsharp.utils.Random.Float();
                    var star = new ColorBlock(size, size, Color.Argb(255, 255, 255, 255));
                    star.X  = pdsharp.utils.Random.Float(WIDTH) - size / 2;
                    star.Y  = pdsharp.utils.Random.Float(HEIGHT) - size / 2;
                    star.Am = size * (1 - star.Y / HEIGHT);
                    window.Add(star);
                }
            }

            const float range = HEIGHT * 2 / 3;

            for (var i = 0; i < Nclouds; i++)
            {
                var cloud = new Cloud((Nclouds - 1 - i) * (range / Nclouds) + pdsharp.utils.Random.Float(range / Nclouds), dayTime);
                window.Add(cloud);
            }

            var nPatches = (int)(sky.Width / GrassPatch.WIDTH + 1);

            for (var i = 0; i < nPatches * 4; i++)
            {
                var patch = new GrassPatch((i - 0.75f) * GrassPatch.WIDTH / 4, HEIGHT + 1, dayTime);
                patch.Brightness(dayTime ? 0.7f : 0.4f);
                window.Add(patch);
            }

            var a = new Avatar(Dungeon.Hero.heroClass);

            a.X = Align((WIDTH - a.Width) / 2);
            a.Y = HEIGHT - a.Height + 1;
            window.Add(a);

            var pet = new Pet();

            pet.Rm = pet.Gm = pet.Bm = 1.2f;
            pet.X  = WIDTH / 2 + 2;
            pet.Y  = HEIGHT - pet.Height;
            window.Add(pet);

            if (dayTime)
            {
                a.Brightness(1.2f);
                pet.Brightness(1.2f);
            }

            //window.Add(new TouchArea(sky) { protected void OnClick(Touch touch) { pet.Jump(); }; });

            for (var i = 0; i < nPatches; i++)
            {
                var patch = new GrassPatch((i - 0.5f) * GrassPatch.WIDTH, HEIGHT, dayTime);
                patch.Brightness(dayTime ? 1.0f : 0.8f);
                window.Add(patch);
            }

            var frame = new Image(Assets.SURFACE);

            if (!dayTime)
            {
                frame.Hardlight(0xDDEEFF);
            }

            frame.Frame(0, 0, 88, 125);
            frame.X = vx - 4;
            frame.Y = vy - 9;
            Add(frame);

            var gameOver = new RedButton("Game Over");

            gameOver.ClickAction = GameOverClickAction;
            gameOver.SetSize(WIDTH - 10, 20);
            gameOver.SetPos(5 + frame.X + 4, frame.Y + frame.Height + 4);
            Add(gameOver);

            Badge.ValidateHappyEnd();

            FadeIn();
        }