Exemplo n.º 1
0
void Player::update(float time, Home & home)
{
	control(time);//управление
	checkCollisionWithHome(home);//столкновение с домом
	checkDeath();//проверка на смерть игрока
	frequencyShoot(time);//частота выстрела
	isShootAlive();// стреляет пока жив
	switch (state)//меняем направление
	{
		case right: acceleration.x = speed; acceleration.y = 0; break;
		case left: acceleration.x = -speed; acceleration.y = 0; break;
		case down: acceleration.x = 0; acceleration.y = speed; break;
		case up: acceleration.x = 0; acceleration.y = -speed; break;
		case left_up: acceleration.x = -speed / 2; acceleration.y = -speed / 2; break;
		case left_down: acceleration.x = -speed / 2; acceleration.y = speed / 2; break;
		case right_up: acceleration.x = speed / 2; acceleration.y = -speed / 2; break;
		case right_down: acceleration.x = speed / 2; acceleration.y = speed / 2; break;
		case stay:acceleration.x = 0; acceleration.y = 0; speed = 0; break;
	}

	position.x += acceleration.x*time;
	position.y += acceleration.y*time;

	speed = 0;
	sprite.setPosition(position.x + spriteSize.x / 2, position.y + spriteSize.y / 2);
}
Exemplo n.º 2
0
/**
 * Runs the game! WHOO!
 */
int Game::start() {
    game_running = true;
    while(window.isOpen()) {
        while(game_running) {
            sf::Event event;

            while(window.pollEvent(event)) {
                if(event.type == sf::Event::Closed) {
                    window.close();
                    game_running = false;
                    game_over = true;
                }
            }

            bullets = p.getBullets();
            spawnEnemies();
            checkInput();
            checkBorderCollision(p);
            checkEntityCollision();
            checkDeath();
            updateAnimations();
            updateScore();
            updateInterface();
            updateGameClocks();

            for(std::vector<Enemy*>::iterator iter  = enemies.begin(); iter != enemies.end(); ++iter) {
                Enemy *eni = *iter;
                eni->stalkPlayer(p);
            }
            window.clear(sf::Color(0,230,0));

            Sword * s = p.getSword();
            if(s->isSwung()) {
                window.draw(s->shape);
            }
            
            window.draw(p.shape);
            for(std::vector<Enemy*>::iterator iter  = enemies.begin(); iter != enemies.end(); ++iter) {
                Enemy *eni = *iter;
                window.draw(eni->shape);
            }

            for(std::vector<Bullet*>::iterator iter = bullets.begin(); iter != bullets.end(); ++iter) {
                Bullet *b = *iter;
                window.draw(b->shape);
            }

            for(std::vector<sf::Drawable*>::iterator iter = interface.begin(); iter != interface.end(); ++iter) {
                sf::Drawable *d = *iter;
                window.draw(*d);
            }

            window.display();
        }

        setupEntities();
        game_running = true;
    }
    return 0;
}
Exemplo n.º 3
0
/***********************************************************************
; Name:         startMatch
; Description:  This function is the main game loop. All player movement
;								and scorekeeping has to be performed inside this loop.
;***********************************************************************/
void startMatch(void)
{
	char quit = 0;

	writeBackground(selected_field);
	display_character(&player0);
	display_character(&player1);

	while (!quit)
	{
		if (hCnt > HSYNCHIGH || hCnt < HSYNCLOW)
		{
			// update horizontal and vertical velocity for player 0
			updateVelAcc(&player0,joy0hor,joy0ver);
			updateVelAcc(&player1,joy1hor,joy1ver);
			// check for jumping.
			checkPlayerJump(&player0);
			checkPlayerJump(&player1);
			// TEMPORARY EXIT CONDITION
			//if (player0.attacking == 2) // pushbutton 2 pressed
			//{
			//		quit = 1;
			//}

			// attack for player
			player0.attack(&player0);
			player1.attack(&player1);

			// move player (it can be any function)
			player0.move(&player0);
			player1.move(&player1);
			//  display the character at his location
			//display_character(&player0);
      displayLives();
      displayDamage();
      quit = quit || checkDeath(&player0);
      quit = quit || checkDeath(&player1);
		}
	}
	
	// reset player lives and other values
	player0.lives = 5;
	player1.lives = 5;
	player0.damage = 0;
	player1.damage = 0;
}
Exemplo n.º 4
0
bool Board::applyDeaths()
{
	bool someoneDied = false;
	for(int i = 0; i < NB_TRAPS; ++i)
	{
		someoneDied |= checkDeath(m_trapList[i]);
	}
	return someoneDied;
}
Exemplo n.º 5
0
void KillDistanceBased::tick(float deltaSeconds)
{
    elapsedTime += deltaSeconds;
    if(elapsedTime > checkInterval)
    {
        checkDeath();
        elapsedTime = 0.0f;
    }
    

    
}
Exemplo n.º 6
0
void Game::timerEvent(QTimerEvent*)
{
	// check to see if any addition is necessary
	checkAddition();

	// advance the scene
	myScene.advance();

	// check to see if the score should be increased
	checkScore();
	// check to see if he wants to jump (and can)
	checkJump();
	// check to see if he is stuck in a wall
	checkWall();
	// check to see if he has hit an obstacle
	checkLose();
	// check to see if removal of items is necessary
	checkDeath();
}
Exemplo n.º 7
0
void RootEngine::destroySlectedArray(CCArray *array, makaCompleteCallback complete)
{
    if (array->count() == 0) {
        if (complete) {
            complete();
        }
        return;
    }
    
    completeCallback = complete;
    
    containerView->unscheduleAllCallbacks();
    for(int i = 0 ; i< array->count() ; i ++)
    {
        StarModel* model = (StarModel*)array->objectAtIndex(i);
        int line = model->line;
        CCArray* rowArray = (CCArray*)dataSource->objectAtIndex(line);
        rowArray->removeObject(model);
        allNodes->removeObject(model->node);
        
        Sprite* sp = model->node->sprite;
        containerView->scheduleOnce([sp,i,this](float dt){
            if (sp->isRunning()==false) {
                return ;
            }
            
            Point p = sp->getPosition();
            ParticleSystem* ps = CommonUtil::getParticleSystemForImageNameAndLayer(__String::create("star.png"),Color3B::ORANGE,perWidth/2);
            ps->setPosition(p);
            containerView->addChild(ps);
            
            sp->removeFromParent();
            if (i<=40) {
                CommonUtil::playSoundWithName(__String::create("pop"),0.8,0.8+i/16.0>1.5?1.5:0.8+i/16.0);
            }
            
            Point f = Point(p.x,p.y+perHeight);
            Point t = Point(containerView->getContentSize().width/2,containerView->getContentSize().height - 100);
            CommonUtil::createLabelMoveTo(f, t, __String::createWithFormat("%d",i*10+10),containerView);
            
        }, .1*i > 4 ? 4 :.1*i, __String::createWithFormat("random%d",i)->getCString());
    }
    
    containerView->scheduleOnce([array,this](float dt){
        CCArray* emptyArray = CCArray::create();
        
        for (int i = 0; i<dataSource->count(); i++) {
            CCArray* arr = (CCArray*)dataSource->objectAtIndex(i);
            
            if (arr->count() == 0) {
                emptyArray->addObject(arr);
            }
        }
        
        dataSource->removeObjectsInArray(emptyArray);
        
        for (int i = 0; i<dataSource->count(); i++) {
            for (int j = 0; j<((CCArray*)dataSource->objectAtIndex(i))->count(); j++) {
                StarModel* model = (StarModel*)((CCArray*)dataSource->objectAtIndex(i))->objectAtIndex(j);
                model->line = i;
                model->row = j;
                StarNode* node = model->node;
                Point p = node->sprite->getPosition();
                Point t = ccp((i+ 0.5)*this->perHeight, (j+0.5)*this->perWidth);
                if (p.x != t.x || p.y != t.y) {
                    CCActionInterval * moveBy = CCMoveBy::create(0.3,Vec2(t.x-p.x, t.y-p.y));
                    CCActionInterval * actionmoveback= moveBy;
                    node->sprite->runAction(actionmoveback);
                }
            }
        }
        
        containerView->scheduleOnce([this](float dt){
            if (completeCallback) {
                completeCallback();
            }else{
                if (checkDeath()) {
                    death();
                }
            }
        }, 0.4, "delayClear");
        
    }, .1*array->count() > 4 ? 4 :array->count()*.1, "relayout");
}
Exemplo n.º 8
0
int main()
{
  memcpy(board2,board,sizeof(int)*rows*columns);
  int height=800,width=800;				//height and width of screen
  gfx_open(width,height,"Pacman");
  gfx_clear_color(0,0,0);
  gfx_clear();
 
  int boardHeight=radius*rows,boardWidth=radius*columns;//Height of the board
  int xtopleft=width/2-boardWidth/2;			//x coord of top left corner of board
  int ytopleft=height/2-boardHeight*9/16; 		//y coord of top left corner of board
  char movement;  
  int i,lives=3;//start with 3 lives
  int win=0;
  int active=0;	//this changes depending on number of dots left
  int initialDots=dotsNumber();
  int remainingDots=dotsNumber();
  int score=0;
  int loop[4]={0,0,0,0};
  int frightenLoop[4]={0};
  int newScore[3]={0,0,0};//values [0]:new score to display(when ghost is killed),[1]:xvalue,[2]:yvalue
  Location pacman;
  Location ghosts[4];// enumerated to blinky, pinky, inky, clyde;
/*There are four states: 0: Chase, 1: Scatter, 2: Frighten, 3: Dead, and 4: Housed */
  int state[4]={scatter,scatter,scatter,scatter};

while(1){ 
 titleScreen(height,width,ghosts,&pacman,state);
 score=0;
 lives=3;
 win=0;
 for(i=0;i<=3;i++) loop[i]=0;	//reset the game
 resetBoard();
 gfx_wait();
/* This is the gameplay loop, will repeat every time a life is lost */
 while(lives>0){
  gfx_clear();
/* Initialize pacman's location */
  pacman.x=pacman.prevX=7;
  pacman.y=pacman.prevY=12;
  pacman.orientation=right;
/* Initialize ghost's locations */
  for(i=blinky;i<=clyde;i++){state[i]=scatter;}
  
  ghosts[blinky].x=7; 
  ghosts[blinky].prevX=8;
  ghosts[blinky].y=ghosts[blinky].prevY=6;
  ghosts[blinky].orientation=left;

  ghosts[pinky].x=7;
  ghosts[pinky].prevX=7;
  ghosts[pinky].y=7;
  ghosts[pinky].prevY=8;
  ghosts[pinky].orientation=up;
  
  ghosts[inky].x=ghosts[inky].prevX=6;
  ghosts[inky].y=7;
  ghosts[inky].prevY=8;
  ghosts[inky].orientation=right;

  ghosts[clyde].x=ghosts[clyde].prevX=8;
  ghosts[clyde].y=7;
  ghosts[clyde].prevY=8;
  ghosts[clyde].orientation=left; 
 
/* These two statements draw pacman and the board to begin the program */
  drawBoard(xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,2,score);
  drawPacman(xtopleft+radius*pacman.x+radius/2,ytopleft+radius*pacman.y+radius/2,pacman.orientation,0);
  for(i=blinky;i<=clyde;i++){
    drawGhost(xtopleft+radius*ghosts[i].x+radius/2,ytopleft+radius*ghosts[i].y+radius/2,i,ghosts[i].orientation,state,frightenLoop[i]);
  }

/* This loop is the gameplay after all initialization */
  while(1){
    /*if(gfx_event_waiting()){prevMovement=movement;*/ movement=gfx_wait();//}
    
  /* This block updates pacman position, checks for death
   * then updates ghosts' positions, then checks for death again */
    movePacman(&pacman,ghosts,movement,xtopleft,ytopleft,boardHeight,boardWidth,active,state,&score,frightenLoop);
    if(checkDeath(&pacman,ghosts,xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,state,&score,newScore,frightenLoop,loop[0])){	//pacman's death?
	for(i=0;i<=3;i++) loop[i]=0;	//reset the game
	lives--;			//decrease the lives
	printf("LIVES: %i\n",lives);
	break;
    }
    targetGhosts(ghosts,&pacman,xtopleft,ytopleft,boardHeight,boardWidth,active,state);
    if(checkDeath(&pacman,ghosts,xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,state,&score,newScore,frightenLoop,loop[0])){	//pacman's death?
	for(i=0;i<=3;i++) loop[i]=0;	//reset the game
	lives--;			//decrease the lives
	printf("LIVES: %i\n",lives);
	break;
    }
    ghostState(loop,state,frightenLoop);
    active=activeGhosts(ghosts,loop);

/* The next function animates the motion of all of the objects (pacman and ghosts */
    animateMotion(xtopleft,ytopleft,boardHeight,boardWidth,&pacman,ghosts,height,width,lives,state,score,newScore,frightenLoop,loop[0]);

/* The case to exit the loop is winning, when there are no dots left */
    if(dotsNumber()==0){	//The player got all the dots, they won the game
	win=1;
	break;
    }
  }
  if(lives<=0){ 
	gfx_clear();
	printf("\n\nGAME OVER\n\n");	
  	drawBoard(xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,0,score);
	if(tolower(gfx_wait())=='n'){ return 0; }//This will start the entire game over including the title screen
	else break;}
  else if(win){ printf("\n\nWINNER!\n\n");	
	drawBoard(xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,win,score);
	if(tolower(gfx_wait())=='n'){ return 0; }//This will end the game 
	else break;}
  }
 }
}