Beispiel #1
0
		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));
			}
		}
Beispiel #2
0
	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);
	}