Example #1
0
void Game::update(){
  //update vars for animation

  //count frame
  framecounter+=framespeed*clock.restart().asSeconds();


  //for smooth motion
  if(playing && framecounter>=50){
    unsigned int i=0;
    while(i<wave.size())
      wave.at(i++).move(1, 0);
  }

  if(framecounter>=keyframe){
    framecounter=0;
    updateSprites(titlesprite, 4);

    //spawn creeps only when playing or game started
    if(playing){
      creepspawndelay++;
      if(creepspawndelay==7){
        creepspawndelay=0;
        wave.spawn_creep();
      }
      player.gain_gold(wave.creep_sanity_check());  //checks creeps if dead or alive and gives player gold on kill
    }

    unsigned int i=0;
    while(i<wave.size()){
      updateSprites(wave.at(i++), 4);
    }
  }
}
Example #2
0
	Map::Map(const std::string & filePath)
	{
		LoadFromFile(filePath);
		_emptySprite.setTexture(_backgroundTexture);
		_emptySprite.setTextureRect(sf::IntRect(0, 0, 0, 0));
		_emptySprite.setPosition(0, 0);
		updateSprites();
	}
Example #3
0
void Scenario::update(){
    updateSprites();
    environment->update();
    light->update();
    player.move();
    if (seed.getTraversal() == Seed::WALK)
        player.setNewHeight();
    
}
Example #4
0
int main(void)  {
	int i;
	int memUsageTemp = 0xFFFFFFFF;

	videoSetMode(MODE_0_2D);
	videoSetModeSub(MODE_0_2D);
	vramSetBankA(VRAM_A_MAIN_SPRITE);
	vramSetBankB(VRAM_B_MAIN_SPRITE);
	vramSetBankD(VRAM_D_SUB_SPRITE);

	consoleDemoInit();
//	consoleDebugInit(DebugDevice_NOCASH); //send stderr to no$gba debug window

	//api: initialize OAM to 1D mapping with XX byte offsets and no external palette
	oamInit(oam, SpriteMapping_1D_128, false);

	//create some sprites
	for(i = 0; i < SPRITE_MAX; i++)
		randomSprite(&sprites[i]);

	//load a randomly colored palette
	for(i = 0; i < 256; i++) {
      SPRITE_PALETTE[i] = rand();
      SPRITE_PALETTE_SUB[i] = rand();
	}

	while(1) { 
		moveSprites();

		updateSprites();

		swiWaitForVBlank();
		
		//api: updates real oam memory 
		oamUpdate(oam);

		if(oom) {	
			memUsageTemp = memUsageTemp > spriteMemoryUsage ? spriteMemoryUsage : memUsageTemp;
    	}	

		consoleClear();
		
		printf("Memory usage: %i %i%% \n",  spriteMemoryUsage, 100 * spriteMemoryUsage / (spriteMemSize));
		printf("Percentage fail: %i%% \n", oomCount * 100 / allocationCount);
		printf("Lowest Usage at fail %i %i%% \n", memUsageTemp, 100 * memUsageTemp / (spriteMemSize));				
	}

	return 0;
}
void SfmlInterface::controllerInput()
{
	//player1
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
		_gameLogic.playControl(FORWARD, 1);
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
		_gameLogic.playControl(REVERSE, 1);
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
		_gameLogic.playControl(ANTI_CLOCKWISE, 1);
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
		_gameLogic.playControl(CLOCKWISE, 1);
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::RShift))
			_gameLogic.playControl(FIRE_ROCKET, 1);
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::RControl))
			_gameLogic.playControl(PLANT_MINE, 1);

	//player2
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
		_gameLogic.playControl(FORWARD, 2);
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
		_gameLogic.playControl(REVERSE, 2);
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
		_gameLogic.playControl(ANTI_CLOCKWISE, 2);
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
		_gameLogic.playControl(CLOCKWISE, 2);
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::LShift))
			_gameLogic.playControl(FIRE_ROCKET, 2);
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::LControl))
			_gameLogic.playControl(PLANT_MINE, 2);

	//misc
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
	{
		_gameLogic.playControl(RESPAWN, 1);
		updateSprites();
	}

}
Example #6
0
UI::MenuItem::MenuItem(Engine* const app_, const std::string& path_)
: Clickable(app_), path(path_), normal(), hovered(), disabled(), app(app_)
{
	updateSprites();
}
void SnakeGame::update(float dt)
{
	
	if (speed_counter == speed)
	{
		Vec2 p = snake.at(0)->getPosition();

		int x = p.x;
		int y = p.y;

		switch (direction){
			case 1:
				y += SPRITE_HEIGHT;
				break;
			case 2:
				y -= SPRITE_HEIGHT;
				break;
			case 3:
				x -= SPRITE_WIDTH;
				break;
			case 4:
				x += SPRITE_WIDTH;
				break;
			default:
				break;
		}
		
		//delete the last body if didnt eat food
		Vec2 phone_p = iPhone->getPosition();
		Vec2 apple_p = apple->getPosition();
		Vec2 mac_p = mac->getPosition();
		if (x == apple_p.x && y == apple_p.y || x == phone_p.x && y == phone_p.y)
		{ 
			if (x == apple_p.x && y == apple_p.y)
			{
				isAppleEaten = true;
			}
			else
			{
				isIPhoneEaten = true;
			}
			CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(
				"gotItem.mp3");

			randomFood();
			score++;

			updateScore();
		}
		else if (x == mac_p.x && y == mac_p.y)
		{
			CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(
				"gotItem.mp3");

			score += 5;
			randomFood();
			updateScore();
			if (snake.size() > 5)
			{
				this->removeChild(snake.at(snake.size() - 1));
				snake.pop_back();
			}
			this->removeChild(snake.at(snake.size() - 1));
			snake.pop_back(); this->removeChild(snake.at(snake.size() - 1));
			snake.pop_back();

			isMacEaten = true;
		}
		else
		{
			this->removeChild(snake.at(snake.size() - 1));
			snake.pop_back();

			if (x < 0 || x > Director::getInstance()->getVisibleSize().width ||
				y < 0 || y > Director::getInstance()->getVisibleSize().height)
			{
				newGame();
				return;
			}
			else if (isHitSnake(x, y))
			{
				newGame();
				return;
			}
			
		}

		//add a new body in front
		auto mySprite = Sprite::create("snakes.png", Rect(SPRITE_WIDTH * 3, 0,
			SPRITE_WIDTH, SPRITE_HEIGHT));
		mySprite->setAnchorPoint(Vec2(0, 0));
		mySprite->setPosition(Vec2(x, y));
		this->addChild(mySprite);

		snake.insert(snake.begin(), mySprite);
		speed_counter = 0;

		updateSprites();
		
	}
	else
	{
		speed_counter++;
	}	
}
Example #8
0
void Scale9Sprite::onContentSizeDirty() {
	DynamicBatchNode::onContentSizeDirty();
	updateSprites();
}