void Enemy::step() { player_visible = !player->dead && world()->level->visible(shared_from_this(), std::static_pointer_cast<Entity>(player)); player_distance = Game::distance(shared_from_this(), std::static_pointer_cast<Entity>(player)); if(!attack) { scope(); if(alert) hunt(); else wander(); } walking(); worldCollision(); dy += gravity; if(alert && frame==0) frame = 5; if(attack) shoot(); processEntities(); light->setPosition(sf::Vector2f(x,y)); sprite.setPosition(round(x),round(y)); sprite.setScale(facing_right?1.0:-1.0,1.0); sprite.setTextureRect(sf::IntRect(frame*24,0,24,24)); }
int main (int argc, char *argv[]) { int ghost[3],pacman[3],target[2], number_ghost=0; char maze[L][C]; char ch,path[20] = "maze.txt"; int i=0,j=0; while (number_ghost != 9) { //clear_screen(); load_maze(maze,path); //print_maze(maze); printf ( "\t>>> GHOSTS <<<\n" ); printf ( "1.BLINK 2.PINK 3.INKY 4.CLYDE 9.SAIR \n" ); do { printf ( "Qual o numero do Ghost? = " ); scanf ("%d", &number_ghost); }while(number_ghost > 4 || number_ghost < 1 || number_ghost == 9 ); //Lendo cordenadas para o ghost if (number_ghost != 9) { print_maze(maze); read_player(maze,ghost,'3'); read_player(maze,pacman,'5'); switch (number_ghost) { case 1: //void blink(maze,ghost,pacman,target); position(maze,pacman,'8'); target[0] = pacman[0]; target[1] = pacman[1]; break; case 2: // void pink(maze,ghost,pacman,target); // position(maze,target,'T'); break; case 3: ink(red,pacman,target); position(maze,target,'8'); break; case 4: // void clyde(maze,ghost,pacman,target); // position(maze,target,'8'); break; } walking(maze,ghost,target);//mudar os parametros print_maze (maze); } } return 0; }
void running() { if (winner < 0) winner = end_game(); if (winner >= 0) game_mode = END; if (game_mode == START) { walking(); if (runners[chosen_runner] -> velocity > 0.001) runners[chosen_runner] -> velocity -= 0.001; for (int i = 0; i < NUMBER_OF_RUNERS; i++) { if (runners[i] -> running_phase == FORWARD) forward(runners[i]); else if (runners[i] -> running_phase == FORWARD_TURN) forward_turn(runners[i]); else if (runners[i] -> running_phase == BACKWARD) backward(runners[i]); else if (runners[i] -> running_phase == BACKWARD_TURN) backward_turn(runners[i]); } } glutPostRedisplay(); glutTimerFunc(FRAME_ON_MILLISECONDS, running, 0); }
void Enemy::update(btDiscreteDynamicsWorld* dynamicsWorld, vec3* playerPosition, const string playerState, bool &isPlayerDead) { rigidBody->activate(true); if (isDead == true) { if (death_anim_frames_count == 0) { rigidBody->activate(false); model->setAnimation(death); } death_anim_frames_count++; } else if (state == State::WALKING) { walking(dynamicsWorld, playerPosition, playerState); } else if (state == State::AGGRESSIVE) { aggressive(dynamicsWorld, playerPosition, isPlayerDead); } else if (state == State::AWARE) { aware(dynamicsWorld, playerPosition, playerState); } angle = -(atan2(direction.z, direction.x) * 180 / 3.14f); /*Wyciagniecie pozycji rigidbody z macierzy*/ btScalar openGlMatrix[16]; rigidBody->getWorldTransform().getOpenGLMatrix(openGlMatrix); position.x = openGlMatrix[12]; position.y = openGlMatrix[13]; position.z = openGlMatrix[14]; float poprawka_wysokosci = -1.4f; model->updatePositon(position.x, position.y + poprawka_wysokosci, position.z); model->updateRotation(angle); rigidBody->setWorldTransform(btTransform(btQuaternion(btScalar(degreesToRadians(angle)), btScalar(0), btScalar(0)), btVector3(position.x, position.y, position.z))); }
int main (int argc, char *argv[]) { int ghost[3],pacman[3], target[2]; char maze[L][C]; char ch; int i=0,j=0; FILE *fp; fp = fopen("maze.txt","r" ); if(fp == NULL) printf("Erro, nao foi possivel abrir o arquivo\n"); else while( (ch=fgetc(fp))!= EOF ) { if (ch != '\n') { maze[i][j] = ch; j++; }else { j = 0; i++; } } fclose(fp); clear_screen(); printf ( "\t>>> BLINKY GHOST <<<\n \n" ); do { print_maze(maze); printf ( "Qual a posição do GHOST? (x,y)\n" ); printf ( "x: " ); scanf ( "%d", &ghost[0] ); // referente a coluna - ghost printf ( "y: " ); scanf ( "%d", &ghost[1] ); // referente a linha - ghost printf ( "Direção do ghost = 1-Down , 2-Right, 3-Up, 4-Left = " ); scanf ("%d", &ghost[2]); clear_screen(); }while (!validate_position(maze,ghost[0],ghost[1]) || ghost[2] > 4 ||ghost[2] < 1); position (maze,ghost,'3'); do { clear_screen(); print_maze (maze); printf ( "Qual a posição do Pacman? (x,y)\n" ); printf ( "x: " ); scanf ( "%d", &pacman[0]); // referente a coluna - ghost printf ( "y: " ); scanf ( "%d", &pacman[1]); // referente a linha - ghost }while (!validate_position(maze,pacman[0],pacman[1])); do { printf ( "Direção do Pac-mam: 1-Down , 2-Right, 3-Up, 4-Left = " ); scanf ("%d",&pacman[2]); }while( pacman[2]>4 ||pacman[2]<1); target_blinky(pacman,target); position (maze,pacman,'5' );//mudar os parametros print_maze (maze); walking(maze,ghost,target);//mudar os parametros print_maze (maze); return 0; }
//寻找路径: 核心算法 void walker() { struct POINT ThisStep; int x; for(x=0; x<LEN; x++) { printf("---"); } printf("\n"); printf(" Walk Direction: Right / Down / Left / Up\n"); for(x=0; x<LEN; x++) { printf("---"); } printf("\n"); //初始化第一步 ThisStep = S; //第一步为起点 G[G_index] = ThisStep; //当前步压栈 G_index++; //指针上移 while(G_index>=0) { //显示逐步绘图 //walking(); G_index--; ThisStep = G[G_index]; //寻线规则:右、下、左、上 //如果已经是终点 if( ThisStep.x == E.x && ThisStep.y == E.y) { break; } //模拟人眼初步判断 if( (E.x-S.x)>(LEN/2) && (E.y-S.y)<(LEN/2) ) { //下边可走 if ( (ThisStep.x+1)<LEN && M[ThisStep.x+1][ThisStep.y]==0) { printf("%d: \t(%d, %d)\t\\/\t", G_index+1, ThisStep.x, ThisStep.y); //下走 ThisStep.x = ThisStep.x +1; //设置已走 M[ThisStep.x][ThisStep.y]--; //步骤入库 G_index++; G[G_index] = ThisStep; printf("\t(%d, %d)\n",ThisStep.x,ThisStep.y); //下一步骤准备 G_index++; continue; } //右边可走 if ( (ThisStep.y+1)<LEN && M[ThisStep.x][ThisStep.y+1]==0) { printf("%d: \t(%d, %d)\t->\t", G_index+1, ThisStep.x, ThisStep.y); //右走 ThisStep.y = ThisStep.y+1; //设置已走 M[ThisStep.x][ThisStep.y]--; //步骤入库 G_index++; G[G_index] = ThisStep; printf("\t(%d, %d)\n",ThisStep.x,ThisStep.y); //下一步骤准备 G_index++; continue; } } else { //右边可走 if ( (ThisStep.y+1)<LEN && M[ThisStep.x][ThisStep.y+1]==0) { printf("%d: \t(%d, %d)\t->\t", G_index+1, ThisStep.x, ThisStep.y); //右走 ThisStep.y = ThisStep.y+1; //设置已走 M[ThisStep.x][ThisStep.y]--; //步骤入库 G_index++; G[G_index] = ThisStep; printf("\t(%d, %d)\n",ThisStep.x,ThisStep.y); //下一步骤准备 G_index++; continue; } //下边可走 if ( (ThisStep.x+1)<LEN && M[ThisStep.x+1][ThisStep.y]==0) { printf("%d: \t(%d, %d)\t\\/\t", G_index+1, ThisStep.x, ThisStep.y); //下走 ThisStep.x = ThisStep.x +1; //设置已走 M[ThisStep.x][ThisStep.y]--; //步骤入库 G_index++; G[G_index] = ThisStep; printf("\t(%d, %d)\n",ThisStep.x,ThisStep.y); //下一步骤准备 G_index++; continue; } } //左边可走 if ( (ThisStep.x-1)>=0 && M[ThisStep.x-1][ThisStep.y]==0) { printf("%d: \t(%d, %d)\t<-\t", G_index+1, ThisStep.x, ThisStep.y); //左走 ThisStep.x = ThisStep.x-1; //设置已走 M[ThisStep.x][ThisStep.y]--; //步骤入库 G_index++; G[G_index] = ThisStep; printf("\t(%d, %d)\n",ThisStep.x,ThisStep.y); //下一步骤准备 G_index++; continue; } //上边可走 if( (ThisStep.y-1)>=0 && M[ThisStep.x][ThisStep.y-1]==0) { printf("%d: \t(%d, %d)\t/\\\t", G_index+1, ThisStep.x, ThisStep.y); //上走 ThisStep.y = ThisStep.y-1; //设置已走 M[ThisStep.x][ThisStep.y]--; //步骤入库 G_index++; G[G_index] = ThisStep; printf("\t(%d, %d)\n",ThisStep.x,ThisStep.y); //下一步骤准备 G_index++; continue; } } if(G_index==-1) { for(x=0; x<LEN; x++) { printf("---"); } printf("\n"); printf("\tNO WAY!!!\n"); } walking(); }
void enemy::bigWolfAI(float elapsed) { if (global_map->dialogueActive() || isInvincible()) return; unsigned int switchTo = DATA_NONE; chargeD = 0; switch(bossPhase) { case 0: //no phase //switch to phase 1 if(rand() % 100 <= bossProb) { switchTo = 1; bossProb = global_data->getValue(DATA_BOSSDATA, magic, 12); } else { switchTo = 3; bossProb = global_data->getValue(DATA_BOSSDATA, magic, 13); } break; case 1: //charge buildup phase { float bTM = global_data->getValue(DATA_BOSSDATA, magic, 1) * 0.01f; if (bossTimer <= bTM / 3) setAttackAnim(global_data->getValue(DATA_BOSSDATA, magic, 0) * BOSSTOOLM); else setAttackAnim(-1); if (bossTimer <= bTM * 2 / 3) { move(-facingX, elapsed * global_data->getValue(DATA_BOSSDATA, magic, 11) * 0.01f); if (x > global_map->getWidth() / 2) facingX = -1; else facingX = 1; } bossTimer -= elapsed; if (bossTimer <= 0) { global_map->forceSound(global_data->getValue(DATA_BOSSDATA, magic, 15)); switchTo = 2; //start charging! } } break; case 2: //charge phase setAttackAnim(-1); float lowestD; if (facingX == 1) lowestD = abs(global_map->getWidth() - x - getMaskWidth() / 2); else lowestD = x + getMaskWidth() / 2; if (lowestD <= TILESIZE * 1.5 + getMaskWidth() / 2) { if (!walking()) //you've stopped moving switchTo = 0; //switch to a random phase } else { chargeD = global_data->getValue(DATA_BOSSDATA, magic, 10); move(facingX, elapsed); } break; case 3: //spray charge { float bTM = global_data->getValue(DATA_BOSSDATA, magic, 4) * 0.01f; bossTimer -= elapsed; if (bossTimer <= 0) switchTo = 4; else if (bossTimer > bTM / 2) setAttackAnim(-1); else { if (x > global_map->getWidth() / 2) facingX = -1; else facingX = 1; bossToolAnimSlideScale(global_data->getValue(DATA_BOSSDATA, magic, 2), global_data->getValue(DATA_BOSSDATA, magic, 3), 1 - 2 * bossTimer / bTM); } } break; case 4: //spray { float bTM = global_data->getValue(DATA_BOSSDATA, magic, 8) * 0.01f; float pInterval = bTM / global_data->getValue(DATA_BOSSDATA, magic, 6); float bTBefore = bossTimer; bossTimer -= elapsed; if (bossTimer < 0) bossTimer = 0; //now how many pIntervals have passed? while (true) { float nearestInterval = 0; while (nearestInterval <= bTBefore) nearestInterval += pInterval; if (nearestInterval > bTBefore) nearestInterval -= pInterval; if (nearestInterval >= bossTimer) { bTBefore -= pInterval; //make a projectile float angle; if (facingX == 1) angle = 0; else angle = (float) M_PI; float angleA = global_data->getValue(DATA_BOSSDATA, magic, 7) * (float) M_PI / 180; angle += (rand() % 200 - 100) * 0.01f * angleA; global_map->forceSound(global_data->getValue(DATA_BOSSDATA, magic, 14)); global_map->addProjectile(projectileStartX(), projectileStartY(), cos(angle), sin(angle), global_data->getValue(DATA_BOSSDATA, magic, 5), global_data->getValue(DATA_BOSSDATA, magic, 9), DATA_NONE, TYPE_ENEMY, DATA_NONE, false); } else break; //there is no interval that is below btbefore and over bosstimer } if (bossTimer <= 0) switchTo = 0; else bossToolAnimSlideScale(global_data->getValue(DATA_BOSSDATA, magic, 2), global_data->getValue(DATA_BOSSDATA, magic, 3), bossTimer / bTM); } break; } if (switchTo != DATA_NONE) { bossPhase = switchTo; switch(bossPhase) { case 0: //no phase break; case 1: //charge buildup timer length bossTimer = global_data->getValue(DATA_BOSSDATA, magic, 1) * 0.01f; break; case 2: //charge break; case 3: //spray charge bossTimer = global_data->getValue(DATA_BOSSDATA, magic, 4) * 0.01f; break; case 4: //spray bossTimer = global_data->getValue(DATA_BOSSDATA, magic, 8) * 0.01f; break; } } }
int main (int argc, char *argv[]) { int ghost[3],pacman[3], red[3], target[2], number_ghost; char maze[L][C]; char ch; int i=0,j=0; FILE *fp; fp = fopen("maze.txt","r" ); if(fp == NULL) printf("Erro, nao foi possivel abrir o arquivo\n"); else while( (ch=fgetc(fp))!= EOF ) { if (ch != '\n') { maze[i][j] = ch; j++; }else { j = 0; i++; } } fclose(fp); clear_screen(); print_maze(maze); printf ( "\t>>> GHOSTS <<<\n" ); printf ( "1.BLINK 2.PINK 3.INKY 4.CLYDE\n" ); do { printf ( "Qual o numero do Ghost? = " ); scanf ("%d", &number_ghost); }while(number_ghost > 4 || number_ghost < 1 ); //number_ghost = 2; do { print_maze(maze); printf ( "Qual a posição do GHOST? (x,y)\n" ); printf ( "x: " ); scanf ( "%d", &ghost[1] ); // referente a coluna - ghost printf ( "y: " ); scanf ( "%d", &ghost[0] ); // referente a linha - ghost printf ( "Direção do ghost = 1-Down , 2-Right, 3-Up, 4-Left = " ); scanf ("%d", &ghost[2]); clear_screen(); }while (!validate_position(maze,ghost[0],ghost[1]) || ghost[2] > 4 ||ghost[2] < 1); //mudar os parametros position (maze,ghost,'3'); do { print_maze(maze); printf ( "Qual a posição do RED? (x,y)\n" ); printf ( "x: " ); scanf ( "%d", &red[1] ); // referente a coluna - ghost printf ( "y: " ); scanf ( "%d", &red[0] ); // referente a linha - ghost printf ( "Direção do red = 1-Down , 2-Right, 3-Up, 4-Left = " ); scanf ("%d", &red[2]); clear_screen(); }while (!validate_position(maze,red[0],red[1]) || red[2] > 4 ||red[2] < 1); //mudar os parametros position (maze,red,'4'); do { clear_screen(); print_maze (maze); printf ( "Qual a posição do Pacman? (x,y)\n" ); printf ( "x: " ); scanf ( "%d", &pacman[1]); // referente a coluna - ghost printf ( "y: " ); scanf ( "%d", &pacman[0]); // referente a linha - ghost }while (!validate_position(maze,pacman[0],pacman[1])); //mudar os parametros do { printf ( "Direção do Pac-mam: 1-Down , 2-Right, 3-Up, 4-Left = " ); scanf ("%d",&pacman[2]); }while( pacman[2]>4 ||pacman[2]<1); position (maze,pacman,'5' );//mudar os parametros dist(pacman); //marca_target aqui// calcular o target aqui e passa-lo para a walking //target[0]=(pacman[0]-red[0])+pacman[0]; //target[1]=(pacman[1]-red[1])+pacman[1]; //verifica_target(maze, target); calcula_target(maze, red, pacman, target); position(maze, target, '8'); print_maze (maze); walking(maze,ghost,target);//mudar os parametros print_maze (maze); return 0; }