Example #1
0
void update_tick_avatar(){

  // boost when player wants to boost, has boost and not currently boosting
  Bool can_boost = !tick_boost_ttl and tick_energie;
  if(input_key_down(INPUT_KEY_UP) and can_boost){ 
    synth_play_channel4(SYNTH_NOTE_CIS, SYNTH_OCTAVE_C0);
    tick_boost_vec = vec_make_float( 0.00, - BOOST_ACCEL);
    tick_boost_ttl = BOOST_TIME;
    tick_energie--;
  } else if(input_key_down(INPUT_KEY_DOWN) and can_boost){ 
    synth_play_channel4(SYNTH_NOTE_CIS, SYNTH_OCTAVE_C0);
    tick_boost_vec = vec_make_float( 0.00, BOOST_ACCEL);
    tick_boost_ttl = BOOST_TIME;
    tick_energie--;
  } else if(input_key_down(INPUT_KEY_A) and can_boost){ 
    synth_play_channel4(SYNTH_NOTE_AIS, SYNTH_OCTAVE_C0);
    if (tick_energie > 1){
      tick_boost_vec = vec_make_float(BOOST_ACCEL + BOOST_ACCEL, 0.00);
      tick_boost_ttl = BOOST_TIME;
      tick_energie -= 2;
    } else {
      tick_boost_vec = vec_make_float(BOOST_ACCEL, 0.00);
      tick_boost_ttl = BOOST_TIME;
      tick_energie--;
    }
  }

  // move tick_avatar
  if (tick_boost_ttl){
    tick_avatar.vec = vec_add(tick_avatar.vec, tick_boost_vec);
    tick_boost_ttl--;
  } 
  tick_avatar.pos = vec_add(tick_avatar.pos, tick_avatar.vec);

  if (tick_avatar.hit_ttl){
    tick_avatar.hit_ttl--;
  }
}
Example #2
0
void
platform_handle_events(Input *in)
{
	Window active;
	int revert_to;
	XGetInputFocus(g_pctx.display, &active, &revert_to);
	// TODO: Stop updating the camera if the mouse pointer isn't inside our window?
	if (active == g_pctx.window)
		platform_update_mouse_pos(&in->mouse);

	// TODO: Set up an auto-pause when we lose focus?
	XEvent xev;
	while (XPending(g_pctx.display)) {
		XNextEvent(g_pctx.display, &xev);
		switch(xev.type) {
		case KeyPress: {
			input_key_down(&in->keyboard, xev.xkey.keycode);
		} break;
		case KeyRelease: {
			input_key_up(&in->keyboard, xev.xkey.keycode);
		} break;
		case ButtonPress: {
			input_mbutton_down((Mouse_Button)xev.xbutton.button, &in->mouse);
		} break;
		case ButtonRelease: {
			input_mbutton_up((Mouse_Button)xev.xbutton.button, &in->mouse);
		} break;
		case FocusOut: {
			in->mouse.motion = {0,0}; // Clear residual mouse motion so we don't keep using it in cam calculations.
		} break;
		case FocusIn: {
			platform_update_mouse_pos(&in->mouse); // Reset mouse position so the view doesn't "jump" when we regain focus.
		} break;
		case ClientMessage:
			if ((Atom)xev.xclient.data.l[0] == g_pctx.wm_delete_window)
				platform_exit();
		}
	}
}
Example #3
0
File: input.c Project: k5g/emulika
int input_button_down(const iprofile *profile, t_button btn)
{
    switch(btn) {
        case BTN_UP:
            switch(profile->base.type) {
                case INP_KEYBOARD:
                    return input_key_down(profile->kbd.up);
                case INP_JOYPAD:
                    return 0;
            }
            break;
        case BTN_DOWN:
            switch(profile->base.type) {
                case INP_KEYBOARD:
                    return input_key_down(profile->kbd.down);
                case INP_JOYPAD:
                    return 0;
            }
            break;
        case BTN_LEFT:
            switch(profile->base.type) {
                case INP_KEYBOARD:
                    return input_key_down(profile->kbd.left);
                case INP_JOYPAD:
                    return 0;
            }
            break;
        case BTN_RIGHT:
            switch(profile->base.type) {
                case INP_KEYBOARD:
                    return input_key_down(profile->kbd.right);
                case INP_JOYPAD:
                    return 0;
            }
            break;
        case BTN_A:
            switch(profile->base.type) {
                case INP_KEYBOARD:
                    return input_key_down(profile->kbd.btn_a);
                case INP_JOYPAD:
                    return input_pad_button_down(profile->pad.index, profile->pad.btn_a);
            }
            break;
        case BTN_B:
            switch(profile->base.type) {
                case INP_KEYBOARD:
                    return input_key_down(profile->kbd.btn_b);
                case INP_JOYPAD:
                    return input_pad_button_down(profile->pad.index, profile->pad.btn_b);
            }
            break;
        case BTN_START:
            switch(profile->base.type) {
                case INP_KEYBOARD:
                    return input_key_down(profile->kbd.btn_start);
                case INP_JOYPAD:
                    return input_pad_button_down(profile->pad.index, profile->pad.btn_start);
            }
            break;
    }

    return 0;
}
Example #4
0
void controller_system_update(ControllerSystem* self) {
    GET_SYSTEM_COMPONENTS(self);

    for (u32 i = 0; i < components->count; ++i) {
        Entity entity = GET_ENTITY(i);
        ControllerComponent* controller = (ControllerComponent*)GET_SYSTEM_COMPONENT(i);

        MovementComponent* movement =
            (MovementComponent*)GET_COMPONENT(entity, COMPONENT_MOVEMENT);

        TransformComponent* transform =
            (TransformComponent*)GET_COMPONENT(entity, COMPONENT_TRANSFORM);

        REQUIRED_COMPONENTS(transform, movement, controller);

        f32 x = 0;
        f32 y = 0;

        if (input_key(SDL_SCANCODE_LEFT)) {
            x -= 1.f;
        }

        if (input_key(SDL_SCANCODE_RIGHT)) {
            x += 1.f;
        }

        if (input_key(SDL_SCANCODE_UP)) {
            y -= 1.f;
        }

        if (input_key(SDL_SCANCODE_DOWN)) {
            y += 1.f;
        }

        //printf("%f\n", controller->moveSpeed);

        x *= controller->moveSpeed;
        y *= controller->moveSpeed;

        vec2_set(&movement->velocity, x, y);

        if (input_key_down(SDL_SCANCODE_Z)) {
            for (u32 i = 0; i < controller->bulletSourceCount; ++i) {
                bullet_source_on(&controller->bulletSources[i]);
            }
        }
        if (input_key_up(SDL_SCANCODE_Z)) {
            for (u32 i = 0; i < controller->bulletSourceCount; ++i) {
                bullet_source_off(&controller->bulletSources[i]);
            }
        }

        for (u32 i = 0; i < controller->bulletSourceCount; ++i) {
            bullet_source_update(&controller->bulletSources[i], globals.time.delta, self->super.entityManager, &transform->position);
        }        

        //if (controller->fireTimer > 0.f) {
        //    controller->fireTimer -= globals.time.delta;
        //}

        //if (input_key(SDL_SCANCODE_Z) && controller->fireTimer <= 0.f) {
        //    Vec2 pos = vec2_clone(&transform->position);
        //    pos.x += 64;
        //    pos.y += 52;
        //    entity_create_bullet(self->super.entityManager,
        //        vec2_clone(&pos),
        //        textures_get("player_bullet_1.png"));
        //    controller->fireTimer = controller->fireDelay;
        //}
    }
}
Example #5
0
int main ( int argc, char** argv )
{
    int done, pause, bookmark;
    int joypads[NJOYSTICKS];

    mastersystem *sms = NULL;
    appenv *environment = NULL;
    romspecs *rspecs = NULL;

    display screen;
    SDL_version sdlvers;

    char *romfilename=NULL;
    int nosound = 0;
    int codemasters = 0;

    tmachine machine = UNDEFINED;
    video_mode vmode = UNDEFINED;

    screen.fullscreen = 0;
    screen.scale = DEFAULT_SCALE;
    screen.minscale = (float)224.0 / 192;

#ifndef DEBUG
    assert(0);
#endif

    environment = getappenv();
    initmodules(environment->basedir);

    log4me_print("-==| %s version %s |==-\n", PACKAGE, VERSION);
#ifdef DEBUG
    log4me_print("  => DEBUG version\n");
#endif
    readoptions(argc, argv, &romfilename, &screen.fullscreen, &machine, &vmode, &nosound, &screen.scale, &codemasters);

    SDL_GetVersion(&sdlvers);
    log4me_print("SDL : %d.%d.%d\n", sdlvers.major, sdlvers.minor, sdlvers.patch);
    log4me_print("SDL : Video driver (%s)\n", getcurrentvideodriver());
    log4me_print("SDL : Rendered driver (%s)\n", getcurrentrendererdriver());
    log4me_print("SDL : Audio driver (%s)\n", SDL_GetCurrentAudioDriver());

    // Init joypads
    int i;
    for(i=0;i<NJOYSTICKS;i++) joypads[i] = input_new_pad();

    // Display joypads informations
    if(input_pad_detected()) {
        padinfos infos;
        for(i=0;i<NJOYSTICKS;i++) {
            if(joypads[i]==NO_JOYPAD) continue;
            input_pad_getinfos(joypads[i], &infos);
            log4me_print("SDL : Player %d joystick detected => %s\n", i+1, infos.name);
            log4me_print("\tButtons : %d, Axis : %d, Hats : %d\n", infos.buttons, infos.axis, infos.hats);
        }
    } else
        log4me_print("SDL : No joystick detected\n");

    rspecs = getromspecs(romfilename, machine, vmode, codemasters);
    machine = getrommachine(rspecs);
    vmode = getromvideomode(rspecs);

    assert((machine==JAPAN) || (machine==EXPORT));
    assert((vmode==VM_NTSC) || (vmode==VM_PAL));
    log4me_print("SMS : Use %s machine with %s video mode\n", machine==EXPORT ? "Export" : "Japan", vmode==VM_PAL ? "PAL" : "NTSC");

    switch(getromgameconsole(rspecs)) {
        case GC_SMS:
            screen.width = 256;
            screen.height = 192;
            screen.margin = DEFAULT_MARGIN;
            break;
        case GC_GG:
            screen.width = 160;
            screen.height = 144;
            screen.margin = 0;
            break;
        default:
            assert(0);
            break;
    }
    setvideomode(&screen);

    sms = ms_init(&screen, rspecs, nosound ? SND_OFF : SND_ON, joypads[0], joypads[1], environment->backup);
    if(sms==NULL) {
        log4me_error(LOG_EMU_MAIN, "Unable to allocate and initialize the SMS emulator.\n");
        exit(EXIT_FAILURE);
    }

    SDL_SetWindowTitle(screen.window, CSTR(sms->romname));

    done = pause = bookmark = 0;

    ms_start(sms);
    while (!done)
    {
        SDL_Event event;
        while(SDL_PollEvent(&event)) {
            input_process_event(&event);
            done |= (event.type==SDL_QUIT);
        }

        done |= input_key_pressed(SDL_SCANCODE_ESCAPE);

        if(input_key_down(SDL_SCANCODE_PAUSE)) {
            pause ^= 1;
            ms_pause(sms, pause);
        }

        if(input_key_down(SDL_SCANCODE_F9))
            takesnapshot(sms, environment->snapshots);

        if(input_key_down(SDL_SCANCODE_F10))
            takescreenshot(sms, environment->screenshots);

        if(input_key_down(SDL_SCANCODE_F2)) {
            ms_pause(sms, 1);
            screen.scale -= 0.2;
            setvideomode(&screen);
            ms_pause(sms, 0);
        }

        if(input_key_down(SDL_SCANCODE_F3)) {
            ms_pause(sms, 1);
            screen.scale += 0.2;
            setvideomode(&screen);
            ms_pause(sms, 0);
        }

        if(input_key_down(SDL_SCANCODE_F4)) {
            ms_pause(sms, 1);
            screen.fullscreen ^= 1;
            setvideomode(&screen);
            ms_pause(sms, 0);
        }

#ifdef DEBUG
        if(input_key_down(SDL_SCANCODE_B))
            log4me_print("[BKM] %d\n", bookmark++);

        if(input_key_down(SDL_SCANCODE_F5))
            savetiles(sms, environment->debug);

        if(input_key_down(SDL_SCANCODE_F6))
            tms9918a_toggledisplaypalette(&sms->vdp);
#endif

        if(!ms_ispaused(sms)) ms_execute(sms);
    }

    releaseobject(sms);
    releaseobject(rspecs);
    for(i=0;i<NJOYSTICKS;i++) input_release_pad(joypads[i]);

    releaseobject(environment);

    return 0;
}