Example #1
0
void update_survivaltime(ALLEGRO_BITMAP *image, float x, float y, int nflags, ALLEGRO_COLOR color)
{
    static int counter = 0;
    GDATAPTR game = get_game_data();
    if(game->paused);
    else if(lives <= 0);
    else
        counter++;
    if(counter >= 60)
    {
        counter = 0;
        seconds++;
    }
    if(seconds >= 60)
    {
        seconds = 0;
        minutes++;
    }
	if(survival_time != NULL) free(survival_time);
    survival_time = (char*)malloc(7*sizeof(char));
    if(minutes < 10 && seconds < 10)
        sprintf(survival_time, "0%d:0%d", minutes, seconds);
    else if(minutes < 10)
        sprintf(survival_time, "0%d:%d", minutes, seconds);
    else if(seconds < 10)
        sprintf(survival_time, "%d:0%d", minutes, seconds);
    else
        sprintf(survival_time, "%d:%d", minutes, seconds);

    al_draw_textf(game->font, color,  x, y, nflags, "Survival Time: %s", survival_time);
}
Example #2
0
void draw_dialogue_ui() {
	if (!dialogue_ui_is_open()) {
		return;
	}
	ne::ortho_camera* camera = &get_game_data()->camera;
	
	ne::set_drawing_shape(0);
	ne::set_font(assets.fonts.tahoma_12);

	ne::set_model_matrix(&dialogue_ui.transform);
	ne::set_texture(assets.textures.blank);
	ne::set_color(0.4f, 0.3f, 0.2f, 0.8f);
	ne::draw_vertices();
	ne::set_color(1.0f, 1.0f, 1.0f, 1.0f);

	ne::draw_text(&dialogue_ui.message);
	for (size_t i = 0; i < dialogue_ui.choices.size(); i++) {
		if (dialogue_ui.current_choice == (int32) i) {
			ne::set_color(1.0f, 0.9f, 0.5f, 1.0f);
		} else {
			ne::set_color(0.8f, 0.8f, 0.8f, 0.8f);
		}
		ne::draw_text(&dialogue_ui.choices[i]);
	}

}
Example #3
0
void handle_dialogue_ui_input() {
	if (!dialogue_ui_is_open()) {
		return;
	}
	ne::keyboard_key_event* e = ne::get_key_event();
	if (!e || !e->is_pressed || e->repeat != 0) {
		return;
	}
	game_data* game = get_game_data();
	switch (e->key) {
	case KEY_W:
	case KEY_UP:
		if (dialogue_ui.current_choice > 0) {
			dialogue_ui.current_choice--;
		}
		break;
	case KEY_S:
	case KEY_DOWN:
		if (dialogue_ui.current_choice + 1 < (int32) dialogue_ui.choices.size()) {
			dialogue_ui.current_choice++;
		}
		break;
	case KEY_SPACE:
	case KEY_RETURN:
		select_dialogue_node_link(dialogue_ui.current_choice);
		break;
	default: break;
	}
}
Example #4
0
void draw_button(BUTTONPTR currentptr)
{
    const int c = 2, d = 2, x = 0, y = 0;
    nscale();
    static ALLEGRO_BITMAP *newbitm = NULL;
    if(newbitm == NULL)
        newbitm = al_create_bitmap(currentptr->bimage->width, currentptr->bimage->height);
    al_set_target_bitmap(newbitm);
    al_clear_to_color(al_map_rgba(0, 0, 0, 0));
    if((currentptr->bdata.bflags & BDRAW) && !(currentptr->bdata.bflags & BLPRESSED))
    {
        al_draw_tinted_bitmap(currentptr->bimage->button_image, currentptr->bdata.b_color, x, y, 0);
        al_draw_text(currentptr->btext.text_f,
                     currentptr->btext.text_c,
                     currentptr->bimage->width/d,
                     currentptr->bimage->height/d-al_get_font_line_height(currentptr->btext.text_f)/d,
                     ALLEGRO_ALIGN_CENTRE,
                     currentptr->btext.text
                     );
    }
    else if((currentptr->bdata.bflags & BDRAW) && (currentptr->bdata.bflags & BLPRESSED))
    {
        al_draw_tinted_bitmap(currentptr->bimage->button_image, currentptr->bdata.b_color, x, y, ALLEGRO_FLIP_VERTICAL);
        al_draw_text(currentptr->btext.text_f,
                     currentptr->btext.text_c,
                     currentptr->bimage->width/d+c,
                     currentptr->bimage->height/d-al_get_font_line_height(currentptr->btext.text_f)/d+c,
                      ALLEGRO_ALIGN_CENTRE,
                      currentptr->btext.text
                      );
    }
    else
    {
        al_draw_tinted_bitmap(currentptr->bimage->button_image, currentptr->bdata.b_color, x, y, 0);
        al_draw_text(currentptr->btext.text_f,
                     currentptr->btext.text_c,
                     currentptr->bimage->width/d,
                     currentptr->bimage->height/d-al_get_font_line_height(currentptr->btext.text_f)/d,
                     ALLEGRO_ALIGN_CENTRE,
                     currentptr->btext.text
                     );
    }
    scale(800.0, 600.0);
    al_set_target_backbuffer(get_game_data()->display);
    al_draw_bitmap(newbitm, currentptr->bdata.x, currentptr->bdata.y, 0);
}
Example #5
0
// Updates all nescessary sprites, images, buttons etc.
void update(void)
{
    static _Bool called = false;
    GDATAPTR game = get_game_data();
    update_background();
    if(game->gamestarted && game->paused)
    {
        paused(score, survival_time, lives);
    }
    else if(lives == 0)
    {
        gameover(score, survival_time);
    }
    else if(game->gamestarted)
    {
        if(!called)
        {
            //cpSpaceResizeStaticHash(get_global_cpSpace(), 700.0, 4*10);
            cpSpaceAddCollisionHandler(get_global_cpSpace(), 1, 2, collision_begin, NULL, NULL, NULL, NULL);
            cpSpaceAddCollisionHandler(get_global_cpSpace(), 0, 2, collision_static_begin, NULL, NULL, NULL, NULL);
            cpSpaceAddCollisionHandler(get_global_cpSpace(), 0, 1, collision_static_begin, NULL, NULL, NULL, NULL);
            called = false;
        }
        logic();
        update_clouds();
        cpSpaceStep(get_global_cpSpace(), 1.0f/60.0f);
        cpSpaceEachBody(get_global_cpSpace(), &update_sprites, NULL);
        update_ground();
        update_lives();
        add_element_to_render_queue(NULL, 0, 0, 0, RCOLOR(0, 0, 0, 255), update_score);
        add_element_to_render_queue(NULL, 290, 0, 0, RCOLOR(0, 0, 0, 255), update_survivaltime);
    }
    else if(game->options)
    {
        options();
    }
    else if(game->howtoplay)
    {
        howtoplay();
    }
    else if(game->highscores)
    {
        highscores();
    }
}
Example #6
0
void enter_warp(warp_entity* warp, player_entity* player) {
	save_player_game();
	if (!original_world_exists(warp->world_id)) {
		// TODO: Better handling
		DEBUG(0, NE_WARNING, "Cannot enter warp to non-existing world " << warp->world_id);
		return;
	}
	player->transform.position.xy = chunk_position(warp->chunk);
	player->transform.position.x += (float) warp->tile.x * tile_pixel_size();
	player->transform.position.y += (float) warp->tile.y * tile_pixel_size();
	game_data* game = get_game_data();
	load_player_world(warp->world_id);
	if (game->world.mode != WORLD_PLAY_MODE) {
		DEBUG(0, NE_WARNING, "World " << warp->world_id << " is not playable after warping to it. Unexpected error.");
		DEBUG(0, NE_ERROR, "Exiting game to avoid corrupted save state. Return code: " << EXIT_CODE_WORLD_LOAD_ERROR);
		ne::show_error("It seems world " + std::to_string(warp->world_id) + " did not load correctly. This is an unexpected case, and it might be related to hard drive failure. The game will close to avoid corruption, but you may restart it.");
		exit(EXIT_CODE_WORLD_LOAD_ERROR);
	}
}
Example #7
0
bool TirFwExtractThread::findCandidates(QString name)
{
  if(quit) return false;
  int i;
  QDir dir(name);
  QStringList patt;
  patt<<QString::fromUtf8("*.dll")<<QString::fromUtf8("*.exe")<<QString::fromUtf8("*.dat");
  QFileInfoList files = dir.entryInfoList(patt, QDir::Files | QDir::Readable);
  for(i = 0; i < files.size(); ++i){
    if(quit) return false;
    if(files[i].fileName().compare(QString::fromUtf8("TIRViews.dll")) == 0){
      QString outfile = QString::fromUtf8("%1/TIRViews.dll").arg(destPath);
      if((tirviewsFound = QFile::copy(files[i].canonicalFilePath(), outfile))){
        emit progress(QString::fromUtf8("Extracted TIRViews.dll..."));
      }
    }else if(files[i].fileName().compare(QString::fromUtf8("sgl.dat"))){
      analyzeFile(files[i].canonicalFilePath());
    }else{
      QString outfile = QString::fromUtf8("%1/gamedata.txt").arg(destPath);
      gameDataFound = get_game_data(files[i].canonicalFilePath().toUtf8().constData(),
                                    outfile.toUtf8().constData(), false);
      emit progress(QString::fromUtf8("Extracted game data..."));
    }
    if(allFound()){
      return true;
    }
  }

  QFileInfoList subdirs =
    dir.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
  QString dirname;
  for(i = 0; i < subdirs.size(); ++i){
    dirname = subdirs[i].canonicalFilePath();
    if((!dirname.endsWith(QString::fromUtf8("windows"))) && findCandidates(dirname)){
      return true;
    }
  }
  return false;
}
Example #8
0
void loader(void)
{
    ALLEGRO_BITMAP *bg = al_load_bitmap("background_day.png");
    PROGRESSBARPTR pb1 = create_new_progress_bar("pb1", 243, 275, 300, 50, 10, 10, al_map_rgba(0, 0, 0, 127),
                                                 al_map_rgba(0, 0, 255, 127), 5, true);
    while(pb1->bar_width < pb1->width)
    {
        pb1->counter++;
        al_acknowledge_resize(get_game_data()->display);
        scale(res_width, res_height);
        al_clear_to_color(data->background_color);
        al_draw_bitmap(bg, 0, 0, 0);
        render_progress_bars();
        al_flip_display();
        if(pb1->counter == 3)
        {
            pb1->bar_width += pb1->increment;
            pb1->counter = 0;
        }
    }
    al_destroy_bitmap(bg);
    remove_element_from_progress_bar_list("pb1");
}
Example #9
0
void update_dialogue_ui() {
	if (!dialogue_ui_is_open()) {
		return;
	}
	ne::ortho_camera* camera = &get_game_data()->camera;

	ne::transform3f t;
	t.position.xy = { ne::camera_x(camera), ne::camera_y(camera) };
	t.scale.xy = { ne::camera_width(camera), ne::camera_height(camera) };
	t.position.x += t.scale.x / 2.0f;
	t.position.y += t.scale.y / 2.0f;
	t.scale.x /= 2.0f;
	t.scale.y /= 2.0f;
	t.position.x -= t.scale.x / 2.0f;
	t.position.y -= t.scale.y / 2.0f;
	dialogue_ui.transform = t;

	dialogue_ui.message.transform.position.xy = { t.position.x + 16.0f, t.position.y + 16.0f };
	dialogue_ui.message.text = dialogue_ui.tree->nodes[dialogue_ui.current_node].message;
	for (size_t i = 0; i < dialogue_ui.choices.size(); i++) {
		dialogue_ui.choices[i].transform.position.xy = { t.position.x + 16.0f, t.position.y + 64.0f + (float)i * 20.0f };
		dialogue_ui.choices[i].text = dialogue_ui.tree->nodes[dialogue_ui.current_node].links[i].reply;
	}
}
Example #10
0
void gameover(int score, char *survival_time)
{
    GDATAPTR game = get_game_data();

    if(quit == NULL)
    {
        quit = create_new_button("QUITTOMENUGO",
                                 "DEFAULT",
                                 "QUIT TO MENU",
                                 game->b_font,
                                 BCOLOR(255, 255, 255, 255), //80, 112/122, 255
                                 BCOLOR(65, 105, 255, 191),
                                 -280, //263
                                 500, //225
                                 50,
                                 BRIGHT,
                                 BVISIBLE,
                                 true
                                );
    }

    add_element_to_render_queue(NULL, 280, 250, 0, RCOLOR(0, 0, 0, 255), update_score);
    add_element_to_render_queue(NULL, 280, 300, 0, RCOLOR(0, 0, 0, 255), update_survivaltime);
}
Example #11
0
void maingame_cleanup(void)
{
    SPRITESPTR stman = search_sprite_list_for_element("STICKMAN");
    SPRITESPTR ground = search_sprite_list_for_element("GROUND");
    GDATAPTR game = get_game_data();
    cpSpace *space = get_global_cpSpace();
    cpSpaceRemoveCollisionHandler(space, 1, 2);
    remove_physics_object(stman);
    remove_element_from_sprite_list_ptr(stman);
    remove_element_from_sprite_list("CLOUD");

    ground->sdata.x = 0;
    ground->sdata.y = 510;

    remove_all_enemies();

    game->gamestarted = false;

    start = false;
    lives = 3;
    score = 0;
    minutes = 0;
    seconds = 0;
}
Example #12
0
int main(int argc, char** argv) { return argc > 1 && get_game_data(argv[1], NULL, false); }
Example #13
0
void update_score(ALLEGRO_BITMAP *image, float x, float y, int nflags, ALLEGRO_COLOR color)
{
    GDATAPTR game = get_game_data();
    al_draw_textf(game->font, color, x, y, nflags, "Score: %d", score);
}