[in progress] a 2d storytelling-oriented game engine, built on allegro 5
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

107 lines
2.7 KiB

#include "err.h"
#include "set.h"
#include <stdbool.h>
#include <allegro5/allegro5.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>
#include <allegro5/allegro_image.h>
#define SCREEN_WIDTH 480
#define SCREEN_HEIGHT 360
static float screen_scale = 2;
static inline void init_resources(ALLEGRO_DISPLAY **d, ALLEGRO_FONT **f,
ALLEGRO_EVENT_QUEUE **q, ALLEGRO_TIMER **t)
{
TRY(al_init(), "failed to initialise allegro");
TRY(al_install_keyboard(), "failed to initialise allegro keyboard");
TRY(al_init_font_addon(), "failed to initialise allegro font addon");
TRY(al_init_ttf_addon(), "failed to initialise allegro ttf addon");
TRY(al_init_image_addon(), "failed to initialise allegro image addon");
al_set_new_display_flags(ALLEGRO_WINDOWED);
al_set_new_window_title("ただのテスト");
*d = al_create_display(SCREEN_WIDTH * screen_scale, SCREEN_HEIGHT * screen_scale);
TRY(*d != NULL, "failed to create display");
*f = al_load_font("data/font/efont/BiwidthMedium.ttf", -24, ALLEGRO_TTF_MONOCHROME | ALLEGRO_TTF_NO_AUTOHINT);
TRY(*f != NULL, "failed to load font");
*q = al_create_event_queue();
TRY(*q != NULL, "failed to create event queue");
*t = al_create_timer(1.0 / 30.0);
TRY(*t != NULL, "failed to create timer");
al_register_event_source(*q, al_get_keyboard_event_source());
al_register_event_source(*q, al_get_display_event_source(*d));
al_register_event_source(*q, al_get_timer_event_source(*t));
}
int main(int argc, char **argv)
{
ALLEGRO_TIMER *t;
ALLEGRO_EVENT_QUEUE *q;
ALLEGRO_DISPLAY *d;
ALLEGRO_FONT *f;
ALLEGRO_EVENT e;
ALLEGRO_BITMAP *buf;
struct set *s;
init_resources(&d, &f, &q, &t);
buf = al_create_bitmap(SCREEN_WIDTH, SCREEN_HEIGHT);
s = set_load("set", 32, 32, 2);
al_start_timer(t);
while (true) {
al_wait_for_event(q, &e);
switch (e.type) {
case ALLEGRO_EVENT_TIMER:
break;
case ALLEGRO_EVENT_KEY_DOWN:
if (e.keyboard.keycode != ALLEGRO_KEY_Q)
continue;
case ALLEGRO_EVENT_DISPLAY_CLOSE:
goto done;
default:
continue;
}
al_set_target_bitmap(buf);
al_clear_to_color(al_map_rgb(0, 0, 0));
al_draw_bitmap(set_at(s, 0)->b, 0, 0, 0);
al_draw_text(f, al_map_rgb(255, 255, 255),
240, 320,
ALLEGRO_ALIGN_CENTRE | ALLEGRO_ALIGN_INTEGER,
"マイクチェック");
al_set_target_backbuffer(d);
al_draw_scaled_bitmap(buf, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
0, 0,
screen_scale * SCREEN_WIDTH, screen_scale * SCREEN_HEIGHT,
0);
al_flip_display();
}
done:
al_destroy_bitmap(buf);
al_destroy_font(f);
al_destroy_display(d);
al_destroy_timer(t);
al_destroy_event_queue(q);
al_uninstall_system();
return EXIT_SUCCESS;
}