Exemplo n.º 1
0
void InputManager::waitForKeys(int key, const InputSource & source){
    InputMap<int> wait;
    wait.set(key, 0, false, 1);
    InputManager::waitForRelease(wait, source, 1);
    InputManager::waitForPress(wait, source, 1);
    InputManager::waitForRelease(wait, source, 1);
}
Exemplo n.º 2
0
int main(int argc, char ** argv){
    if (argc > 1){
        Global::InitConditions conditions;
        Global::init(conditions);
        
        Global::setDebug(0);
        std::string file = argv[1];

        Paintown::Mod::loadDefaultMod();
        
        InputManager manager;
        Graphics::Bitmap screen(*Graphics::getScreenBuffer());
        Util::Parameter<Graphics::Bitmap*> use(Graphics::screenParameter, &screen);
        Keyboard::pushRepeatState(true);
        
        InputMap<Keys> input;
        input.set(Keyboard::Key_ESC, 0, true, Esc);
        input.set(Keyboard::Key_ENTER, 0, true, Enter);
        input.set(Keyboard::Key_UP, 0, true, Up);
        input.set(Keyboard::Key_DOWN, 0, true, Down);
        input.set(Keyboard::Key_LEFT, 0, true, Left);
        input.set(Keyboard::Key_RIGHT, 0, true, Right);
       
        try {
            
            Filesystem::AbsolutePath path(file);
            CharacterSelect select(path);
            
            Logic logic(input, select);
            Draw draw(select);

            Util::standardLoop(logic, draw);
            
        } catch (const LoadException & ex){
            Global::debug(0) << "Problem loading file [" << file << "]. Reason: " << ex.getTrace() << std::endl;
        } catch (const TokenException & ex){
            Global::debug(0) << "Problem parsing file [" << file << "]. Reason: " << ex.getTrace() << std::endl;
        }
        
    } else {
        std::cout << "Usage: ./" << argv[0] << " select-screen.txt" << std::endl;
    }
    return 0;
}
Exemplo n.º 3
0
static void checkFullscreen(){
    InputMap<int> input;
    input.set(Keyboard::Key_F11, 0, true, 5);
    std::vector<InputMap<int>::InputEvent> events = InputManager::getEvents(input, InputSource(true));

    for (std::vector<InputMap<int>::InputEvent>::iterator it = events.begin(); it != events.end(); it++){
        InputMap<int>::InputEvent event = *it;

        if (!event.enabled){
            continue;
        }

        if (event.out == 5){
            changeScreenMode();
        }
    }
}
Exemplo n.º 4
0
int main(int argc, char ** argv){
    if (argc > 1){
        Global::InitConditions conditions;
        Global::init(conditions);
        
        Global::setDebug(0);
        std::string file = argv[1];
        
        InputManager manager;
        Graphics::Bitmap screen(*Graphics::getScreenBuffer());
        Util::Parameter<Graphics::Bitmap*> use(Graphics::screenParameter, &screen);
        Keyboard::pushRepeatState(true);
        
        InputMap<Keys> input;
        input.set(Keyboard::Key_ESC, 0, true, Esc);
        input.set(Keyboard::Key_ENTER, 0, true, Enter);
        input.set(Keyboard::Key_UP, 0, true, Up);
        input.set(Keyboard::Key_DOWN, 0, true, Down);
        input.set(Keyboard::Key_LEFT, 0, true, Left);
        input.set(Keyboard::Key_RIGHT, 0, true, Right);
        input.set(Keyboard::Key_S, 0, true, S);
        input.set(Keyboard::Key_P, 0, true, P);
        input.set(Keyboard::Key_R, 0, true, R);
        input.set(Keyboard::Key_SPACE, 0, true, SpaceBar);
        input.set(Keyboard::Key_1, 0, true, Key1);
        input.set(Keyboard::Key_2, 0, true, Key2);
        input.set(Keyboard::Key_3, 0, true, Key3);
        input.set(Keyboard::Key_4, 0, true, Key4);
        input.set(Keyboard::Key_5, 0, true, Key5);
        input.set(Keyboard::Key_6, 0, true, Key6);
       
        try {
            
            CutSceneTool cutscene(file);
            
            Logic logic(input, cutscene);
            Draw draw(cutscene);

            Util::standardLoop(logic, draw);
            
        } catch (const LoadException & ex){
            Global::debug(0) << "Problem loading file [" << file << "]. Reason: " << ex.getTrace() << std::endl;
        } catch (const TokenException & ex){
            Global::debug(0) << "Problem parsing file [" << file << "]. Reason: " << ex.getTrace() << std::endl;
        } catch (const Storage::NotFound & ex){
            Global::debug(0) << "Couldn't find file. Reason: " << ex.getTrace() << std::endl;
        }
        
    } else {
        std::cout << "Usage: ./" << argv[0] << " cutscene.txt" << std::endl;
    }
    return 0;
}
Exemplo n.º 5
0
vector<Input::PaintownInput> Player::fillKeyCache(){
    /*
    acts += 1;
    if (acts > GLOBAL_KEY_DELAY){
        if (!key_cache.empty()){
            key_cache.pop_front();
        }

        acts = 0;
    }
    */

    InputMap<Input::PaintownInput> input;
    InputSource useSource(true);
    if (source != NULL){
        useSource = *source;
    }

    int facing = getFacing();
    /* set up keyboard */
    if (useSource.useKeyboard()){
        enum Input::PaintownInput all[] = {Input::Forward, Input::Back, Input::Up, Input::Down, Input::Attack1, Input::Attack2, Input::Attack3, Input::Attack4, Input::Attack5, Input::Attack6, Input::Jump, Input::Grab};
        for (vector<int>::const_iterator it = useSource.getKeyboard().begin(); it != useSource.getKeyboard().end(); it++){
            for (unsigned int i = 0; i < sizeof(all) / sizeof(Input::PaintownInput); i++){
                input.set(getKey(*it, all[i], facing), 0, false, all[i]);
            }
        }
    }

    /* set up joystick */
    if (useSource.useJoystick()){
        enum Input::PaintownInput all[] = {Input::Forward, Input::Back, Input::Up, Input::Down, Input::Attack1, Input::Attack2, Input::Attack3, Input::Attack4, Input::Attack5, Input::Attack6, Input::Jump, Input::Grab};

        for (unsigned int i = 0; i < sizeof(all) / sizeof(Input::PaintownInput); i++){
            input.set(getJoystickKey( all[i], facing), 0, false, all[i]);
        }
    }

    acts += 1;

    // keyHold.back = false;

    vector<InputMap<Input::PaintownInput>::InputEvent> events = InputManager::getEvents(input, useSource);
    for (vector<InputMap<Input::PaintownInput>::InputEvent>::iterator it = events.begin(); it != events.end(); it++){
        InputMap<Input::PaintownInput>::InputEvent event = *it;

        /*
        switch (event.out){
            case Input::Forward: keyHold.forward = event.enabled; break;
            case Input::Back: keyHold.back = event.enabled; break;
            case Input::Up: keyHold.up = event.enabled; break;
            case Input::Down: keyHold.down = event.enabled; break;
            default: break;
        }
        */

        if (!event.enabled){
            continue;
        }

        key_cache.push_back(event.out);
        
        acts = 0;
    }

    while (key_cache.size() > KEY_CACHE_SIZE){
        key_cache.pop_front();
    }

    if (acts > GLOBAL_KEY_DELAY){
        key_cache.clear();
    }
        
    InputMap<Input::PaintownInput> inputHold;

    /* normalize such that forward is left */
    int facingHold = FACING_LEFT;
    enum Input::PaintownInput allHold[] = {Input::Forward, Input::Back, Input::Up, Input::Down};
    for (unsigned int i = 0; i < sizeof(allHold) / sizeof(Input::PaintownInput); i++){
        for (vector<int>::const_iterator it = useSource.getKeyboard().begin(); it != useSource.getKeyboard().end(); it++){
            inputHold.set(getKey(*it, allHold[i], facingHold), 0, false, allHold[i]);
        }

        if (useSource.useJoystick()){
            inputHold.set(getJoystickKey(allHold[i], facingHold), 0, false, allHold[i]);
        }
    }

    vector<InputMap<Input::PaintownInput>::InputEvent> eventsHold = InputManager::getEvents(inputHold, useSource);
    for (vector<InputMap<Input::PaintownInput>::InputEvent>::iterator it = eventsHold.begin(); it != eventsHold.end(); it++){
        InputMap<Input::PaintownInput>::InputEvent event = *it;

        switch (event.out){
            case Input::Forward: keyHold.left = event.enabled; break;
            case Input::Back: keyHold.right = event.enabled; break;
            case Input::Up: keyHold.up = event.enabled; break;
            case Input::Down: keyHold.down = event.enabled; break;
            default: break;
        }
    }

    vector<Input::PaintownInput> real_input;
    if (keyHold.up){
        real_input.push_back(Input::Up);
    }
    if (keyHold.down){
        real_input.push_back(Input::Down);
    }
    if (keyHold.left){
        if (getFacing() == FACING_LEFT){
            real_input.push_back(Input::Forward);
        } else {
            real_input.push_back(Input::Back);
        }
    }
    if (keyHold.right){
        if (getFacing() == FACING_LEFT){
            real_input.push_back(Input::Back);
        } else {
            real_input.push_back(Input::Forward);
        }
        // keyHold.forward = true;
    }

    return real_input;
}
Exemplo n.º 6
0
static InputMap<Keys> getKeys(){
    InputMap<Keys> input;
    input.set(Keyboard::Key_F1, 10, false, F1);
    input.set(Keyboard::Key_F2, 10, false, F2);
    input.set(Keyboard::Key_F3, 10, false, F3);
    input.set(Keyboard::Key_F4, 10, false, F4);
    input.set(Keyboard::Key_F5, 10, false, F5);
    input.set(Keyboard::Key_F6, 10, false, F6);
    input.set(Keyboard::Key_F7, 10, false, F7);
    input.set(Keyboard::Key_F8, 10, false, F8);
    input.set(Keyboard::Key_F9, 10, false, F9);
    input.set(Keyboard::Key_F10, 10, false, F10);
    input.set(Keyboard::Key_F11, 10, false, F11);
    input.set(Keyboard::Key_F12, 10, false, F12);
    input.set(Keyboard::Key_ESC, 10, false, Esc);
    input.set(Keyboard::Key_ENTER, 10, false, Enter);
    input.set(Keyboard::Key_UP, 10, false, Up);
    input.set(Keyboard::Key_DOWN, 10, false, Down);
    input.set(Keyboard::Key_LEFT, 10, false, Left);
    input.set(Keyboard::Key_RIGHT, 10, false, Right);
    input.set(Keyboard::Key_SPACE, 10, false, Space);
    input.set(Keyboard::Key_PGUP, 10, false, PageUp);
    input.set(Keyboard::Key_PGDN, 10, false, PageDown);
    input.set(Keyboard::Key_M, Action1);
    input.set(Keyboard::Key_P, Action2);
    
    return input;
}
Exemplo n.º 7
0
void doBackground(const std::string &file, const std::string &section){
    Mugen::Background background = Mugen::Background(Filesystem::AbsolutePath(file), section);
    Graphics::Bitmap workArea(320,240);
    Graphics::Bitmap screen(640,480);
    
    double runCounter = 0;
    Global::speed_counter4 = 0;
    Global::second_counter = 0;
    int game_time = 100;
    
    // Set game keys temporary
    InputMap<int> gameInput;
    gameInput.set(Keyboard::Key_ESC, 10, true, 0);
    gameInput.set(Keyboard::Key_UP, 1, false, 1);
    gameInput.set(Keyboard::Key_DOWN, 1, false, 2);
    gameInput.set(Keyboard::Key_LEFT, 1, false, 3);
    gameInput.set(Keyboard::Key_RIGHT, 1, false, 4);
    gameInput.set(Keyboard::Key_F1, 10, true, 5);
    gameInput.set(Keyboard::Key_LSHIFT, 1, false, 6);
    
    bool done = false;

    Mugen::Point camera;
    
    while ( ! done ){
    
	bool draw = false;
	
	if ( Global::speed_counter4 > 0 ){
	    draw = true;
	    runCounter += Global::speed_counter4 * Global::ticksPerSecond(60);
	    while ( runCounter >= 1.0 ){
		runCounter -= 1;
		// Key handler
		InputManager::poll();
		
                /*
		InputMap<int>::Output out = InputManager::getMap(gameInput);
		if (out[0]){
		    done = true;
		}

                int speed = 1;
                if (out[6]){
                    speed = 10;
                }

                if (out[1]){
		    camera.y -= speed;
		}
                if (out[2]){
		    camera.y += speed;
		}
                if (out[3]){
		    camera.x -= speed;
		}
                if (out[4]){
		    camera.x += speed;
		}
                if (out[5]){
                    // Reset camera
                    camera.x = camera.y = 0;
                }
                */
		
		// Backgrounds
		background.act();
	    }
	    
	    Global::speed_counter4 = 0;
	}
		
	while ( Global::second_counter > 0 ){
	    game_time--;
	    Global::second_counter--;
	    if ( game_time < 0 ){
		    game_time = 0;
	    }
	}

	if ( draw ){
	    // render backgrounds
	    background.renderBackground(camera.x, camera.y, workArea);
	    
	    // render Foregrounds
	    background.renderForeground(camera.x, camera.y, workArea);

            // This is a reminder of where the current 0,0 position is
            workArea.vLine(0,160,240,Graphics::makeColor(0,255,0));
            Font::getDefaultFont().printf( 5, 0, Graphics::makeColor(255,0,0), workArea, "Camera X: %i",0, camera.x );
            Font::getDefaultFont().printf( 5, 10, Graphics::makeColor(255,0,0), workArea, "Camera Y: %i",0, camera.y );
	    
	    // Finally render to screen
	    workArea.Stretch(screen);
	    screen.BlitToScreen();
	}

	while ( Global::speed_counter4 < 1 ){
		PaintownUtil::rest( 1 );
	}
    }
}