diff --git a/Readme.md b/Readme.md index ae2f73b..17075c5 100644 --- a/Readme.md +++ b/Readme.md @@ -20,7 +20,7 @@ Speeds are in px/s (play area is 270×224). | 1 | Marisa Kirisame | 208 | 130 | Attract bonus when on top of the screen | | 2 | Sariel | 241 | | Do not attract bullets when not focused | | 3 | Koakuma | | | +15% chance of getting a powerup | -| 4 | Iku Nagae | | | Start with 4 bombs instead of 3 | +| 4 | Iku Nagae | | | Start with 4 spells instead of 3 | | 5 | Sumireko Usami | | | Wider fire angle when not focused | | 6 | Hina Kagiyama | | | +10% power when not focused | | 7 | Kurumi | | | | diff --git a/Touhou.g3a b/Touhou.g3a index ef5e64a..34558a7 100644 Binary files a/Touhou.g3a and b/Touhou.g3a differ diff --git a/assets-cg/limg/big_witches/witch7.png b/assets-cg/limg/witches/hina.png similarity index 100% rename from assets-cg/limg/big_witches/witch7.png rename to assets-cg/limg/witches/hina.png diff --git a/assets-cg/limg/big_witches/witch5.png b/assets-cg/limg/witches/iku.png similarity index 100% rename from assets-cg/limg/big_witches/witch5.png rename to assets-cg/limg/witches/iku.png diff --git a/assets-cg/limg/big_witches/witch4.png b/assets-cg/limg/witches/koakuma.png similarity index 100% rename from assets-cg/limg/big_witches/witch4.png rename to assets-cg/limg/witches/koakuma.png diff --git a/assets-cg/limg/big_witches/witch8.png b/assets-cg/limg/witches/kurumi.png similarity index 100% rename from assets-cg/limg/big_witches/witch8.png rename to assets-cg/limg/witches/kurumi.png diff --git a/assets-cg/limg/big_witches/witch2.png b/assets-cg/limg/witches/marisa.png similarity index 100% rename from assets-cg/limg/big_witches/witch2.png rename to assets-cg/limg/witches/marisa.png diff --git a/assets-cg/limg/big_witches/witch1.png b/assets-cg/limg/witches/reimu.png similarity index 100% rename from assets-cg/limg/big_witches/witch1.png rename to assets-cg/limg/witches/reimu.png diff --git a/assets-cg/limg/big_witches/witch3.png b/assets-cg/limg/witches/sariel.png similarity index 100% rename from assets-cg/limg/big_witches/witch3.png rename to assets-cg/limg/witches/sariel.png diff --git a/assets-cg/limg/big_witches/witch6.png b/assets-cg/limg/witches/sumikero.png similarity index 100% rename from assets-cg/limg/big_witches/witch6.png rename to assets-cg/limg/witches/sumikero.png diff --git a/contents/dialogs/dialog1.txt b/contents/dialogs/dialog1.txt new file mode 100644 index 0000000..90ec0fb --- /dev/null +++ b/contents/dialogs/dialog1.txt @@ -0,0 +1 @@ +hina diff --git a/include/animation.h b/include/animation.h new file mode 100644 index 0000000..e8e16b6 --- /dev/null +++ b/include/animation.h @@ -0,0 +1,32 @@ +#ifndef _ANIMATION_H +#define _ANIMATION_H + +// Objects +typedef struct { + uint16_t x, y, r; // Position and radius + struct { + uint8_t enabled :1; // Object enabled (visible, updated) + uint8_t col_nor :1; // Collisions in normal mode + uint8_t col_foc :1; // Collisions in focused mode + uint8_t color :4; // Color. 3 bits used, maybe 4 in the future + uint8_t type :8; // Type of object. Linked to image_t + } meta; +} object_t; + +// Animations +typedef struct animation_s animation_t; +typedef struct { + uint32_t timestamp; // Timestamp of the animation + uint32_t n_objects; // Number of objects + object_t *objects; // Table of object_t + void (*updater)(animation_t*, uint32_t); // Updater function +} animation_s; + +// Utils +animation_t *new_animation(uint32_t objects, void (*updater)(animation_t*)); +void del_animation(animation_t *animation); + +// List of animation functions +void dummy_updater(animation_t *animation, uint32_t us_elapsed); + +#endif // _ANIMATION_H diff --git a/include/config.h b/include/config.h index a69cc32..b46792e 100644 --- a/include/config.h +++ b/include/config.h @@ -1,6 +1,11 @@ #ifndef _CONFIG_H #define _CONFIG_H +#define SCREEN_X 270 +#define SCREEN_Y 224 + +#define NULL (void*)(0) + enum { WITCH_1 = 0, WITCH_2, @@ -13,4 +18,12 @@ enum { N_WITCHES }; +// Profiling +enum { + PROFCTX_FPS = 0, + PROFCTX_ENGINE, + PROFCTX_DISPLAY, + PROFCTX_COUNT +}; + #endif diff --git a/include/dialog.h b/include/dialog.h new file mode 100644 index 0000000..1eba2e2 --- /dev/null +++ b/include/dialog.h @@ -0,0 +1,16 @@ +#ifndef _DIALOG_H +#define _DIALOG_H + +/* Some requirements for dialogs */ + +#include +#include +#include +#include + +/* Define some structures used for dialogs */ +typedef struct { + img_t *character; +} dialog_t; + +#endif // _DIALOG_H diff --git a/include/engine.h b/include/engine.h index 73e5ca0..9e95c9d 100644 --- a/include/engine.h +++ b/include/engine.h @@ -1,9 +1,10 @@ #ifndef _ENGINE_H #define _ENGINE_H -struct player_s { - char witch_id; +#include -}; +void engine(void); +void physics(void); +void graphics(void); #endif diff --git a/include/player.h b/include/player.h new file mode 100644 index 0000000..e0269de --- /dev/null +++ b/include/player.h @@ -0,0 +1,13 @@ +#ifndef _PLAYER_H +#define _PLAYER_H + +#include "utils/vector.h" + +typedef struct { + float x, y; + char power; + char lives; + char bombs; +} player_t; + +#endif diff --git a/src/dialog.c b/src/dialog.c new file mode 100644 index 0000000..f0c5b98 --- /dev/null +++ b/src/dialog.c @@ -0,0 +1,23 @@ +#include "dialog.h" + +void dialog(dialog_t *dialog) +{ + img_t chars_img[1][2] = { + { img_copy(*(dialog->character)), img_darken_create(*(dialog->character))} + }; + + dclear(C_BLACK); + + img_render_vram(chars_img[0][0], 15, 20); + + dupdate(); + getkey(); + + /* Destroy temporary images */ + for(int i = 0; i < 1; i++) + { + for(int j = 0; j < 2; j++) { + img_destroy(chars_img[i][j]); + } + } +} diff --git a/src/engine.c b/src/engine.c index 4d28e17..60ab8e7 100644 --- a/src/engine.c +++ b/src/engine.c @@ -1,3 +1,113 @@ #include #include #include +#include + +#include "config.h" +#include "engine.h" + +// Speed in px/us +#define SPEED_FAST 0.000208 +#define SPEED_SLOW 0.000104 + + +extern image_t *img_witches[8]; +extern image_t *img_battlefields[3]; + + +float speeds[2] = {SPEED_FAST, SPEED_SLOW}; + +void engine(void) +{ + uint32_t frame = 0; + uint32_t us_elapsed = 1; + + // Profiling + prof_t prof_fps = prof_make(); + prof_t prof_engine = prof_make(); + prof_t prof_display = prof_make(); + + char witch = 0; + char mode = 0; // 0 = normal, 1 = focused + float px = SCREEN_X / 2; + float py = SCREEN_Y / 2; + + char battlefield = 0; + + while(!keydown(KEY_EXIT)) + { + // Profiling + prof_enter(prof_fps); + + // Get keyboard events + clearevents(); + + + //*** Some debug inputs *********************************************** + if(keydown(KEY_F1)) battlefield = 0; + if(keydown(KEY_F2)) battlefield = 1; + if(keydown(KEY_F3)) battlefield = 2; + if(keydown(KEY_1)) witch = 0; + if(keydown(KEY_2)) witch = 1; + if(keydown(KEY_3)) witch = 2; + if(keydown(KEY_4)) witch = 3; + //*** End debug ******************************************************* + + prof_enter(prof_engine); + // Fast or slow witch + mode = keydown(KEY_OPTN); + float base_speed = us_elapsed * speeds[mode] * ( + keydown_any(KEY_LEFT, KEY_RIGHT, 0) && + keydown_any(KEY_UP, KEY_DOWN, 0) ? 0.707 : 1.0); + + // Move witch + if(keydown(KEY_UP)) + py -= base_speed; + if(keydown(KEY_DOWN)) + py += base_speed; + if(keydown(KEY_LEFT)) + px -= base_speed; + if(keydown(KEY_RIGHT)) + px += base_speed; + + prof_leave(prof_engine); + + + prof_enter(prof_display); + // Clear VRAM + dclear(C_BLACK); + + // Draw battlefield + dimage(0, 0, img_battlefields[battlefield]); + + // Draw our cute witch + image_t *w = img_witches[witch * 2 + mode]; + dimage(px - w->width / 2, py - w->height / 2, w); + + prof_leave(prof_display); + + // Print FPS + dprint(273, 184, C_WHITE, "%i FPS", 1000000 / us_elapsed); + dprint(273, 194, C_WHITE, "Tot: %i us", us_elapsed); + dprint(273, 204, C_WHITE, "Eng: %i us", prof_time(prof_engine)); + dprint(273, 214, C_WHITE, "Dsp: %i us", prof_time(prof_display)); + + // Update VRAM + dupdate(); + + // Update FPS & frame + prof_leave(prof_fps); + us_elapsed = prof_time(prof_fps); + frame++; + } +} + +void physics(void) +{ + +} + +void graphics(void) +{ + +} diff --git a/src/images.c b/src/images.c new file mode 100644 index 0000000..a693243 --- /dev/null +++ b/src/images.c @@ -0,0 +1,40 @@ +#include + +// TODO: generate those tables in `fxconv` instead of this dirty file + +extern image_t img_witch1_back; +extern image_t img_witch2_back; +extern image_t img_witch3_back; +extern image_t img_witch4_back; +extern image_t img_witch5_back; +extern image_t img_witch6_back; +extern image_t img_witch7_back; +extern image_t img_witch8_back; +image_t *img_witches[8] = { + &img_witch1_back, &img_witch2_back, &img_witch3_back, &img_witch4_back, + &img_witch5_back, &img_witch6_back, &img_witch7_back, &img_witch8_back +}; + + +extern image_t img_battlefield1; +extern image_t img_battlefield2; +extern image_t img_battlefield3; +image_t *img_battlefields[3] = { + &img_battlefield1, &img_battlefield2, &img_battlefield3 +}; + + +extern image_t img_bullet1_1; +extern image_t img_bullet1_2; +extern image_t img_bullet1_3; +extern image_t img_bullet2_1; +extern image_t img_bullet2_2; +extern image_t img_bullet2_3; +extern image_t img_bullet3_1; +extern image_t img_bullet3_2; +extern image_t img_bullet3_3; +image_t *img_bullets[3][3] = { + {&img_bullet1_1, &img_bullet1_2, &img_bullet1_3}, + {&img_bullet2_1, &img_bullet2_2, &img_bullet2_3}, + {&img_bullet3_1, &img_bullet3_2, &img_bullet3_3}, +}; diff --git a/src/main.c b/src/main.c index 8d84c02..6986469 100644 --- a/src/main.c +++ b/src/main.c @@ -2,41 +2,23 @@ #include #include -void draw() { - extern image_t img_battlefield1; - extern image_t img_battlefield2; - extern image_t img_battlefield3; - extern image_t img_bullet3_2; +#include "config.h" +#include "engine.h" - prof_clear(0); - prof_enter(0); +#include "dialog.h" - dclear(C_BLACK); - // dimage(0, 0, &img_battlefield1); - // dimage(0, 0, &img_battlefield2); - dimage(0, 0, &img_battlefield3); - - for(int i = 0; i < 2000; i++) { - dimage((i*79) % 216, (i*41) % 216, &img_bullet3_2); - } - - prof_leave(0); - - dprint(300, 10, C_NONE, C_NONE, "%i us", prof_time(0)); - dprint(300, 40, C_WHITE, C_NONE, "%i us", prof_time(0)); - dprint(300, 70, C_BLACK, C_NONE, "%i us", prof_time(0)); - dupdate(); -} +// Dev +void dialog(dialog_t*); int main(void) -{ - prof_init(1, 0); +{ + extern img_t limg_hina; - for(int i = 0; i < 100; i++) { - draw(); - } + prof_init(); - getkey(); + dialog_t d = {&limg_hina}; + + dialog(&d); prof_quit();