/*------------------------------------------------------------------------------
 * Function: bulletTask
 *
 * Description: This task polls the state of the button that fires a bullet
 *  every 10 milliseconds. If a bullet is fired, this task blocks for half a
 *  second to regulate the fire rate.  If a bullet is not fired, the task
 *  blocks for a frame delay (FRAME_DELAY_MS)
 *
 * param vParam: This parameter is not used.
 *----------------------------------------------------------------------------*/
void bulletTask(void *vParam) {
	 /* Note:
     * The ship heading is stored in ship.angle.
     * The ship's position is stored in ship.pos.x and ship.pos.y
     *
     * You will need to use the following code to add a new bullet:
     * bullets = createBullet(x, y, vx, vy, bullets);
     */
	// variable to hold ticks value of last task run
	//portTickType xLastWakeTime;
   
	// Initialize the xLastWakeTime variable with the current time.
	//xLastWakeTime = xTaskGetTickCount();
   uint8_t firebutton;
   uint8_t tank_num = (uint8_t) *vParam; 
   if(tank_num == 2)
      firebutton =
   while (1) {
      if(fire_button1 || fire_button2) {
         xSemaphoreTake(usartMutex, portMAX_DELAY);
         if(fire_button1) {
            fire_button1 = 0;
            //Make a new bullet and add to linked list
            bullets_ship1 = createBullet(
               ship1.pos.x,
               ship1.pos.y,
               -sin(ship1.angle*DEG_TO_RAD)*BULLET_VEL,
               -cos(ship1.angle*DEG_TO_RAD)*BULLET_VEL,
               SNES_P1,
               ship1.angle,
               bullets_ship1);
         }
         if(fire_button2) {
            fire_button2 = 0;
            //Make a new bullet and add to linked list
            bullets_ship2 = createBullet(
               ship2.pos.x,
               ship2.pos.y,
               -sin(ship2.angle*DEG_TO_RAD)*BULLET_VEL,
               -cos(ship2.angle*DEG_TO_RAD)*BULLET_VEL,
               SNES_P2,
               ship2.angle,
               bullets_ship2);
         }
         xSemaphoreGive(usartMutex);
         vTaskDelay(BULLET_DELAY_MS/portTICK_RATE_MS);
      }
      else
         vTaskDelay(FRAME_DELAY_MS / portTICK_RATE_MS);
   }
}
示例#2
0
Aircraft::Aircraft(Type type, const TextureHolder& textures, const FontHolder& fonts)
: Entity(Table[type].hitpoints)
, mType(type), mSprite(textures.get(Table[mType].texture), Table[mType].textRect),mHealthDisplay(nullptr)
, mTravelledDistance(0.f), mDirectionIndex(0), mIsFiring(false), mFireCountdown(sf::Time::Zero)
, mFireRateLevel(1), mFireCommand(), mSpreadLevel(1), mIsMarkedForRemoval(false)
, mMissileCommand(), mIsLaunchMissile(false), mMissileAmmo(2), mDropPickupCommand()
{
    if (!isAllied())
        mFireRateLevel = 0;
    centerOrigin(mSprite);
    
    std::unique_ptr<TextNode>   healthDisplay(new TextNode(fonts, ""));
    mHealthDisplay = healthDisplay.get();
    
    attachChild(std::move(healthDisplay));
    
    mFireCommand.category = Category::Scene;
    mFireCommand.action = [this, &textures](SceneNode& node, sf::Time)
    {
        createBullet(node, textures);
    };
    mMissileCommand.category = Category::Scene;
    mMissileCommand.action   = [this, &textures] (SceneNode& node, sf::Time)
    {
        createProjectile(node, Projectile::Missile, 0.f, 0.5f, textures);
    };
    
    mDropPickupCommand.category = Category::Scene;
    mDropPickupCommand.action   = [this, &textures] (SceneNode& node, sf::Time)
    {
        createPickup(node, textures);
    };
}
示例#3
0
void RoleShow::createBulletAtPos2(float dt)
{
	CCPoint createPoint = startPoint + ccp(5,5);
	float tx = endPoint.x + 5;
	float ty = endPoint.y + 5;

	createBullet(m_bulletType, createPoint, ccp(tx, ty));
}
示例#4
0
void GameLayer::onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event)
{
	Point location = touches[0]->getLocationInView();
	location = Director::getInstance()->convertToGL(location);
	
	if( location.x <= 300 )
	{
		cannon->shoot();
		createBullet();
	}
	else cannon->resetSoldiers();
}
示例#5
0
void Plane::addBullet(float dt)
{
	if (m_bulletType == BULLET) {
        auto pFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName("bullet1.png");
        Point pos(getPositionX(), getPositionY() + getContentSize().height * 0.5);
        float distance = Director::getInstance()->getWinSize().height + 100;
        Sprite *bullet = createBullet(pFrame, pos, distance);
		m_bullets->addChild(bullet);
	} else if (m_bulletType == DOUBLE_BULLET) {
        auto pFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName("bullet2.png");
        float sx = getPositionX(); float sy = getPositionY();
        Size content = getContentSize();

        Point pos(sx - content.width * 0.25, sy + content.height * 0.5);
        float distance = Director::getInstance()->getWinSize().height + 100;
        Sprite *bullet1 = createBullet(pFrame, pos, distance);
        m_bullets->addChild(bullet1);

        Point pos2(sx + content.width * 0.25, sy + content.height * 0.5);
        Sprite *bullet2 = createBullet(pFrame, pos2, distance);
        m_bullets->addChild(bullet2);
	}
}
示例#6
0
void GameEngine::Update(float dt)
{
    if (gameover)
        return;
    
    handleInput();
    
    // simulate physics
    m_world->Step(dt, 8, 3);
    
    // update entity
    bot.Update();

    // update game scenario
    elapsedTime = glutGet(GLUT_ELAPSED_TIME) - initializedTime;
    
    long additionalBullets = elapsedTime / 2000;
    
    if (m_bulletCount < MAX_BULLET_COUNT + additionalBullets) {
        createBullet();
    }
    
    typedef std::list<b2Body*> BodyList;
    BodyList::iterator end = m_bullets.end();
    for (BodyList::iterator it = m_bullets.begin(); it != end; ++it) {
        b2Body* bullet = *it;
        const b2Vec2& pos = bullet->GetPosition();
        if (pos.x < 0 || pos.x > m_stage.upperBound.x || pos.y < 0 || pos.y > m_stage.upperBound.y) {
            --m_bulletCount;
            m_bullets.erase(it);
            continue;
        }
    }
    
    if (bot.GetState() == BOT_STATE_DEAD) {
        // stop the world
        gameover = true;

#ifdef _WIN32
        PlaySound(TEXT("scifi011.wav"), NULL, SND_ASYNC);
#endif
    }
}
示例#7
0
Command* CommandSkill::create(SkillResult* result)
{
	if (result->skill.track == SKILL_TRACK_HACK)
	{
		return createHack(result);
	}
	else if (result->skill.track == SKILL_TRACK_BULLET)
	{
		return createBullet(result);
	}
	else if (result->skill.track == SKILL_TRACK_FIXXED)
	{
		return createFixed(result);
	}
	else if (result->skill.track == SKILL_TRACK_ARC)
	{
		return createArc(result);
	}
	return NULL;
}
//Fires a weapon from the @p unit.
//This hook affects the following iscript opcodes: attackwith, attack, castspell
//This also affects CUnit::fireWeapon().
void fireWeaponHook(CUnit *unit, u8 weaponId) {

  //Retrieve the spawning position for the bullet.
  s32 x, y;

  if (weapons_dat::Behavior[weaponId] == WeaponBehavior::AppearOnTargetUnit) {
    if (!unit->orderTarget.unit)
      return;

    getWeaponHitPos(unit, &x, &y);
  }

  else if (weapons_dat::Behavior[weaponId] == WeaponBehavior::AppearOnTargetSite) {
    x = unit->orderTarget.pt.x;
    y = unit->orderTarget.pt.y;
  }

  else {
    s32 forwardOffset = weapons_dat::ForwardOffset[weaponId];

    x = unit->getX()
        + (forwardOffset * angleDistance[unit->currentDirection1].x / 256);
    y = unit->getY()
        + (forwardOffset * angleDistance[unit->currentDirection1].y / 256)
        - weapons_dat::VerticalOffset[weaponId];
  }

  if (weapons_dat::FlingyId[weaponId]) {
    u8 bulletDirection = unit->currentDirection1;
    //Make Vultures and Lurkers always fire at the target direction
    if (weapons_dat::Behavior[weaponId] == WeaponBehavior::GoToMaxRange
        && unit->orderTarget.unit)
      bulletDirection = scbw::getAngle(
        unit->getX(), unit->getY(),
        unit->orderTarget.unit->getX(), unit->orderTarget.unit->getY());

    createBullet(weaponId, unit, x, y, unit->playerId, bulletDirection);
  }
}
示例#9
0
void Game::bulletLogic() {
	if (kbd.EnterIsPressed() && weaponChoice == BULLET && !keysPressedLastFrame){
		weaponChoice = MISSILE;
		keysPressedLastFrame = true;
	}

	else if (kbd.EnterIsPressed() && weaponChoice == MISSILE && !keysPressedLastFrame){
		weaponChoice = BULLET;
		keysPressedLastFrame = true;
	}

	if (mouse.LeftIsPressed() && weaponChoice == BULLET/*&& !keysPressedLastFrame*/) {
		if (frameCount % 8 == 0) //perfect for slowing bullets down
		createBullet(true);
		keysPressedLastFrame = true;
	}

	else if (weaponChoice == MISSILE/*&& !keysPressedLastFrame*/) {
		allLocking();
	}

	
	//if (!(mouse.LeftIsPressed())) keysPressedLastFrame = false;
	//if (!(kbd.EnterIsPressed())) keysPressedLastFrame = false;

	//movement and boundaries of bullets and animation
	for (int i = 0; i < AMOUNTOFVECTORS; i++) {
		for (int j = 0; j < arrayOfVectors[i].size(); j++) {
			arrayOfVectors[i].at(j).x += arrayOfVectors[i].at(j).vx;
			arrayOfVectors[i].at(j).y += arrayOfVectors[i].at(j).vy;
			arrayOfVectors[i].at(j).frameExposure++;
			if (arrayOfVectors[i].at(j).frameExposure > 4) {
				arrayOfVectors[i].at(j).frame++;
				if (arrayOfVectors[i].at(j).frame > 4) arrayOfVectors[i].at(j).frame = 0;
				arrayOfVectors[i].at(j).frameExposure = 0;
			}

			if (arrayOfVectors[i].at(j).y > LOWERBOUNDARY || arrayOfVectors[i].at(j).y < UPPERBOUNDARY || arrayOfVectors[i].at(j).x > RIGHTBOUNDARY || arrayOfVectors[i].at(j).x < LEFTBOUNDARY) {
				//FOR A MOTHERFUCKIN CLUSTERFUCK
				//arrayOfVectors[i].at(j).vx = arrayOfVectors[i].at(j).vx * - 1;
				//arrayOfVectors[i].at(j).vy = arrayOfVectors[i].at(j).vy * - 1;
				arrayOfVectors[i].erase(arrayOfVectors[i].begin() + j);
			}
		}
	}

	for (int a = 0; a < enemyBulletVector.size(); a++) {
		enemyBulletVector[a].x += enemyBulletVector[a].vx;
		enemyBulletVector[a].y += enemyBulletVector[a].vy;

		enemyBulletVector[a].frameExposure++;
		if (enemyBulletVector[a].frameExposure > 4) {
			enemyBulletVector[a].frame++;
			if (enemyBulletVector[a].frame > 4) enemyBulletVector[a].frame = 0;
			enemyBulletVector[a].frameExposure = 0;
		}

		if (enemyBulletVector[a].y > LOWERBOUNDARY || enemyBulletVector[a].y < UPPERBOUNDARY || enemyBulletVector[a].x > RIGHTBOUNDARY || enemyBulletVector[a].x < LEFTBOUNDARY)
		{
			enemyBulletVector.erase(enemyBulletVector.begin() + a);
		}
	}

	for (int j = 0; j < missileVector.size(); j++) {
		if (missileVector[j].target) findRotation(missileVector[j].x, missileVector[j].y, missileVector[j].target->x, missileVector[j].target->y, missileVector[j].rotation);
		else missileVector[j].target = NULL;
		//not needed should be done elsewhere instead of all the time
		missileVector[j].vx = cos(missileVector[j].rotation) * PLAYERMSSILESPEED;
		missileVector[j].vy = sin(missileVector[j].rotation) * PLAYERMSSILESPEED;

		missileVector[j].x += missileVector[j].vx;
		missileVector[j].y += missileVector[j].vy;

		if (missileVector[j].y > LOWERBOUNDARY || missileVector[j].y < UPPERBOUNDARY || missileVector[j].x > RIGHTBOUNDARY || missileVector[j].x < LEFTBOUNDARY) {
			missileVector[j].target = NULL;
			missileVector.erase(missileVector.begin() + j);
		}
	}
}
示例#10
0
void Game::updateEnemyShip1s() {
	//rotation, movement, boundaries, bullet and ship collision
	for (int i = 0; i < enemyShipFleet.size(); i++) {
		findRotation(enemyShipFleet[i].x, enemyShipFleet[i].y, playerShip.x, playerShip.y, enemyShipFleet[i].rotation);
		enemyShipFleet[i].x += enemyShipFleet[i].vx;
		enemyShipFleet[i].y += enemyShipFleet[i].vy;

		/*
		**************************************************************************************************************

		changes to try(change direction somehow if boundary hit) Talking about enemyship1 (which he is called from now on to avoid ambiguity with the insect with just enemyship itself):
		1. Make his y = x * x
		2. y = x * x * x, log(x) sqrt(x), sin(x) etc
		3. his y = cos(rotation) and x = y * y
		4. find circle formula (based on centre maybe)
		5. semi circle
		6. form function which takes distance close to player and works dynamic circle  which changes every frame if player moves. Then try semi circle. Work it maybe with angles, or maybe just come circumference follower
		7. Finally work some way finally after doing all that to make him avoid his fellow teammates ships which will be hard.
		Function that takes in x and y of every teammate within 200-400 pixels and moves in a direction away from them but towards you if possible. Have them go slow so they can easily plan in a group mentality kinda way?
		Maybe have them eventually just go fast and slow. They slow down when clsoe to an enemy ship and eventually move away. They maybe never get too close to an enemy ship because they slow down same with yours.
		8. And separate point as to how it will look if you do eventually collide off an enemy ship. Maybe just bounce off and lose health so player avoids hitting them then.
		9. make them go in a parade kinda way. or a big s towards you and instead of avoiding you maybe enemyship1s also eventually crash into you but take their time about it.
		left all the way then small or mediumu turn towards right
		*/

		if (enemyShipFleet[i].x + (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 > RIGHTBOUNDARY) enemyShipFleet[i].x = RIGHTBOUNDARY - (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2;
		else if (enemyShipFleet[i].x - (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 < LEFTBOUNDARY) enemyShipFleet[i].x = LEFTBOUNDARY + (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2;
		if (enemyShipFleet[i].y + (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 > LOWERBOUNDARY) {
			enemyShipFleet[i].y = LOWERBOUNDARY - (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2;
			enemyShipFleet[i].vy *= -1;
		}
		else if (enemyShipFleet[i].y - (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 < UPPERBOUNDARY) {
			enemyShipFleet[i].y = UPPERBOUNDARY + (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2;
			enemyShipFleet[i].vy *= -1;
		}
		if (enemyShipFleet[i].ifHit) {
			enemyShipFleet[i].framesSinceHit++;
			if (enemyShipFleet[i].framesSinceHit > FRAMESPERFLASH) {
				enemyShipFleet[i].framesSinceHit = 0;
				enemyShipFleet[i].ifHit = false;
			}
		}
	}

	for (int k = 0; k < enemyShipFleet.size(); k++) {
		for (int i = 0; i < AMOUNTOFVECTORS; i++) {
			for (int j = 0; j < arrayOfVectors[i].size(); j++) {
				if (arrayOfVectors[i].at(j).x > enemyShipFleet[k].x - (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 &&
					arrayOfVectors[i].at(j).x < enemyShipFleet[k].x + (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 &&
					arrayOfVectors[i].at(j).y > enemyShipFleet[k].y - (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 &&
					arrayOfVectors[i].at(j).y < enemyShipFleet[k].y + (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2) {
					arrayOfVectors[i].erase(arrayOfVectors[i].begin() + j);
					enemyShipFleet[k].lives -= BULLETDAMAGE;
					if (enemyShipFleet[k].lives <= 0) {
						createExplosion(explosion(), enemyShipFleet[k].x, enemyShipFleet[k].y, enemyShipFleet[k].rotation, 0.6f, rand() % 255, rand() % 255, rand() % 255);
						for (int a = 0; a < pShipTargets.size(); a++) {
							;//if (pShipTargets[a].ship == &enemyShipFleet[k]) pShipTargets.erase(pShipTargets.begin() + a);
						}			
						enemyShipFleet.erase(enemyShipFleet.begin() + k);
						totalEnemyShipKillsLevel++;
						break;
					}
					else {
						enemyShipFleet[k].ifHit = true;
						enemyShipFleet[k].framesSinceHit = 0;
					}
				}
			}
		}
	}

	for (int k = 0; k < enemyShipFleet.size(); k++) {
		for (int i = 0; i < missileVector.size(); i++) {
			if (missileVector[i].x > enemyShipFleet[k].x - (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 &&
				missileVector[i].x < enemyShipFleet[k].x + (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 &&
				missileVector[i].y > enemyShipFleet[k].y - (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 &&
				missileVector[i].y < enemyShipFleet[k].y + (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2) {
				missileVector[i].target = NULL;
				missileVector.erase(missileVector.begin() + i);
				enemyShipFleet[k].lives -= MISSILEDAMAGE;
				if (enemyShipFleet[k].lives <= 0) {
					createExplosion(explosion(), enemyShipFleet[k].x, enemyShipFleet[k].y, enemyShipFleet[k].rotation, 0.6f, 255, 255, 255);
					for (int a = 0; a < pShipTargets.size(); a++) {
						if (pShipTargets[a].ship == &enemyShipFleet[k]) {
							//pShipTargets[a].ship = NULL;
							//pShipTargets.erase(pShipTargets.begin() + a);
							noOfLockedOn--;
							break;
						}
					}
					//pShipTargets[k].ship = NULL;
					pShipTargets.erase(pShipTargets.begin() + k); //on the way to getting there. Fixes killing 1 guy and another green lock on showing hmm ///wont work with insects
					enemyShipFleet.erase(enemyShipFleet.begin() + k);
					for (int i = 0; i < pShipTargets.size(); i++) {
						pShipTargets[i].ship = &enemyShipFleet[i];
					}
					totalEnemyShipKillsLevel++;
					break;
				}
				else {
					enemyShipFleet[k].ifHit = true;
					enemyShipFleet[k].framesSinceHit = 0;
				}
			}
		}
	}

	if (frameCount % 60 == 0 && enemyShipFleet.size() > 0) createBullet(false);
}
void PlayerSwimmingState:: onFirePressed()
{
    if( pData -> verticalDir.isDown())
    {
        pData ->setiCurrentArray (PlayerData :: DIVEDOWN);
    }

    else if( pData -> verticalDir.isUp())
    {
        pData ->setiCurrentArray (PlayerData :: SWIMUP);
    }
    else
        pData ->setiCurrentArray (PlayerData :: DIVENFIRE);

    pData ->isFiring = true;
    pData ->count = 0;

    float bulletX;
    float bulletY;
    float angle;

    if(pData -> dir.isRight())
    {
        bulletX = pData -> ppTextureArrays[ pData ->iCurrentArr] ->getWidth() / 2 + pData -> x;
    }
    else
    {
        bulletX = -pData -> ppTextureArrays[ pData ->iCurrentArr] ->getWidth() / 2 + pData -> x;

    }

    if ( pData -> verticalDir.isUp())
    {
        bulletY = pData -> y - pData -> ppTextureArrays[ pData ->iCurrentArr] ->getHeight();
    }
    else if ( pData -> verticalDir.isNone())
    {
        bulletY = pData -> y - pData -> ppTextureArrays[ pData ->iCurrentArr] ->getHeight() / 2;
    }


    if(pData -> dir.isRight())
    {

        if ( pData -> verticalDir.isUp() )
        {
            angle = -M_PI_4;
        }
        else if (pData -> verticalDir.isNone())
        {
            angle = 0.0f;
        }
    }
    else
    {

        if ( pData -> verticalDir.isUp() )
        {
            angle = -M_PI_4 - M_PI_2;
        }
        else if (pData -> verticalDir.isNone())
        {
            angle = M_PI;
        }

    }


    if( !pData ->verticalDir.isDown())

        createBullet(bulletX, bulletY, angle );
}
示例#12
0
void RoleShow::addBullet(float dt)
{
	//startPoint = ccp(m_size.width*0.1,-m_size.height*0.2);
	endPoint = CCPointZero;

	int distance = 200;
	float x =cos(CC_DEGREES_TO_RADIANS(90-heroAngle)) * distance;
	float y = sin(CC_DEGREES_TO_RADIANS(90-heroAngle)) * distance;
	endPoint = ccp(x,y);

	distance=100;
	float sx =cos(CC_DEGREES_TO_RADIANS(90-heroAngle)) * distance;
	float sy = sin(CC_DEGREES_TO_RADIANS(90-heroAngle)) * distance;
	CCPoint gunPoint = zhujiaogun->getPosition();
	startPoint = ccp(sx+gunPoint.x, sy+gunPoint.y);

	if(m_currentHero == k_battle_ironmen)
	{
		m_ironmanBullet++;
		if(m_ironmanBullet < 1)
		{
			return;
		}
		m_ironmanBullet = 0;
		m_bulletType = M1014;

		createLaserBullet(startPoint);
		
		m_ironmanBulletTwo++;
		if(m_ironmanBulletTwo <4)
		{
			return;
		}
		m_ironmanBulletTwo = 0;

		createBullet(MG4, startPoint, endPoint);
		

	} else if(m_currentHero == k_battle_blackwidow)
	{
		m_blackBullet++;
		if(m_blackBullet < 3)
		{
			return;
		}
		m_blackBullet = 0;
		m_bulletType = VulcanM61;
		createBullet(m_bulletType, startPoint, endPoint);

	} else if(m_currentHero == k_battle_wolverine)
	{
		bulletSpeed = 5;
		m_bulletType = RPG_7;
		
		wolverineGunAnimation();

		scheduleOnce(schedule_selector(RoleShow::createBulletAtPos),0.08f);
		scheduleOnce(schedule_selector(RoleShow::createBulletAtPos2),0.16f);
		createBullet(m_bulletType, startPoint, endPoint);
	}
		
	//shoot(VulcanM61, startPoint, endPoint);
}
示例#13
0
int main(int argc, char* argv[]) {
    // Init
    initPath(argv[0]);
    SDL_Surface* screen = NULL;
    SDL_Event event;
    int *seed;
    srand((int)seed);
    int previousTime = 0, currentTime = 0;
    Events *flags = createEventFlags();

    SDL_Init(SDL_INIT_VIDEO);
    SDL_SetEventFilter(eventFilter);

    screen = SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_DOUBLEBUF | SDL_NOFRAME);
    SDL_WM_SetCaption("Tower Defense", NULL);
    Action *actionList = initAction();

    Map* map = createMap(getPath("resources/Forest.png"));
    _map = map;

    SDL_Rect surface = {0, 0, 720, 600};
    Viewport* viewport = createViewport(screen, surface, map);
    _viewport = viewport;

    // FIXME uh? what's this thing?
    surface.x = 800 - 80;
    surface.y = 0;
    surface.h = 80;
    surface.w = 600;

    // Creation of the enemies
    TypeEn *whiteCat = createTypeEn(100, 5, false, true, true, false, 1,getPath("resources/white_transparent_cat.png"));
    TypeEn *blackCat = createTypeEn(100, 5, false, true, true, false, 1,getPath("resources/black_transparent_cat.png"));
    Enemy *cat1 = createEnemy(1,1,whiteCat);
    Enemy *cat2 = createEnemy(1,10,whiteCat);
    Enemy  *cat3 = createEnemy(5,5,blackCat);
    Enemy *cat4 = createEnemy(21,4,blackCat);

    TypeEn *zombie = createTypeEn(100,5,false,true,true,false,1,getPath("resources/zombie.png"));
    Enemy *zombie1 = createEnemy(4,4,zombie);
    Enemy *zombie2 = createEnemy(9,4,zombie);
    Enemy *zombie3 = createEnemy(9,9,zombie);
    Enemy *zombie4 = createEnemy(7,14,zombie);

    //Add enemy in the List
    List *catList = newList(cat4);
    pushList((void*)catList,cat2);
    pushList((void*)catList,cat3);
//   pushList((void*)catList,cat1);

    List *zombieList = newList(zombie1);
    /*   pushList((void*)zombieList,zombie2);*/
    /*   pushList((void*)zombieList,zombie3);*/
    /*   pushList((void*)zombieList,zombie4);*/

//   removeEnemyFromList(cat4,catList);

    //TOWER
    TypeBul *bullet = createTypeBul(getPath("resources/bullet.png"), 1);
    TypeTo *tower = createTypeTo(0,5,0,0,false,false,false,false,bullet,NULL,getPath("resources/tower.png"));
    upgradeTypeTo(tower,0.5,getPath("resources/towerUP.png"));
    flags->selectedTower = tower->nextType;
    Tower *tower1 = createTower(7,7,tower);

    List *towerList = newList(tower1);
    flags->towerList = towerList;

    // Create and Renders the right panel game menu
    SDL_Rect surfaceMenu = {720, 0, 800, 600};
    Menu* menu = menu_create(screen, surfaceMenu);
    menu_loadBackground(menu, "resources/enemyFont.gif");
    // For testing only, we add a few random buttons
    menu_addButton(menu, button_createBuildButton(tower));
    menu_addButton(menu, button_createBuildButton(tower));
    menu_addButton(menu, button_createBuildButton(tower));
    menu_render(menu);


    _cell = *getCase(20,11);
    // Main loop
    while(actionList[QUIT].boolean == NULL) {
        // Managing the events
        manageEvents(viewport, flags,actionList);
        for(int i=1; i<ACTION_LENGTH; i++) {
            if(actionList[i].boolean) {
                int repeat = (*actionList[i].action)(viewport,flags,actionList[i].boolean);
                if(!repeat) {
                    actionList[i].boolean = NULL;
                }
            }
        }

        // Redraws the map (viewport contents) before blitting stuff on it
        updateViewport(viewport);


///////////////////////////// DEBUG WALL /////////////////////////////
        SDL_Rect position;
        for(int i=0; i < _map->nbCaseW; i++) {
            for(int j=0; j < _map->nbCaseH; j++) {
                Case cell = *getCase(i,j);
                position.x = cell.x;
                position.y = cell.y;
                if(map->matrice[i][j].hasTower == 2) {
                    SDL_Surface *wall = IMG_Load(getPath("resources/brick.png"));
                    blitToViewport(viewport, wall, NULL, &position);
                }
            }
        }
        position.x = _cell.x;
        position.y = _cell.y;
        blitToViewport(viewport, IMG_Load(getPath("resources/candy_cane.png")), NULL, &position);
/////////////////////////////////////////////////////////////////////

        // Move enemies
        if(flags->enemy_Path_Calculation) {
            pathReCalculation(catList);
            pathReCalculation(zombieList);
            flags->enemy_Path_Calculation = false;
        }
        moveEnemyList(zombieList);
        moveEnemyList(catList);

        // Blit enemies
        drawEnemyList(zombieList);
        drawEnemyList(catList);
        //Blit TOWER
        /*      if(event.key.keysym.sym == SDLK_u){*/
        /*         upgrade(tower1);*/
        /*      }*/
        Bullet *bullet1 = createBullet(tower1);
        animateBullet(bullet1);
        drawTowerList(towerList);

        /* This should be handled by event.c
          switch(event.key.keysym.sym){
             case SDLK_a:
                flags->selectedTower = tower;
              break;
             case SDLK_b:
                flags->selectedTower = tower->nextType;
              break;
             default:
              break;

          }*/
        /*      */


        // Ask SDL to swap framebuffers to update the displayed screen
        SDL_Flip(screen);

        // Managing frames
        currentTime = SDL_GetTicks();
        if (currentTime - previousTime <= 20) {
            SDL_Delay(20 - (currentTime - previousTime));
        }

        // DEBUG
        printf("Frame %i : %ims\n", framecounter++, currentTime - previousTime);

        previousTime = SDL_GetTicks();
    }
    free(actionList);
    SDL_Quit();

    return EXIT_SUCCESS;
}
示例#14
0
Bullet * BulletFactory::createBullet(bool Evert){
	return createBullet("bullet",Evert);
}
void MiniBoss::attack2_2()
{
	createBullet(Vec2(bossSprite2->getPositionX(), bossSprite2->getPositionY()), true);
}
void MiniBoss::attack1_2()
{
	createBullet(Vec2(bossSprite1->getPositionX(), bossSprite1->getPositionY()), false);
}