void PlanLayer::update(float dt){ if (CCUserDefault::sharedUserDefault()->getBoolForKey("isGamePause")) { this->setTouchEnabled(false); }else{ this->setTouchEnabled(true); } if (hero->getPosition().x-hero->getContentSize().width/4<0 ){ hero->setPositionX(hero->getContentSize().width/4); } if (hero->getPosition().x+hero->getContentSize().width/4>win_size.width ){ hero->setPositionX(win_size.width-hero->getContentSize().width/4); } if (hero->getPosition().y-hero->getContentSize().height/4<0 ){ hero->setPositionY(hero->getContentSize().height/4); } if (hero->getPosition().y+hero->getContentSize().height/4>win_size.height ){ hero->setPositionY(win_size.height-hero->getContentSize().height/4); } if (!heroDie) { for (int j=0; j<pBullets->capacity(); j++) { Bullet* bullet_check=(Bullet*)pBullets->objectAtIndex(j); CCSize bullet_check_size = bullet_check->getContentSize(); CCPoint bullet_pos=bullet_check->getPosition(); for (int i=0; i<pEnemys->capacity(); i++) { enemy_check=(Enemy*)pEnemys->objectAtIndex(i); CCSize enemy_check_size = enemy_check->getContentSize(); CCPoint enemy_pos=enemy_check->getPosition(); CCSize hero_check_size = hero->getContentSize(); CCPoint hero_pos=hero->getPosition(); if (heroDie) { enemy_check->setIsNotVisiable(); } if(enemy_check->boundingBox().intersectsRect(hero->boundingBox())){ CCLOG("hero and enemy"); heroDie=true; bullet_check->setIsNotVisiable(); heroDie=true; this->heroBomb(); } if(bullet_check->boundingBox().intersectsRect(enemy_check->boundingBox())){ CCLOG("bullet and enemy"); SimpleAudioEngine::sharedEngine()->playEffect("bomb.mp3"); enemy_check->setIsNotVisiable(); changeScore(); bullet_check->setIsNotVisiable(); } } } } }
void GameOverLayer::beginChangeHighestScore(Node* pNode) { CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("achievement.mp3"); Value changeScore(_score); _highestScore->setString(changeScore.asString()); }
//function which centrally controls the execution of game void gameHandler(){ settextstyle(0,0,6); outtextxy(180,200,"DX-Ball"); getch(); clearviewport(); brickLen=25,brickBred=15; for(int i=0;i<20;i++) for(int j=0;j<8;j++) isBrick[i][j]=1; drawBricks(); b.cx=20; b.cy=240; b.xIncre=1; b.yIncre=1; b.radius=5; br.size=80; br.movement=10; score=0; livesRemain[0]=' '; livesRemain[1]=' '; strcat(livesRemain,"live(s) remaining."); b.lives=3; line(500,0,500,480); settextstyle(0,0,2); outtextxy(535,200,"Score:"); settextstyle(0,0,2); setScoreString(); outtextxy(535,230,scoreString); outtextxy(535,320,"Lives:"); setLivesString(); outtextxy(565,350,livesString); b.ulimit=0; b.llimit=0; b.rlimit=500; br.llimit=0; br.rlimit=500; br.rePositionBar(0); br.drawBar(); int ch='a'; while(1){ while(!kbhit()){ delay(4); b.removePreviousBall(); changeScore(); initializeVariables(); whetherBallTouchesBrick(); b.drawBall(); br.removePreviousBar(); br.drawBar(); line(500,0,500,480); } ch=getch(); if(ch=='a'){ br.removePreviousBar(); br.rePositionBar('a'); br.drawBar(); } if(ch=='s'){ br.removePreviousBar(); br.rePositionBar('s'); br.drawBar(); } if(ch=='p') ch=getch(); if(ch=='q'){ displayAbout(); getch(); exit(0); } } }
void Snake::doMoveSnake() {//Move the snack by 1 step hasMoved=true; QString str_x = QString::number(pre_x); QString str_y = QString::number(pre_y); QString position = str_x + "," + str_y; setlabel->setText(position); //Sequence 0 is the present coordinate value and sequence 1 is the last coordinate value seq_x[1] = seq_x[0]; seq_y[1] = seq_y[0]; seq_x[0] = pre_x; seq_y[0] = pre_y; //Decide when to make a turn if(seq_x[0] - seq_x[1] > 12 && pre_x > 60) { //Turn left; if(Dir!=2&&Dir!=3) { Dir=3; hasMoved=false; } } else if(seq_x[0] - seq_x[1] < -12 && pre_x < 40) { //Turn right; if(Dir!=2&&Dir!=3) { Dir=2; hasMoved=false; } } else if(seq_y[0] - seq_y[1] < -12 && pre_y < 40) { //Turn Up if(Dir!=0&&Dir!=1) { Dir=0; hasMoved=false; } } else if(seq_y[0] - seq_y[1] > 12 && pre_y > 60) { //Turn Down if(Dir!=0&&Dir!=1) { Dir=1; hasMoved=false; } } if(isGameOver()) {//Game over QMessageBox::information(this,"GameOver","Game is Over"); iniGame(); } header_Index=(header_Index-1+Max)%Max; SnakeBody[header_Index][0]=tempx; SnakeBody[header_Index][1]=tempy; if(isEating()) { changeScore(); changeLevel(); while(true) {//Random the position of food, not covered by the snake eat_X=qrand()%(map_col); eat_Y=qrand()%(map_row); int i; for(i=header_Index;i!= tail_Index;i=(i+1)%Max) if(eat_X==SnakeBody[i][0]&&eat_Y==SnakeBody[i][1]) break; if(i==tail_Index) break; } } else tail_Index=(tail_Index-1+Max)%Max; update(); }