Input manager demonstration
This commit is contained in:
parent
c95d92f6d1
commit
baa6071ebf
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "vec.h"
|
||||
#include "camera.h"
|
||||
#include "input.h"
|
||||
|
||||
typedef struct Player
|
||||
{
|
||||
|
@ -11,7 +12,7 @@ typedef struct Player
|
|||
Vec origin; /* the origin of the player (offset) */
|
||||
} Player;
|
||||
|
||||
void player_step(Player *player);
|
||||
void player_step(Player *player, Input *input);
|
||||
void player_draw(Player *player, Camera *camera);
|
||||
|
||||
#endif /* _DEF_PLAYER */
|
||||
|
|
|
@ -57,7 +57,7 @@ int play_level(int level_id)
|
|||
input.keys[K_DOWN] = KEY_DOWN;
|
||||
|
||||
//vec_cpy(&camera.pos, player.pos);
|
||||
while ((int)camera.pos.x != (int)player.pos.x)
|
||||
while ((int)camera.pos.x != (int)player.pos.x || (int)camera.pos.y != (int)player.pos.y)
|
||||
{
|
||||
step_event(&player, &level, &camera, &input);
|
||||
draw_event(&player, &level, &camera, &input);
|
||||
|
@ -68,7 +68,7 @@ int play_level(int level_id)
|
|||
void step_event(Player *player, Level *level, Camera *camera, Input *input)
|
||||
{
|
||||
input_step(input);
|
||||
player_step(player);
|
||||
player_step(player, input);
|
||||
level_step(level);
|
||||
camera_step(camera);
|
||||
}
|
||||
|
|
14
src/player.c
14
src/player.c
|
@ -2,9 +2,21 @@
|
|||
|
||||
#include "player.h"
|
||||
#include "camera.h"
|
||||
#include "input.h"
|
||||
|
||||
void player_step(Player *player)
|
||||
void player_step(Player *player, Input *input)
|
||||
{
|
||||
Vec move = {
|
||||
input_is_down(*input, K_RIGHT) - input_is_down(*input, K_LEFT),
|
||||
input_is_down(*input, K_DOWN) - input_is_down(*input, K_UP)
|
||||
};
|
||||
#ifdef FX9860G
|
||||
vec_div(&move, 50);
|
||||
#endif /* FX9860G */
|
||||
#ifdef FXCG50
|
||||
vec_mul(&move, 2);
|
||||
#endif /* FXCG50 */
|
||||
vec_add(&player->pos, move);
|
||||
}
|
||||
|
||||
void player_draw(Player *player, Camera *camera)
|
||||
|
|
Reference in New Issue