1 #include "libs/savepng/savepng.h"
2 #include "libs/lazyass/lazyass.h"
3 #include "libs/binaryheap/binhl.h"
4 #include "libs/SDL_inprint/SDL2_inprint.h"
20 void init_factions() {
22 memset(factions
, 0, sizeof(faction_t
) * 8);
24 strcpy(factions
[0].title
, "Your Kingdom");
25 factions
[0].color
.r
= 0;
26 factions
[0].color
.g
= 0;
27 factions
[0].color
.b
= 0xff;
28 factions
[0].gold
= 10000;
30 strcpy(factions
[1].title
, "Reavers");
31 factions
[1].color
.r
= 0xff;
32 factions
[1].color
.g
= 0;
33 factions
[1].color
.b
= 0;
34 factions
[1].gold
= 10000;
40 void clear_house(int id
) {
41 house_t
*h
= &houses
[id
];
47 void clear_unit(int id
) {
48 unit_t
*u
= &units
[id
];
58 for (i
= 0; i
< MAX_STAT
; i
++) {
67 u
->axis_refs
[UAXIS_TYPE
] = &u
->tile
;
68 u
->axis_refs
[UAXIS_MODE
] = &u
->mode
;
69 u
->axis_refs
[UAXIS_FRAME
] = &u
->frame
;
75 for (i
= 0; i
< MAX_HOUSES
; i
++) {
87 for (i
= 0; i
< MAX_UNITS
; i
++) {
92 int add_house(Uint32 tx
, Uint32 ty
) {
95 house_p
*m
= &bhouses
[ui
.builder
];
97 house_t
*h
= &houses
[id
];
100 h
->tile
= ui
.builder
;//m->tile;
110 h
->faction
= 0;/* :( */
112 h
->capacity
= h
->w
* h
->h
;
114 your
->gold
-= m
->gold_cost
;
121 void stress_unit(int id
, int dmg
) {
122 unit_t
*u
= &units
[id
];
126 void kill_unit(int id
) {
127 unit_t
*u
= &units
[id
];
131 /* When devotee dies, his link to lord is removed */
133 ///* Lord is alarmed */
134 //unit_t *l = u->link;
135 //while (l->link) l = l->link;
138 u
->link
->ref_count
[u
->link_stat
]--;
139 u
->link
->ref_counts
--;
142 /* When lord dies, his devotees are freed! */
143 if (u
->ref_count
[u
->link_stat
]) {
145 for (i
= 0; i
< num_units
; i
++) {
146 if (units
[i
].link
== u
) {
148 units
[i
].link
= NULL
;
149 u
->ref_count
[u
->link_stat
]--;
160 unit_t
*u
= &units
[id
];
163 strcpy(u
->name
, "Path Finder");
165 u
->base_stat
[S_STR
] = 5;
166 u
->base_stat
[S_DEX
] = 0;
167 u
->base_stat
[S_CON
] = 5;
168 u
->base_stat
[S_INT
] = 0;
178 u
->x
= rand() % LEVEL_W
;
179 u
->y
= rand() % LEVEL_H
;
189 unit_t
*u
= &units
[id
];
194 u
->base_stat
[S_STR
] = 5;
195 u
->base_stat
[S_DEX
] = 0;
196 u
->base_stat
[S_CON
] = 5;
197 u
->base_stat
[S_INT
] = 0;
207 u
->x
= rand() % LEVEL_W
;
208 u
->y
= rand() % LEVEL_H
;
212 u
->axis_refs
[UAXIS_TYPE
] = &u
->tile
;
213 u
->axis_refs
[UAXIS_MODE
] = &u
->mode
;
214 u
->axis_refs
[UAXIS_FRAME
] = &u
->frame
;
220 int find_houseT(Uint32 tx
, Uint32 ty
) {
222 for (i
= 0; i
< num_houses
; i
++) {
223 house_t
*h
= &houses
[i
];
224 if (tx
>= h
->x
&& tx
<= h
->x
+(h
->w
-1) &&
225 ty
>= h
->y
&& ty
<= h
->y
+(h
->h
-1))
233 int find_house(Uint32 x
, Uint32 y
) {
235 (ui
.x
+ ui
.vx
) / TILE_W
,
236 (ui
.y
+ ui
.vy
) / TILE_H
240 int find_unitT(Uint32 tx
, Uint32 ty
) {
242 for (i
= 0; i
< num_units
; i
++) {
243 unit_t
*u
= &units
[i
];
244 unit_p
*p
= &bunits
[u
->tile
];
245 if (u
->visiting
) continue;
246 if (tx
>= u
->x
&& tx
<= u
->x
+(p
->w
-1) &&
247 ty
>= u
->y
&& ty
<= u
->y
+(p
->h
-1))
255 int find_unit(Uint32 x
, Uint32 y
) {
259 for (i
= 0; i
< num_units
; i
++) {
260 unit_t
*u
= &units
[i
];
261 unit_p
*p
= &bunits
[u
->tile
];
262 if (u
->visiting
) continue;
263 if (x
>= u
->x
* TILE_W
+ u
->ox
264 && x
<= u
->x
* TILE_W
+ u
->ox
+ (TILE_W
* p
->w
)
265 && y
>= (u
->y
-(p
->h
-1)) * TILE_H
+ u
->oy
266 && y
<= (u
->y
-(p
->h
-1)) * TILE_H
+ u
->oy
+ (TILE_H
* p
->h
))
274 int xcollide(Uint32 tx
, Uint32 ty
, Uint8 w
, Uint8 h
) {
276 for (j
= 0; j
< h
; j
++) {
277 for (i
= 0; i
< w
; i
++) {
278 if (find_houseT(tx
+ i
, ty
+ j
) != -1) return 1;
279 if (find_unitT (tx
+ i
, ty
+ j
) != -1) return 1;
285 #include "SDL2_particles.h"
287 particle_system psystems
[128];
288 int num_psystems
= 0;
290 void add_fire(Sint16 x
, Sint16 y
, Uint16 limit
) {
291 int id
= num_psystems
++;
292 particle_system
*ps
= &psystems
[id
];
297 ps
->init
= &basic_particle_init
;
298 ps
->move
= &basic_particle_move
;
299 ps
->reset
= &basic_particle_reset
;
303 void update_particles() {
305 for (i
= 0; i
< num_psystems
; i
++) {
306 particle_system
*ps
= &psystems
[i
];
311 void draw_particles(SDL_Renderer
*target
, Uint32 bx
, Uint32 by
) {
313 SDL_Color reds
[16] = { { 0xff } };
316 for (i
= 0; i
< num_psystems
; i
++) {
317 particle_system
*ps
= &psystems
[i
];
318 if (!ps
->limit
) continue;
319 PS_Render(target
, ps
, reds
, 1, bx
, by
);
327 for (ty
= 0; ty
< LEVEL_H
; ty
++) {
328 for (tx
= 0; tx
< LEVEL_W
; tx
++) {
330 scent_human
[ty
][tx
] = 0;
339 for (ty
= 0; ty
< LEVEL_H
; ty
++) {
340 for (tx
= 0; tx
< LEVEL_W
; tx
++) {
342 if (scent_human
[ty
][tx
] > 0) scent_human
[ty
][tx
]--;
343 if (scent_human
[ty
][tx
] > 255) scent_human
[ty
][tx
] = 255;
348 for (i
= 0; i
< num_houses
; i
++) {
349 house_t
*h
= &houses
[i
];
350 int j
, k
, bl
= h
->h
/2;
351 for (j
= -h
->h
+bl
; j
< h
->h
+bl
+1; j
++) {
352 if (h
->y
+ j
< 0) continue;
353 if (h
->y
+ j
>= LEVEL_H
) break;
354 for (k
= -h
->w
; k
< h
->w
+1; k
++) {
355 if (h
->x
+ k
< 0) continue;
356 if (h
->x
+ k
>= LEVEL_W
) break;
357 fog
[h
->y
+ j
][h
->x
+ k
] = 0;
362 for (i
= 0; i
< num_units
; i
++) {
363 unit_t
*u
= &units
[i
];
364 unit_p
*p
= &bunits
[u
->tile
];
366 for (j
= -1; j
< 2; j
++) {
367 if (u
->y
+ j
< 0) continue;
368 if (u
->y
+ j
>= LEVEL_H
) break;
369 for (k
= -1; k
< 2; k
++) {
370 if (u
->x
+ k
< 0) continue;
371 if (u
->x
+ k
>= LEVEL_W
) break;
372 fog
[u
->y
+ j
][u
->x
+ k
] = 0;
373 scent_human
[u
->y
+ j
][u
->x
+ k
] += p
->base_scent
[SCENT_HUMAN
];
380 void draw_ui(SDL_Renderer
*screen
) {
381 SDL_Rect src
= { 0, 0, 640, 480 };
382 SDL_Rect dst
= { 0, 0, LOG_WIDTH
, LOG_HEIGHT
};
383 SDL_RenderCopy(screen
, uibg
, &src
, &dst
);
385 draw_goldbox(screen
, 2, 3, 0, your
->ore
);
386 draw_goldbox(screen
, 80, 3, 1, your
->gold
);
388 draw_minimap(screen
);
390 if (ui
.unit
!= -1) draw_unitbox(screen
);
391 else if (ui
.house
!= -1) draw_housebox(screen
);
393 draw_buildset(screen
);
397 if (ui
.hint
!= -1) draw_hintbox(screen
);
399 incolor(0xffffff, 0);
400 rprintf(screen
, LOG_WIDTH
- 128, 0, "FPS: %d", ui
.fps
);
403 void draw_screen(SDL_Renderer
*screen
) {
405 SDL_SetRenderDrawColor(screen
, 0x11, 0x33, 0x11, 255);
406 SDL_RenderClear(screen
);
412 if (ui
.draw_fog
) draw_fog(screen
);
413 if (ui
.draw_scent
) draw_scent(screen
);
415 draw_particles(screen
, 100,100);
417 if (ui
.draw_overlays
) draw_overlays(screen
, ui
.unit
, 0, 0, NULL
);
419 if (ui
.draw_path
) draw_paths(screen
, ui
.unit
, 0, 0);
421 if (ui
.draw_pools
) draw_pools(screen
);
423 if (ui
.builder
> -1) draw_builder(screen
);
424 if (ui
.stat
> -1) draw_forcible(screen
);
430 void prepare_units() {
434 for (i
= 0; i
< num_bunits
; i
++) {
435 unit_p
*u
= &bunits
[i
];
439 printf("unit %s stands on %d, %d, occupies %d, %d\n", u
->title
, lx
, ly
, u
->w
, u
->h
);
455 add_fire(100,100,25000);
464 SDL_Color tcol
= { 0xff, 0xff, 0xff };
466 tiles
= ASS_LoadTexture("data/gfx/runelord.bmp", &tcol
);
468 printf("Tiles: %p, %s\n", tiles
, SDL_GetError());
471 cfg_load("data/rune.cfg");
473 uibg
= ASS_LoadTexture("data/gfx/woodui.bmp", &tcol
);
475 SDL_Color magenta
= { 0xff, 0, 0xff };
477 small_font
= ASS_LoadTexture("data/fonts/oddball6x8.bmp", &magenta
);
479 mid_font
= ASS_LoadTexture("data/fonts/webby8.bmp", &magenta
);
481 large_font
= NULL
; /* aka inline */
492 for (i
= 0; i
< 50; i
++) {
498 units
[0].x
= units
[0].y
= units
[0].tx
= units
[0].ty
= 5;
500 units
[1].tx
= units
[1].x
= (units
[1].x
- 3);
501 units
[1].ty
= units
[1].y
= (units
[1].y
+ 2);
502 units
[2].tx
= units
[2].x
= (units
[2].x
- 2);
503 units
[2].ty
= units
[2].y
= (units
[2].y
+ 4);
507 void focus_on_unit() {
508 unit_t
*u
= &units
[ui
.unit
];
509 ui
.vx
= u
->tx
* TILE_W
- LOG_WIDTH
/ 2;
510 ui
.vy
= u
->ty
* TILE_H
- LOG_HEIGHT
/ 2;
512 if (ui
.vx
< 0) ui
.vx
= 0;
513 if (ui
.vy
< 0) ui
.vy
= 0;
516 void do_update_grids(void) {
519 for (j
= 0; j
< LEVEL_H
; j
++)
520 for (i
= 0; i
< LEVEL_W
; i
++) {
522 unit_grid
[j
][i
] = NULL
;
523 house_grid
[j
][i
] = NULL
;
527 for (i
= 0; i
< num_units
; i
++) {
529 unit_t
*unit
= &units
[i
];
530 unit_grid
[unit
->ty
][unit
->tx
] = unit
;
535 void do_update_links(void) {
543 void do_scroll_out() {
544 if (ui
.unit
== -1) return;
545 unit_t
*su
= &units
[ui
.unit
];
551 for (i
= 0; i
< num_units
; i
++) if (units
[i
].link
== su
) fs
[f
++] = i
;
554 printf("Rand is: %d\n", i
);
560 void do_scroll_in() {
561 if (ui
.unit
== -1) return;
562 unit_t
*u
= &units
[ui
.unit
];
565 ui
.unit
= u
->link_id
;
566 unit_t
*u2
= &units
[ui
.unit
];
571 void do_pin_click() {
576 Uint32 w
= PANE_WIDTH
;
580 for (i
= 0; i
< num_units
; i
++) {
581 unit_t
*u
= &units
[i
];
582 if (u
->tile
&& u
->pin
) {
583 if (ui
.x
>= x
+ 8 && ui
.y
>= y
+ 4 && ui
.x
<= x
+ 120 && ui
.y
<= y
+ 4 + 16) {
587 if (ui
.x
>= x
+ 120 + 8 && ui
.y
>= y
+ 4 && ui
.x
<= x
+ 120 + 16 && ui
.y
<= y
+ 4 + 6) {
597 void do_minimap_click() {
599 int x
= ui
.x
- minimap
.x
;
600 int y
= ui
.y
- minimap
.y
;
613 unit_t
*u
= &units
[ui
.unit
];
616 if (u
->tile
== U_PEASANT
) {
618 int next
= U_PEASANT
;
620 case 0: next
= U_MILITIA
; cost
= 250; break;
621 case 1: next
= U_ARCHER
; u
->base_stat
[S_DEX
]+=5; cost
= 200; break;
622 case 2: next
= U_KNIGHT
; cost
= 350; break;
623 case 3: next
= U_FLAMER
+rand()%4; cost
= 500; break;
633 void do_event_click(Uint32 x
, Uint32 y
) {
635 //printf("Clicked on %d, %d\n", x, y);
637 /* Building houses? */
638 if (ui
.builder
!= -1) {
640 if (ui
.hover_top
== overMap
) {
642 if (ui
.hover_xcollide
) {
643 //game.log("Can't place here");
648 ui
.house
= add_house(ui
.hover_tx
, ui
.hover_ty
);
665 case overBuildButton
:
667 ui
.builder
= ui
.hover_id
;
677 units
[ui
.unit
].pin
= 1 - units
[ui
.unit
].pin
;
682 /* Start rune linking */
683 if (units
[ui
.unit
].link
== NULL
) ui
.stat
= ui
.hover_id
;
689 if (units
[ui
.unit
].link
== NULL
) ui
.btn
= ui
.hover_id
;
702 if (ui
.hover_id
!= ui
.unit
) { // add other verefications, like factions, costs, etc
704 add_link(ui
.unit
, ui
.hover_id
, ui
.stat
);
706 ui
.unit
= ui
.hover_id
; /* Also select */
708 /* Stop rune-linking, if it's not possible */
709 if (units
[ui
.unit
].link
!= NULL
|| units
[ui
.unit
].ref_count
[ui
.stat
] > 1) ui
.stat
= -1;
715 ui
.unit
= ui
.hover_id
;
722 ui
.house
= ui
.hover_id
;
730 void do_event_key(int sym
) {
731 if (sym
== SDLK_1
) ui
.game_speed
= 25;
732 if (sym
== SDLK_5
) ui
.game_speed
= 1;
734 if (sym
== SDLK_s
) ui
.draw_scent
= 1 - ui
.draw_scent
;
735 if (sym
== SDLK_t
) ui
.draw_path
= 1 - ui
.draw_path
;
736 if (sym
== SDLK_f
) ui
.draw_fog
= 1 - ui
.draw_fog
;
737 if (sym
== SDLK_l
) ui
.draw_overlays
= 1 - ui
.draw_overlays
;
738 if (sym
== SDLK_p
) ui
.draw_pools
= 1 - ui
.draw_pools
;
740 if (sym
== SDLK_z
) add_reaver();
741 if (sym
== SDLK_a
) add_peasant();
742 if (sym
== SDLK_n
) units
[ui
.unit
].tile
++;
743 if (sym
== SDLK_k
) stress_unit(ui
.unit
,1000);
744 if (sym
== SDLK_r
) rebuild_pools();
745 if (sym
== SDLK_c
) collect_pools();
746 //if (sym == SDLK_x) prop_pools();
747 if (sym
== SDLK_d
) distrib_pools();
748 if (sym
== SDLK_e
&& ui
.unit
) units
[ui
.unit
].gold
+= 100;
751 units
[ui
.unit
].tx
= ui
.x
/ 16;
752 units
[ui
.unit
].ty
= ui
.y
/ 16;
754 if (ui
.house
!= -1) {
755 houses
[ui
.house
].hp
+= 20;
761 void do_event_cancel() {
774 void do_event(SDL_Event
*e
) {
776 int tracking_mouse
= 0;
778 if (e
->type
== SDL_FINGERDOWN
) {
780 ui
.x
= (int) (e
->tfinger
.x
* LOG_WIDTH
);
781 ui
.y
= (int) (e
->tfinger
.x
* LOG_HEIGHT
);
783 do_event_click(ui
.x
, ui
.y
);
785 if (e
->type
== SDL_MOUSEMOTION
&& e
->motion
.which
!= SDL_TOUCH_MOUSEID
) {
790 ui
.vx
-= e
->motion
.xrel
;
791 ui
.vy
-= e
->motion
.yrel
;
793 if (ui
.vx
< 0) ui
.vx
= 0;
794 if (ui
.vy
< 0) ui
.vy
= 0;
800 if ((e
->type
== SDL_MOUSEBUTTONDOWN
|| e
->type
== SDL_MOUSEBUTTONUP
) && e
->button
.which
!= SDL_TOUCH_MOUSEID
) {
807 if (e
->type
== SDL_KEYDOWN
) {
809 do_event_key(e
->key
.keysym
.sym
);
812 if (e
->type
== SDL_MOUSEWHEEL
) {
813 if (e
->wheel
.y
> 0) {
815 } else if (e
->wheel
.y
< 0) {
819 if (e
->type
== SDL_MOUSEBUTTONDOWN
&& e
->button
.which
!= SDL_TOUCH_MOUSEID
) {
820 if (e
->button
.button
== 2) { /* hold middle button */
823 if (e
->button
.button
== 1) { /* left click (handled on mousedown for smoother UI animations) */
824 do_event_click(ui
.x
, ui
.y
);
827 if (e
->type
== SDL_MOUSEBUTTONUP
&& e
->button
.which
!= SDL_TOUCH_MOUSEID
) {
828 if (e
->button
.button
== 2) { /* release middle button */
831 if (e
->button
.button
== 3) { /* right click */
837 if (tracking_mouse
) track_mouse();
842 void do_unit_in_house(unit_t
*u
, house_t
*h
) {
845 if (u
->gold
>= 100 && h
->tile
== 7) {
847 if (u
->progress
>= 10) {
855 if (h
->tile
== 2 && u
->gold
< 100) {
857 if (u
->progress
>= 10) {
859 int mined
= u
->calc_stat
[S_STR
] * 3;
861 u
->stat_bid
[S_STR
] = 1;
865 /* Seeking shelter? */
877 void do_unit_hit_unit(unit_t
*u
, int j
) {
878 unit_t
*target
= &units
[j
];
880 if (target
->faction
== u
->faction
) return;
887 void do_unit_hit_house(unit_t
*u
, int k
) {
888 house_t
*h
= &houses
[k
];
890 if (u
->faction
!= h
->faction
) {
897 if (u
->progress
>= 10) {
901 if (h
->hp
>= h
->max_hp
) {
909 if (!u
->visiting
&& h
->visitors
< h
->capacity
)
919 if (u
->progress
>= 10) {
925 /* Visiting (to unload gold) ? */
926 if (h
->tile
== 7 && u
->gold
>= 100) {
927 if (!u
->visiting
&& h
->visitors
< h
->capacity
)
933 //printf("%s HITTING HOUSE %s\n", u->name, h->title);
936 void do_unit_walk(unit_t
*u
) {
941 if (u
->x
< u
->tx
) next_x
= + 1;
942 if (u
->x
> u
->tx
) next_x
= - 1;
943 if (u
->y
< u
->ty
) next_y
= + 1;
944 if (u
->y
> u
->ty
) next_y
= - 1;
945 //printf("Walk: %d, %d\n", next_x, next_y);
946 #ifndef ALLOW_DIAGONALS
947 if (next_x
&& next_y
) if (rand() % 2) next_y
= 0; else next_x
= 0;
949 int k
= find_houseT(next_x
+ u
->x
, next_y
+ u
->y
);
951 do_unit_hit_house(u
, k
);
955 int j
= find_unitT(next_x
+ u
->x
, next_y
+ u
->y
);
957 do_unit_hit_unit(u
, j
);
961 u
->ox
= - next_x
* TILE_W
;
962 u
->oy
= - next_y
* TILE_H
;
972 u
->mode
= ANIM_CARRY
;
976 void do_unit_anim(unit_t
*u
) {
977 unit_p
*p
= &bunits
[u
->tile
];
979 Uint8 anim
= u
->mode
;
982 u
->mode
= ANIM_CARRY
;
986 if (u
->framecnt
>= p
->anims
[anim
]) {
989 if (p
->anim
[anim
][u
->framecnt
] < 0) {
990 u
->framecnt
+= p
->anim
[anim
][u
->framecnt
];
992 if (u
->framecnt
<= 0) {
997 static const char anim_names
[10][80] = {
1005 //printf("Mode: %d(%s) Frame counter: %d/%d => %d\n", u->mode, anim_names[u->mode], u->framecnt, p->anims[u->mode], p->anim[u->mode][u->framecnt]);
1006 u
->frame
= p
->anim
[u
->mode
][u
->framecnt
];
1009 //if (u->mode == 1) u->frame = 1 - u->frame;
1010 //else u->frame = 0;
1015 if (ui
.y
>= 480-1) ui
.vy
+= step
;
1016 if (ui
.y
<= 0) ui
.vy
-= step
;
1017 if (ui
.x
>= 640-1) ui
.vx
+= step
;
1018 if (ui
.x
<= 0) ui
.vx
-= step
;
1019 if (ui
.vy
> 200) ui
.vy
= 200;
1020 if (ui
.vy
< 0) ui
.vy
= 0;
1021 if (ui
.vx
< 0) ui
.vx
= 0;
1026 binh_list unit_list
= { 0 };
1028 int max_energy
= 1000;
1030 for (i
= 0; i
< num_units
; i
++) {
1031 binhl_push(&unit_list
, i
, 1000 - units
[i
].energy
);
1035 if (ui
.freq
> 1000) ui
.freq
= 0;
1039 //for (i = 0; i < num_units; i++) {
1040 while (unit_list
.len
) {
1042 i
= binhl_pop(&unit_list
);
1043 unit_t
*u
= &units
[i
];
1044 if (u
->energy
== 0) break;
1046 if (u
->energy
>= 10) {
1047 do_unit_in_house(u
, u
->visiting
);
1053 if (u
->ox
!= 0 || u
->oy
!= 0) {
1054 if (u
->energy
>= 5) {
1055 #ifndef ALLOW_DIAGONALS
1056 if (u
->ox
) u
->ox
+= (u
->ox
> 0 ? -1 : 1);
1057 else u
->oy
+= (u
->oy
> 0 ? -1 : 1);
1059 u
->ox
+= (u
->ox
> 0 ? -1 : 1);
1060 u
->oy
+= (u
->oy
> 0 ? -1 : 1);
1066 if (u
->x
!= u
->tx
|| u
->y
!= u
->ty
) {
1068 if (u
->energy
>= 10) {
1076 if (ui
.hover_top
== overMap
) track_mouse_map();
1080 // do_update_links();
1083 for (i
= 0; i
< num_units
; i
++) {
1084 unit_t
*u
= &units
[i
];
1087 u
->energy
+= u
->calc_stat
[S_DEX
] * 3;
1088 if (u
->energy
> (u
->calc_stat
[S_DEX
]+1) * 10) u
->energy
= (u
->calc_stat
[S_DEX
]+1) * 10;
1091 if (u
->mode
!= ANIM_DEATH
) u
->framecnt
= 0;
1092 u
->mode
= ANIM_DEATH
;
1104 for (i
= 0; i
< num_units
; i
++) {
1105 unit_t
*u
= &units
[i
];
1107 unit_pick_strategy(i
);
1113 static Uint32 wait
= 0;
1114 static Uint32 ticks
= 0;
1115 static Uint32 phases
= 0;
1117 Uint32 tick
= SDL_GetTicks();
1118 Uint32 pass
= tick
- wait
;
1120 if (ticks
% 2) do_scroll();
1122 if (pass
> ui
.game_speed
) {
1139 int rune_main(int argc
, char* argv
[]) {
1144 SDL_Renderer
*screen
;
1145 Uint32 fs
= 0;//SDL_FULLSCREEN;
1148 if (SDL_Init(SDL_INIT_VIDEO
) < 0) {
1149 fprintf(stderr
, "SDL initialization failed: %s\n", SDL_GetError());
1154 window
= SDL_CreateWindow("RuneMen",
1155 //SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
1157 weight
* 2, height
* 2,
1160 if (window
== NULL
) {
1161 fprintf(stderr
, "Window creation failed: %s\n", SDL_GetError());
1166 /* Create renderer */
1167 screen
= SDL_CreateRenderer(window
, -1, 0);
1169 if (screen
== NULL
) {
1170 fprintf(stderr
, "Renderer creation failed: %s\n", SDL_GetError());
1171 SDL_DestroyWindow(window
);
1176 /* Scale the window */
1177 SDL_RenderSetLogicalSize(screen
, LOG_WIDTH
, LOG_HEIGHT
);
1179 /* Draw lines, points and rects with alpha blending */
1180 SDL_SetRenderDrawBlendMode(screen
, SDL_BLENDMODE_BLEND
);
1185 prepare_inline_font();
1187 mainRenderer
= screen
;
1191 //int next = mainmenu_loop(screen);
1192 //if (next == -1) goto done;
1199 SDL_Event event
= { 0 };
1200 while (SDL_PollEvent(&event
)) {
1201 if (event
.type
== SDL_QUIT
) loops
= 0;
1202 if (event
.type
== SDL_KEYDOWN
&& event
.key
.keysym
.sym
== SDLK_ESCAPE
) loops
= 0;
1208 draw_screen(screen
);
1210 ui
.fps
= count_fps();
1212 SDL_RenderPresent(screen
);
1216 fprintf(stdout
, "Normal termination...\n");
1220 SDL_DestroyRenderer(screen
);
1221 SDL_DestroyWindow(window
);