Пример #1
0
void CEffectsGame::DoPicking()
{
	bool hit = false;
	Vector3 tileHitPos;
	SMapTile *tileHit;
	Vector3 start = pCamera->GetWorldPosition();
	Vector3 end = start + pCamera->forward * 1000.0f;
	Vector3 pos;

	pLevel->UnHighlightTile();

	// find tile we are pointing at
	if (hit = pLevel->CastRay(start, end, OUT tileHitPos, OUT &tileHit, OUT &pos))
	{
		pLevel->HighlightTile(tileHitPos.x, tileHitPos.y, tileHitPos.z);		
	}

	static float force = 10;
	if (gInput.WasKeyPressed(K_PGUP)) force += 5.0f;
	if (gInput.WasKeyPressed(K_PGDN)) force -= 5.0f;
	//gVGUI.AddTextMessage(300,200,WHITE,"Force: %f",force);

	//car->pBarrel->DrawAxis();

	// shooting - delete tile
	if (gInput.IsKeydown(K_MOUSE1))
	{
		static float delay = 0;
		delay += frametime;
		if (delay > 0.05f)
		{
			
			// shoot a bullet
			CreateBullet(car->pBarrel->GetWorldPosition(), car->pBarrel->up);

			float puffSpeed = 0.35;

			// add puff effect
			for (int i = 0; i<3; i++)
			{					
				static CTexture *puffTex = new CTexture("particles/explosion4.dds");
				CParticle *p = new CParticle(puffTex);
				p->size = Vector2(0.15, 0.15);
				p->position = car->pBarrel->GetWorldPosition() + car->pBarrel->up/2;
				p->velocity = Vector3( frand(-puffSpeed,puffSpeed), frand(-puffSpeed,puffSpeed)+1, frand(-puffSpeed,puffSpeed) );
				//p->gravity = -10;
				p->lifetime = 0.25;
				p->color = SRGBA(255,255,255,50);
				p->sizeVel = Vector2(1,1);
				p->colorChange = SRGBA(255,255,255,0);
				particles->Add(p);
			}

			// add muzzle flash
			static CTexture *muzzleTex[] = {
				new CTexture("particles/flame1.dds"),
				new CTexture("particles/explosion1.dds")				
			};
		
			{
				CParticle *p = new CParticle(muzzleTex[rand()%2]);
				p->size = Vector2(0.7, 0.7);
				p->position = car->pBarrel->GetWorldPosition() + car->pBarrel->up/2;								
				p->lifetime = 0.01;
				p->additive = true;
				//p->color = SRGBA(255,255,255,50);
				//p->sizeVel = Vector2(1,1);
				//p->colorChange = SRGBA(255,255,255,0);
				particles->Add(p);
			}

			
			delay = 0;

			// if hit a tile, destroy it
	/*		if (hit)
			{
				EnterCriticalSection(&renderCS);
				tileHit->type = 0;
				LeaveCriticalSection(&renderCS);

				SMapChunk *chunk = pLevel->GetChunk(
					floor(tileHitPos.x/SMapChunk::Size),
					floor(tileHitPos.y/SMapChunk::Size),
					floor(tileHitPos.z/SMapChunk::Size) );

				chunk->dirtyBody = true;
				chunk->dirty = true;

				//pLevel->UpdateTile(tileHitPos.x, tileHitPos.y, tileHitPos.z);

				SSpawnTile s;
				s.pos = tileHitPos;
				s.vel = pCamera->forward * force;
				boxesToSpawn.push(s);
			
				// create a physical entity in this place
				/*NewtonBody *box = AddBox(pScene, pWorld, tileHitPos+Vector3(0.5, 0.5, 0.5), Vector3(0.95f,0.95f,0.95f), Vector3(), 100);

				// add some velocity
				Vector3 vel = pCamera->forward * force;
				Vector3 pos;
				NewtonBodySetVelocity(box, &vel[0]);*/				
		//	}
		}
	}

	static float lastRocketFire = -100;

	if (gInput.WasKeyPressed(K_MOUSE2) )
	{
		float r = 3;
		int x = tileHitPos.x;
		int y = tileHitPos.y;
		int z = tileHitPos.z;

		if (lastRocketFire + 0 < realtime)
		{
			Debug("Create rocket!");
			lastRocketFire = realtime;

			if (!hit)
			{
				CreateRocket(car->pBarrel->GetWorldPosition() + car->pBarrel->up/2, car->pBarrel->up);
			}
			else
			{
				Vector3 dir = (p os-(car->pBarrel->GetWorldPosition() + Vector3(0,10,0))).Normalize();
				if (dir.y < -0.25) 
				{
					dir.y = -0.25;
					dir.Normalize();
				}
				CreateRocket(car->pBarrel->GetWorldPosition() + car->pBarrel->up/2, dir );
			}
			
		}
	
	}


	// show car meshes
	if (car)
	{
		CArray<CObject3D*> meshes;
		GetMeshesList(car, meshes);

		float minT = 99999.0f;

		static int current = 0;
		if (KeyPressed(']')) { meshes[current]->color = WHITE; current++; if (current == meshes.Size()) current = 0; meshes[current]->color = RED;  }
		if (KeyPressed('[')) { meshes[current]->color = WHITE; current--; if (current < 0) current = meshes.Size()-1; meshes[current]->color = RED; }
		//gVGUI.AddTextMessage(200,90,YELLOW,"%d",current);

		car->aimTarget = end;
	}
}
Пример #2
0
void Gamestate_Logic(struct Game *game, struct RocketsResources* data) {

	  if ((data->spawncounter == data->currentspawn) && ((data->counter < data->timelimit) || (data->lost))) {
			  if (rand() % 2 == 0) {
					  data->rockets_left = CreateRocket(game, data, data->rockets_left, false);
				} else {
					  data->rockets_right = CreateRocket(game, data, data->rockets_right, true);
				}
				data->spawncounter = 0;
		}

		if (!data->flash) {
			  UpdateRockets(game, data, data->rockets_left);
				UpdateRockets(game, data, data->rockets_right);
		} else {
			  data->flash--;
		}

		if (data->lost) {
			  data->zadyma++;
				if (data->zadyma >= 255) {
					  data->zadyma = 255;
				}
		}

		AnimateCharacter(game, data->usa_flag, 1);
		AnimateCharacter(game, data->ru_flag, 1);
		AnimateCharacter(game, data->riot, 1);
		if ((data->lost) && (data->hearts > 80)) {
			  AnimateCharacter(game, game->data->mediator.heart, 1);
				if (game->data->mediator.heart->pos == 6) {
					  al_play_sample_instance(data->boom_sound);
				}
		}

		if (data->lost) {
			  data->hearts++;
		}

		if (data->won) {
			  AnimateCharacter(game, data->euro, 1);
		}

		if ((data->counter >= data->timelimit) && (!data->lost) && (!data->won)) {
			  bool stillthere = false;
				struct Rocket *tmp = data->rockets_left;
				while (tmp) {
					  if (!tmp->blown) {
							  stillthere = true;
								break;
						}
						tmp = tmp->next;
				}
				tmp = data->rockets_right;
				while (tmp) {
					  if (!tmp->blown) {
							  stillthere = true;
								break;
						}
						tmp = tmp->next;
				}
				if (!stillthere) {
					  SelectSpritesheet(game, data->euro, "euro");
						SetCharacterPosition(game, data->euro, 0, 0, 0);
						al_play_sample_instance(data->wuwu_sound);
						data->won = true;
						AdvanceLevel(game, true);
						SelectSpritesheet(game, data->usa_flag, "poland");
						SelectSpritesheet(game, data->ru_flag, "poland");
						TM_AddDelay(data->timeline, 2500);
						TM_AddAction(data->timeline, switchMinigame, NULL, "switchMinigame");
				}
		}


		void iterate(struct Rocket *start) {
			  struct Rocket *tmp1 = start;
				while (tmp1) {
					  if (!tmp1->blown) {
							//  if (CheckCollision(game, data, data->cursor, tmp1->character)) {

							  if ( (abs(GetCharacterY(game, tmp1->character) - GetCharacterY(game, data->cursor)) <= 10) &&
								     (((GetCharacterX(game, tmp1->character) <= GetCharacterX(game, data->cursor) + al_get_bitmap_width(data->cursor->bitmap)) && (GetCharacterX(game, tmp1->character) + al_get_bitmap_width(tmp1->character->bitmap) >= GetCharacterX(game, data->cursor) + al_get_bitmap_width(data->cursor->bitmap)))  ||

								     ((GetCharacterX(game, tmp1->character) + al_get_bitmap_width(tmp1->character->bitmap) >= GetCharacterX(game, data->cursor)) && (GetCharacterX(game, tmp1->character) + al_get_bitmap_width(tmp1->character->bitmap) <= GetCharacterX(game, data->cursor) + al_get_bitmap_width(data->cursor->bitmap))) )) {

									  if (GetCharacterY(game, tmp1->character) < GetCharacterY(game, data->cursor)) {
											  tmp1->dx = 0;
												tmp1->dy = 0;
												tmp1->modifier = 0;
												tmp1->blown = true;
												SelectSpritesheet(game, tmp1->character, "blank");
										} else if (tmp1->dy < 0) {
											  tmp1->dy *= -1;
										}

										al_play_sample_instance(data->rocket_sound);

								}

						}
						tmp1 = tmp1->next;
				}

		}
		iterate(data->rockets_left);
		iterate(data->rockets_right);

		data->counter++;
		data->spawncounter++;
		data->cloud_rotation += 0.002;

		TM_Process(data->timeline);
}