diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/eetg.c | 8 | ||||
-rw-r--r-- | src/eetg.h | 1 | ||||
-rw-r--r-- | src/et/et.c | 100 | ||||
-rw-r--r-- | src/et/et.h | 13 |
4 files changed, 97 insertions, 25 deletions
@@ -770,6 +770,14 @@ eetg_object_move(struct eetg_object *object, int x, int y) } } +void +eetg_object_update(struct eetg_object *object) +{ + assert(object); + + eetg_object_move(object, object->x, object->y); +} + int eetg_object_get_cell(const struct eetg_object *object, int x, int y) { @@ -113,6 +113,7 @@ int eetg_object_get_width(const struct eetg_object *object); int eetg_object_get_height(const struct eetg_object *object); bool eetg_object_is_empty(const struct eetg_object *object); void eetg_object_move(struct eetg_object *object, int x, int y); +void eetg_object_update(struct eetg_object *object); int eetg_object_get_cell(const struct eetg_object *object, int x, int y); struct eetg_world *eetg_object_get_world(const struct eetg_object *object); diff --git a/src/et/et.c b/src/et/et.c index 3a7200d..8488b9c 100644 --- a/src/et/et.c +++ b/src/et/et.c @@ -39,6 +39,8 @@ #define ET_CURRENT_PIECE_SPEED 1 #define ET_LOCKDOWN_DELAY 2 +#define ET_NR_LOCKDOWN_MOVES 15 + #define ET_SCORE_MISSILE 40 #define ET_SCORE_ALIENS0 30 #define ET_SCORE_ALIENS12 20 @@ -513,6 +515,36 @@ et_piece_move_down(struct et_piece *piece) } static void +et_piece_rotate_left(struct et_piece *piece) +{ + assert(piece); + + piece->orientation--; + + if (piece->orientation < 0) { + piece->orientation = ET_NR_ORIENTATIONS - 1; + } + + et_piece_update_sprite(piece); + eetg_object_update(&piece->object); +} + +static void +et_piece_rotate_right(struct et_piece *piece) +{ + assert(piece); + + piece->orientation++; + + if (piece->orientation >= ET_NR_ORIENTATIONS) { + piece->orientation = 0; + } + + et_piece_update_sprite(piece); + eetg_object_update(&piece->object); +} + +static void et_piece_move_left(struct et_piece *piece) { struct eetg_object *object; @@ -682,6 +714,13 @@ et_game_switch_to_next_piece(struct et_game *game) assert(game); + game->gravity_counter = game->gravity_counter_reload; + game->nr_lockdown_moves = -1; + + if (game->current_piece) { + et_piece_move_up(game->current_piece); + } + game->current_piece = et_game_get_next_piece(game); object = et_piece_get_object(game->current_piece); @@ -714,10 +753,9 @@ et_game_start(struct et_game *game) et_game_switch_to_next_piece(game); - game->current_piece_counter_reload = ET_FPS / ET_CURRENT_PIECE_SPEED; - game->current_piece_counter = game->current_piece_counter_reload; + game->gravity_counter_reload = ET_FPS / ET_CURRENT_PIECE_SPEED; + game->gravity_counter = game->gravity_counter_reload; game->lockdown_counter_reload = ET_FPS / ET_LOCKDOWN_DELAY; - game->lockdown_counter = 0; game->nr_lockdown_moves = -1; game->last_move = ET_MOVE_DOWN; @@ -745,8 +783,8 @@ et_game_start_lockdown(struct et_game *game) assert(game); - game->lockdown_counter = game->lockdown_counter_reload; - game->nr_lockdown_moves = 0; + game->gravity_counter = game->lockdown_counter_reload; + game->nr_lockdown_moves = ET_NR_LOCKDOWN_MOVES; game_over = et_piece_move_up(game->current_piece); @@ -775,7 +813,11 @@ et_game_handle_collision(struct eetg_object *object1, } else if (et_has_type(object1, object2, ET_TYPE_RIGHT_WALL)) { et_piece_move_left(game->current_piece); } else if (et_has_type(object1, object2, ET_TYPE_BOTTOM_WALL)) { - et_game_start_lockdown(game); + if (game->nr_lockdown_moves < 0) { + et_game_start_lockdown(game); + } else { + et_game_switch_to_next_piece(game); + } } else if ((eetg_object_get_type(object1) == ET_TYPE_PIECE) && (eetg_object_get_type(object2) == ET_TYPE_PIECE)) { if (game->last_move == ET_MOVE_LEFT) { @@ -783,7 +825,11 @@ et_game_handle_collision(struct eetg_object *object1, } else if (game->last_move == ET_MOVE_RIGHT) { et_piece_move_left(game->current_piece); } else if (game->last_move == ET_MOVE_DOWN) { - et_game_start_lockdown(game); + if (game->nr_lockdown_moves < 0) { + et_game_start_lockdown(game); + } else { + et_game_switch_to_next_piece(game); + } } } } @@ -834,19 +880,31 @@ et_game_process_game_input(struct et_game *game, char c) game->last_move = ET_MOVE_RIGHT; et_piece_move_right(game->current_piece); } else if (c == 'd') { + game->gravity_counter = game->gravity_counter_reload; + game->last_move = ET_MOVE_DOWN; et_piece_move_down(game->current_piece); + } else if (c == 'j') { + game->last_move = ET_MOVE_ROTATE_LEFT; + et_piece_rotate_left(game->current_piece); + } else if (c == 'k') { + game->last_move = ET_MOVE_ROTATE_RIGHT; + et_piece_rotate_right(game->current_piece); + } + + if (game->nr_lockdown_moves > 0) { + game->nr_lockdown_moves--; + game->gravity_counter = game->lockdown_counter_reload; } } if (c == ' ') { - game->last_move = ET_MOVE_DOWN; - while (game->nr_lockdown_moves < 0) { + game->last_move = ET_MOVE_DOWN; et_piece_move_down(game->current_piece); } - game->lockdown_counter = 1; + game->gravity_counter = 1; game->nr_lockdown_moves = 0; } @@ -858,14 +916,14 @@ et_game_move_current_piece(struct et_game *game) { assert(game); - assert(game->current_piece_counter > 0); - game->current_piece_counter--; + assert(game->gravity_counter > 0); + game->gravity_counter--; - if (game->current_piece_counter != 0) { + if (game->gravity_counter != 0) { return; } - game->current_piece_counter = game->current_piece_counter_reload; + game->gravity_counter = game->gravity_counter_reload; game->last_move = ET_MOVE_DOWN; et_piece_move_down(game->current_piece); @@ -877,16 +935,20 @@ et_game_process_lockdown(struct et_game *game) assert(game); assert(game->nr_lockdown_moves >= 0); - assert(game->lockdown_counter > 0); - game->lockdown_counter--; + assert(game->gravity_counter > 0); + game->gravity_counter--; - if (game->lockdown_counter != 0) { + if (game->gravity_counter != 0) { return; } - game->nr_lockdown_moves = -1; + game->last_move = ET_MOVE_DOWN; + et_piece_move_down(game->current_piece); - et_game_switch_to_next_piece(game); + if (game->nr_lockdown_moves >= 0) { + game->gravity_counter = game->gravity_counter_reload; + game->nr_lockdown_moves = -1; + } } static void diff --git a/src/et/et.h b/src/et/et.h index 2f8d675..c942cce 100644 --- a/src/et/et.h +++ b/src/et/et.h @@ -46,9 +46,11 @@ #define ET_ORIENTATION_LEFT 3 #define ET_NR_ORIENTATIONS 4 -#define ET_MOVE_LEFT 0 -#define ET_MOVE_RIGHT 1 -#define ET_MOVE_DOWN 2 +#define ET_MOVE_LEFT 0 +#define ET_MOVE_RIGHT 1 +#define ET_MOVE_DOWN 2 +#define ET_MOVE_ROTATE_LEFT 3 +#define ET_MOVE_ROTATE_RIGHT 4 /* * Take into account the following : @@ -87,10 +89,9 @@ struct et_game { struct et_piece *held_piece; struct eetg_object end_title; unsigned int score; - int8_t current_piece_counter_reload; - int8_t current_piece_counter; + int8_t gravity_counter_reload; int8_t lockdown_counter_reload; - int8_t lockdown_counter; + int8_t gravity_counter; int8_t nr_lockdown_moves; int8_t last_move; int8_t state; |