Skip to content

Commit d1c12fd

Browse files
authored
Merge pull request #19 from mardy/hat-movement
Support movement via directional pad keys
2 parents d54e466 + c9adba3 commit d1c12fd

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/game.c

+21
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,27 @@ void control (struct hero *jean,uint *keyp) {
427427

428428
}
429429

430+
if (event.type == SDL_JOYHATMOTION) {
431+
jean->push[1] = 0;
432+
jean->push[2] = 0;
433+
jean->push[3] = 0;
434+
jean->ducking = 0;
435+
if (event.jhat.value & SDL_HAT_LEFT) {
436+
jean->push[2] = 1;
437+
jean->push[3] = 0;
438+
} else if (event.jhat.value & SDL_HAT_RIGHT) {
439+
jean->push[3] = 1;
440+
jean->push[2] = 0;
441+
}
442+
if (event.jhat.value & SDL_HAT_DOWN) {
443+
jean->push[1] = 1;
444+
jean->ducking = 1;
445+
} else if (event.jhat.value & SDL_HAT_UP) {
446+
jean->push[1] = 0;
447+
jean->ducking = 0;
448+
}
449+
}
450+
430451
if (event.type == SDL_JOYBUTTONDOWN) {
431452
if (event.jbutton.button == JUMP_JOYBUTTON)
432453
if ((jean->push[0] == 0) && (jean->jump == 0) && (jean->ducking == 0))

0 commit comments

Comments
 (0)