forked from kdx/jtmm2-old
91 lines
1.8 KiB
C
91 lines
1.8 KiB
C
#include <gint/display.h>
|
|
#include <gint/keyboard.h>
|
|
#include <gint/std/string.h>
|
|
#include <stdbool.h>
|
|
|
|
#include "main.h"
|
|
#include "debug.h"
|
|
#include "init.h"
|
|
#include "vec.h"
|
|
#include "player.h"
|
|
#include "level.h"
|
|
#include "camera.h"
|
|
#include "input.h"
|
|
|
|
int main(void)
|
|
{
|
|
init(); /* initialize gint */
|
|
|
|
/* main game loop */
|
|
play_level(0);
|
|
|
|
/* return to menu */
|
|
return 1;
|
|
}
|
|
|
|
int play_level(int level_id)
|
|
{
|
|
/* create player */
|
|
Player player = {
|
|
.pos = {16 * VEC_PRECISION, 16 * VEC_PRECISION},
|
|
.hbox = {7 * VEC_PRECISION, 7 * VEC_PRECISION},
|
|
.origin = {4 * VEC_PRECISION, 4 * VEC_PRECISION}
|
|
};
|
|
|
|
/* create level */
|
|
Level level = {
|
|
.width = 0,
|
|
.height = 0
|
|
};
|
|
|
|
/* create camera */
|
|
Camera camera = {
|
|
.pos = {DWIDTH * VEC_PRECISION, DHEIGHT * VEC_PRECISION},
|
|
.target = &player.pos,
|
|
#ifdef FX9860G
|
|
.speed = 0.0005
|
|
#endif /* FX9860G */
|
|
#ifdef FXCG50
|
|
.speed = 0.05
|
|
#endif /* FXCG50 */
|
|
};
|
|
|
|
/* create input manager */
|
|
Input input;
|
|
input.keys[K_LEFT] = KEY_LEFT;
|
|
input.keys[K_RIGHT] = KEY_RIGHT;
|
|
input.keys[K_UP] = KEY_UP;
|
|
input.keys[K_DOWN] = KEY_DOWN;
|
|
|
|
//vec_cpy(&camera.pos, player.pos);
|
|
while (camera.pos.x / VEC_PRECISION != player.pos.x / VEC_PRECISION ||
|
|
camera.pos.y / VEC_PRECISION != player.pos.y / VEC_PRECISION)
|
|
{
|
|
step_event(&player, &level, &camera, &input);
|
|
draw_event(&player, &level, &camera, &input);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void step_event(Player *player, Level *level, Camera *camera, Input *input)
|
|
{
|
|
//getkey();
|
|
input_step(input);
|
|
player_step(player, input);
|
|
level_step(level);
|
|
camera_step(camera);
|
|
}
|
|
|
|
void draw_event(Player *player, Level *level, Camera *camera, Input *input)
|
|
{
|
|
dclear(C_WHITE);
|
|
level_draw(level, camera);
|
|
player_draw(player, camera);
|
|
#ifdef DEBUG
|
|
camera_draw_debug(camera);
|
|
//input_draw_debug(input);
|
|
player_draw_debug(player);
|
|
#endif
|
|
dupdate();
|
|
}
|