예제 #1
0
        public void Draw(Bitmap bgimg, FallingStone Pebble, List <Obstacle> Obstacles, int speed, int tick)
        {
            if (shift > destinationRect.Width / 2)
            {
                shift = shift % (destinationRect.Width / 2);
            }
            if (tick % 15 == 1)
            {
                score += (5 * (speed - 2));
            }
            destinationRect.X = shift += (1 + speed);
            graphics.DrawImage(bgimg, sourceRect, destinationRect, GraphicsUnit.Pixel);
            graphics.DrawImage(Pebble.Pic, Pebble.ScaledPengRect, Pebble.DefPengRect, GraphicsUnit.Pixel);

            //Debug
            //graphics.FillRectangle(new SolidBrush(Color.Red), 450 / 2, 450 / 2, 2, 2);
            //graphics.DrawRectangle(new Pen(new SolidBrush(Color.Black), 1), Pebble.ScaledPengRect);

            Pebble.Fly();
            foreach (Obstacle obs in Obstacles)
            {
                graphics.DrawImage(Ice, obs.rectangle, obs.defrectangle, GraphicsUnit.Pixel);
                obs.Shift(speed);
            }
            graphics.DrawString
            (
                score.ToString(),
                new Font(FontFamily.GenericMonospace, 30, FontStyle.Bold, GraphicsUnit.Pixel),
                new SolidBrush(Color.WhiteSmoke),
                450 - 21 * (score.ToString().Length),
                0
            );
            Parent.Invalidate();
        }
예제 #2
0
        public GameDrawing(Bitmap bm, ref PictureBox _Parent, FallingStone Pebble)
        {
            this.Game         = bm;
            this.graphics     = Graphics.FromImage(Game);
            this.Parent       = _Parent;
            this.Parent.Image = Game;

            destinationRect = new Rectangle(0, 0, bm.Width, bm.Height);
            sourceRect      = destinationRect;
        }
예제 #3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            tick   = 0;
            speed  = 2;
            _score = 0;

            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);

            Pebble = new FallingStone();

            Obstacles = new List <Obstacle>();

            gameDrawing = new GameDrawing(new Bitmap(BgCitySrc), ref pictureBox1, Pebble);

            timer1.Interval = 1000 / 60;
            timer1.Start();
            GameState = 1;
        }