Example #1
0
        public bool process()
        {
            // Check input states

            SDL.SDL_Event e;
            while (SDL.SDL_PollEvent(out e) != 0)
            {
                switch (e.type)
                {
                case SDL.SDL_EventType.SDL_QUIT:
                    SDL.SDL_PushEvent(ref e);
                    return(false);

                case SDL.SDL_EventType.SDL_KEYDOWN:
                    // Figure out which key
                    switch (e.key.keysym.sym)
                    {
                    case SDL.SDL_Keycode.SDLK_ESCAPE:
                        return(false);

                    case SDL.SDL_Keycode.SDLK_SPACE:
                        harambe.startJump();
                        break;

                    case SDL.SDL_Keycode.SDLK_a:
                        harambe.startLeft();
                        break;

                    case SDL.SDL_Keycode.SDLK_d:
                        harambe.startRight();
                        break;
                    }
                    break;

                case SDL.SDL_EventType.SDL_KEYUP:
                    // Figure out which key
                    switch (e.key.keysym.sym)
                    {
                    case SDL.SDL_Keycode.SDLK_SPACE:
                        harambe.stopJump();
                        break;

                    case SDL.SDL_Keycode.SDLK_a:
                        harambe.stopLeft();
                        break;

                    case SDL.SDL_Keycode.SDLK_d:
                        harambe.stopRight();
                        break;
                    }
                    break;
                }
            }

            // Process physics
            if (ticks == 0)
            {
                ticks = SDL.SDL_GetTicks();
            }
            else
            {
                uint newticks = SDL.SDL_GetTicks();
                uint delta    = newticks - ticks;
                ticks = newticks;

                harambe.process((float)delta);
            }

            // Loss detection
            if (harambe.getY() > height * TILE_SIZE)
            {
                MenuView loss = new MenuView("You dun f****d up");
                loss.addOption("Return");
                loss.HandleOptionEvent += Loss_HandleOptionEvent;

                Engine.AddView(loss);
                return(false);
            }

            return(true);
        }