本文整理汇总了C++中player::get_center方法的典型用法代码示例。如果您正苦于以下问题:C++ player::get_center方法的具体用法?C++ player::get_center怎么用?C++ player::get_center使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类player
的用法示例。
在下文中一共展示了player::get_center方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: move
void move(const player &player, bullets_type &bullets) override
{
auto now = std::chrono::system_clock::now();
auto v = player.get_center() - get_center();
auto rad = std::atan2(v.y, v.x);
set_vector(transform::rotation(rad) * vector(3.f, 0.f));
character::move();
if(std::chrono::duration_cast<std::chrono::milliseconds>(now - time).count() >= 500){
time = now;
bullets.push_back(new bullet(holder));
auto &b = bullets.back();
b->set_position(get_center());
b->set_vector(transform::rotation(rad) * vector(static_cast<float>(rand() % 4 + 3), 0.f));
}
}
示例2:
shooting(main_window *w):
window(*w),
config(keyconfig::get_instance()),
holder(std::make_shared<resource_holder>()),
player_(holder)
{
register_resource(holder.get());
register_object(&dialog);
dialog.set_button_text(0, L"はい");
dialog.set_button_handler(0, [this](){
this->dialog.hide();
on_hide();
on_show();
});
dialog.set_button_text(1, L"いいえ");
dialog.set_button_handler(1, [this](){
this->dialog.hide();
this->window.select_scene(main_window::scene::title);
});
dialog.set_size(paint::size(300, 200));
dialog.set_position(paint::point(250, 200));
add_keyboard_handler([this](unsigned keycode, bool push){
config->set_keyboard_state(keycode, push);
}, keycode_range(0, 255));
add_timer_handler([this](...){
if(pause)
return;
auto state = config->get_state();
vector v;
const float velocity = 7.f;
if(state.up){
v[1][0] -= velocity;
}
if(state.down){
v[1][0] += velocity;
}
if(state.left){
v[0][0] -= velocity;
}
if(state.right){
v[0][0] += velocity;
}
player_.set_vector(v);
auto now = std::chrono::system_clock::now();
if(state.b && now - bullet_time >= std::chrono::milliseconds(192)){
auto it = std::find(bullets.begin(), bullets.end(), false);
if(it != bullets.end()){
float r = it->get_radius();
it->set_position(player_.get_center());
it->set_vector(vector(0, -10));
it->set_active();
auto trans = transform::scale(1.f, 1.01f);
if(state.a){
trans = transform::rotation(to_rad(-0.5)) * trans;
}
if(state.c){
trans = transform::rotation(to_rad(0.5)) * trans;
}
it->set_transform(trans);
}
bullet_time = now;
}
if(now - enemy_time >= enemy_duration){
enemy_duration = std::chrono::milliseconds(this->rand() % 750 + 250);
enemy_time = now;
enemies.push_back(new enemy1(holder));
enemies.back()->set_position(paint::point(static_cast<float>(this->rand() % 800), -50));
}
move();
this->window.repaint();
}, timer_id);
}