Пример #1
0
        void timer_Tick(object sender, EventArgs e)
        {
            if (running)
            {
                if (tolvl != 0)
                {
                    if (tolvl != levelno)
                    {
                        drawadv = 100;
                    }
                    if (tolvl == 1)
                    {
                        currentLevel = LoadLevel(Properties.Resources.level1, this, imageset);
                        levelno      = 1;
                    }
                    if (tolvl == 2)
                    {
                        currentLevel = LoadLevel(Properties.Resources.level2, this, imageset);
                        levelno      = 2;
                    }
                    tolvl = 0;
                }

                if (drawadv > 0)
                {
                    drawadv--;
                }

                if (lives <= 0)
                {
                    gameover = true;
                    running  = false;
                }

                Matrix m = new Matrix();
                m.Translate(camera.X, camera.Y);
                inputstate.CameraMatrix = m;
                foreach (Sprite s in currentLevel.GetSpriteList())
                {
                    s.Update(currentLevel, inputstate, inputstateP);
                }
                Invalidate();
                inputstateP = (InputState)inputstate.Clone();
            }
            else
            {
                Invalidate();
            }
        }
Пример #2
0
        public override void UpdateSelf(Level l, InputState s, InputState sp)
        {
            angle = X * ((128 * (float)Math.PI) / 360);
            if (s.KeyDown(Keys.Up))
            {
                jump = 10;
            }
            if (s.KeyDown(Keys.Right))
            {
                XVel += 1;
                //cam -= 10;
            }
            if (s.KeyDown(Keys.Left))
            {
                XVel -= 1;
                //cam += 10;
            }
            if (s.KeyDown(Keys.R))
            {
                X    = 500;
                Y    = 500;
                XVel = 0;
                YVel = 0;
            }
            if (s.KeyDown(Keys.Space))
            {
                //Friction = 0.99F;
                Friction = 1.01F;
            }
            else
            {
                Friction = 0.95F;
            }
            cam -= XVel;
            if (cam < 256)
            {
                cam = 256;
            }
            if (cam > (l.Owner.Width - 512))
            {
                cam = (l.Owner.Width - 512);
            }
            l.Owner.Camera = new PointF(cam - X, 0);
            if (l.Owner.Camera.X > 0)
            {
                l.Owner.Camera = new PointF(0, 0);
            }

            topC    = false;
            rightC  = false;
            bottomC = false;
            leftC   = false;

            foreach (Sprite t in l.GetSpriteList())
            {
                if (t.GetType().Name.Equals("FloorTile"))
                {
                    switch (CollisionState(t))
                    {
                    case 1:
                        topC = true;
                        break;

                    case 2:
                        rightC = true;
                        break;

                    case 3:
                        bottomC = true;
                        break;

                    case 4:
                        leftC = true;
                        break;
                    }
                }
                if (t.GetType().Name.Equals("BounceTile"))
                {
                    switch (CollisionState(t))
                    {
                    case 1:
                        boost = 10;
                        topC  = true;
                        break;

                    case 2:
                        rightC = true;
                        break;

                    case 3:
                        bottomC = true;
                        break;

                    case 4:
                        leftC = true;
                        break;
                    }
                }
                if (CollisionState(t) != 0)
                {
                    if (t.GetType().Name.Equals("Door"))
                    {
                        l.Owner.ToLevel(l.Owner.levelno + 1);
                    }
                    if (t.GetType().Name.Equals("SpikeTile"))
                    {
                        l.Owner.ToLevel(l.Owner.levelno);
                        l.Owner.lives -= 1;
                    }
                }
            }
            if ((jump > 0) && topC)
            {
                if (boost > 0)
                {
                    YVel = -70;
                    jump = 0;
                }
                else
                {
                    YVel = -40;
                    jump = 0;
                }
            }
            if (jump > 0)
            {
                jump -= 1;
            }
            if (boost > 0)
            {
                boost -= 1;
            }
            if (topC)
            {
                YVel = -(float)Math.Abs(YVel);
            }
            else
            {
                YVel += 2;
            }
            if (rightC)
            {
                XVel = (float)Math.Abs(XVel);
            }
            if (bottomC)
            {
                YVel = (float)Math.Abs(YVel);
            }
            if (leftC)
            {
                XVel = -(float)Math.Abs(XVel);
            }
            if (Y > l.Owner.Height + 256)
            {
                l.Owner.ToLevel(l.Owner.levelno);
                l.Owner.lives -= 1;
            }
        }