/* *-------------------------------------- * Program Name: HOT CHICKS * Author: commandblockguy * License: * Description: *-------------------------------------- */ #include #include #include #include #include #include "background.h" #include "colors.h" #include "gameover.h" #include "gfx/gfx.h" #include "logic.h" #include "save.h" #include "ui.h" void game(void); void graphics(struct game_state *state); int main(void) { dbg_printf("\nProgram started\n"); ti_CloseAll(); srand(rtc_Time()); kb_SetMode(MODE_3_CONTINUOUS); gfx_Begin(); gfx_SetPalette(mypalette, sizeof_mypalette, 0); gfx_SetDrawBuffer(); gen_stars(); if(time(NULL) < 1617177025) { gfx_FillScreen(BLACK); gfx_SetTextFGColor(WHITE); const char *str = "Please set system time."; gfx_PrintStringXY(str, (LCD_WIDTH - gfx_GetStringWidth(str)) / 2, LCD_HEIGHT / 2); const char *str2 = "(Press mode on homescreen)"; gfx_PrintStringXY(str2, (LCD_WIDTH - gfx_GetStringWidth(str2)) / 2, LCD_HEIGHT / 2 + 16); gfx_BlitBuffer(); while(kb_AnyKey()); while(!kb_AnyKey()); } else { init_chick_sprites(); game(); } gfx_End(); ti_CloseAll(); return 0; } void game(void) { for(;;) { loading_screen(); struct save_contents save_contents; bool save_valid = load_save(&save_contents); if(!save_valid) { dbg_printf("Save file invalid\n"); if(gameover(STATUS_GAME_OVER_TIME, -1)) { return; } } struct game_state current_state; load_save_data(&save_contents, ¤t_state); uint8_t status = STATUS_IN_PROGRESS; while(status == STATUS_IN_PROGRESS) { struct game_state new_state; status = update(&new_state, ¤t_state); current_state = new_state; if(status == STATUS_IN_PROGRESS) { graphics(&new_state); } } if(status == STATUS_EXIT) { struct save_contents new_save; gen_save_data(&new_save, ¤t_state); save(&new_save); break; } else { if(gameover(status, current_state.num_days)) break; } } } void graphics(struct game_state *state) { draw_background(state->time, state->lamp_on); for(uint8_t i = 0; i < NUM_CHICKS; i++) { draw_chick(&state->chicks[i]); } draw_overlay(state->time, state->num_days, are_chicks_hot(state->time, state->lamp_on), are_chicks_cold(state->time, state->lamp_on)); gfx_SwapDraw(); }