本文整理汇总了C++中TileGraphic::get_width方法的典型用法代码示例。如果您正苦于以下问题:C++ TileGraphic::get_width方法的具体用法?C++ TileGraphic::get_width怎么用?C++ TileGraphic::get_width使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TileGraphic
的用法示例。
在下文中一共展示了TileGraphic::get_width方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: add_npc_remove_animation
void Tournament::add_npc_remove_animation(SpawnableNPC *npc) {
const std::string& animation_name = npc->npc->get_value("kill_animation");
const std::string& sound_name = npc->npc->get_value("kill_sound");
if (animation_name.length()) {
try {
Animation *ani = resources.get_animation(animation_name);
TileGraphic *tg = npc->npc->get_tile(DirectionLeft, NPCAnimationStanding)->get_tilegraphic();
int width = tg->get_width();
int height = tg->get_height();
GAnimation *sgani = new GAnimation;
memset(sgani, 0, GAnimationLen);
strncpy(sgani->animation_name, ani->get_name().c_str(), NameLength - 1);
strncpy(sgani->sound_name, sound_name.c_str(), NameLength - 1);
sgani->id = npc->state.id;
sgani->duration = ani->get_duration();
TileGraphic *anitg = ani->get_tile()->get_tilegraphic();
sgani->x = npc->state.x + width / 2 - anitg->get_width() / 2;
sgani->y = npc->state.y - height / 2 - anitg->get_height() / 2;
sgani->accel_x = 0.0f;
sgani->accel_y = 0.0f;
sgani->to_net();
add_state_response(GPCAddAnimation, GAnimationLen, sgani);
} catch (const Exception& e) {
subsystem << e.what() << std::endl;
}
}
}
示例2: spawn_object
void Tournament::spawn_object(Object *obj, identifier_t id, int x, int y, flags_t flags) {
GameObject *nobj = new GameObject;
nobj->object = obj;
nobj->origin_x = x;
nobj->origin_y = y;
nobj->state.id = id;
nobj->state.accel_x = 0.0f;
nobj->state.accel_y = 0.0f;
nobj->state.x = static_cast<double>(x);
nobj->state.y = static_cast<double>(y);
nobj->spawned_object = true;
game_objects.push_back(nobj);
if (!server) {
if (flags & PlaceObjectWithAnimation) {
const std::string& spawn_animation = obj->get_value("spawn_animation");
if (spawn_animation.length()) {
TileGraphic *tg = obj->get_tile()->get_tilegraphic();
add_animation(spawn_animation, 0, 0, 0, x, y, 0.0f, 0.0f,
tg->get_width(), tg->get_height());
}
}
if (flags & PlaceObjectWithSpawnSound) {
const std::string& sound_name = obj->get_value("spawn_sound");
if (sound_name.length()) {
Sound *sound = resources.get_sound(sound_name);
subsystem.play_sound(sound, 0);
}
}
}
}
示例3: player_dies
void Tournament::player_dies(Player *p, const std::string& die_message) {
player_died(p);
p->state.server_state.health = 0;
p->state.server_state.flags |= PlayerServerFlagDead;
p->state.server_state.kills++;
if (die_message.length()) {
add_msg_response(die_message.c_str());
}
try {
Animation *tempani = resources.get_animation(properties.get_value("die_animation"));
GAnimation *ani = new GAnimation;
memset(ani, 0, sizeof(GAnimation));
strncpy(ani->animation_name, tempani->get_name().c_str(), NameLength - 1);
strncpy(ani->sound_name, properties.get_value("die_sound").c_str(), NameLength - 1);
TileGraphic *tg = p->get_characterset()->get_tile(DirectionLeft, CharacterAnimationStanding)->get_tilegraphic();
TileGraphic *tga = tempani->get_tile()->get_tilegraphic();
int x = static_cast<int>(p->state.client_server_state.x) + tg->get_width() / 2 - tga->get_width() / 2;
int y = static_cast<int>(p->state.client_server_state.y) - tg->get_height() / 2 - tga->get_height() / 2;
ani->id = ++animation_id;
ani->x = x;
ani->y = y;
ani->to_net();
add_state_response(GPCAddAnimation, sizeof(GAnimation), ani);
} catch (const Exception& e) {
subsystem << e.what() << std::endl;
}
}
示例4: add_pick_object
void Tournament::add_pick_object(GPickObject *po) {
for (GameObjects::iterator it = game_objects.begin();
it != game_objects.end(); it++)
{
GameObject *obj = *it;
if (obj->state.id == po->id) {
obj->picked = true;
obj->delete_me = obj->object->is_spawnable();
const std::string& pickup_animation = obj->object->get_value("pickup_animation");
if (pickup_animation.length()) {
TileGraphic *tg = obj->object->get_tile()->get_tilegraphic();
add_animation(pickup_animation, 0, 0, 0, static_cast<int>(obj->state.x),
static_cast<int>(obj->state.y), 0.0f, 0.0f, tg->get_width(), tg->get_height());
}
if (!server) {
const std::string& pickup_sound = obj->object->get_value("pickup_sound");
if (pickup_sound.length()) {
Sound *sound = resources.get_sound(pickup_sound);
subsystem.play_sound(sound, 0);
}
}
break;
}
}
/* delete marked objects */
game_objects.erase(std::remove_if(game_objects.begin(),
game_objects.end(), erase_element<GameObject>),
game_objects.end());
}
示例5: add_animation
void Tournament::add_animation(const std::string& name, identifier_t id,
scounter_t duration, identifier_t owner, int x, int y,
double accel_x, double accel_y, int width, int height)
{
GameAnimation *gani = 0;
try {
Animation *ani = resources.get_animation(name);
TileGraphic *tg = ani->get_tile()->get_tilegraphic();
gani = new GameAnimation;
gani->animation = ani;
gani->state.id = id; /* client side generated are 0 */
gani->state.duration = duration;
gani->state.owner = owner;
gani->state.x = x + width / 2 - tg->get_width() / 2;
gani->state.y = y + height / 2 - tg->get_height() / 2;
gani->state.accel_x = accel_x;
gani->state.accel_y = accel_y;
game_animations.push_back(gani);
if (!server) {
subsystem.play_sound(ani->get_sound(), ani->get_sound_loops());
}
} catch (const ResourcesException& e) {
if (gani) delete gani;
subsystem << "creating animation failed: " << e.what() << std::endl;
}
}
示例6: add_player_spawn_animation
void Tournament::add_player_spawn_animation(Player *p) {
const std::string& spawn_animation = p->get_characterset()->get_value("spawn_animation");
if (spawn_animation.length()) {
Animation *ani = resources.get_animation(spawn_animation);
TileGraphic *tg = ani->get_tile()->get_tilegraphic();
int x = static_cast<int>(p->state.client_server_state.x);
int y = static_cast<int>(p->state.client_server_state.y) - p->get_characterset()->get_height();
add_animation(spawn_animation, 0, 0, 0, x, y, 0.0f, 0.0f, tg->get_width(), tg->get_height());
subsystem.play_sound(resources.get_sound("respawn"), 0);
}
}
示例7: add_place_object
void Tournament::add_place_object(GPlaceObject *po) {
for (GameObjects::iterator it = game_objects.begin();
it != game_objects.end(); it++)
{
GameObject *obj = *it;
if (obj->state.id == po->id) {
obj->picked = false;
obj->state.x = po->x;
obj->state.y = po->y;
if (po->flags & PlaceObjectWithAnimation) {
const std::string& spawn_animation = obj->object->get_value("spawn_animation");
if (spawn_animation.length()) {
TileGraphic *tg = obj->object->get_tile()->get_tilegraphic();
add_animation(spawn_animation, 0, 0, 0, static_cast<int>(obj->state.x),
static_cast<int>(obj->state.y), 0.0f, 0.0f, tg->get_width(), tg->get_height());
}
}
if (po->flags & PlaceObjectResetVelocity) {
obj->state.accel_x = 0;
obj->state.accel_y = 0;
}
if (!server) {
if (po->flags & PlaceObjectWithSpawnSound) {
const std::string& sound_name = obj->object->get_value("spawn_sound");
if (sound_name.length()) {
Sound *sound = resources.get_sound(sound_name);
subsystem.play_sound(sound, 0);
}
}
if (po->flags & PlaceObjectWithScoredSound) {
const std::string& sound_name = obj->object->get_value("score_sound");
if (sound_name.length()) {
Sound *sound = resources.get_sound(sound_name);
subsystem.play_sound(sound, 0);
}
}
if (po->flags & PlaceObjectWithDropSound) {
const std::string& sound_name = obj->object->get_value("drop_sound");
if (sound_name.length()) {
Sound *sound = resources.get_sound(sound_name);
subsystem.play_sound(sound, 0);
}
}
}
break;
}
}
}
示例8: spawn_player_base
void Tournament::spawn_player_base(Player *p, SpawnPoints& spawn_points) {
// TODO: better selection of spawn points, maybe order by last spawn point usage
GameObject *obj = spawn_points[rand() % spawn_points.size()];
const CollisionBox& colbox = p->get_characterset()->get_colbox();
TileGraphic *tg = obj->object->get_tile()->get_tilegraphic();
int w = tg->get_width();
int h = tg->get_height();
int x = static_cast<int>(obj->state.x);
int y = static_cast<int>(obj->state.y);
x += w / 2;
y += h;
x = x - colbox.width / 2 - colbox.x;
p->spawn(x, y);
}
示例9: draw_team_colours
void TournamentTeam::draw_team_colours() {
for (Players::iterator it = players.begin(); it != players.end(); it++) {
Player *p = *it;
if (p->is_alive_and_playing()) {
/* draw team colours */
Tile *t = p->get_characterset()->get_tile(
static_cast<Direction>(p->state.client_server_state.direction),
static_cast<CharacterAnimation>(p->state.client_state.icon));
TileGraphic *tg = t->get_tilegraphic();
const int bar_width = 32;
const int bar_height = 4;
int x = static_cast<int>(p->state.client_server_state.x) + (tg->get_width() / 2) - (bar_width / 2);
int y = static_cast<int>(p->state.client_server_state.y) - (tg->get_height()) - bar_height + 2;
if (p->state.server_state.flags & PlayerServerFlagTeamRed) {
subsystem.set_color(1.0f, 0.0f, 0.0f, 1.0f);
} else {
subsystem.set_color(0.0f, 0.0f, 1.0f, 1.0f);
}
subsystem.draw_box(x + left, y + top, bar_width, bar_height);
subsystem.reset_color();
}
}
}
示例10:
GuiTextbox *OptionsMenu::create_field(GuiWindow *parent, int x, int y,
const std::string& text, GuiVirtualButton::OnClick on_click, bool erase_pic)
{
Icon *select = resources.get_icon("select");
TileGraphic *stg = select->get_tile()->get_tilegraphic();
int iw = stg->get_width();
int ih = stg->get_height();
gui.create_label(parent, x, y, text);
GuiTextbox *tb = gui.create_textbox(parent, x + 50, y, 80, "");
int tbh = tb->get_height();
if (!erase_pic) {
tb->set_locked(true);
GuiButton *btn = gui.create_button(parent, x + 129, y, tbh, tbh, "", on_click, this);
btn->show_bolts(false);
gui.create_picture(btn, tbh / 2 - iw / 2, tbh / 2 - ih / 2, stg);
} else {
tb->set_locked(false);
GuiButton *btn = gui.create_button(parent, x + 129, y, tbh, tbh, "...", on_click, this);
btn->show_bolts(false);
}
return tb;
}
示例11: update_npc_states
void Tournament::update_npc_states(double period_f) {
for (SpawnableNPCs::iterator it = spawnable_npcs.begin();
it != spawnable_npcs.end(); it++)
{
SpawnableNPC *npc = *it;
/* update physics */
TileGraphic *tg = npc->npc->get_tile(DirectionLeft, NPCAnimationStanding)->get_tilegraphic();
int width = tg->get_width();
int height = tg->get_height();
const CollisionBox& colbox = npc->npc->get_colbox();
bool killing = false;
double y = npc->state.y - height;
bool col = render_physics(period_f, false, 0, 0.0f, 0,
npc->npc->get_springiness_x(), 0.0f, colbox,
npc->state.x, y, npc->state.accel_x, npc->state.accel_y,
width, height, npc->npc->get_friction_factor(), false, npc->falling,
npc->last_falling_y_pos, &killing, npc->npc->get_name());
npc->state.y = y + height;
/* update ownership */
if (server && npc->init_owner) {
npc->ignore_owner_counter -= period_f;
if (npc->ignore_owner_counter <= 0.0f) {
npc->init_owner = 0;
}
}
/* update motion */
Sound *idle_sound = 0;
if (!npc->in_idle) {
npc->move_counter -= period_f;
if (npc->move_counter <= 0.0f) {
npc->move_counter = static_cast<double>(npc->npc->get_move_init_randomized());
int action = rand() % 5;
switch (action) {
case 0:
case 1:
{
/* jump */
if (server) {
if (!npc->falling) {
npc->state.accel_y = -npc->npc->get_jump_y_impulse_randomized();
npc->state.accel_x = npc->npc->get_jump_x_impulse_randomized() *
(static_cast<Direction>(npc->state.direction) == DirectionLeft ? -1 : 1);
}
}
break;
}
case 2:
{
/* change direction */
if (server && !col && !npc->falling) {
npc->state.direction = static_cast<unsigned char>(rand() % 2 ? DirectionLeft : DirectionRight);
}
break;
}
case 3:
{
/* idle 1 */
if (!server) {
npc->in_idle = true;
npc->idle_counter_init = npc->npc->get_idle1_counter();
npc->idle_counter = npc->idle_counter_init;
npc->icon = NPCAnimationIdle1;
npc->iconindex = 0;
const std::string& sound = npc->npc->get_value("idle1_sound");
if (sound.length()) {
try {
idle_sound = resources.get_sound(sound);
} catch (const Exception& e) {
subsystem << e.what() << std::endl;
}
}
}
break;
}
case 4:
{
/* idle 2 */
if (!server) {
npc->in_idle = true;
npc->idle_counter_init = npc->npc->get_idle2_counter();
npc->idle_counter = npc->idle_counter_init;
npc->icon = NPCAnimationIdle2;
npc->iconindex = 0;
const std::string& sound = npc->npc->get_value("idle2_sound");
if (sound.length()) {
try {
idle_sound = resources.get_sound(sound);
} catch (const Exception& e) {
subsystem << e.what() << std::endl;
}
//.........这里部分代码省略.........
示例12: integrate
void Tournament::integrate(ns_t ns) {
double period_f = ns / static_cast<double>(ns_fc);
/* show stats, if game is over? */
if (!game_state.seconds_remaining) {
if (!warmup) {
game_over = true;
show_statistics = true;
}
return;
}
/* update time counter */
if (server) {
second_counter += ns;
if (second_counter >= ns_sec) {
second_counter -= ns_sec;
if (game_state.seconds_remaining) {
game_state.seconds_remaining--;
if (!game_state.seconds_remaining) {
if (!warmup) {
add_state_response(GPCGameOver, 0, 0);
if (logger) {
logger->log(ServerLogger::LogTypeGameOver, "game over");
write_stats_in_server_log();
logger->log(ServerLogger::LogTypeEndOfStats, "end of stats");
}
}
}
}
}
}
/* update game objects -> respawning */
if (server) {
for (GameObjects::iterator it = game_objects.begin();
it != game_objects.end(); it++)
{
GameObject *obj = *it;
int spawn_time = obj->object->get_spawning_time();
if (obj->picked && spawn_time) {
obj->spawn_counter += period_f;
if (obj->spawn_counter >= spawn_time) {
obj->picked = false;
obj->spawn_counter = 0.0f;
GPlaceObject *gpo = new GPlaceObject;
gpo->id = obj->state.id;
gpo->flags = PlaceObjectWithAnimation | PlaceObjectWithSpawnSound;
gpo->x = static_cast<pos_t>(obj->state.x);
gpo->y = static_cast<pos_t>(obj->state.y);
gpo->to_net();
add_state_response(GPCPlaceObject, GPlaceObjectLen, gpo);
}
}
}
}
/* update typing animation */
player_afk_counter += period_f * AnimationMultiplier;
if (player_afk_counter > player_afk->get_animation_speed()) {
player_afk_counter = 0.0f;
player_afk_index = player_afk_index + 1;
if (player_afk_index >= player_afk->get_tile()->get_tilegraphic()->get_tile_count()) {
player_afk_index = 0;
}
}
/* update animation states and its physics */
for (GameAnimations::iterator it = game_animations.begin();
it != game_animations.end(); it++)
{
GameAnimation *gani = *it;
gani->animation_counter += period_f * AnimationMultiplier;
double speed = static_cast<double>(gani->animation->get_animation_speed());
bool finished = false;
if (gani->animation_counter > speed) {
TileGraphic *tg = gani->animation->get_tile()->get_tilegraphic();
gani->animation_counter = 0.0f;
gani->index++;
if (gani->index >= static_cast<int>(tg->get_tile_count())) {
if (gani->state.duration) {
gani->state.duration--;
if (!gani->state.duration) {
finished = true;
}
} else {
finished = true;
}
}
}
if (gani->animation->get_physics()) {
TileGraphic *tg = gani->animation->get_tile()->get_tilegraphic();
int width = tg->get_width();
int height = tg->get_height();
double springiness = gani->animation->get_springiness();
bool projectile = gani->animation->is_projectile();
double recoil = gani->animation->get_recoil();
//.........这里部分代码省略.........