Пример #1
0
st_position class_config::move_weapon_curstor_up()
{
    // from position to top
    //std::cout << "$$$$$ move_weapon_curstor_up - ini: " << (ingame_menu_pos.y-1) << std::endl;
    for (int i=ingame_menu_pos.y-1; i>=0; i--) {
        //std::cout << "move_weapon_curstor_up - looking slot [" << ingame_menu_pos.x << "][" << i << "] value: " << _weapons_matrix[ingame_menu_pos.x][i] << std::endl;
        if (_weapons_matrix[ingame_menu_pos.x][i] == true) {
            //std::cout << "move_weapon_curstor_up - found slot at [" << ingame_menu_pos.x << "][" << i << "]" << std::endl;
            return st_position(ingame_menu_pos.x, i);
        }
    }
    // if not on energy tanks, move to it
    if (ingame_menu_pos.y != 6) {
        return st_position(ingame_menu_pos.x, 6);
    }

    // from bottom to position
    for (int i=WPN_ROWS-1; i>ingame_menu_pos.y; i--) {
        if (_weapons_matrix[ingame_menu_pos.x][i] == true) {
            return st_position(ingame_menu_pos.x, i);
        }
    }

    return st_position(-1, -1);


}
Пример #2
0
st_position class_config::move_weapon_curstor_left() const // moving from right-column to left-column
{
    /*
    int stage_pos = convert_menu_pos_to_weapon_n(st_position(0, ingame_menu_pos.y));
    if (game_save.stages[stage_pos] == 1) { // have the same-line weapon on the other columns
        return st_position(0, ingame_menu_pos.y);
    } else { // use the first weapon (normal) from left column
        return st_position(0, 0);
    }
    */
    int new_x = 1;
    if (ingame_menu_pos.x == 1) {
        new_x = 0;
    }
    // search for a existing slot to move to
    for (int i=ingame_menu_pos.y; i<WPN_ROWS; i++) { // start on current y
        if (_weapons_matrix[new_x][i] == true) {
            return st_position(new_x, i);
        }
    }
    for (int i=0; i<ingame_menu_pos.y; i++) { // remaining y positions
        if (_weapons_matrix[new_x][i] == true) {
            return st_position(new_x, i);
        }
    }
    return st_position(-1, -1);
}
Пример #3
0
st_position class_config::move_weapon_curstor_down()
{

    // from position to bottom
    for (int i=ingame_menu_pos.y+1; i<WPN_ROWS; i++) {
        int stage_id = i;
        //std::cout << "CONFIG::move_weapon_curstor_down - slot[" << ingame_menu_pos.x << "][" << stage_id << "]: " << _weapons_matrix[ingame_menu_pos.x][stage_id] << std::endl;
        if (_weapons_matrix[ingame_menu_pos.x][stage_id] == true) {
            //std::cout << "CONFIG::move_weapon_curstor_down - found slot at [" << ingame_menu_pos.x << "][" << i << "]" << std::endl;
            return st_position(ingame_menu_pos.x, stage_id);
        }
    }
    // if not on energy tanks, move to it
    if (ingame_menu_pos.y != 6) {
        return st_position(ingame_menu_pos.x, 6);
    }

    // from top to position
    for (int i=0; i<ingame_menu_pos.y; i++) {
        if (_weapons_matrix[ingame_menu_pos.x][i] == true) {
            return st_position(ingame_menu_pos.x, i);
        }
    }

    return st_position(-1, -1);

}
Пример #4
0
// @TODO - this should only set some variables in a global and the drawinbg should be handled my show_scene()
// That way we can move the run_XXX methods into threads to run in paralel
void sceneShow::run_image_scene(CURRENT_FILE_FORMAT::file_scene_show_image scene_image)
{
    std::cout << "** sceneShow::run_image_scene::START" << std::endl;
    float x = scene_image.ini_x;
    float y = scene_image.ini_y;
    graphicsLib_gSurface image;
    graphicsLib_gSurface bg_image;
    graphLib.initSurface(st_size(RES_W, RES_H), &bg_image);
    graphLib.copy_gamescreen_area(st_rectangle(0, 0, RES_W, RES_H), st_position(0, 0), &bg_image);
    graphLib.surfaceFromFile(FILEPATH + "images/scenes/" + scene_image.filename, &image);

    std::cout << "** sceneShow::run_image_scene::total_dist: " << total_dist << std::endl;

    while (total_dist > 0) {
        input.read_input();
        //std::cout << "total_dist: " << total_dist << std::endl;
        timer.delay(scene_image.move_delay);
        // @TODO - copy background, but should be done in a smarter way as there can be several moving elements
        graphLib.showSurfaceAt(&bg_image, st_position(0, 0), false);
        graphLib.showSurfaceAt(&image, st_position(x, y), false);
        graphLib.updateScreen();
        x += speed_x;
        y += speed_y;
        total_dist--;
    }
    graphLib.showSurfaceAt(&image, st_position(x, y), false);
    graphLib.updateScreen();
}
Пример #5
0
void draw::show_boss_intro_sprites(short boss_id, bool show_fall)
{
    UNUSED(show_fall);
    unsigned int intro_frames_n = 0;
    //int intro_frames_rollback = 0;
    st_position boss_pos(20, -37);
    st_position sprite_size;
    graphicsLib_gSurface bgCopy, boss_graphics;


    std::string graph_filename = FILEPATH + "data/images/sprites/enemies/" + std::string(game_data.game_npcs[boss_id].graphic_filename);
    sprite_size.x = game_data.game_npcs[boss_id].frame_size.width;
    sprite_size.y = game_data.game_npcs[boss_id].frame_size.height;
    graphLib.surfaceFromFile(graph_filename.c_str(), &boss_graphics);

    graphLib.initSurface(st_size(RES_W, RES_H), &bgCopy);
    graph_filename = FILEPATH + "data/images/backgrounds/stage_boss_intro.png";
    graphLib.surfaceFromFile(graph_filename.c_str(), &bgCopy);
    st_position bg_pos(0, (RES_H/2)-(bgCopy.height/2));
    graphLib.copyArea(bg_pos, &bgCopy, &graphLib.gameScreen);

    update_screen();

    int sprite_pos_y = RES_H/2 - sprite_size.y/2;

    for (int i=0; i<ANIM_FRAMES_COUNT; i++) {
        if (game_data.game_npcs[boss_id].sprites[ANIM_TYPE_INTRO][i].used == true) {
            intro_frames_n++;
        }
    }

    // fall into position
    while (boss_pos.y < sprite_pos_y) {
        boss_pos.y += 4;
        graphLib.copyArea(bg_pos, &bgCopy, &graphLib.gameScreen);
        graphLib.copyArea(st_rectangle(0, 0, sprite_size.x, sprite_size.y), st_position(boss_pos.x, boss_pos.y), &boss_graphics, &graphLib.gameScreen);
        graphLib.wait_and_update_screen(5);
    }
    graphLib.wait_and_update_screen(500);


    // show intro sprites
    if (intro_frames_n > 1) {
        for (int i=0; i<ANIM_FRAMES_COUNT; i++) {
            if (game_data.game_npcs[boss_id].sprites[ANIM_TYPE_INTRO][i].used == true) {
                //std::cout << "i: " << i << ", used: " << game_data.game_npcs[boss_id].sprites[ANIM_TYPE_INTRO][i].used << ", duration: " << game_data.game_npcs[boss_id].sprites[ANIM_TYPE_INTRO][i].duration << std::endl;
                graphLib.copyArea(bg_pos, &bgCopy, &graphLib.gameScreen);
                graphLib.copyArea(st_rectangle(sprite_size.x * game_data.game_npcs[boss_id].sprites[ANIM_TYPE_INTRO][i].sprite_graphic_pos_x, 0, sprite_size.x, sprite_size.y), st_position(boss_pos.x, boss_pos.y), &boss_graphics, &graphLib.gameScreen);
                graphLib.wait_and_update_screen(game_data.game_npcs[boss_id].sprites[ANIM_TYPE_INTRO][i].duration);
            }
        }
    } else { // just frow first sprite
        graphLib.copyArea(bg_pos, &bgCopy, &graphLib.gameScreen);
        graphLib.copyArea(st_rectangle(0, 0, sprite_size.x, sprite_size.y), st_position(boss_pos.x, boss_pos.y), &boss_graphics, &graphLib.gameScreen);
        graphLib.wait_and_update_screen(200);
    }
}
void classPlayer::add_coil_object()
{
    if (map->have_player_object() == true) {
        return;
    }
    if (game_save.items.weapons[selected_weapon] > 0) {
        //std::cout << ">>>>>>> adding coil object" << std::endl;
		st_position obj_pos;
        obj_pos.y = position.y;
		if (state.direction == ANIM_DIRECTION_LEFT) {
            obj_pos.x = position.x - 2;
		} else {
            obj_pos.x = position.x + frameSize.width + 2;
		}

        object temp_obj(game_data.player_items[0], this->map, st_position(position.x/TILESIZE, position.y/TILESIZE)); /// @TODO - remove hardcoded number
        temp_obj.set_precise_position(obj_pos, state.direction);
		temp_obj.set_duration(2500);
        temp_obj.use_teleport_in_out();
        temp_obj.set_colision_mode(COLISION_MODE_Y);
        temp_obj.set_direction(state.direction);
		map->add_object(temp_obj);
        game_save.items.weapons[selected_weapon]--;
	}
}
Пример #7
0
void dialogs::show_timed_dialog(std::string face_file, bool is_left, std::string lines[], short delay, bool show_btn=true)
{
    UNUSED(is_left);
    std::string temp_text;
    char temp_char;

    timer.pause();

    draw_dialog_bg(show_btn);
    draw_lib.update_screen();
    st_position dialog_pos = graphLib.get_dialog_pos();
    graphLib.place_face(face_file, st_position(dialog_pos.x+16, dialog_pos.y+16));
    draw_lib.update_screen();

    /// @TODO: usar show_config_bg e hide_config_bg da graphLib - modificar para aceitar centered (que é o atual) ou top ou bottom
    for (int i=0; i<3; i++) {
        for (unsigned int j=0; j<lines[i].size(); j++) {
            temp_char = lines[i].at(j);
            temp_text = "";
            temp_text += temp_char;

            graphLib.draw_text(j*9+(dialog_pos.x+52), i*11+(dialog_pos.y+16), temp_text);
            //graphLib.draw_text(j*9+53, i*11+9, "A");
            draw_lib.update_screen();
            input.waitTime(15);
        }
    }
    input.waitTime(delay);
    timer.unpause();
}
Пример #8
0
void draw::show_bubble(int x, int y)
{
    if (_bubble_gfx.gSurface == NULL) {
        std::string filename = FILEPATH + "/data/images/tilesets/bubble.png";
        graphLib.surfaceFromFile(filename, &_bubble_gfx);
    }
    graphLib.showSurfaceAt(&_bubble_gfx, st_position(x, y), false);
}
Пример #9
0
void class_config::set_player_ref(classPlayer* set_player_ref)
{
	player_ref = set_player_ref;
	if (_player_surface.width == 0) {
		graphLib.initSurface(st_size(player_ref->get_char_frame(ANIM_DIRECTION_RIGHT, ANIM_TYPE_ATTACK, 0)->width, player_ref->get_char_frame(ANIM_DIRECTION_RIGHT, ANIM_TYPE_ATTACK, 0)->height), &_player_surface);
		graphLib.copyArea(st_position(0, 0), player_ref->get_char_frame(ANIM_DIRECTION_RIGHT, ANIM_TYPE_ATTACK, 0), &_player_surface);
	}
}
Пример #10
0
bool dialogs::show_leave_game_dialog() const
{
    bool res = false;
    bool repeat_menu = true;
    int picked_n = -1;

    timer.pause();

    std::cout << ">>>>>>> show_leave_game_dialog::START" << std::endl;

    graphicsLib_gSurface bgCopy;
    graphLib.initSurface(st_size(RES_W, RES_H), &bgCopy);
    graphLib.copyArea(st_position(0, 0), &graphLib.gameScreen, &bgCopy);

    graphLib.show_dialog(0, false);
    st_position dialog_pos = graphLib.get_dialog_pos();
    graphLib.draw_text(dialog_pos.x+30, dialog_pos.y+16, "QUIT GAME?");
    std::vector<std::string> item_list;
    item_list.push_back("YES");
    item_list.push_back("NO");
    option_picker main_picker(false, st_position(dialog_pos.x+40, dialog_pos.y+16+11), item_list, false);
    draw_lib.update_screen();
    while (repeat_menu == true) {
        picked_n = main_picker.pick();
        std::cout << "picked_n: " << picked_n << std::endl;
        if (picked_n == 0) {
            res = true;
            repeat_menu = false;
        } else if (picked_n == 1) {
            res = false;
            repeat_menu = false;
        } else {
            main_picker.draw();
        }
    }
    input.clean();
    input.waitTime(200);
    graphLib.copyArea(st_position(0, 0), &bgCopy, &graphLib.gameScreen);
    draw_lib.update_screen();
    timer.unpause();

    std::cout << ">>>>>>> show_leave_game_dialog::END" << std::endl;

    return res;
}
Пример #11
0
void draw::show_credits()
{
    int line_n=0;
    unsigned int scrolled=0;
    int posY = -RES_H;
    st_rectangle dest;
    graphicsLib_gSurface credits_surface;

    graphLib.initSurface(st_size(RES_W, RES_H+12), &credits_surface);
    graphLib.blank_surface(credits_surface);
    graphLib.blank_screen();


    // add the initial lines to screen
    create_credits_text(credits_surface);

    update_screen();

    // scroll the lines
    while (scrolled < (credits_list.size()*12)+RES_H/2+46) {
        graphLib.copyArea(st_rectangle(0, posY, RES_W, RES_H), st_position(0, 0), &credits_surface, &graphLib.gameScreen);
        update_screen();
        timer.delay(60);
        posY++;
        scrolled++;
        if (posY > 12) {
            graphLib.copyArea(st_rectangle(0, posY, credits_surface.width, RES_H), st_position(0, 0), &credits_surface, &credits_surface);
            // scroll the lines
            dest.x = 0;
            dest.y = RES_H;
            dest.w = RES_W;
            dest.h = 12;
            graphLib.blank_area(dest.x, dest.y, dest.w, dest.h, credits_surface);
            draw_credit_line(credits_surface, line_n+21);
            posY = 0;
            line_n++;
        }
    }
    update_screen();
}
Пример #12
0
void class_config::change_player_frame_color()
{
	short int selected_weapon = convert_menu_pos_to_weapon_n(ingame_menu_pos);
    CURRENT_FILE_FORMAT::file_weapon_colors colors = player_ref->get_weapon_colors(selected_weapon);

	if (colors.color1.r != -1) {
        graphLib.change_surface_color(0, colors.color1, &_player_surface);
	}
	if (colors.color2.r != -1) {
        graphLib.change_surface_color(1, colors.color2, &_player_surface);
	}
	if (colors.color3.r != -1) {
        graphLib.change_surface_color(2, colors.color3, &_player_surface);
	}
	graphLib.copyArea(st_position(26, 190), &_player_surface, &graphLib.gameScreen);
}
void classPlayer::add_jet_object()
{
    if (map->have_player_object() == true) {
        return;
    }
    if (game_save.items.weapons[selected_weapon] > 0) {
        //std::cout << ">>>>>>> adding JET object" << std::endl;
		st_position obj_pos;
        obj_pos.y = position.y;
        if (state.direction == ANIM_DIRECTION_LEFT) {
            obj_pos.x = position.x - 2;
        } else {
            obj_pos.x = position.x + frameSize.width + 2;
        }
        object temp_obj(game_data.player_items[1], this->map, st_position(position.x/TILESIZE, position.y/TILESIZE));
        temp_obj.set_precise_position(obj_pos, state.direction);
        temp_obj.use_teleport_in_out();
		temp_obj.set_duration(4500);
		temp_obj.set_direction(state.direction);
		map->add_object(temp_obj);
	}
}
Пример #14
0
void key_map::draw_screen()
{
    bool finished = false;
    st_position config_text_pos;
    st_position cursor_pos;
    short _pick_pos = 0;

    config_text_pos.x = graphLib.get_config_menu_pos().x + 74;
    config_text_pos.y = graphLib.get_config_menu_pos().y + 40;
    cursor_pos = config_text_pos;

    graphLib.clear_area(config_text_pos.x-1, config_text_pos.y-1, 180,  180, 0, 0, 0);
    input.clean();
    input.waitTime(300);

    for (unsigned int i=0; i<_keys_list.size(); i++) {
        graphLib.draw_text(config_text_pos.x, config_text_pos.y + i*CURSOR_SPACING, _keys_list[i].c_str());
        redraw_line(i);
    }
    graphLib.draw_text(config_text_pos.x, config_text_pos.y + _keys_list.size()*CURSOR_SPACING, "RETURN");
    draw_lib.update_screen();

    //cout << "scenesLib::option_picker::START\n";
    graphLib.drawCursor(st_position(cursor_pos.x-CURSOR_SPACING, cursor_pos.y+(_pick_pos*CURSOR_SPACING)));

    while (finished == false) {
        input.readInput();
        if (input.p1_input[BTN_START]) {
            if (_pick_pos == (short)_keys_list.size()) {
                std::cout << "key_map::draw_screen - FINISHED #1" << std::endl;
                finished = true;
            } else {
                graphLib.draw_text(config_text_pos.x, config_text_pos.y + _keys_list.size()*CURSOR_SPACING+CURSOR_SPACING*2, "PRESS NEW KEY/BUTTON"); //input code (number)
                draw_lib.update_screen();
                //format_v_2_1_1::st_key_config new_key = input.get_pressed_key();
                graphLib.clear_area(config_text_pos.x, config_text_pos.y + _keys_list.size()*CURSOR_SPACING+CURSOR_SPACING*2-1, 180,  CURSOR_SPACING+1, 0, 0, 0);
                ///@TODO - key_config[_pick_pos].key_type = new_key.key_type;
                ///@TODO - key_config[_pick_pos].key_number = new_key.key_number;
                redraw_line(_pick_pos);
                draw_lib.update_screen();
            }
        }
        if (input.p1_input[BTN_DOWN]) {
                soundManager.play_sfx(SFX_CURSOR);
                graphLib.eraseCursor(st_position(cursor_pos.x-CURSOR_SPACING, cursor_pos.y+(_pick_pos*CURSOR_SPACING)));
                _pick_pos++;
                if (_pick_pos >= (short)_keys_list.size()+1) {
                    _pick_pos = 0;
                }
                graphLib.drawCursor(st_position(cursor_pos.x-CURSOR_SPACING, cursor_pos.y+(_pick_pos*CURSOR_SPACING)));
        }
        if (input.p1_input[BTN_UP]) {
                soundManager.play_sfx(SFX_CURSOR);
                graphLib.eraseCursor(st_position(cursor_pos.x-CURSOR_SPACING, cursor_pos.y+(_pick_pos*CURSOR_SPACING)));
                _pick_pos--;
                if (_pick_pos < 0) {
                    _pick_pos = _keys_list.size();
                }
                graphLib.drawCursor(st_position(cursor_pos.x-CURSOR_SPACING, cursor_pos.y+(_pick_pos*CURSOR_SPACING)));
        }
        if (input.p1_input[BTN_QUIT]) {
            std::cout << "key_map::draw_screen - FINISHED #2" << std::endl;
            finished = true;
        }
        input.clean();
        input.waitTime(10);
        draw_lib.update_screen();
    }
}
Пример #15
0
void classboss::exec_daisiebot()
{
	unsigned short int shot_type = IA_STATE_SHOT_RAINBOW;

	std::cout << "classboss::exec_daisiebot" << std::endl;

	if (IA_state == IA_STATE_WAIT_TIME) {
		IA_state = IA_STAND;
	}

	// stand -> shot rainbow -> cross screen -> use flowers
	if (IA_state == IA_STAND) {
		IA_state = IA_STATE_CROSS_SCREEN;
		state.animation_type = ANIM_TYPE_WALK;
		return;
	}

	if (IA_state == IA_STATE_SHOT_RAINBOW) {
		state.animation_type = ANIM_TYPE_STAND;
		/// @TODO (use attacks/weapons system) shot_rainbow();
		IA_state = IA_STATE_CROSS_SCREEN;

		initial_position.x = position.x;
		initial_position.y = position.y;
		IA_state = IA_STATE_WAIT_TIME;
		state.move_timer = timer.getTimer()+300;
	}

	if (IA_state == IA_STATE_SHOT_FLOWER) {
		state.animation_type = ANIM_TYPE_STAND;
		/// @TODO (use attacks/weapons system) shot_flower(temp_npc);
		/// temp_npc->projectile.timer = getTimer()+60;
		initial_position.x = position.x;
		initial_position.y = position.y;
		IA_state = IA_STATE_WAIT_TIME;
		state.move_timer = timer.getTimer()+3000;
	}

	// TODO: move to generic npc, once more will use it
	if (IA_state == IA_STATE_CROSS_SCREEN) {
		// check if must stop/invert
		state.move_timer = timer.getTimer() + 10;
		if (state.direction == ANIM_DIRECTION_LEFT) {
			int map_tile_x = (position.x-move_speed)/16;
			int map_tile_y = position.y/16;
			if (distance.width < 18*TILESIZE && (position.x-move_speed > 0 && (map->getMapPointLock(st_position(map_tile_x, map_tile_y)) == 0 || map->getMapPointLock(st_position(map_tile_x, map_tile_y)) == TERRAIN_WATER))) {
				position.x-= move_speed;
				distance.width += move_speed;
			} else {
				distance.width = 0;
				invert_direction();
				if (shot_type == IA_STATE_SHOT_RAINBOW) {
					shot_type = IA_STATE_SHOT_FLOWER;
				} else {
					shot_type = IA_STATE_SHOT_RAINBOW;
				}
				IA_state = shot_type;
			}
		} else { // ANIM_RIGHT
			int map_tile_x = (position.x+frameSize.width+move_speed)/16;
			int map_tile_y = position.y/16;
			//map->getMapPointLock(st_position(map_tile_x, map_tile_y))
			if (distance.width < 18*TILESIZE && (map->getMapPointLock(st_position(map_tile_x, map_tile_y)) == 0 || map->getMapPointLock(st_position(map_tile_x, map_tile_y)) == TERRAIN_WATER)) {
				position.x+= move_speed;
				distance.width += move_speed;
			} else {
				distance.width = 0;
				invert_direction();
				IA_state = shot_type;
			}
		}
	}

}
Пример #16
0
void draw::show_teleport_small(int x, int y)
{
    graphLib.showSurfaceAt(&_teleport_small_gfx, st_position(x+_teleport_small_gfx.width/2, y+_teleport_small_gfx.height/2), false);
}
Пример #17
0
void class_config::use_tank(int tank_type)
{
	int n = 0;

    // check tank number
    if (tank_type == TANK_ENERGY && game_save.items.energy_tanks == 0) {
        return;
    }
    if (tank_type == TANK_WEAPON && game_save.items.weapon_tanks == 0) {
        return;
    }
    if (tank_type == TANK_SPECIAL && game_save.items.special_tanks == 0) {
        return;
    }

	// no need for tank usage
	if (tank_type == TANK_ENERGY && player_ref->get_hp().current == player_ref->get_hp().total) {
		return;
	}
	if (tank_type == TANK_ENERGY || tank_type == TANK_SPECIAL) {
		while (player_ref->get_hp().current < player_ref->get_hp().total) {
			player_ref->set_current_hp(1);
			if (n == 0 || n % 6 == 0) {
				soundManager.play_sfx(SFX_GOT_ENERGY);
			}
			n++;
			//graphLib.draw_horizontal_hp_bar(WPN_COLUMN_Y, 2, player_ref->get_hp().current);
			graphLib.draw_weapon_cursor(st_position(0, 0), player_ref->get_hp().current, -1);
            draw_lib.update_screen();
			input.waitTime(50);
		}
	}
	if (tank_type == TANK_SPECIAL || tank_type == TANK_WEAPON) {
		st_position weapon_pos(0, 0);
		for (int i=0; i<WEAPON_COUNT; i++) {
			n = 0;
			short unsigned int value = player_ref->get_weapon_value(i);
			if (value < player_ref->get_hp().total) {
				while (value < player_ref->get_hp().total) {
					value++;
					player_ref->set_weapon_value(i, value);
					if (n == 0 || n % 6 == 0) {
						soundManager.play_sfx(SFX_GOT_ENERGY);
					}
					n++;
					graphLib.draw_weapon_cursor(weapon_pos, player_ref->get_weapon_value(i), -1);
                    draw_lib.update_screen();
					input.waitTime(50);
				}
			}
			weapon_pos.y = weapon_pos.y+1;
			if (weapon_pos.y > 5) {
				weapon_pos.y = 1;
				weapon_pos.x = 1;
			}
		}
	}
    // consume tank
    if (tank_type == TANK_ENERGY) {
        game_save.items.energy_tanks--;
    }
    if (tank_type == TANK_WEAPON) {
        game_save.items.weapon_tanks--;
    }
    if (tank_type == TANK_SPECIAL) {
        game_save.items.special_tanks--;
    }
}
Пример #18
0
void draw::show_rain()
{
    if (rain_obj.gSurface == NULL) {
        // load rain
        std::string filename = FILEPATH + "/data/images/tilesets/rain.png";
        graphLib.surfaceFromFile(filename, &rain_obj);
    }
    for (int i=0; i<MAP_W; i++) {
        for (int j=0; j<MAP_H; j++) {
            graphLib.showSurfaceRegionAt(&rain_obj, st_rectangle(_rain_pos*TILESIZE, 0, TILESIZE, TILESIZE), st_position(i*TILESIZE, j*TILESIZE));
        }
    }
    if (timer.getTimer() > _rain_timer) {
        _rain_pos++;
        if (_rain_pos > 2) {
            _rain_pos = 0;
        }
        _rain_timer = timer.getTimer() + RAIN_DELAY;
    }
}
void classPlayer::attack(bool dont_update_colors)
{
    UNUSED(dont_update_colors);
	st_position proj_pos;

	if (selected_weapon == WEAPON_DEFAULT) {
		character::attack();
		return;
    } else if (game_save.items.weapons[selected_weapon] <= 0) {
		std::cout << "invalid weapon" << std::endl;
		return;
	}

	if (moveCommands.attack == 0 && attack_button_released == false) {
		attack_button_released = true;
		return;
	}

    int effect_type = is_executing_effect_weapon();
    int used_weapon = selected_weapon;
    if (effect_type == TRAJECTORY_FREEZE) { // freeze can shoot normal projectiles
        if (max_projectiles > get_projectile_count()) {
            //std::cout << "TRAJECTORY_FREEZE weapon detected!" << std::endl;
            character::attack(true);
        }
        return;
    } else if (effect_type != -1) {
        return;
    }
	if (max_projectiles <= get_projectile_count()) {
        std::cout << "attack - projectile limit reached - max_projectiles: " << max_projectiles << ", projectile_list.size(): " << projectile_list.size() << ", get_projectile_count(): " << get_projectile_count() << std::endl;
		return;
	}

	if (moveCommands.attack != 0 && (timer.getTimer()-state.attack_timer) > 100 && attack_button_released == true) {
		attack_button_released = false;
		if (state.direction == ANIM_DIRECTION_LEFT) {
            proj_pos = st_position(position.x, position.y+frameSize.height/2);
		} else {
            proj_pos = st_position(position.x+frameSize.width-TILESIZE*2, position.y+frameSize.height/2);
		}

        short int weapon_id = 0;


        if (used_weapon == WEAPON_ITEM_COIL) {
            add_coil_object();
        } else if (used_weapon == WEAPON_ITEM_JET) {
            add_jet_object();
        } else {
            weapon_id = used_weapon;
        }

		if (weapon_id == 0) { /// @TODO - this is a temporary exit to handle incomplete weapons
			return;
		}

        projectile_list.push_back(projectile(game_data.weapons[weapon_id].id_projectile, state.direction, proj_pos, map, is_player()));
        projectile &temp_proj = projectile_list.back();
        temp_proj.set_is_permanent();
        temp_proj.set_weapon_id(weapon_id);


        //std::cout << "weapon_id: " << weapon_id << ", projectile_id: " << game_data.weapons[weapon_id].id_projectile << std::endl;

        int weapon_trajectory = game_data.projectiles[game_data.weapons[weapon_id].id_projectile].trajectory;
        if (weapon_trajectory == TRAJECTORY_CENTERED) {
            temp_proj.set_owner_direction(&state.direction);
            temp_proj.set_owner_position(&position);
        } else if (weapon_trajectory == TRAJECTORY_FOLLOW) {
			classnpc* temp = find_nearest_npc();
			if (temp != NULL) {
                //std::cout << "PLAYER::attack - could not find target" << std::endl;
                temp_proj.set_target_position(temp->get_position_ref());
			}
		}

		//std::cout << "Added projectile - id: " << game_data.weapons[weapon_id].id_projectile << std::endl;

		if (selected_weapon != WEAPON_DEFAULT) {
            if (weapon_trajectory == TRAJECTORY_QUAKE) {
                game_save.items.weapons[selected_weapon] -= 4;
            } else if (weapon_trajectory == TRAJECTORY_FREEZE) {
                game_save.items.weapons[selected_weapon] -= 2;
            } else {
                game_save.items.weapons[selected_weapon]--;
            }

		}


		attack_state = ATTACK_START;
		state.attack_timer = timer.getTimer();
		if (state.animation_type == ANIM_TYPE_STAND) {
            set_animation_type(ANIM_TYPE_ATTACK);
		} else if (state.animation_type == ANIM_TYPE_JUMP) {
            set_animation_type(ANIM_TYPE_JUMP_ATTACK);
		} else if (state.animation_type == ANIM_TYPE_STAIRS || state.animation_type == ANIM_TYPE_STAIRS_SEMI || state.animation_type == ANIM_TYPE_STAIRS_MOVE) {
            set_animation_type(ANIM_TYPE_STAIRS_ATTACK);
		} else if (state.animation_type == ANIM_TYPE_WALK) {
            set_animation_type(ANIM_TYPE_WALK_ATTACK);
		}
	}
}
Пример #20
0
void sceneShow::show_animation(int n, int repeat_n, int repeat_mode)
{
    int frame_n = 0;
    CURRENT_FILE_FORMAT::file_scene_show_animation scene = animation_list.at(n);
    long frame_timer = timer.getTimer() + scene.frame_delay;
    long started_timer = timer.getTimer();
    int repeat_times = 0;

    graphicsLib_gSurface image;
    graphLib.surfaceFromFile(FILEPATH + "images/scenes/animations/" + scene.filename, &image);
    int max_frames = image.width / scene.frame_w;

    graphicsLib_gSurface bg_image;
    graphLib.initSurface(st_size(scene.frame_w, scene.frame_h), &bg_image);
    graphLib.copy_gamescreen_area(st_rectangle(scene.x, scene.y, scene.frame_w, scene.frame_h), st_position(0, 0), &bg_image);

    while (true) {

        std::cout << "sceneShow::show_animation::LOOP" << std::endl;

        //graphLib.showSurfaceAt(&bg_image, st_position(scene.x, scene.y), false);

        int x = frame_n*scene.frame_w;
        std::cout << "origin.x: " << x << ", dest.x: " << scene.x << ", frame.w: " << scene.frame_w << ", frame.h: " << scene.frame_h << std::endl;

        graphLib.showSurfaceRegionAt(&image, st_rectangle(x, 0, scene.frame_w, scene.frame_h), st_position(scene.x, scene.y));


        graphLib.updateScreen();

        if (frame_timer < timer.getTimer()) {
            frame_n++;
            if (frame_n > max_frames) {
                frame_n = 0;
                repeat_times++;
            }
            frame_timer = timer.getTimer() + scene.frame_delay;
        }

        // stop condition
        if (repeat_times > 0 && repeat_n <= 1) {
            std::cout << "sceneShow::show_animation::LEAVE#1" << std::endl;
            return;
        } else {
            if (repeat_mode == 0) { // time-mode
                if ((timer.getTimer() - started_timer) > repeat_n) {
                    std::cout << "sceneShow::show_animation::LEAVE#2" << std::endl;
                    return;
                }
            } else { // repeat number mode
                if (repeat_times > repeat_n) {
                    std::cout << "sceneShow::show_animation::LEAVE#3" << std::endl;
                    return;
                }
            }
        }
        timer.delay(10);
    }
}
Пример #21
0
void sceneShow::show_animation(int n, int repeat_n, int repeat_mode)
{
    int frame_n = 0;
    CURRENT_FILE_FORMAT::file_scene_show_animation scene = animation_list.at(n);
    long frame_timer = timer.getTimer() + scene.frame_delay;
    long started_timer = timer.getTimer();
    int repeat_times = 0;

    graphicsLib_gSurface image;
    graphLib.surfaceFromFile(FILEPATH + "images/scenes/animations/" + scene.filename, &image);
    int max_frames = image.width / scene.frame_w;

    graphicsLib_gSurface bg_image;
    graphLib.initSurface(st_size(scene.frame_w, scene.frame_h), &bg_image);
    graphLib.copy_gamescreen_area(st_rectangle(scene.x, scene.y, scene.frame_w, scene.frame_h), st_position(0, 0), &bg_image);


    std::cout << "max_frames[" << max_frames << "], image.w[" << image.width << "], scene.frame_w[" << scene.frame_w << "]" << std::endl;

    while (true) {
        input.read_input();
        int x = frame_n*scene.frame_w;


        // stop condition
        if (repeat_times > 0 && repeat_n <= 1) {
            std::cout << "sceneShow::show_animation::LEAVE#1" << std::endl;
            break;
        } else {
            if (repeat_mode == 0) { // time-mode
                if ((timer.getTimer() - started_timer) > repeat_n) {
                    std::cout << "sceneShow::show_animation::LEAVE#2" << std::endl;
                    break;
                }
            } else { // repeat number mode
                if (repeat_times > repeat_n) {
                    std::cout << "sceneShow::show_animation::LEAVE#3" << std::endl;
                    break;
                }
            }
        }
        graphLib.showSurfaceAt(&bg_image, st_position(scene.x, scene.y), false);
        std::cout << "x[" << x << "], img.w[" << image.width << "], frame.w[" << scene.frame_w << "]" << std::endl;
        graphLib.showSurfaceRegionAt(&image, st_rectangle(x, 0, scene.frame_w, scene.frame_h), st_position(scene.x, scene.y));
        graphLib.updateScreen();
        timer.delay(scene.frame_delay);


        if (frame_timer < timer.getTimer()) {
            frame_n++;
            if (frame_n >= max_frames) {
                frame_n = 0;
                repeat_times++;
            }
            frame_timer = timer.getTimer() + scene.frame_delay;
        }

    }
    // avoid leaving animation image trail if it is a repeating one
    if (repeat_n > 1) {
        graphLib.showSurfaceAt(&bg_image, st_position(scene.x, scene.y), false);
        graphLib.updateScreen();
        timer.delay(scene.frame_delay);
    }
}
void classPlayer::execute_projectiles()
{
    // animate projectiles
    vector<projectile>::iterator it;
    bool ignore_hit_timer = false;
    if (_simultaneous_shots > 1) {
        ignore_hit_timer = true;
    }

    for (it=projectile_list.begin(); it<projectile_list.end(); it++) {
        if ((*it).is_finished == true) {
            projectile_list.erase(it);
            break;
        }
        st_size moved = (*it).move();

        //std::cout << "projectile.move_type: " << (*it)->get_move_type() << std::endl;

        /// @TODO projectiles that are tele-guided
        if ((*it).get_move_type() == TRAJECTORY_CHAIN) {
            (*it).set_y(position.y+frameSize.height/2);
        } else if ((*it).get_move_type() == TRAJECTORY_QUAKE) {
            damage_ground_npcs();
            continue;
        }
        (*it).draw();
        if ((*it).is_reflected == true) {
            continue;
        }
        // check colision agains enemies
        std::vector<classnpc*>::iterator enemy_it;
        for (enemy_it=map->_npc_list.begin(); enemy_it != map->_npc_list.end(); enemy_it++) {
            if ((*it).is_finished == true) {
                projectile_list.erase(it);
                break;
            }
            if ((*enemy_it)->is_on_visible_screen() == false) {
                continue;
            }
            if ((*enemy_it)->is_dead() == true) {
                continue;
            }



            //classnpc* enemy = (*enemy_it);
            if ((*it).check_colision(st_rectangle((*enemy_it)->getPosition().x, (*enemy_it)->getPosition().y, (*enemy_it)->get_size().width, (*enemy_it)->get_size().height), st_position(moved.width, moved.height)) == true) {
                if ((*enemy_it)->is_shielded((*it).get_direction()) == true) { // shielded NPC -> reflects shot
                    if ((*it).get_trajectory() == TRAJECTORY_CHAIN) {
                        (*it).consume_projectile();
                    } else {
                        (*it).reflect();
                    }
                    continue;
                }
                if ((*enemy_it)->is_invisible() == true) { // invisible NPC -> ignore shot
                    continue;
                }





                // check if have hit area, and if hit it
                st_rectangle enemy_hit_area = (*enemy_it)->get_hit_area();
                st_size enemy_size = (*enemy_it)->get_size();
                enemy_hit_area.x += (*enemy_it)->getPosition().x-1;
                enemy_hit_area.y += (*enemy_it)->getPosition().y;

                //std::cout << ">> PLAYER::execute_projectiles[" << (*enemy_it)->getName() << "] - npc.h: " << enemy_size.height << ", hit_area.h: " << enemy_hit_area.h << std::endl;
                if (enemy_hit_area.w != enemy_size.width || enemy_hit_area.h != enemy_size.height) {
                    //std::cout << ">> PLAYER::execute_projectiles[" << (*enemy_it)->getName() << "] - use hit_area" << std::endl;
                    if ((*it).check_colision(enemy_hit_area, st_position(moved.width, moved.height)) == false) { // hit body, but not the hit area -> reflect
                        //std::cout << ">> PLAYER::execute_projectiles[" << (*enemy_it)->getName() << "]Projectile missed - enemy_hit_area.w: " << enemy_hit_area.w << ", enemy_hit_area.h: " << enemy_hit_area.h << std::endl;
                        (*it).consume_projectile();
                        continue;
                    }
                //} else {
                    //std::cout << ">> PLAYER::execute_projectiles[" << (*enemy_it)->getName() << "] - DONT use hit_area" << std::endl;
                }

                short wpn_id = (*it).get_weapon_id();

                //std::cout << "******* wpn_id: " << wpn_id << std::endl;
                if (wpn_id < 0) {
                    wpn_id = 0;
                }

                //std::cout << ">> player weapon damage #1" << std::endl;
                //std::cout << "******* (*enemy_it)->is_using_circle_weapon(): " << (*enemy_it)->is_using_circle_weapon() << ", (*it)->get_trajectory(): " << (*it)->get_trajectory() << ", TRAJECTORY_CHAIN: " << TRAJECTORY_CHAIN << std::endl;
                // NPC using cicrcle weapon, is only be destroyed by CHAIN, but NPC won't take damage
                if ((*enemy_it)->is_using_circle_weapon() == true ) {
                    if ((*it).get_trajectory() == TRAJECTORY_CHAIN) {
                        //std::cout << "PLAYER projectile hit NPC centered-weapon" << std::endl;
                        (*enemy_it)->consume_projectile();
                    }
                    (*it).consume_projectile();
                    return;
                }

                if ((*it).get_damage() > 0) {
                    int multiplier = game_data.game_npcs[(*enemy_it)->get_number()].weakness[wpn_id].damage_multiplier;
                    if (multiplier <= 0) {
                        multiplier = 1;
                    }
                    (*enemy_it)->damage((*it).get_damage() * multiplier, ignore_hit_timer);
                }
                if ((*it).get_damage() > 0) {
                    (*it).consume_projectile();
                    soundManager.play_sfx(SFX_NPC_HIT);
                }
            }
        }
    }
}