Exemplo n.º 1
0
Configuration::Configuration() {
	Logfile::log("+Configuration at 0x%x\n", this);
	
	// Load in the config data
	set_config_file("lander.ini");

	showFPS = get_config_int("window","fps",0);
	fullscreen = get_config_int("window", "fullscreen", FALSE);

	sfx = get_config_int("audio","sfx",TRUE);
	music = get_config_int("audio","music",TRUE);

	musicVol = get_config_float("audio","musicvol",1.0f);
	soundVol = get_config_float("audio","soundvol",1.0f);
	
	Logfile::log("Configuration read:\n",0);
	Logfile::log(	"\tshowFPS: %d\n"
			"\tsfx: %d\n"
			"\tmusic: %d\n"
			"\tfullscreen: %d\n",
			showFPS, sfx, music, fullscreen);
	
	
	// This is lame, I know, but it gets the job done of turning
	// sound and music either on or off as specified in the file
	toggleSFX(); toggleSFX();
	toggleMusic(); toggleMusic();
}
Exemplo n.º 2
0
void event(SDL_Event e, int deltaTimeMs)
{
    if (e.type == SDL_KEYDOWN) {
        SDL_Scancode key = e.key.keysym.scancode;
        if (key == SDL_SCANCODE_SPACE) {
            toggleMusic();
        } else if (key == SDL_SCANCODE_C) {
            if (curr_buffer == buffer) curr_buffer = collision_buffer;
            else curr_buffer = buffer;
        } else if (key == SDL_SCANCODE_E) {
            character->torso_angle += 5;
            if (character->torso_angle > 360) {
                character->torso_angle = 0;
            }
        } else if (key == SDL_SCANCODE_Q) {
            character->torso_angle -= 5;
            if (character->torso_angle < 0) {
                character->torso_angle = 360;
            }
        }
    } else if (e.type == SDL_MOUSEMOTION) {
        mouse_x = e.motion.x + camera.x;
        mouse_y = e.motion.y + camera.y;

        deltaX = mouse_x - character->x - character->w/2;
        deltaY = mouse_y - character->y - character->h/2;

        double rad = atan2(deltaY, deltaX);
        if (rad < 0) {
            rad += 2*PI;
        }
        character->torso_angle = 90 + (rad * 360 / 2*PI) / 10;
    }
    eventEntity(character, e, (float) deltaTimeMs / 1000);
}
Exemplo n.º 3
0
void event(SDL_Event e, int deltaTimeMs)
{
    if (e.type == SDL_KEYDOWN) {
        SDL_Scancode key = e.key.keysym.scancode;
        if (key == SDL_SCANCODE_SPACE) {
            toggleMusic();
        } else if (key == SDL_SCANCODE_C) {
            if (curr_buffer == buffer) curr_buffer = collision_buffer;
            else curr_buffer = buffer;
        }
    }
    eventEntity(character, e, (float) deltaTimeMs / 1000);
}
Exemplo n.º 4
0
void MyWindow::handleEvent(SDL_Event e) {
    // MAIN FNS

    if (e.type == SDL_QUIT ||
            (e.type == SDL_KEYUP && e.key.keysym.sym == SDLK_q)) {
        isRunning = false;
    } else if (e.type == SDL_KEYUP) {
        switch(e.key.keysym.sym) {
        case SDLK_p:
            printStatus();
            break;
        case SDLK_m:
            toggleMusic();
            break;
        case SDLK_i: //toggleInventory(); break;// TODO: implement method
        default:
            break;
        }
    }

    // MOVEMENT

    if (e.type == SDL_KEYDOWN) {
        switch(e.key.keysym.sym) {
        case SDLK_a:
        case SDLK_LEFT:
            keys.left = true;
            break;
        case SDLK_s:
        case SDLK_DOWN:
            keys.down = true;
            break;
        case SDLK_d:
        case SDLK_RIGHT:
            keys.right = true;
            break;
        case SDLK_w:
        case SDLK_UP:
            keys.up = true;
            break;
        default:
            break;
        }
    } else if (e.type == SDL_KEYUP) {
        switch(e.key.keysym.sym) {
        case SDLK_a:
        case SDLK_LEFT:
            keys.left = false;
            break;
        case SDLK_s:
        case SDLK_DOWN:
            keys.down = false;
            break;
        case SDLK_d:
        case SDLK_RIGHT:
            keys.right = false;
            break;
        case SDLK_w:
        case SDLK_UP:
            keys.up = false;
            break;
        default:
            break;
        }
    }

    // MOUSE CLICKS

    for (unsigned int i = 0; i < MAX_BUTTON_COUNT; i++) {
        if (buttons[i] && !buttons[i]->isClicked()) {
            buttonsPressed[i] = buttons[i]->handleEvent(e);
        }
    }
}
Exemplo n.º 5
0
//The function responible for handling my finite state machine
void finiteStateMachine(int button){
	//May be a button debounce so exit the function
	if(doNotTriggerButton > 0)
		return;

	//The next bit contains the code monitoring the buttons
	//The buttons change their function depending on what mode the clock is
	//If the clock is running in normal mode
	if(state == RunNormal)
		switch(button){
			case 4  :
				switchTwelveHourMode();
			   break;
			case 5  :
				startModifyingTime(Alarm);
			   break;
			case 8  :
				//Stop the clock from operating
				startModifyingTime(Time);
				break;
			case 9  :
				toggleAlarm();
				break;
			case 11  :
				toggleMusic();
				break;
		}
	else if(state == SetupClocks)
		switch(button){
			case 4  :
				incrementModifyMinute(down);
				break;
			case 5  :
				incrementModifyMinute(up);
			   break;
			case 8  :
				incrementModifyHour(down);
				break;
			case 9  :
				incrementModifyHour(up);
				break;
			case 11  :
				finishModifyingTime();
				break;
		}
	else if(state == AlarmOn)
			switch(button){
				case 4  :
					switchTwelveHourMode();
					break;
				case 5  :
					enterSnoozeMode(10);
				   break;
				case 8  :
					enterSnoozeMode(15);
					break;
				case 9  :
					changeState(RunNormal);
					turnOffAlarm();
					break;
				case 11  :
					changeState(RunNormal);
					turnOffAlarm();
					break;
			}

	doNotTriggerButton = 50; //Set the debounce time
}