コード例 #1
0
        // Private methods

        private GotchiTransform[] _getAnimationTransforms(GotchiState type)
        {
            GotchiTransform[] transforms = new GotchiTransform[2];

            for (int i = 0; i < transforms.Count(); ++i)
            {
                transforms[i] = new GotchiTransform();
            }

            // The emote should bob up and down for all animations.
            transforms[0].EmoteOffset.Y = 0;
            transforms[1].EmoteOffset.Y = -2;

            switch (type)
            {
            default:
            case GotchiState.Hungry:
                transforms[0].Offset.Y = 0;
                transforms[1].Offset.Y = 2;
                break;

            case GotchiState.Eating:
            case GotchiState.Happy:
                transforms[0].Angle = 10;
                transforms[1].Angle = -10;
                break;

            case GotchiState.Sleeping:
                transforms[0].Angle = 90;
                transforms[1].Angle = 90;
                break;

            case GotchiState.Dead:
                transforms[0].Angle = 180;
                transforms[1].Angle = 180;
                break;

            case GotchiState.Tired:
                transforms[0].Offset.Y = 0;
                transforms[1].Offset.Y = 1;
                break;

            case GotchiState.Energetic:
                transforms[0].Angle    = 10;
                transforms[1].Angle    = -10;
                transforms[0].Offset.Y = 0;
                transforms[1].Offset.Y = -4;
                break;
            }

            return(transforms);
        }
コード例 #2
0
        private void _drawGotchi(Graphics gfx, GotchiParams gotchi, GotchiTransform transform)
        {
            Bitmap img = gotchi.Image.Bitmap;

            if (img is null)
            {
                return;
            }

            // Scale gotchi image so all gotchis are drawn at an appropriate size.

            int   max_w   = 75;
            int   max_h   = 75;
            float scale_w = max_w / (float)img.Width;
            float scale_h = max_h / (float)img.Height;

            float scale = Math.Min(scale_w, scale_h);

            int w = (int)(img.Width * scale);
            int h = (int)(img.Height * scale);

            // Draw the gotchi's shadow.

            using (Brush brush = new SolidBrush(Color.FromArgb(40, Color.Black))) {
                int shadow_w = (int)((float)w * 0.75);

                gfx.FillEllipse(brush, gotchi.Position.X - (shadow_w / 2), gotchi.Position.Y + h / 2, shadow_w, 10);
            }

            // Draw the gotchi.

            gotchi.Position.X += transform.Offset.X;
            gotchi.Position.Y += transform.Offset.Y;

            gfx.TranslateTransform(gotchi.Position.X, gotchi.Position.Y);
            gfx.RotateTransform(transform.Angle);
            gfx.TranslateTransform(-gotchi.Position.X, -gotchi.Position.Y);

            gfx.DrawImage(img, new Rectangle(gotchi.Position.X - (w / 2), gotchi.Position.Y - (h / 2), w, h));

            gfx.ResetTransform();

            gotchi.Position.X -= transform.Offset.X;
            gotchi.Position.Y -= transform.Offset.Y;

            // Draw the emote.

            _drawEmote(gfx, gotchi.Type, gotchi.Position.X, gotchi.Position.Y + transform.EmoteOffset.Y, w, h);
        }