summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c180
1 files changed, 180 insertions, 0 deletions
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..417ba5f
--- /dev/null
+++ b/main.c
@@ -0,0 +1,180 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+#include <time.h>
+
+#include <raylib.h>
+#include "game-state.h"
+#include "textures.h"
+
+/* Texture2D sheet = LoadTexture("asset/8-dir.png"); */
+/* Texture2D tile_texture = LoadTexture("asset/grass_tiles.png"); */
+/* Texture2D dirt_texture = LoadTexture("asset/dirt-path.png"); */
+/* Texture2D tower_texture = LoadTexture("asset/tower.png"); */
+/* Image dust_gif = LoadImageAnim("asset/dust.gif"); */
+
+
+
+char _frame_info_buf[128];
+void _draw_info(gs_t *gs);
+
+int main(){
+ srand(time(NULL));
+ InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "oyun");
+ InitAudioDevice();
+ HideCursor();
+ SetTargetFPS(FPS);
+
+ load_textures();
+ BEAM_SOUND = LoadSound("asset/laser.wav");
+
+ gs_t gs = {
+ .tower_count = 0,
+ .enemy_count = 0,
+ .textures = &textures[0],
+ .spawner = DEFAULT_ENEMY_SPAWNER
+ };
+ add_tower(&gs, make_tower(1, 100, WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2, 20, 30, &textures[T_TOWER]));
+ /* add_enemy(&gs, make_enemy(&sheet, 3, WINDOW_WIDTH / 2 + 80, WINDOW_HEIGHT / 2 - 80, 30)); */
+ /* add_enemy(&gs, make_enemy(&sheet, 3, WINDOW_WIDTH / 2 - 80, WINDOW_HEIGHT / 2 - 80, 30)); */
+ gs.player = make_player(&textures[T_PLAYER]);
+
+ Rectangle grass_tile1_rect = (Rectangle){ 0, 0, 16, 16 };
+ RenderTexture2D bg_tiles = LoadRenderTexture(WINDOW_WIDTH, WINDOW_HEIGHT);
+ gs.bg_tiles = bg_tiles;
+ // https://stackoverflow.com/questions/78609155/what-is-the-difference-between-begintexturemode-and-drawtexture-in-raylib
+ BeginTextureMode(bg_tiles);
+ int edge_len = 16;
+ for (int i = 0; i < WINDOW_WIDTH; i += edge_len)
+ for (int j = 0; j < WINDOW_HEIGHT; j += edge_len){
+ DrawTextureRec(textures[T_GRASS], grass_tile1_rect, (Vector2){i, j}, WHITE);
+ /* char buf[32]; */
+ /* snprintf(buf, 32, "%d", (i + j) % 10); */
+ /* DrawText(buf, i, j + 2, 4, BLACK); */
+ }
+ EndTextureMode();
+
+ /* int yy = 0; */
+ int paused = 0;
+ while (!WindowShouldClose()){
+
+ if (IsKeyPressed(KEY_P)){
+ paused = !paused;
+ } /* else if (IsKeyReleased(KEY_P)){ */
+ /* paused = 0; */
+ /* } */
+
+ if (!paused){
+ update_game(&gs, GetFrameTime());
+ }
+ /* update_frame(&anim); */
+
+ BeginDrawing();
+
+ ClearBackground(WHITE);
+
+ /* draw_frame(&anim); */
+ BeginMode2D(gs.player.camera);
+
+ /* for (int i = 0; i < WINDOW_WIDTH; i += edge_len) */
+ /* DrawLine(i, 0, i, WINDOW_HEIGHT, LIGHTGRAY); */
+ /* for (int i = 0; i < WINDOW_HEIGHT; i += edge_len) */
+ /* DrawLine(0, i, WINDOW_WIDTH, i, LIGHTGRAY); */
+ /* for (int i = 0; i < WINDOW_WIDTH; i += edge_len) */
+ /* for (int j = 0; j < WINDOW_HEIGHT; j += edge_len) */
+ /* DrawTextureRec(tile_texture, grass_tile1_rect, (Vector2){i, j}, WHITE); */
+ DrawTexture(bg_tiles.texture, 0, 0, WHITE);
+ /* DrawTextureRec(bg_tiles.texture, (Rectangle){ 0, 0, bg_tiles.texture.width, -bg_tiles.texture.height }, (Vector2){0, 0}, WHITE); */
+ draw_game(&gs);
+
+ EndMode2D();
+
+ _draw_info(&gs);
+ if (paused){
+ DrawText("PAUSED", WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2, 10, BLACK);
+ }
+
+ EndDrawing();
+ }
+
+ unload_textures();
+ /* UnloadTexture(sheet); */
+ /* UnloadTexture(tile_texture); */
+ /* UnloadTexture(tower_texture); */
+ /* UnloadTexture(dirt_texture); */
+ UnloadSound(BEAM_SOUND);
+ UnloadRenderTexture(bg_tiles);
+
+ CloseAudioDevice();
+ CloseWindow();
+ return EXIT_SUCCESS;
+}
+
+
+void _draw_info(gs_t *gs){
+ player_t *p = &gs->player;
+ sprintf(_frame_info_buf, "player (%.2f, %.2f)", p->position.x, p->position.y);
+ DrawText(_frame_info_buf, 20, 20, 20, BLACK);
+
+ sprintf(_frame_info_buf, "mouse (%d, %d)", GetMouseX(), GetMouseY());
+ DrawText(_frame_info_buf, 20, 50, 20, BLACK);
+
+ sprintf(_frame_info_buf, "camera target (%.2f, %.2f)", p->camera.target.x, p->camera.target.y);
+ DrawText(_frame_info_buf, 20, 80, 20, BLACK);
+
+ sprintf(_frame_info_buf, "camera offset (%.2f, %.2f)", p->camera.offset.x, p->camera.offset.y);
+ DrawText(_frame_info_buf, 20, 110, 20, BLACK);
+
+ sprintf(_frame_info_buf, "enemy count %d / %d", gs->enemy_count, ENEMY_COUNT_MAX);
+ DrawText(_frame_info_buf, 20, 140, 20, BLACK);
+
+ sprintf(_frame_info_buf, "tower count %d / %d", gs->tower_count, TOWER_COUNT_MAX);
+ DrawText(_frame_info_buf, 20, 170, 20, BLACK);
+
+
+ /* animation_player_t *anim = p->animation; */
+ /* sprintf(_frame_info_buf, "counter %d", anim->frame_counter); */
+ /* DrawText(_frame_info_buf, 20, 20, 20, BLACK); */
+
+ /* sprintf(_frame_info_buf, "current %d", anim->frame_current); */
+ /* DrawText(_frame_info_buf, 20, 50, 20, BLACK); */
+
+ /* sprintf(_frame_info_buf, "frec.x %f", anim->frame_rec.x); */
+ /* DrawText(_frame_info_buf, 20, 80, 20, BLACK); */
+
+ /* sprintf(_frame_info_buf, "frec.y %f", anim->frame_rec.y); */
+ /* DrawText(_frame_info_buf, 20, 110, 20, BLACK); */
+
+ /* sprintf(_frame_info_buf, "pos.x %f", p->position.x); */
+ /* DrawText(_frame_info_buf, 20, 140, 20, BLACK); */
+
+ /* sprintf(_frame_info_buf, "pos.y %f", p->position.y); */
+ /* DrawText(_frame_info_buf, 20, 170, 20, BLACK); */
+
+ /* if (gs->enemy_count > 0){ */
+ /* sprintf(_frame_info_buf, "(%f, %f)", */
+ /* gs->enemies[0].direction.x, */
+ /* gs->enemies[0].direction.y); */
+ /* DrawText(_frame_info_buf, 20, 200, 20, BLACK); */
+
+ /* sprintf(_frame_info_buf, "hp %d", gs->enemies[0].health); */
+ /* DrawText(_frame_info_buf, 20, 230, 20, BLACK); */
+
+ /* sprintf(_frame_info_buf, "dist %f", distance(gs->towers[0].center, gs->enemies[0].center)); */
+ /* DrawText(_frame_info_buf, 20, 260, 20, BLACK); */
+
+ /* animation_player_t *anim = &gs->enemies[0].animation; */
+ /* sprintf(_frame_info_buf, "counter %d", anim->frame_counter); */
+ /* DrawText(_frame_info_buf, 20, 20, 20, BLACK); */
+
+ /* sprintf(_frame_info_buf, "current %d", anim->frame_current); */
+ /* DrawText(_frame_info_buf, 20, 50, 20, BLACK); */
+
+ /* sprintf(_frame_info_buf, "frec.x %f", anim->frame_rec.x); */
+ /* DrawText(_frame_info_buf, 20, 80, 20, BLACK); */
+
+ /* sprintf(_frame_info_buf, "frec.y %f", anim->frame_rec.y); */
+ /* DrawText(_frame_info_buf, 20, 110, 20, BLACK); */
+
+ /* } */
+}