Beispiel #1
0
// dodac mozliwosc zakresu reg i wskazniki, bo teraz to nic nie dzia³a xD
void regulacja(uint8_t *var_tim,const uint8_t min,const uint8_t max){
	if(key_down(KEY_PLUS)) {
		++*var_tim;
		if (*var_tim == (max+1)) *var_tim = max;
	}

	if(key_down(KEY_MINUS)){
		--*var_tim;
		if (*var_tim == (min-1)) *var_tim = min;
	}

	PORTB = pgm_read_byte(&znak[*var_tim]);
}
Beispiel #2
0
int main(int argc, char *argv[])
{
	UNUSED(argc); UNUSED(argv);
	int exit_status = EXIT_FAILURE;
	bit quit = 0;
	SDL_Event e;

	INIT_SDL();

	font1 = TTF_OPENFONT("sdl/OpenSans-Regular.ttf", 28);
	font2 = TTF_OPENFONT("sdl/OpenSans-Regular.ttf", 100);
	text1 = TEXTURE_FROM_TEXT(font1, "Press S to start / stop, P to pause / unpause.", (SDL_Color){0xFF, 0xFF, 0xFF, 0xFF});
	text3 = TEXTURE_FROM_TEXT(font2, "BOGOMETER", (SDL_Color){0xFF, 0x7F, 0x3F, 0xFF});

	while (!quit) {
		DRAW();
		if (SDL_PollEvent(&e)) {
			if (e.type == SDL_QUIT)
				quit = 1;
			else if (e.type == SDL_KEYDOWN)
				key_down(e.key.keysym.sym);
		}
	}

	exit_status = EXIT_SUCCESS;
error:
	SDL_DestroyTexture(text1);
	SDL_DestroyTexture(text3);
	TTF_CloseFont(font1);
	TTF_CloseFont(font2);
	close_sdl();
	exit(exit_status);
}
int main(int argc, char *argv[])
{
	UNUSED(argc); UNUSED(argv);
	int exit_status = EXIT_FAILURE;
	bit quit = 0;
	SDL_Event e;

	INIT_SDLGL();

	while (!quit) {
		while (SDL_PollEvent(&e)) {
			if (e.type == SDL_QUIT)
				quit = 1;
			if (e.type == SDL_KEYDOWN)
				key_down(e.key.keysym.sym);
		}

		draw();
		SDL_GL_SwapWindow(window);
		GL_CHECK("GL Frame");
	}

	exit_status = EXIT_SUCCESS;
error:
	close_sdl();
	exit(exit_status);
}
Beispiel #4
0
int main(int argc, char *argv[])
{
	UNUSED(argc); UNUSED(argv);
	int exit_status = EXIT_FAILURE;
	bit quit = 0;
	SDL_Event e;

	INIT_SDL();

	sprite_sheet = LOAD_TEXTURE("sdl/sprite_sheet.png");

	DRAW();
	while (!quit) {
		SDL_WAITEVENT(&e);
		if (e.type == SDL_QUIT)
			quit = 1;
		else if (e.type == SDL_KEYDOWN) {
			key_down(e.key.keysym.sym);
			DRAW();
		}
	}

	exit_status = EXIT_SUCCESS;
error:
	SDL_DestroyTexture(sprite_sheet);
	close_sdl();
	exit(exit_status);
}
Beispiel #5
0
void serwis (void){
//wchodzimy w tryb serwisowy
//	tutaj zapisujemy dane do eepromu
	uint8_t n = 0;
	uint8_t t_kropki = eeprom_read_byte(0x01);
	uint8_t t_kreski = eeprom_read_byte(0x02);
	uint8_t t_pauzy  = eeprom_read_byte(0x03);
	PORTB=0x00;

	for ( uint8_t i = 6 ; i ; --i){
		PORTB = ~PORTB;
		_delay_ms(300);
	}
//tu pole do popisu :
	// mo¿na przerobiæ kod na tablice i wykorzystaæ n do indeksowania,
	// argumentem funkcji by³oby tab[n] !
	while ( n<3 ){
		if ( key_down ( KEY_SET)){ ++n; zamigaj(); }

		if (n == 0)regulacja(&t_kropki,1,5);
			//ustaw pauzê // regulacja od 0.1 do 0.5
		if (n == 1)regulacja(&t_kreski,3,15);
			//ustaw kropkê  // regulacja od 0.1 do 0.5
		if (n == 2)regulacja(&t_pauzy,1,5);
			//ustaw kreskê // regulacja od 0.3 do 1.5
	}
	//wpisz z powrotem dane do eepromu
	eeprom_write_byte(0x01,t_kropki);
	eeprom_write_byte(0x02,t_kreski);
	eeprom_write_byte(0x03,t_pauzy);
	PORTB=0xff;
}
Beispiel #6
0
void Menu::HandleEvent(const SDL_Event& evnt)
{
  if (evnt.type == SDL_QUIT) {
#if defined MAEMO || defined __SYMBIAN32__
    AppWarmux::EmergencyExit();
#else
    key_cancel();
#endif
  } else if (evnt.type == SDL_KEYDOWN) {

    // Drop key events that are purely modifiers
    if (Keyboard::IsModifier(evnt.key.keysym.sym))
      return;

    // Allow widgets to interpret any key they want,
    // and do not reserve esc/return/delete/backspace
    bool used_by_widget = widgets.SendKey(evnt.key.keysym);

    if (!used_by_widget) {
      switch (evnt.key.keysym.sym) {
      case SDLK_ESCAPE:
        key_cancel();
        break;
      case SDLK_RETURN:
      case SDLK_KP_ENTER:
        key_ok();
        break;
      case SDLK_UP:
        key_up();
        break;
      case SDLK_DOWN:
        key_down();
        break;
      case SDLK_LEFT:
        key_left();
        break;
      case SDLK_RIGHT:
        key_right();
        break;
      case SDLK_TAB:
        key_tab();
        break;
      default:
        // should have been handle upper!
        break;
      }
    }
  } else if (evnt.type == SDL_MOUSEBUTTONUP) {
    Point2i mousePosition(evnt.button.x, evnt.button.y);

    if (!BasicOnClickUp(mousePosition)) {
      OnClickUp(mousePosition, evnt.button.button);
    }
  } else if (evnt.type == SDL_MOUSEBUTTONDOWN) {
    Point2i mousePosition(evnt.button.x, evnt.button.y);
    OnClick(mousePosition, evnt.button.button);
  }
}
Beispiel #7
0
/* The wizard is controlled using the keyboard (for now).
 * **animate\_wizard()** sets the wizard animation
 * based on the player keypresses and the animation user-data
 * as it was set up in the **create\_wizard()** function.
 *
 * We use the user-data value as a speed constant. This
 * was setup as part of the animation.
 */
static void animate_wizard(struct wizard* wizard, float elapsed_ms)
{
    const void* px;

    struct animation* active_anim;
    active_anim = key_down(KB_SPACE) ? wizard->spell : key_down(KB_RIGHT)
                                                       ? wizard->walk_right
                                                       : key_down(KB_LEFT)
                                                         ? wizard->walk_left
                                                         : wizard->stand;
    play_animation(wizard->sprite, active_anim);

    if ((px = animate_sprite(wizard->sprite, elapsed_ms)) != NULL) {
        wizard->speed = *((const float*)px);
    }

    wizard->pos.x += wizard->speed;
}
bool InputHandler::key_down(std::vector<sf::Keyboard::Key> keys)
{
	for(int i = 0; i < keys.size(); ++i)
	{
		if(key_down(keys[i]))
			return true;
	}
	return false;
}
Beispiel #9
0
void TEST_key_up() {
    char *routine = "TEST_key_up";
    printf(testing, routine);
    //It's necessary to send both down and up commands
    //"100" happens to be the code for "Left" on my computer
    assert(key_down(100));
    assert(key_up(100));
    printf(done, routine);
}
Beispiel #10
0
void EMU::press_button(int num)
{
	int code = buttons[num].code;
	
	if(code) {
		key_down(code, false);
		key_status[code] = KEY_KEEP_FRAMES;
	}
	else {
		// code=0: reset virtual machine
		vm->reset();
	}
}
Beispiel #11
0
void
step()
{
    canvas_clear(1);

    if (key_down(KEY_ESCAPE)) {
        CORE->running = 0;
    }

    if (key_pressed(KEY_RETURN)) {
        window_fullscreen_toggle();
    }

    player_step(&GAME->player,
                key_down(KEY_LEFT), key_down(KEY_RIGHT), key_pressed(KEY_UP));

    tilemap_draw(GAME->scene.tilemap);

    char buf[256];
    sprintf(buf, "%.3fms %.3f", CORE->perf_step * 1e3, CORE->time_delta);
    text_draw(buf, 0, 0, 2);
}
Beispiel #12
0
void simulation_process_input(simulation_t* sim)
{
	if(key_pressed(KEY_MINUS))sim->camera.scale*=0.5;
	else if(key_pressed(KEY_PLUS))sim->camera.scale*=2;
	if(key_pressed(KEY_LEFT_BRACKET)&&sim->speedup>1)sim->speedup/=10;
	else if(key_pressed(KEY_RIGHT_BRACKET))sim->speedup*=10;

sim->current_spacecraft->firing=key_down(KEY_UP)&&sim->current_spacecraft->fuel>0;

    if(key_down(KEY_LEFT))sim->current_spacecraft->base.delta_rot+=0.1/sim->speedup;
    else if(key_down(KEY_RIGHT))sim->current_spacecraft->base.delta_rot-=0.1/sim->speedup;

    //Temporary, for testing docking
    if(key_pressed(KEY_DOWN))
    {
    spacecraft_t* craft=sim->current_spacecraft->docks[0].docked_spacecraft;
    printf("%d\n",craft->parent);
    spacecraft_undock(sim->current_spacecraft,0);
    //sim->current_spacecraft=craft;
    int i;
        for(i=0;i<sim->num_spacecraft;i++)sim->spacecraft[i].parent=NULL;
    }
}
// The player is dead
	void
dead(Player * me)
{

	InputState * is;

	is = me->is;

	set_animation(me->body, (char *) "dead");

	if (key_down(is, SDLK_RETURN))
	{
		stop(me->halter);
	}

}
    void CameraController::update(float delta_time)
    {
        const Matrix3 rot = get_object()->get_rotation_matrix();

        Vector3 right, up, forward;
        rot.get_basis(right, up, forward);

        const float move_speed = 2.5f * (key_down(Key::Left_Shift) ? 4.0f : 1.0f); // meters/second
        const float rotate_speed = 0.002f; // rad/pixel

        Vector3 delta = Vector3::zero;

        if (key_down(Key::W))
            delta += forward;
        if (key_down(Key::S))
            delta -= forward;
        if (key_down(Key::D))
            delta += right;
        if (key_down(Key::A))
            delta -= right;
        if (key_down(Key::Space))
            delta += up;
        if (key_down(Key::Left_Control))
            delta -= up;

        get_object()->move(delta * move_speed * m_speed_up * delta_time);

        if (key_pressed(Key::Left_Alt))
            toggle_mouse_captured();

        if (is_mouse_captured())
        {
            const Vector2 mouse_delta = get_mouse_delta() * rotate_speed;
            m_rot_x += mouse_delta.y;
            m_rot_y += mouse_delta.x;

            m_speed_up += get_delta_scroll() * 0.5f;
            m_speed_up = std::max(m_speed_up, 0.0f);
        }

        Quaternion rot_x, rot_y;
        rot_x.rotation_x(m_rot_x);
        rot_y.rotation_y(m_rot_y);
        get_object()->set_rotation(rot_y * rot_x);
    }
Beispiel #15
0
/**
 * Function called when a keyboard key is pressed
 */
static void keyboard_down_func(unsigned char key, int x, int y){
	key_down(key);
	switch(key){
		case 'x':
			set_time_scale(0);
			break;
		case 'p':
			set_time_scale(1.0);
			break;
		case 'n':
			set_time_scale(get_time_scale()*1.10);
			break;
		case 'm':
			set_time_scale(get_time_scale()*0.9);
			break;
		default:
			break;
	}
	return;
}
Beispiel #16
0
//***************************************************************************
// ----------*********** MAIN *************----------------------------------
//***************************************************************************
int main (void){

	DDRB = 0xff; // wyjscia wyswietlacza
	PORTB = 0xff; //zgaszam wysw.
	DDRD |= (1<<PD3)|(1<<PD4)|(1<<PD5); //3 wyjscia mocy

	DDRD &=~ ((1<<PD0)|(1<<PD1)|(1<<PD2)); //klawisze
	PORTD |= (1<<PD0)|(1<<PD1)|(1<<PD2); //podci¹gam wejscia przycikow

	if ( key_down ( KEY_SET)) serwis();

	TCCR0B |= (1<<CS02) | (1<<CS00); // prescale 1024
	TIMSK |= (1<<TOIE0); //zezwolenie na przerwanie od przepe³nienia
	TCNT0 = 157 ; // wychodzi nam przerwanie co
	sei(); //globalny uk³ad przerwañ

	// zmienne przechowuj¹ce opóŸnienia
	uint8_t czas[3];
	czas[0]= eeprom_read_byte(0x01); // czas kropki
	czas[1]= eeprom_read_byte(0x02); // czas kreski
	czas[2]= eeprom_read_byte(0x03); // czas pauzy

	uint8_t n=0;
	srand(pgm_read_byte(&ziarno[eeprom_read_byte(0x00)]));
	n=eeprom_read_byte(0x00);
	++n;
	if(n==190) n=0;
	eeprom_write_byte(0x00,n);


	uint8_t i = 0;
	while (1){
		if ( flag ){
			if ( wyjscie[i].czy_pauza){
				if( i==0){PORTB |=(1<<0); PORTD &=~(1<<PD3); }
				if( i==1){PORTB |=(1<<3); PORTD &=~(1<<PD4); }
				if( i==2){PORTB |=(1<<6); PORTD &=~(1<<PD5); }

				++wyjscie[i].licznik_pauzy;
				if (wyjscie[i].licznik_pauzy == czas[2]){
					wyjscie[i].czy_pauza = 0;
					wyjscie[i].losowa = rand();
					wyjscie[i].licznik_pauzy = 0;//czas na kropkê lub kreskê// byæ mo¿e do poprwaki
				}
			}
			else{
				if( i==0){PORTB &=~(1<<0); PORTD |= (1<<PD3); }
				if( i==1){PORTB &=~(1<<3); PORTD |= (1<<PD4); }
				if( i==2){PORTB &=~(1<<6); PORTD |= (1<<PD5); }

				if ( wyjscie[i].losowa & 0b00000001 ){ // sprawdzam czy liczmy czas kreski czy kropki
					//tu liczmy czas kreski
					//za³¹cz wyj 1
					++wyjscie[i].licznik_kreski;
					if ( wyjscie[i].licznik_kreski >= czas[1] ) {
						wyjscie[i].czy_pauza = 1;
						wyjscie[i].licznik_kreski =0;	//dobijam do koñca - czas na pauzê
					}
				}
				else{
					++wyjscie[i].licznik_kropki;
					//tu liczymy czas kropki
					if ( wyjscie[i].licznik_kropki >= czas[0] ){
						wyjscie[i].czy_pauza = 1; //dobijam do koñca - czas na pauzê
						wyjscie[i].licznik_kropki =0; //zeruje czas tak jak wszêdzie po dobiciu do max'a
					}
				}
			}
			++i;
			if ( i == 3) {
				i = 0;
				flag = 0 ;
			}
		}
	}

}
Beispiel #17
0
void EMU::update_input()
{
#ifdef USE_SHIFT_NUMPAD_KEY
	// update numpad key status
	if(key_shift_pressed && !key_shift_released) {
		if(key_status[VK_SHIFT] == 0) {
			// shift key is newly pressed
			key_status[VK_SHIFT] = 0x80;
#ifdef NOTIFY_KEY_DOWN
			vm->key_down(VK_SHIFT, false);
#endif
		}
	}
	else if(!key_shift_pressed && key_shift_released) {
		if(key_status[VK_SHIFT] != 0) {
			// shift key is newly released
			key_status[VK_SHIFT] = 0;
#ifdef NOTIFY_KEY_DOWN
			vm->key_up(VK_SHIFT);
#endif
			// check l/r shift
			if(!(GetAsyncKeyState(VK_LSHIFT) & 0x8000)) key_status[VK_LSHIFT] &= 0x7f;
			if(!(GetAsyncKeyState(VK_RSHIFT) & 0x8000)) key_status[VK_RSHIFT] &= 0x7f;
		}
	}
	key_shift_pressed = key_shift_released = false;
#endif
	
	// release keys
#ifdef USE_AUTO_KEY
	if(lost_focus && autokey_phase == 0) {
#else
	if(lost_focus) {
#endif
		// we lost key focus so release all pressed keys
		for(int i = 0; i < 256; i++) {
			if(key_status[i] & 0x80) {
				key_status[i] &= 0x7f;
#ifdef NOTIFY_KEY_DOWN
				if(!key_status[i]) {
					vm->key_up(i);
				}
#endif
			}
		}
	}
	else {
		for(int i = 0; i < 256; i++) {
			if(key_status[i] & 0x7f) {
				key_status[i] = (key_status[i] & 0x80) | ((key_status[i] & 0x7f) - 1);
#ifdef NOTIFY_KEY_DOWN
				if(!key_status[i]) {
					vm->key_up(i);
				}
#endif
			}
		}
	}
	lost_focus = false;
	
	// update joystick status
	memset(joy_status, 0, sizeof(joy_status));
	for(int i = 0; i < joy_num && i < 2; i++) {
		JOYINFOEX joyinfo;
		joyinfo.dwSize = sizeof(JOYINFOEX);
		joyinfo.dwFlags = JOY_RETURNALL;
		if(joyGetPosEx(i, &joyinfo) == JOYERR_NOERROR) {
			if(joyinfo.dwYpos < 0x3fff) joy_status[i] |= 0x01;	// up
			if(joyinfo.dwYpos > 0xbfff) joy_status[i] |= 0x02;	// down
			if(joyinfo.dwXpos < 0x3fff) joy_status[i] |= 0x04;	// left
			if(joyinfo.dwXpos > 0xbfff) joy_status[i] |= 0x08;	// right
			joy_status[i] |= ((joyinfo.dwButtons & joy_mask[i]) << 4);
		}
	}
#ifdef USE_KEY_TO_JOY
	// emulate joystick #1 with keyboard
	if(key_status[0x26]) joy_status[0] |= 0x01;	// up
	if(key_status[0x28]) joy_status[0] |= 0x02;	// down
	if(key_status[0x25]) joy_status[0] |= 0x04;	// left
	if(key_status[0x27]) joy_status[0] |= 0x08;	// right
#endif
	
	// update mouse status
	memset(mouse_status, 0, sizeof(mouse_status));
	if(mouse_enabled) {
		// get current status
		POINT pt;
		GetCursorPos(&pt);
		ScreenToClient(main_window_handle, &pt);
		mouse_status[0]  = pt.x - display_width / 2;
		mouse_status[1]  = pt.y - display_height / 2;
		mouse_status[2]  = (GetAsyncKeyState(VK_LBUTTON) & 0x8000) ? 1 : 0;
		mouse_status[2] |= (GetAsyncKeyState(VK_RBUTTON) & 0x8000) ? 2 : 0;
		mouse_status[2] |= (GetAsyncKeyState(VK_MBUTTON) & 0x8000) ? 4 : 0;
		// move mouse cursor to the center of window
		if(!(mouse_status[0] == 0 && mouse_status[1] == 0)) {
			pt.x = display_width / 2;
			pt.y = display_height / 2;
			ClientToScreen(main_window_handle, &pt);
			SetCursorPos(pt.x, pt.y);
		}
	}
	
#ifdef USE_AUTO_KEY
	// auto key
	switch(autokey_phase) {
	case 1:
		if(autokey_buffer && !autokey_buffer->empty()) {
			// update shift key status
			int shift = autokey_buffer->read_not_remove(0) & 0x100;
			if(shift && !autokey_shift) {
				key_down(VK_SHIFT, false);
			}
			else if(!shift && autokey_shift) {
				key_up(VK_SHIFT);
			}
			autokey_shift = shift;
			autokey_phase++;
			break;
		}
	case 3:
		if(autokey_buffer && !autokey_buffer->empty()) {
			key_down(autokey_buffer->read_not_remove(0) & 0xff, false);
		}
		autokey_phase++;
		break;
	case USE_AUTO_KEY:
		if(autokey_buffer && !autokey_buffer->empty()) {
			key_up(autokey_buffer->read_not_remove(0) & 0xff);
		}
		autokey_phase++;
		break;
	case USE_AUTO_KEY_RELEASE:
		if(autokey_buffer && !autokey_buffer->empty()) {
			// wait enough while vm analyzes one line
			if(autokey_buffer->read() == 0xd) {
				autokey_phase++;
				break;
			}
		}
	case 30:
		if(autokey_buffer && !autokey_buffer->empty()) {
			autokey_phase = 1;
		}
		else {
			stop_auto_key();
		}
		break;
	default:
		if(autokey_phase) {
			autokey_phase++;
		}
	}
#endif
}

#ifdef USE_SHIFT_NUMPAD_KEY
static const int numpad_table[256] = {
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
//	0x00, 0x69, 0x63, 0x61, 0x67, 0x64, 0x68, 0x66, 0x62, 0x00, 0x00, 0x00, 0x00, 0x60, 0x6e, 0x00,
	0x00, 0x69, 0x63, 0x61, 0x67, 0x64, 0x68, 0x66, 0x62, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00,	// remove shift + period
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
#endif

void EMU::key_down(int code, bool repeat)
{
	bool keep_frames = false;
	
	if(code == VK_SHIFT) {
		if(GetAsyncKeyState(VK_LSHIFT) & 0x8000) key_status[VK_LSHIFT] = 0x80;
		if(GetAsyncKeyState(VK_RSHIFT) & 0x8000) key_status[VK_RSHIFT] = 0x80;
		if(!(key_status[VK_LSHIFT] || key_status[VK_RSHIFT])) key_status[VK_LSHIFT] = 0x80;
	}
	else if(code == VK_CONTROL) {
		if(GetAsyncKeyState(VK_LCONTROL) & 0x8000) key_status[VK_LCONTROL] = 0x80;
		if(GetAsyncKeyState(VK_RCONTROL) & 0x8000) key_status[VK_RCONTROL] = 0x80;
		if(!(key_status[VK_LCONTROL] || key_status[VK_RCONTROL])) key_status[VK_LCONTROL] = 0x80;
	}
	else if(code == VK_MENU) {
		if(GetAsyncKeyState(VK_LMENU) & 0x8000) key_status[VK_LMENU] = 0x80;
		if(GetAsyncKeyState(VK_RMENU) & 0x8000) key_status[VK_RMENU] = 0x80;
		if(!(key_status[VK_LMENU] || key_status[VK_RMENU])) key_status[VK_LMENU] = 0x80;
	}
	else if(code == 0xf0) {
		code = VK_CAPITAL;
		keep_frames = true;
	}
	else if(code == 0xf2) {
		code = VK_KANA;
		keep_frames = true;
	}
	else if(code == 0xf3 || code == 0xf4) {
		code = VK_KANJI;
		keep_frames = true;
	}
#ifdef USE_SHIFT_NUMPAD_KEY
	if(code == VK_SHIFT) {
		key_shift_pressed = true;
		return;
	}
	else if(numpad_table[code] != 0) {
		if(key_shift_pressed || key_shift_released) {
			key_converted[code] = 1;
			key_shift_pressed = true;
			code = numpad_table[code];
		}
	}
#endif
	if(!(code == VK_SHIFT || code == VK_CONTROL || code == VK_MENU)) {
		code = keycode_conv[code];
	}
	
#ifdef DONT_KEEEP_KEY_PRESSED
	if(!(code == VK_SHIFT || code == VK_CONTROL || code == VK_MENU)) {
		key_status[code] = KEY_KEEP_FRAMES;
	}
	else
#endif
	key_status[code] = keep_frames ? KEY_KEEP_FRAMES : 0x80;
#ifdef NOTIFY_KEY_DOWN
	if(keep_frames) {
		repeat = false;
	}
	vm->key_down(code, repeat);
#endif
}
Beispiel #18
0
void wait_key_release()
{
	do {
		;
	} while (key_down());
}
Beispiel #19
0
void
step(void)
{


	if (key_pressed(KEY_ESCAPE)) {
		CORE->running = 0;
		return;
	}

	     if (key_pressed(KEY_1)) set_palette_set(PS_WHITE);
	else if (key_pressed(KEY_2)) set_palette_set(PS_GREEN);
	else if (key_pressed(KEY_3)) set_palette_set(PS_BEIGE);
	else if (key_pressed(KEY_4)) set_palette_set(PS_BLUE);
	else if (key_pressed(KEY_5)) set_palette_set(PS_RED);
	else if (key_pressed(KEY_6)) set_palette_set(PS_PASTEL_MIX);
	else if (key_pressed(KEY_7)) set_palette_set(PS_RED_GREEN);




	switch (game.mode) {
	case GAME_MODE_TITLE: {
		if (game.intro_cooldown --> 0) {
			canvas_clear(PC_TRANSPARENT);
			bitmap_draw(0, 0, 0, 0, &title_screen, NULL, 0, 0);
		} else {
			game.mode = GAME_MODE_MAP;
		}
	} break;

	case GAME_MODE_MAP: {
		Map *map = &game.maps[game.curr_map_index];
		i32 i, j, x, y;
		gbVec2 old_player_pos = game.player.pos;
		b32 render_doctor_text = false;


		canvas_clear(PC_TRANSPARENT);

		game.player.vel = gb_vec2_zero();
		if (key_down(KEY_UP))    { game.player.vel.y -= 1.0f; }
		if (key_down(KEY_DOWN))  { game.player.vel.y += 1.0f; }
		if (key_down(KEY_LEFT))  { game.player.vel.x -= 1.0f; }
		if (key_down(KEY_RIGHT)) { game.player.vel.x += 1.0f; }
		gb_vec2_norm0(&game.player.vel, game.player.vel);
		gb_vec2_muleq(&game.player.vel, game.player.in_grass ? 2.5f : 3.5f);
		gb_vec2_addeq(&game.player.pos, game.player.vel);
		game.player.in_grass = false;

		game.player.is_moving = (gb_vec2_mag(game.player.vel) > 0);

		if (game.player.vel.x < 0) game.player.orientation = 2;
		if (game.player.vel.x > 0) game.player.orientation = 3;
		if (game.player.vel.y > 0) game.player.orientation = 0;
		if (game.player.vel.y < 0) game.player.orientation = 1;

		game.player.pos.x = gb_clamp(game.player.pos.x, 0, (map->width-1) *TILE_SIZE);
		game.player.pos.y = gb_clamp(game.player.pos.y, 0, (map->height-1)*TILE_SIZE);


		game.grass_event_cooldown--;
		if (game.grass_event_cooldown < 0)
			game.grass_event_cooldown = 0;

		draw_tooltip = false;
		gb_zero_array(tooltip_messages, gb_count_of(tooltip_messages));


		{ // Handle Interactions
			Rect player_rect = rect_make_size(game.player.pos.x+2, game.player.pos.y+12,
			                                  12, 4);
			for (j = 0; j < map->height; j++) {
				y = j*TILE_SIZE;
				for (i = 0; i < map->width; i++) {
					Rect tile_rect;
					char t = map->tiles[j][i];
					x = i*TILE_SIZE;
					tile_rect = rect_make_size(x, y, TILE_SIZE, TILE_SIZE);

					if (gb_char_is_digit(t)) {
						if (rect_collides(player_rect, tile_rect, NULL)) {
							change_map_to(t-'0');
							return;
						}
					}
					if ((t != ' ' && t != '.' && t != 'g')) {
						Rect inter;
						b32 do_collision = true;
						if (t == 'L') { // NOTE(bill): Lab Chemicals Top
							tile_rect = rect_make_size(x, y+7, TILE_SIZE, TILE_SIZE-7);
						}

						if (t == 'Q' && game.has_chosen_transmog) {
							do_collision = false;
						}
						if (do_collision && rect_collides(player_rect, tile_rect, &inter)) {
							game.player.pos = old_player_pos;
							game.player.is_moving = false;
						}

					}


					if (t == 'g' && game.player.is_moving && rect_collides(player_rect, tile_rect, NULL)) {
						i32 random = gb_random_range_int(0, 100);
						game.player.in_grass = true;
						if ((random < 7) && (game.grass_event_cooldown <= 0)) {
							game.grass_event_cooldown = 50;
#if 1
							change_to_battle_mode(BATTLE_TYPE_GRASS);
#endif
							return;
						}
					}

					if (t == 'D') {
						f32 dx = game.player.pos.x - (x + TILE_SIZE/2);
						f32 dy = game.player.pos.y - (y + TILE_SIZE/2);
						if (dx*dx+dy*dy < square(2*TILE_SIZE)) render_doctor_text = true;
					}

					if (t == 'Y') {
						set_tooltip(x, y, 1.5f,
						            "Hello! I'm your worst nightmare!",
						            "My name is Yugi the Boss.",
						            "Want to battle [z]?");

						if (key_pressed(KEY_Z)) {
							change_to_battle_mode(BATTLE_TYPE_BOSS);
							return;
						}
					}

					if (t == 'Q' && !game.has_chosen_transmog) {
						set_tooltip(x, y, 1.5f,
						            "It's dangerous to go alone",
						            "in there! You might get hurt.",
						            "Go see The Doctor in The Lab.");
					}

					if (t == 'L' || t == 'l') {
						set_tooltip(x, y, 1.0f,
						            "It appears to be weird chemicals.", NULL, NULL);
					}

					if (t == 'm' || t == 'c') {
						set_tooltip(x, y, 1.0f,
						            "State of the art computers",
						            "The new Pear Bartlett!",
						            NULL);
					}
					if (t == 'P') {
						set_tooltip(x, y, 0.6f,
						            "Such a lovely picture!", NULL, NULL);
					}

					if (t == 'B' || t == 'b') {
						set_tooltip(x, y, 1.2f,
						            "It is not time to sleep.", NULL, NULL);
					}

					if (t == 'W') {
						set_tooltip(x, y, 0.6f,
						            "It's a beautiful view outside.",
						            "Why not go outside and explore?", NULL);
					}
				}
			}
		}

		move_game_camera(map);


		// Render 1x1 Sprites
		for (j = 0; j < map->height; j++) {
			y = j*TILE_SIZE;
			for (i = 0; i < map->width; i++) {
				char t = map->tiles[j][i];
				x = i*TILE_SIZE;
				switch (t) {
				case ' ':
				case '.':
				case 'g':
				case 'Q':
				case 'D':
				case 'Y': {
					i32 sx = 0;
					i32 sy = map->outside;
					if (map->outside) {
						sx = (i+j)%2;
					}
					draw_sprite(x, y, sx, sy, 0);

					if (t == 'g') draw_sprite(x, y, 2, 1, 0); // grass
					if (t == 'Q' && !game.has_chosen_transmog)
						draw_sprite(x, y, 0, 3, 0); // Person in the way
					if (t == 'D') draw_sprite(x, y, 1, 3, 0); // Dr.
					if (t == 'Y') draw_sprite(x, y, 2, 3, 0); // Yugi
				} break;
				case 'x': draw_sprite(x, y,  1, 0, 0); break; // Wall
				case 'P': draw_sprite(x, y,  2, 0, 0); break; // Hanging Picture
				case 'W': draw_sprite(x, y,  3, 0, 0); break; // Window
				case 'T': draw_sprite(x, y,  3, 1, 0); break; // Thick Grass
				case 't': draw_sprite(x, y,  4, 1, 0); break; // Tree trunk
				case 'B': draw_sprite(x, y,  5, 0, 0); break; // Bed Top
				case 'b': draw_sprite(x, y,  5, 1, 0); break; // Bed bottom
				case 'M': draw_sprite(x, y,  6, 0, 0); break; // Computer monitor
				case 'm': draw_sprite(x, y,  6, 1, 0); break; // Computer keyboard
				case 'C': draw_sprite(x, y,  7, 0, 0); break; // Computer case
				case 'c': draw_sprite(x, y,  7, 1, 0); break; // Computer mouse
				case 'L': draw_sprite(x, y,  8, 0, 0); break; // Lap Chemicals top
				case 'l': draw_sprite(x, y,  8, 1, 0); break; // Lap Chemicals bottom

				default: {
					if (gb_char_is_digit(t)) draw_sprite(x, y, 4, 0, 0);
				} break;
				}
			}
		}

		// Render NxM Sprites
		// TODO(bill): Be more efficient
		for (j = 0; j < map->height; j++) {
			y = j*TILE_SIZE;
			for (i = 0; i < map->width; i++) {
				char t = map->tiles[j][i];
				x = i*TILE_SIZE;
				switch (t) {
				case 'h': draw_sprite_size(x, y, 12, 2, 4, 4, 0); break;
				case 'd': draw_sprite_size(x, y,  8, 2, 4, 4, 0); break;
				}
			}
		}

		{ // Render player and particles
			i32 sx = 0;
			u32 flags = 0;
			// 0 - down
			// 1 - up
			// 2 - left
			// 3 - right (-ve left)
			if (game.player.orientation == 0) sx = 0;
			if (game.player.orientation == 1) sx = 1;
			if (game.player.orientation == 2) sx = 2;
			if (game.player.orientation == 3) { sx = 2; flags |= DrawFlags_FlipH; }
			if (game.player.is_moving) {
				u32 flip = 10.0f*CORE->perf_frame.stamp;
				b32 use_flip = true;
				if (game.player.orientation == 0) {
					if (use_flip) {
						sx = 3;
						flags |= DrawFlags_FlipH * (flip%2);
					}
				} else if (game.player.orientation == 1) {
					if (use_flip) {
						sx = 4;
						flags |= DrawFlags_FlipH * (flip%2);
					}
				} else {
					sx += 3 * (flip%2);
				}
			}
			draw_sprite(game.player.pos.x, game.player.pos.y, sx, 2, flags);
		}

		{ // Render Text
			CORE->translate_x = 0;
			CORE->translate_y = 0;

			if (game.show_map_name_ticks-- > 0) {
				if (game.show_map_name_ticks < 0)
					game.show_map_name_ticks = 0;

				{
					char *name = game.maps[game.curr_map_index].name;
					i32 name_len = gb_strlen(name);
					i32 w = name_len*font.char_width+6;
					i32 h = font.char_height+6;

					rect_draw(rect_make_size(1, 1, w, h), PC_WHITE);
					rect_draw(rect_make_size(1,   0, w, 1), PC_DARK_GREY);
					rect_draw(rect_make_size(1, h+1, w, 1), PC_DARK_GREY);
					rect_draw(rect_make_size(0,   1, 1, h), PC_DARK_GREY);
					rect_draw(rect_make_size(w+1, 1, 1, h), PC_DARK_GREY);


					text_draw(4, 4, name, PC_BLACK);
				}
			}

			if (render_doctor_text) {
				if (game.doctor_line_index < gb_count_of(doctor_lines)) {
					draw_message_box(doctor_lines[game.doctor_line_index], "", "[Z] to continue");

					if (key_pressed(KEY_Z)) game.doctor_line_index++;
				} else if (!game.has_chosen_transmog) {
					draw_message_box("Line          [X]",
					                 "Triangle      [C]",
					                 "Square        [V]");
					if (key_pressed(KEY_X)) {
						game.player.my_transmog = make_transmog(TRANSMOG_TYPE_LINE);
						game.has_chosen_transmog = true;
					} else if (key_pressed(KEY_C)) {
						game.player.my_transmog = make_transmog(TRANSMOG_TYPE_TRIANGLE);
						game.has_chosen_transmog = true;
					} else if (key_pressed(KEY_V)) {
						game.player.my_transmog = make_transmog(TRANSMOG_TYPE_SQUARE);
						game.has_chosen_transmog = true;
					}

				} else {
					draw_message_box("Go now and find Transmogs!", "", "");
				}
			} else if (draw_tooltip) {
				draw_message_box(tooltip_messages[0], tooltip_messages[1], tooltip_messages[2]);
			}
		}
	} break;

	case GAME_MODE_BATTLE: {
		i32 i, w = CANVAS_WIDTH, h = CANVAS_HEIGHT;
		Transmog *enemy_mog = &game.battle_mode.enemy_mog;
		Transmog *player_mog = game.battle_mode.player_mog;
		char name_buf[32] = "";
		char *attack_names[3] = {
			"TRANSLATE",
			"ROTATE",
			"DIVIDE",
		};
		i32 level_diff = enemy_mog->shift_level - player_mog->shift_level;


		CORE->translate_x = 0;
		CORE->translate_y = 0;

		canvas_clear(PC_WHITE);

		// Enemy Transmog
		gb_snprintf(name_buf, gb_size_of(name_buf),
		            "%s LVL%d", transmog_name(enemy_mog->type), enemy_mog->shift_level);
		text_draw(8, 5, name_buf, PC_BLACK);
		draw_sprite_size(8, 12,
		                 2, 4,
		                 3, 1, 0);
		draw_sprite_size(24, 15,
		                 3, 5,
		                 2, 1, 0);
		{
			f32 hp_percent = cast(f32)enemy_mog->health/cast(f32)enemy_mog->max_health;
			rect_draw(rect_make_size(25, 16, hp_percent*30, 1), PC_LIGHT_GREY);
			draw_big_transmog(84, 4, enemy_mog->type);
		}


		// Player Transmog
		gb_snprintf(name_buf, gb_size_of(name_buf),
		            "%s LVL%d", transmog_name(player_mog->type), player_mog->shift_level);
		text_draw(100, 80, name_buf, PC_BLACK);
		draw_sprite_size(104, 92,
		                 5, 4,
		                 3, 1, 0);
		draw_sprite_size(117, 95,
		                 3, 5,
		                 2, 1, 0);
		{
			f32 hp_percent = cast(f32)player_mog->health/cast(f32)player_mog->max_health;
			char buf[16] = {0};
			gb_snprintf(buf, gb_size_of(buf),
			            "%03d/%03d", player_mog->health, player_mog->max_health);
			rect_draw(rect_make_size(118, 96, hp_percent*30, 1), PC_LIGHT_GREY);
			text_draw(118, 99, buf, PC_BLACK);

			draw_big_transmog(4, 54, player_mog->type);
		}

		if (!game.battle_mode.is_enemies_turn) {
			switch (game.battle_mode.state) {
			case BATTLE_TURN_STATE_INTRO: {
				char buf[32] = {0};
				gb_snprintf(buf, gb_size_of(buf),
				            "A wild %s appears!", transmog_name(enemy_mog->type));
				draw_message_box(buf, "", "[Z] to continue");

				if (key_pressed(KEY_Z)) {
					game.battle_mode.state = BATTLE_TURN_STATE_WHAT_TO_DO;
					return;
				}
			} break;
			case BATTLE_TURN_STATE_WHAT_TO_DO: {
				u32 hot_item = 0;
				if (game.battle_mode.type == BATTLE_TYPE_GRASS) {
					game.battle_mode.state_index %= 3;
					hot_item = game.battle_mode.state_index;
	 				draw_message_box("What to do?           Fight     ",
					                 "                      Substitute",
					                 "                      Escape    ");
					draw_sprite(70, 111, 0, 4, 0);
					draw_sprite(70, 127, 0, 5, 0);
					draw_sprite(90, 117 + hot_item*font.char_height, 5, 5, 0);

					if (key_pressed(KEY_DOWN)) {
						game.battle_mode.state_index++;
					}
					if (key_pressed(KEY_UP)) {
						if (game.battle_mode.state_index == 0)
							game.battle_mode.state_index = 2;
						else
							game.battle_mode.state_index--;
					}

					if (key_pressed(KEY_Z)) {
						switch (hot_item) {
						case 0:
							game.battle_mode.state = BATTLE_TURN_STATE_FIGHT;
							game.battle_mode.state_index = 0;
							game.battle_mode.fighting_state = FIGHTING_STATE_NONE;
							return;
						case 1:
							game.battle_mode.state = BATTLE_TURN_STATE_SUBSTITUTE;
							game.battle_mode.state_index = 0;
						case 2:
							game.battle_mode.state = BATTLE_TURN_STATE_ESPACE;
							game.battle_mode.state_index = 0;
							return;
						}
					}
				} else {
					game.battle_mode.state_index %= 2;
					hot_item = game.battle_mode.state_index;
	 				draw_message_box("What to do?           Fight     ",
					                 "                      Escape    ",
					                 "                                ");
					draw_sprite(70, 111, 0, 4, 0);
					draw_sprite(70, 127, 0, 5, 0);
					draw_sprite(90, 117 + hot_item*font.char_height, 5, 5, 0);

					if (key_pressed(KEY_DOWN)) {
						game.battle_mode.state_index++;
					}
					if (key_pressed(KEY_UP)) {
						if (game.battle_mode.state_index == 0)
							game.battle_mode.state_index = 1;
						else
							game.battle_mode.state_index--;
					}

					if (key_pressed(KEY_Z)) {
						switch (hot_item) {
						case 0:
							game.battle_mode.state = BATTLE_TURN_STATE_FIGHT;
							game.battle_mode.state_index = 0;
							game.battle_mode.fighting_state = FIGHTING_STATE_NONE;
							return;
						case 1:
							game.battle_mode.state = BATTLE_TURN_STATE_ESPACE;
							game.battle_mode.state_index = 0;
							return;
						}
					}
				}


			} break;
			case BATTLE_TURN_STATE_FIGHT: {
				char buf[32] = "";
				switch (game.battle_mode.fighting_state) {
				case FIGHTING_STATE_NONE: {
					u32 hot_item = game.battle_mode.state_index;
					draw_message_box("Which attack?         Translate ",
					                 "                      Rotate    ",
					                 "                      Divide    ");
					draw_sprite(70, 111, 0, 4, 0);
					draw_sprite(70, 127, 0, 5, 0);
					draw_sprite(90, 117 + hot_item*font.char_height, 5, 5, 0);

					if (key_pressed(KEY_DOWN)) {
						game.battle_mode.state_index++;
						game.battle_mode.state_index %= 3;
					}
					if (key_pressed(KEY_UP)) {
						if (game.battle_mode.state_index == 0)
							game.battle_mode.state_index = 2;
						else
							game.battle_mode.state_index--;
					}

					if (key_pressed(KEY_X)) {
						game.battle_mode.state_index = 0;
						game.battle_mode.state = BATTLE_TURN_STATE_WHAT_TO_DO;
						return;
					}

					if (key_pressed(KEY_Z)) {
						game.battle_mode.attack_index = hot_item;
						game.battle_mode.state_index = 0;
						game.battle_mode.fighting_state = FIGHTING_STATE_USE;
						return;
					}
				} break;
				case FIGHTING_STATE_USE: {
					gb_snprintf(buf, gb_size_of(buf),
					            "Your %s used %s",
					            transmog_name(enemy_mog->type),
					            attack_names[game.battle_mode.attack_index]);
					draw_message_box(buf, NULL, NULL);

					if (key_pressed(KEY_Z)) {
					if (-level_diff < 0) { // Higher level enemy
						game.battle_mode.fighting_state = FIGHTING_STATE_SUPER_EFFECTIVE;
					} else {
						if (gb_random_range_int(0, -level_diff+1) == 0) {
							game.battle_mode.fighting_state = FIGHTING_STATE_SUPER_EFFECTIVE;
						} else {
							if (gb_random_range_int(0, -level_diff/2 + 1) == 0)
								game.battle_mode.fighting_state = FIGHTING_STATE_EFFECTIVE;
							else
								game.battle_mode.fighting_state = FIGHTING_STATE_NO_EFFECT;
						}
					}
					return;
				}
				} break;
				case FIGHTING_STATE_EFFECTIVE: {
					gb_snprintf(buf, gb_size_of(buf),
					            "%s was effective",
					            attack_names[game.battle_mode.attack_index]);
					draw_message_box(buf, NULL, NULL);

					if (key_pressed(KEY_Z)) {
						i32 damage = gb_clamp(0, player_mog->attack_power/3 + level_diff/2, 1000);
						enemy_mog->health -= damage;

						game.battle_mode.fighting_state = FIGHTING_STATE_NEXT_TURN;
					}
				} break;
				case FIGHTING_STATE_SUPER_EFFECTIVE: {
					gb_snprintf(buf, gb_size_of(buf),
					            "%s was super effective",
					            attack_names[game.battle_mode.attack_index]);
					draw_message_box(buf, NULL, NULL);

					if (key_pressed(KEY_Z)) {
						i32 damage = gb_clamp(0, player_mog->attack_power/1 + level_diff/2, 1000);
						enemy_mog->health -= damage;
						game.battle_mode.fighting_state = FIGHTING_STATE_NEXT_TURN;
						game.battle_mode.state_index = 0;
					}
				} break;
				case FIGHTING_STATE_NO_EFFECT: {
					gb_snprintf(buf, gb_size_of(buf),
					            "%s had no effect",
					            attack_names[game.battle_mode.attack_index]);
					draw_message_box(buf, NULL, NULL);

					if (key_pressed(KEY_Z))
						game.battle_mode.fighting_state = FIGHTING_STATE_NEXT_TURN;
				} break;
				case FIGHTING_STATE_NEXT_TURN: {
					char *end_message = "";
					if (enemy_mog->health <= 0 &&
					    !(game.battle_mode.state_index & 1)) {
						enemy_mog->health = 0;
						player_mog->xp += clamp(1, 4 + level_diff, 1000);

						while (player_mog->xp >= 10) {
							player_mog->xp -= 10;
							player_mog->shift_level++;
							update_transmog_stats(player_mog);
							player_mog->health = player_mog->max_health;
							game.battle_mode.state_index |= 2;
						}

						game.battle_mode.state_index |= 1;
					}
					if (game.battle_mode.state_index & 1) {
						if (game.battle_mode.type == BATTLE_TYPE_GRASS) {
							if (game.battle_mode.state_index & 2)
								end_message = "Your Transmog has levelled up!";
							draw_message_box("You win this battle!", end_message, "Exit the battle.");
							if (key_pressed(KEY_Z)) {
								game.mode = GAME_MODE_MAP;
								game.battle_mode.state_index = 0;
								return;
							}
						} else {
							canvas_clear(PC_WHITE);
							draw_sprite(72, 40,
							            2, 3, 0);

							draw_message_box("You defeated me?! HOW?!",
							                 "Well it's my first battle...",
							                 "Well done and thank you!");

							if (key_pressed(KEY_Z)) {
								game.mode = GAME_MODE_END_SUCCESS;
								return;
							}
						}
					} else {
						draw_message_box("End turn.", NULL, NULL);
						if (key_pressed(KEY_Z)) {
							end_battle_mode_turn();
							return;
						}
					}
				} break;
				}
			} break;
			case BATTLE_TURN_STATE_SUBSTITUTE: {
				i32 level_diff = enemy_mog->shift_level - player_mog->shift_level;

				if (level_diff <= 0) {
					draw_message_box("Failed to substitute",
					                 "",
					                 "End turn.");

					if (key_pressed(KEY_Z)) {
						end_battle_mode_turn();
						return;
					}

				} else {
					if (game.battle_mode.state_index == 0) {
						if (gb_random_range_int(0, level_diff) != 0)
							game.battle_mode.state_index = 1; // Success
						else
							game.battle_mode.state_index = 2; // Failure
					}

					if (game.battle_mode.state_index == 1) {
						draw_message_box("Well done!",
						                 "You successfully substituted.",
						                 "Exit to world");

						if (key_pressed(KEY_Z)) {
							// Change it!
							game.player.my_transmog = *enemy_mog;
							game.mode = GAME_MODE_MAP;
							return;
						}
					} else {
						draw_message_box("Substitution failed!",
						                 "",
						                 "End turn.");

						if (key_pressed(KEY_Z)) {
							end_battle_mode_turn();
							return;
						}
					}
				}
			} break;
			case BATTLE_TURN_STATE_ESPACE: {
				if (game.battle_mode.state_index == 0) {
					if (gb_random_range_int(0, 100) < 90) {
						game.battle_mode.state_index = 1;
					} else {
						game.battle_mode.state_index = 2;
					}
				}

				if (game.battle_mode.state_index == 1) {
					draw_message_box("You escaped from this battle!",
					                 "",
					                 "[Z] to return to the world.");

					if (key_pressed(KEY_Z)) {
						game.mode = GAME_MODE_MAP;
						return;
					}
				} else {
					draw_message_box("You could not escape!",
					                 "You'll have to try again!",
					                 "[Z] to end turn.");
					end_battle_mode_turn();
					return;
				}
			} break;
			}
		} else {
		// NOTE(bill): Enemies Turn
			char buf[32] = {0};

			switch (game.battle_mode.fighting_state) {
			case FIGHTING_STATE_NONE: {
				game.battle_mode.attack_index = gb_random_range_int(0, 2);
				game.battle_mode.fighting_state = FIGHTING_STATE_USE;
				return;
			} break;
			case FIGHTING_STATE_USE: {
				gb_snprintf(buf, gb_size_of(buf),
				            "Enemy %s used %s",
				            transmog_name(enemy_mog->type),
				            attack_names[game.battle_mode.attack_index]);
				draw_message_box(buf, NULL, NULL);

				if (key_pressed(KEY_Z)) {
					if (level_diff < 0) { // Higher level enemy
						game.battle_mode.fighting_state = FIGHTING_STATE_SUPER_EFFECTIVE;
					} else {
						if (gb_random_range_int(0, -level_diff+3) == 0) {
							game.battle_mode.fighting_state = FIGHTING_STATE_SUPER_EFFECTIVE;
						} else {
							if (gb_random_range_int(0, -level_diff/2 + 3) == 0)
								game.battle_mode.fighting_state = FIGHTING_STATE_EFFECTIVE;
							else
								game.battle_mode.fighting_state = FIGHTING_STATE_NO_EFFECT;
						}
					}
					return;
				}
			} break;
			case FIGHTING_STATE_EFFECTIVE: {
				gb_snprintf(buf, gb_size_of(buf),
				            "%s was effective",
				            attack_names[game.battle_mode.attack_index]);
				draw_message_box(buf, NULL, NULL);

				if (key_pressed(KEY_Z)) {
					i32 damage = gb_clamp(0, enemy_mog->attack_power/6.0f - level_diff/3.0f, 1000);

					player_mog->health -= damage;

					game.battle_mode.fighting_state = FIGHTING_STATE_NEXT_TURN;
				}

			} break;
			case FIGHTING_STATE_SUPER_EFFECTIVE: {
				gb_snprintf(buf, gb_size_of(buf),
				            "%s was super effective",
				            attack_names[game.battle_mode.attack_index]);
				draw_message_box(buf, NULL, NULL);

				if (key_pressed(KEY_Z)) {
					i32 damage = gb_clamp(0, enemy_mog->attack_power/3.0f - level_diff/2.0f, 1000);

					player_mog->health -= damage;

					game.battle_mode.fighting_state = FIGHTING_STATE_NEXT_TURN;
				}
			} break;
			case FIGHTING_STATE_NO_EFFECT: {
				gb_snprintf(buf, gb_size_of(buf),
				            "%s had no effect",
				            attack_names[game.battle_mode.attack_index]);
				draw_message_box(buf, NULL, NULL);

				if (key_pressed(KEY_Z))
					game.battle_mode.fighting_state = FIGHTING_STATE_NEXT_TURN;
			} break;
			case FIGHTING_STATE_NEXT_TURN: {
				char *end_message = "";
				if (player_mog->health <= 0 &&
				    !(game.battle_mode.state_index & 1)) {
					player_mog->health = 0;

					game.battle_mode.state_index |= 1;
				}
				if (game.battle_mode.state_index & 1) {
					draw_message_box("You lost this battle!", "And the game :(", "Exit the battle.");
					if (key_pressed(KEY_Z)) {
						game.mode = GAME_MODE_END_FAIL;
						return;
					}
				} else {
					draw_message_box("The enemy's turn has ended.", NULL, NULL);
					if (key_pressed(KEY_Z)) {
						end_battle_mode_turn();
						return;
					}
				}
			} break;
			}

		}
	} break;

	case GAME_MODE_END_FAIL: {
		canvas_clear(PC_BLACK);
		draw_message_box("You have failed :(",
		                 "Would you like to try again?",
		                 "Try again [z] Exit [esc]");
		if (key_pressed(KEY_Z)) {
			init_game();
			return;
		}
	} break;

	case GAME_MODE_END_SUCCESS: {
		canvas_clear(PC_BLACK);

		text_draw(4, 4,
		          "Thank you for playing Transmog!\n"
		          "Ginger Bill (c) 2016\n"
		          "\n"
		          "Ludum Dare 35\n"
		          "Theme: Shapeshift\n"
		          "\n"
		          "Please remember for vote!\n",
		          PC_WHITE);

		draw_message_box("Exit [esc]", NULL, NULL);
	} break;
	}
}
void EventHandler::handle_events()
{
  SDL_Event event;
  while (SDL_PollEvent(&event))
  {
    switch (event.type)
    {
      case SDL_VIDEORESIZE:
        resize_window(event.resize.w, event.resize.h);
        break;

      case SDL_JOYAXISMOTION:
        joystick_motion(&event.jaxis);
        break;

      case SDL_JOYBUTTONDOWN:
        if (nJoystickDlg)
          joystickDlg->joystickDlgButton(&event.jbutton);
        else
          joystick_button(&event.jbutton);
        break;

      case SDL_MOUSEMOTION:
        /**
         * GUI_MOUSE_MOTION_WORKAROUND
         * The GUI sometimes returns that it used the event, although it is not visible anymore!
         * Therefore we need to check whether it is visible at all.
         * Where it works:
         *   -ESC to show GUI
         *   -open dialog (for example video)
         *   -close dialog
         *   -ESC to hide GUI
         * Everything is fine, the mouse-motions are not used by the GUI.
         *   -ESC to show GUI
         *   -toggle something from the menu bar (for example Verbosity)
         *   -ESC to hide GUI
         * Now the GUI still uses the mouse motions, although it is invisible!
         */
        if (Global::TXInterface->inputMethod() == T_TX_Interface::eIM_mouse)
        {
          // always update the mouse interface
          mouse_motion(&event.motion);
          if (Global::gui)
            Global::gui->mouseMotionHandler(event.motion.x, event.motion.y);
        }
        else if (!Global::gui || !Global::gui->isVisible()
            ||
            !Global::gui->mouseMotionHandler(event.motion.x, event.motion.y))
        {
          // GUI did not use the event, pass it to the simulation itself
          mouse_motion(&event.motion);
        }
        break;

      case SDL_MOUSEBUTTONDOWN:
#if TEST_WITHOUT_JOYSTICK > 0
        if (nJoystickDlg && event.button.button != SDL_BUTTON_LEFT)
        {
          SDL_JoyButtonEvent jevent;
          jevent.type   = SDL_JOYBUTTONDOWN;
          jevent.state  = SDL_PRESSED;
          jevent.which  = 0;
          switch (event.button.button)
          {
            case SDL_BUTTON_MIDDLE:
              jevent.button = 0;
              break;
            case SDL_BUTTON_RIGHT:
              jevent.button = 1;
              break;
            default:
              jevent.button = 2;
              break;
          }
          joystickDlg->joystickDlgButton(&jevent);
        }
#endif
        if (!Global::gui || !Global::gui->mouseButtonDownHandler(event.button.button, event.button.x, event.button.y))
        {
          // GUI did not use the event, pass it to the simulation itself
          mouse_button(&event.button);
        }
        break;

      case SDL_MOUSEBUTTONUP:
        if (Global::gui)
          Global::gui->mouseButtonUpHandler(event.button.button, event.button.x, event.button.y);
        break;

      case SDL_KEYDOWN:
        if (!Global::gui || !Global::gui->keyDownEventHandler(event.key.keysym))
        {
          // GUI did not use the event, pass it to the simulation itself
          key_down(&event.key.keysym);
        }
        break;

      case SDL_KEYUP:
        if (Global::gui)
          Global::gui->keyUpEventHandler(event.key.keysym);
        break;

      case SDL_QUIT:
        if (Global::gui)
          Global::gui->doQuitDialog();
        else
          Global::Simulation->quit();
        break;
    }
  }
}
int commandes_clavier()//la fonction sprintf tue l acces clavier
{
if ( keypressed())
{

int chi = readkey(); 
scan_ascii_is=(chi & 0xff);//prend pas en compte touches fonctions
scan_allegro_key_is=(chi >> 8);//prend en compte tout le monde mais à redistribuer fr et anglais


switch (chi >> 8)  
{	
    

case KEY_ESC://nettoyage chaine de caractere et deselection totale

reset_indexs_confirmation();
reset_index_actions();
key_unselect_ch();
if(window_focus_id==W_PLOT )
{
if(index_menus_lighting_plot==1) unselect_all_shapes();
else if( index_menus_lighting_plot==2 || index_menus_lighting_plot==4)
{reset_symbols_selected(view_plot_calc_number_is);}
}
else if(window_focus_id==W_ASKCONFIRM)
{
 substract_a_window(W_ASKCONFIRM);
 substract_a_window(previous_window_focus_id);
 mouse_released=1;
 window_focus_id=previous_window_focus_id;
 add_a_window(window_focus_id);      
}
sprintf(string_key_id,list_keyname[9]);
break;

///////////////////////PAGE UP DOWN POUR FENETRES /////////////////////////////
case KEY_PGUP: 
sprintf(string_key_id,list_keyname[0]);
key_switch_window_up();
break; 
case KEY_PGDN: 
sprintf(string_key_id,list_keyname[0]);
key_switch_window_down();
break; 
//////////////////SPECIAL KEYS ////////////////////////////////////////////////
case  KEY_TILDE://carré
if(window_focus_id==W_PLOT) {index_move_plot_view_port=toggle(index_move_plot_view_port);}
break;

case KEY_F1://dock mode
if (key_shifts & KB_CTRL_FLAG  || index_false_control==1) 
{
reset_indexs_confirmation();
index_ask_confirm=1; 
index_do_overrecord_mem=1;
clear_keybuf();

}
else if (key_shifts & KB_SHIFT_FLAG || index_false_shift==1) 
{
int mem_to_rec=(int)(atof(numeric)*10);

reset_indexs_confirmation();
index_ask_confirm=1; 
index_do_create_mem=1;
}
else
{
index_do_report=0;
index_do_modify=0; 
index_main_clear=0;
index_do_dock=toggle(index_do_dock);

switch (window_focus_id)
{
case W_CHASERS:
index_affect_chaser_to_dock=index_do_dock;
break;   
case W_GRID:
for(int i=0;i<4;i++)
{
if(index_show_grid_player[i]==1)
{
gridplayer_to_affect_is=i; break;
}
}
break;
case W_MOVER:
index_affect_to_dock_mover=index_do_dock;     
break;    
case W_DRAW:
index_affect_draw_to_dock=index_do_dock;
break;
case W_ECHO:
index_affect_echo_to_dock=index_do_dock;
break;
case W_TIME:
index_affect_time=index_do_dock;   
break;
case W_TRACKINGVIDEO:
index_affect_video_tracking_to_dock=index_do_dock; 
break;
case W_TRICHROMY:
index_affect_color_to_dock=index_do_dock; 
break;
case W_AUDIO:
index_affect_audio_to_dock=index_do_dock;
player_to_affect_to_dock=0;
audio_type_for_dock_affectation_is=0;
break;
case W_CFGMENU:
if(config_page_is==1) { index_affect_dmxin=index_do_dock; }
else if(config_page_is==3) {index_do_affect_net_to_dock=index_do_dock; } 
break;
default:
break;      
}

}
break;
      
case KEY_F2:
index_do_dock=0;
index_do_report=0;
index_main_clear=0;
index_do_modify=toggle(index_do_modify);;      
break;      

case KEY_F3:
if (key_shifts & KB_CTRL_FLAG  || index_false_control==1) 
{
index_do_dock=0;
index_do_modify=0; 
index_main_clear=0;
index_do_report=1;
reset_indexs_confirmation();
index_ask_confirm=1; 
index_do_overecord_mem_plus_faders=1;               
}     
else if (key_shifts & KB_SHIFT_FLAG || index_false_shift==1) //creation mémoires en mode merge Faders / seq
{
index_do_dock=0;
index_do_modify=0; 
index_main_clear=0;
index_do_report=1;
int mem_to_rec=(int)(atof(numeric)*10);
reset_indexs_confirmation();
index_ask_confirm=1; 
index_do_create_mem_plus_faders=1;
}
else
{
index_do_dock=0;
index_do_modify=0; 
index_main_clear=0;
index_do_report=toggle(index_do_report); 
}
break;  

case KEY_F4:
index_do_dock=0;
index_do_modify=0; 
index_do_report=0;     
index_main_clear=toggle(index_main_clear);
break;  

case KEY_F5:
              index_type=toggle(index_type);
              sprintf(numeric,"");numeric_postext=0;
break; 

case KEY_F6:
         if(index_time==0){add_a_window(W_TIME);  } 
           else {   substract_a_window(W_TIME); }
break;  

case KEY_F7:
if(index_trichro_window==0){add_a_window(W_TRICHROMY);} 
else  { substract_a_window(W_TRICHROMY);  }
break;  

case KEY_F8:
  if(index_video_window==0){ add_a_window(W_TRACKINGVIDEO); } 
 else{ substract_a_window(W_TRACKINGVIDEO);}
break;  

case KEY_F9:
          if(index_window_sequentiel==0){;add_a_window(W_SEQUENCIEL);}
          else {substract_a_window(W_SEQUENCIEL);}
break;
case KEY_F10:
if (key_shifts & KB_SHIFT_FLAG  || index_false_shift==1) //CONFIG
{
if(index_show_minifaders==0){add_a_window(W_MINIFADERS);}
else {substract_a_window(W_MINIFADERS);}
}
else
{
if(index_show_faders==0){add_a_window(W_FADERS);}
else {substract_a_window(W_FADERS);}
}

break;  

case KEY_F11:
if (key_shifts & KB_SHIFT_FLAG  || index_false_shift==1) //CONFIG
{
if(index_show_config_window==0){add_a_window(W_CFGMENU);}
else {substract_a_window(W_CFGMENU);}     
}
else if (key_shifts & KB_CTRL_FLAG  || index_false_control==1 ) 
{index_blind=toggle(index_blind);   }
else
{
if(index_show_banger_window==0)
          {add_a_window(W_BANGER);mouse_level_for_event=mouse_z;mouse_level_for_banger=mouse_z;}
          else {substract_a_window(W_BANGER);}       
}
break;  
              
case KEY_F12://black out

if (key_shifts & KB_CTRL_FLAG  || index_false_control==1) 
{
index_ask_confirm=1;index_do_quit_with_save=1;
}

else if (key_shifts & KB_SHIFT_FLAG   || index_false_shift==1) 
{
for (int i=0;i<12;i++)
{
specify_who_to_save_load[i]=0;}
reset_save_load_report_string();     
index_ask_confirm=1;index_do_quit_without_save=1;
}

else
{
if(index_blind==0)
{
for (int rs=0;rs<513;rs++)
{bufferSaisie[rs]=0;Selected_Channel[rs]=0;   }   
sprintf(string_Last_Order,">> Black Out done for On Stage channels");      
}     
else if(index_blind==1)
{
for (int rs=0;rs<513;rs++)
{bufferBlind[rs]=0; Selected_Channel[rs]=0;   }    
sprintf(string_Last_Order,">> Black Out done for On Blind channels");                       
}
             
substract_channel_selection_to_layers_plot();
}  
break;    


case KEY_UP:
key_up();
sprintf(string_key_id,list_keyname[1]);
break;

case KEY_DOWN:
key_down();
sprintf(string_key_id,list_keyname[2]);
break;

case KEY_ENTER :
key_affectation();
sprintf(string_key_id,list_keyname[3]);
break; 

case KEY_ENTER_PAD:
key_affectation();
sprintf(string_key_id,list_keyname[4]);
break; 

case KEY_EQUALS://+
key_add_ch();
sprintf(string_key_id,list_keyname[5]);
break;

case KEY_PLUS_PAD://+ num
key_add_ch();
sprintf(string_key_id,list_keyname[6]);
break;

case KEY_MINUS://-
key_minus_ch();
sprintf(string_key_id,list_keyname[7]);
break;

case KEY_MINUS_PAD://- num
key_minus_ch();
sprintf(string_key_id,list_keyname[8]);
break;


case KEY_TAB:
if(numeric_postext>0)
{
key_thruth();
sprintf(string_key_id,list_keyname[10]);
}
else 
{
if(window_focus_id==W_PLOT) {index_tab_on=toggle(index_tab_on); }  
}
break;
////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////TEXT TYPING OR FUNCTIONS CALLING//////////////////////////////////////////

case KEY_SPACE: 
              if (index_type==0)
             {
             key_go();
             }
              else if(index_type==1)
             {
             numeric[numeric_postext]=' ';
             numeric_postext++;
             }
       sprintf(string_key_id,list_keyname[11]);
       break;
             
         

        case KEY_Q: //lettre a
        if (key_shifts & KB_CTRL_FLAG  || index_false_control==1)
        {
        if(index_show_audio_window==0){add_a_window(W_AUDIO);}
        else {substract_a_window(W_AUDIO);}
        reset_audio_indexs_to_dock();       
        }
        else 
        {

             if(index_type==0)
             {
             key_presetvideo(0);
             }
             else  if (index_type==1)
             {
             numeric[numeric_postext]='A';
             numeric_postext++;
             }
         }
         sprintf(string_key_id,list_keyname[12]);
         break;  
       case KEY_B:
           if (index_type==0)
           {
           key_roi(10);
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='B';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[13]);
           break;
           
        case KEY_C:
            if (index_type==0)
           { 
            if (key_shifts & KB_CTRL_FLAG  || index_false_control==1) 
            {
            if(numeric_postext==0)
            {
            channel_copy();
            }
            else
            {
            snap_mem_to_copy();  
            }
            } 
            else  if (key_shifts & KB_SHIFT_FLAG || index_false_shift==1) 
            {
            if(index_window_chasers==0){add_a_window(W_CHASERS);} 
            else {substract_a_window(W_CHASERS);}
            } 
           else
           {
           key_roi(8);         }
           } 
           else if (index_type==1)
           {
           numeric[numeric_postext]='C';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[14]);
           break;
           
        case KEY_D://dock mode on
           if(index_type==0)
           {
            key_roi(2);
           }
           else if(index_type==1)
           {
           numeric[numeric_postext]='D';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[15]);
           break;
           
        case KEY_E:
            if (index_type==0)
           {
           key_presetvideo(2);
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='E';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[16]);
           break;
           
        case KEY_F:
           if(index_type==0)
           {
           key_roi(3);
           }
           
           else if (index_type==1)
           {
           numeric[numeric_postext]='F';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[17]);
           break;
           
        case KEY_G:
            if (index_type==0)
           {
           if ((key_shifts & KB_CTRL_FLAG || index_false_control==1 ) && numeric_postext>0)
           {
           //GET CHANNELS FROM A MEMORY     
           int mem_to_take=(int)(atof(numeric)*10);
           if(MemoiresExistantes[mem_to_take]==1)
           {
           Get_channels_from_memory(mem_to_take);  
           }
           else {sprintf(string_Last_Order,"Get Sel. channel from %d.%d: mem doesn't exist",mem_to_take/10,mem_to_take%10);}   
           } 
           else {key_roi(4);}
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='G';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[18]);
           break;
           
           case KEY_H:

            if (index_type==0)
           {
           key_roi(5);   
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='H';
           numeric_postext++;
           }
           
           sprintf(string_key_id,list_keyname[19]);
           break;
        
        case KEY_I:    
           if(index_type==0) //full
           {
           key_full();
           }
           else if(index_type==1)
           {
           numeric[numeric_postext]='I';
           numeric_postext++;
           }
         sprintf(string_key_id,list_keyname[20]);
           break;
           
        case KEY_J:
           if (index_type==0)
           {
           key_time_out();
           }        
           if (index_type==1)
           {
           numeric[numeric_postext]='J';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[21]);
           break;
           
        case KEY_K:
            if (index_type==0)
           {
           key_time_in();
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='K';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[22]);
           break;
           
        case KEY_L://in + out
           if(index_type==0)
           {
           key_time_in_out();
           }
           else if(index_type==1)
           {
           numeric[numeric_postext]='L';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[23]);
           break;
        
        case KEY_SEMICOLON:
           if(index_type==0)//le M qui est point en clavier americain
           {
           if (key_shifts & KB_SHIFT_FLAG || index_false_shift==1) 
           { if(index_show_mover_window=0){add_a_window(W_MOVER);}
           else {substract_a_window(W_MOVER);}}
           }
           else if(index_type==1)
           {
           numeric[numeric_postext]='M';
           numeric_postext++;     
           }
           sprintf(string_key_id,list_keyname[38]);
           break;  
                
        case KEY_N:
           if (index_type==0)
           {
           key_roi(11);          
           } 
           else if (index_type==1)
           {
           numeric[numeric_postext]='N';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[24]);
           break;
           
        case KEY_O:
       
         
           if(index_type==0)
           { 
           key_at_zero();
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='O';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[25]);
           break;
           
        case KEY_P:

          if (key_shifts & KB_SHIFT_FLAG || index_false_shift==1) 
           {
           if(index_patch_window==0){add_a_window(W_PATCH);}
           else {substract_a_window(W_PATCH);} 
           } 
           else{
           if (index_type==0)
           {
             if(index_visual_pad==0){add_a_window(W_NUMPAD);}
             else {substract_a_window(W_NUMPAD);}  
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='P';
           numeric_postext++;
           }
           }
           sprintf(string_key_id,list_keyname[39]);
           break;

        case KEY_A: // lettre Q
            if (index_type==0)
           {
           key_roi(1);
            }
           else if (index_type==1)
           {
           numeric[numeric_postext]='Q';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[26]);
           break;        
  
        case KEY_R://report mode on
        if(index_type==0 )
        {
        key_presetvideo(3);;//les banques de tracking cam
        }
        else if(index_type==1)
        {
           numeric[numeric_postext]='R';
           numeric_postext++;
        }
        sprintf(string_key_id,list_keyname[27]);
           break;
           
        case KEY_S:
            if (index_type==0)
           {
           if (key_shifts & KB_CTRL_FLAG  || index_false_control==1) 
           {
           if(index_is_saving==0){index_save_global_is=1;index_do_quick_save=1;}
           }
           else
           {
           key_roi(1);
           }
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='S';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[28]);
           break;
           
       case KEY_T:
           if(index_type==0)
           {
           key_presetvideo(4);//les banques de tracking cam
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='T';
           numeric_postext++;
           }         
           sprintf(string_key_id,list_keyname[29]);
           break;
           
        case KEY_U://inverse selection
           if (index_type==0)
           {
           key_select_inv();
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='U';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[30]);
           break;
           
        case KEY_V:
           if (index_type==0)
           {
           if (key_shifts & KB_CTRL_FLAG  || index_false_control==1) 
           {
           if(numeric_postext==0)
            {
            channel_paste();
            }
            else//si chiffre de mem tapée
            {
            index_copy_mem_in=1; 
            index_ask_confirm=1;
            
            }              
           } 
           else
           {
           //les aires de tracking cam
           key_roi(9);
           }
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='V';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[31]);
           break;
           
        case KEY_Z://w
           if (index_type==0)
           {
           if(key_shifts )
           {
           key_backward();
           }
           else{//les aires de tracking cam
           key_roi(6);
           }        
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='W';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[32]);
           break;
           
        case KEY_X:
           if (index_type==0)
           {
           if(key_shifts)
           {
           key_forward();
           }
          
           else{//les aires de tracking cam
           key_roi(7);
           }
           }
           else  if (index_type==1)
           {
           numeric[numeric_postext]='X';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[33]);
           break;
           
        case KEY_Y://select all 
          
          if (index_type==0)
           {
          key_select_all();
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='Y';
           numeric_postext++;
           }
           sprintf(string_key_id,list_keyname[34]);
           break;
           
        case KEY_W://z
           if (key_shifts & KB_CTRL_FLAG  || index_false_control==1)
             {
             //ctrl Z reload mem as recorded
             index_do_reload_mem=1;
             index_ask_confirm=1;                   
             }
             else if (key_shifts & KB_SHIFT_FLAG || index_false_shift==1)
             {
             //ctrl Z resurrect mem as recorded
             mem_to_resurrect=(int)(atof(numeric)*10);   
             index_do_resurrect_mem=1;  
             index_ask_confirm=1;                            
             }
           else
           {
            if (index_type==0 )
           {
           key_presetvideo(1);//les banques de tracking cam
           }
           else if (index_type==1)
           {
           numeric[numeric_postext]='Z';
           numeric_postext++;
           }
           }
           sprintf(string_key_id,list_keyname[35]);
           break;
           
    case KEY_LEFT:
    key_left(); 
    sprintf(string_key_id,list_keyname[36]);
    break;
       
       case KEY_RIGHT:
       key_right();
       sprintf(string_key_id,list_keyname[37]);
       break;
      
      case KEY_DEL:
      if (key_shifts & KB_SHIFT_FLAG || index_false_shift==1) 
      {
      reset_indexs_confirmation(); 
      index_do_delete_mem=1;  
      index_ask_confirm=1;       
      }
      break;
//////////////////////ENTREES NUMERIQUES COMMUNES//////////////////////////////////////////

case KEY_0:
numeric[numeric_postext]='0';
numeric_postext++;
break;
case KEY_0_PAD:
numeric[numeric_postext]='0';
numeric_postext++;
break;
case KEY_1:
numeric[numeric_postext]='1';
numeric_postext++;
break;
case KEY_1_PAD:
numeric[numeric_postext]='1';
numeric_postext++;
break;

case KEY_2:
numeric[numeric_postext]='2';
numeric_postext++;
break;
case KEY_2_PAD:
numeric[numeric_postext]='2';
numeric_postext++;
break;
case KEY_3:
numeric[numeric_postext]='3';
numeric_postext++;
break;
case KEY_3_PAD:
numeric[numeric_postext]='3';
numeric_postext++;
break;
case KEY_4:
numeric[numeric_postext]='4';
numeric_postext++;
break;
case KEY_4_PAD:
numeric[numeric_postext]='4';
numeric_postext++;
break;
case KEY_5:
numeric[numeric_postext]='5';
numeric_postext++;
break;
case KEY_5_PAD:
numeric[numeric_postext]='5';
numeric_postext++;
break;
case KEY_6:
numeric[numeric_postext]='6';
numeric_postext++;
break;
case KEY_6_PAD:
numeric[numeric_postext]='6';
numeric_postext++;
break;
case KEY_7:
numeric[numeric_postext]='7';
numeric_postext++;
break;
case KEY_7_PAD:
numeric[numeric_postext]='7';
numeric_postext++;
break;
case KEY_8:
numeric[numeric_postext]='8';
numeric_postext++;
break;
case KEY_8_PAD:
numeric[numeric_postext]='8';
numeric_postext++;
break;
case KEY_9:
numeric[numeric_postext]='9';
numeric_postext++;
break;
case KEY_9_PAD:
numeric[numeric_postext]='9';
numeric_postext++;
break;   

case KEY_COMMA:
numeric[numeric_postext]='.';
numeric_postext++;
break;

case  KEY_DEL_PAD:
numeric[numeric_postext]='.';
numeric_postext++;
break;

case  KEY_M:
numeric[numeric_postext]='.';
numeric_postext++;
break;


case KEY_BACKSPACE:
numeric[numeric_postext]=' ';
numeric_postext--;
numeric[numeric_postext]=' ';
if (numeric_postext<0) {numeric_postext=0;}
break;   

////////////////////MISE EN MEMOIRES DES FENETRES ET TOGGLE/////////////////////
case KEY_PRTSCR:
key_printscreen();              
break; 

default:
      
break;
}  
for(int u=0;u<nbre_key_persos;u++)
{
//keys persos
if( (int)(chi & 0xff)==mapping_temporaire[u])
{
switch(u)
{
case 0://AT level
key_affectation();
sprintf(string_key_id,"At Level");//max 16 char
break;
case 1://CH+
key_add_ch();
sprintf(string_key_id,"Ch +");//max 16 char
break;
case 2://CH-
key_minus_ch();
sprintf(string_key_id,"Ch -");//max 16 char     
break;
case 3://CH THRUTH
key_thruth();
sprintf(string_key_id,"To Ch");//max 16 char     
break;
case 4://CLEAR
key_unselect_ch();
sprintf(string_key_id,"Clear");//max 16 char        
break;
default:
break;
}
}
}



   
//protections

if (numeric_postext>maxchar_numeric){numeric[numeric_postext]=' ';numeric_postext=maxchar_numeric-1;}

if (numeric_postext<0) {numeric_postext=0;} 


       
}
sprintf(string_numeric_entry,"<< %s",numeric);


//CTRL-S
if(index_do_quick_save==1 )
      {
      Save_Show();
      sprintf(string_Last_Order,">> Show Saved at %s", tmp_time);
      index_do_quick_save=0;
      }
      
poll_keyboard();
      
return(0);  
}
// The player is alive
void
alive(Player * me)
{
	InputState * is;
	Camera * cam;
	EntitySet * others;
	Level world;

	unsigned int mousex;
	unsigned int mousey;

	float playerx, playery;

	float fake_lookx, fake_looky;
	float lookx, looky;
	unsigned int dir;

	float x, y;

	float dx = 0;
	float dy = 0;

	gboolean shoot;
	gboolean firing;

	Entity * target;

	is = me->is;
	cam = me->cam;
	others = me->others;
	world = me->world;

	firing = mouse_press(is);
	shoot = expired(me->attack_timer); 

	// Get the mouse position
	mouse_position(is, &mousex, &mousey);

	// Get the mouse position with regards to the level.
	camera_inverse_transform(cam, mousex, mousey, &fake_lookx, &fake_looky);
	lookx = fake_lookx / square_size;
	looky = fake_looky / square_size;

	entity_position(me->body, &playerx, &playery);

	dir = look(playerx, playery, lookx, looky);

	// Set the direction of the player with regards to key presses
	if (key_down(is, SDLK_a) || key_down(is, SDLK_LEFT))
	{
		dx = -1;
	} else if (key_down(is, SDLK_d) || key_down(is, SDLK_RIGHT))
	{
		dx = 1;
	}

	if (key_down(is, SDLK_w) || key_down(is, SDLK_UP))
	{
		dy = -1;
	} else if (key_down(is, SDLK_s) || key_down(is, SDLK_DOWN))
	{
		dy = 1;
	}

	entity_set_direction(me->body, dx, dy);

	// Try to shoot a KITTY!
	if (firing)
	{
		if (shoot)
		{
			play_wav(me->fire);

			entity_position(me->body, &x, &y);

			if (can_see(world, x, y, lookx, looky))
			{
				target = collision(me->body, lookx, looky, others);



				if (target)
				{
					entity_destroy(target);
					me->score ++;
				}
			}
		}


		if (dx != 0 || dy != 0)
		{
			if (dir == LEFT)
			{
				set_animation(me->body, (char *) "shoot_walk_left");
			}
			else if (dir == RIGHT)
			{
				set_animation(me->body, (char *) "shoot_walk_right");
			}
			else if (dir == UP)
			{
				set_animation(me->body, (char *) "shoot_walk_up");
			}
			else if (dir == DOWN)
			{
				set_animation(me->body, (char *) "shoot_walk_down");
			}
		}
		else
		{
			if (dir == LEFT)
			{
				set_animation(me->body, (char *) "shoot_idle_left");
			}
			else if (dir == RIGHT)
			{
				set_animation(me->body, (char *) "shoot_idle_right");
			}
			else if (dir == UP)
			{
				set_animation(me->body, (char *) "shoot_idle_up");
			}
			else if (dir == DOWN)
			{
				set_animation(me->body, (char *) "shoot_idle_down");
			}

		}
	}
	else
	{
		if (dx != 0 || dy != 0)
		{
			if (dir == LEFT)
			{
				set_animation(me->body, (char *) "walk_left");
			}
			else if (dir == RIGHT)
			{
				set_animation(me->body, (char *) "walk_right");
			}
			else if (dir == UP)
			{
				set_animation(me->body, (char *) "walk_up");
			}
			else if (dir == DOWN)
			{
				set_animation(me->body, (char *) "walk_down");
			}
		}
		else
		{
			if (dir == LEFT)
			{
				set_animation(me->body, (char *) "idle_left");
			}
			else if (dir == RIGHT)
			{
				set_animation(me->body, (char *) "idle_right");
			}
			else if (dir == UP)
			{
				set_animation(me->body, (char *) "idle_up");
			}
			else if (dir == DOWN)
			{
				set_animation(me->body, (char *) "idle_down");
			}

		}

	}

}
Beispiel #23
0
bool change_settings_ui(menu_e *menu, u1_t key, bool *skip_first, cfg_t *cfg)
{
	int i;
	bool save_cfg = FALSE;
	s1_t ki;

	// scroll the menu list forward
	if (key == KEY(TI)) {
		if (*skip_first) {
			*skip_first = FALSE;
		} else {
			*menu = *menu+1;
			if (*menu == M_LAST) *menu = 0;
		}
menu_up_down:
		dsp_7seg_str(DSP_LEFT, menu_str[*menu], DSP_CLEAR);
		if (((*menu == M_IP) || (*menu == M_NM) || (*menu == M_GW))) {
			display_ipaddr(cfg->if_ipinfo[*menu-M_IP]);
		}
		wait_key_release();
	} else

	// scroll the menu list backward
	if (key == KEY(FREQ)) {
		if (*skip_first) {
			*skip_first = FALSE;
		} else {
			if (*menu == 0) *menu = M_LAST;
			*menu = *menu-1;
		}
		goto menu_up_down;
	}
	
	// inc/dec a byte of the ip/nm/gw address
	// hold key down for auto-repeat
	ki = 0;

	for (i=0; settings_keys[i].key; i++) {
		if (key == KEY(settings_keys[i].key)) {
			ki = settings_keys[i].key_idx;
			break;
		}
	}
	
	if (ki) {
		bool first_time = TRUE;
		u4_t td, tref = timer_ms(), tcmp = 256, tinc = 32;
		do {
			td = time_diff(timer_ms(), tref);
			if (((*menu == M_IP) || (*menu == M_NM) || (*menu == M_GW)) && (first_time || (td >= tcmp))) {
				if (ki > 0) {
					cfg->if_ipinfo[*menu-M_IP][ki-1]++;
				} else {
					cfg->if_ipinfo[*menu-M_IP][-ki-1]--;
				}
				display_ipaddr(cfg->if_ipinfo[*menu-M_IP]);
				first_time = FALSE;
				tcmp += tinc;
			}
		} while (key_down());
		save_cfg = TRUE;	// change has been made
	}
	
	return save_cfg;
}
Beispiel #24
0
void
curses_loop()
{
	int key, w_height, w_width;

	notimeout(main_win, true);

	for (;;) {
		getmaxyx(status_win, w_height, w_width);
		mvwprintw(status_win, w_height - 2 , 1, "p - play, s - stop, q - quit");
		wrefresh(status_win);

		key = wgetch(main_win);
		switch (key) {
		case KEY_UP:
			break;
		case 10:	// 10 == ENTER
		case 'p':
			key_enter();
			break;
		case ' ':
			mvwprintw(status_win, 1, 5, "CMD: PAUSE");
			send_pause_command(sock_fd);
			break;
		case 'q':
			mvwprintw(status_win, 1, 5, "CMD: QUIT ");
			send_quit_command(sock_fd);
			wrefresh(status_win);
			return;
		case 's':
			mvwprintw(status_win, 1, 5, "CMD: STOP ");
			send_stop_command(sock_fd);
			break;
		case 68:
			mvwprintw(status_win, 1, 5, "CMD: REV  ");
			send_rev_command(sock_fd);
			break;
		case 67:
			mvwprintw(status_win, 1, 5, "CMD: FF   ");
			send_ff_command(sock_fd);
			break;
		case 66:
			// DOWN - scroll files
			key_down();
			break;
		case 65:
			// UP - scroll files
			key_up();
			break;
		//case 410:
		case KEY_RESIZE:
			resize_windows();
			break;
		default:
			mvwprintw(status_win, 10, 1, "pressed:");
			mvwprintw(status_win, 11, 1, "%3d as '%c'", key, key);
			break;
		}
		wrefresh(status_win);
	}
}
Beispiel #25
0
Datei: gx.c Projekt: LWSS/gx
static void tick_camera(struct Input *input, struct Camera *camera, float dt)
{
    //
    // move
    //

    vec2 camera_up = vec2_direction(camera->rotation);
    vec2 camera_right = vec2_direction(camera->rotation - PI_OVER_TWO);

    vec2 move_acceleration = vec2_zero();
    if (key_down(GLFW_KEY_W, input))
        move_acceleration = vec2_add(move_acceleration, camera_up);
    if (key_down(GLFW_KEY_A, input))
        move_acceleration = vec2_add(move_acceleration, vec2_negate(camera_right));
    if (key_down(GLFW_KEY_S, input))
        move_acceleration = vec2_add(move_acceleration, vec2_negate(camera_up));
    if (key_down(GLFW_KEY_D, input))
        move_acceleration = vec2_add(move_acceleration, camera_right);

    if (vec2_length2(move_acceleration) > FLOAT_EPSILON)
    {
        const float acceleration_magnitude = camera->zoom * 10.0f;
        move_acceleration = vec2_normalize(move_acceleration);
        move_acceleration = vec2_mul(move_acceleration, acceleration_magnitude);

        // v = v0 + (a*t)
        camera->move_velocity = vec2_add(camera->move_velocity, vec2_mul(move_acceleration, dt));

        // Clamp move velocity.
        const float max_move_speed = 5.0f * sqrtf(camera->zoom);
        if (vec2_length2(camera->move_velocity) > (max_move_speed * max_move_speed))
            camera->move_velocity = vec2_mul(vec2_normalize(camera->move_velocity), max_move_speed);
    }

    // Number of seconds required for friction to stop movement completely.
    // (because velocity is sampled each frame, actual stop time longer than this)
    float stop_time = 0.1f;
    float inv_stop_time = 1.0f / stop_time;

    if (move_acceleration.x == 0.0f)
        camera->move_velocity.x -= camera->move_velocity.x * inv_stop_time * dt;
    if (move_acceleration.y == 0.0f)
        camera->move_velocity.y -= camera->move_velocity.y * inv_stop_time * dt;

    // r = r0 + (v0*t) + (a*t^2)/2
    camera->position = vec2_add(vec2_add(camera->position, vec2_mul(camera->move_velocity, dt)), vec2_div(vec2_mul(move_acceleration, dt * dt), 2.0f));


    //
    // zoom
    //

    float zoom_acceleration = 0.0f;
    if (key_down(GLFW_KEY_SPACE, input))
        zoom_acceleration += 1.0f;
    if (key_down(GLFW_KEY_LEFT_CONTROL, input))
        zoom_acceleration -= 1.0f;
    zoom_acceleration *= camera->zoom * 50.0f;

    if (zoom_acceleration == 0.0f)
        camera->zoom_velocity -= camera->zoom_velocity * (1.0f / 0.1f) * dt;

    // v = v0 + (a*t)
    camera->zoom_velocity += zoom_acceleration * dt;

    // r = r0 + (v0*t) + (a*t^2)/2
    camera->zoom += (camera->zoom_velocity * dt) + (zoom_acceleration * dt * dt) / 2.0f;

    // Clamp zoom velocity.
    const float max_zoom_speed = 3.0f * camera->zoom;
    camera->zoom_velocity = clamp_float(camera->zoom_velocity, -max_zoom_speed, max_zoom_speed);

    float unclamped_zoom = camera->zoom;
    camera->zoom = clamp_float(camera->zoom, 1.0f, 1000.0f);
    if (camera->zoom != unclamped_zoom)
        camera->zoom_velocity = 0.0f;
}