void Caisse::bouge() { if (pousseX==0 && pousseY==0) return; if (pousseX>0) { pousseX-=2; moveX(2); } if (pousseX<0) { pousseX+=2; moveX(-2); } if (pousseY>0) { pousseY-=2; moveY(2); } if (pousseY<0) { pousseY+=2; moveY(-2); } if (pousseX==0 && pousseY==0) { if (gpJeu->isVide(x, y, 16, 16)) { vie = 0; gpJeu->getAudio()->playSound(6); } else if (gpJeu->isWater(x, y, 16, 16)) { vie = 0; gpJeu->ajouteProjectile(8, direction, x, y, 0); } gpJeu->testAnim(); } if (vie) gpJeu->testEpee(x, y, w, h, CAISSE, 999, direction); }
/************************************************************ All arrow keypresses are handled in this function **************************************************************/ void handleSpecialKeys(int key, int x, int y) { lua_State *pLuaControl = lua_open(); createLuaState(pLuaControl, "scripts/control.lua"); switch(key) { case GLUT_KEY_LEFT : if(mines[startX-1][startY]!= 'B') startX = moveX(1,startX,pLuaControl); // passing 1 tells Lua the function its a "-" break; case GLUT_KEY_RIGHT : if(mines[startX+1][startY]!= 'B') startX = moveX(2,startX,pLuaControl); // passing 2 tells Lua the function its a "+" break; case GLUT_KEY_DOWN : if(mines[startX][startY-1]!= 'B') startY = moveY(1,startY,pLuaControl); break; case GLUT_KEY_UP : if(mines[startX][startY+1]!= 'B') startY = moveY(2,startY,pLuaControl); break; } glutPostRedisplay(); }
void Caisse::bouge() { if (pousseX==0 && pousseY==0) return; if (pousseX>0) { pousseX-=2; moveX(2); } if (pousseX<0) { pousseX+=2; moveX(-2); } if (pousseY>0) { pousseY-=2; moveY(2); } if (pousseY<0) { pousseY+=2; moveY(-2); } if (pousseX==0 && pousseY==0) { if (gpJeu->isVide(x, y, 16, 16)) { vie = 0; gpJeu->getAudio()->playSound(6); } } if (vie) gpJeu->testEpee(x, y, w, h, CAISSE, 999, direction); }
void goRightWall() { moveX(0); moveY(30); while(!digitalInput(0)) { delayMs(50); } moveY(-20); delayMs(200); moveY(0); moveXAdjusted(30); while(analog(3) < 50) { delayMs(50); } delayMs(100); moveX(0); moveY(20); while(!digitalInput(0)) { delayMs(50); } moveY(-20); while(analog(3) < 50) { delayMs(50); } delayMs(150); moveY(0); pickSuperBall(); moveXAdjusted(30); while(analog(0) < 127) { delayMs(50); } moveX(0); }
void Pnj::suit() { Joueur* gpJoueur = gpJeu->getJoueur(); int pnjCX = x + gpZoneBase->getZone()->x + (gpZoneBase->getZone()->w/2); int pnjCY = y + gpZoneBase->getZone()->y + (gpZoneBase->getZone()->h); int linkCX = gpJoueur->getX() + 8; int linkCY = gpJoueur->getY() + 24; int difx = pnjCX - linkCX; int dify = pnjCY - linkCY; //test portée if ( max(abs(difx),abs(dify))>128) { if (gpJoueur->getAvancement()==6) gpJoueur->setAvancement(5); return; } // if (max(abs(difx),abs(dify))<16) return; if (gpJoueur->getAvancement()==5) gpJoueur->setAvancement(6); if (abs(difx) > abs(dify)) { if (difx>0) direction=O; else direction=E; } else { if (dify>0) direction=N; else direction=S; } if (gpJeu->getJoueur()->getX() < x) moveX(-1); if (gpJeu->getJoueur()->getX() > x) moveX(1); if (gpJeu->getJoueur()->getY() < y) moveY(-1); if (gpJeu->getJoueur()->getY() > y) moveY(1); }
uint4 getInput( uint x, uint y, uint direction, const __global int* map ) { const __global int * myMap = map + 2; int x1 = x, y1 = y; x1 = moveX( x, direction ); y1 = moveY( y, direction ); uint4 out; out.x = myMap[x1 + c_x_size*y1]; out.y = myMap[ moveX( x1, left( direction ) ) + c_x_size*moveY( y1, left( direction ) ) ]; out.z = myMap[ moveX( x1, right( direction ) ) + c_x_size*moveY( y1, right( direction ) ) ]; out.w = myMap[ moveX( x1, direction ) + c_x_size*moveY( y1, direction ) ]; return out; }
void AIController::run(int frameRate) { Controller::run(frameRate); coord[pos][0] = shipCoord().getX(); coord[pos][1] = shipCoord().getY(); pos++; it++; pos %= LOG_SIZE; if (it >= 5) { if (coord[pos][0] < coord[(pos + 1) % LOG_SIZE][0] && shipCoord().getX() < 0 && shipCoord().getZ() < 0 && !rotated) { // std::cout << "*"; if (getYaw() <= MAX_ROTATE_POWER) { plusYaw(); } } else { rotateX(); moveX(); rotateY(); moveY(); moveForward(); shoot(); } } // std::cout << "coord: " << shipCoord().getX() << " " << shipCoord().getY() << " " << shipCoord().getZ() << " "; // std::cout << "speed: " << radar->targetSpeed().getX() << " " << radar->targetSpeed().getY() << " " << // radar->targetSpeed().getZ() << " "; // std::cout << "angular: " << m_object->angularVelocity().getX() << " " << m_object->angularVelocity().getY() << " "; // std::cout << "thrust: " << thrust << " " << thrustY << " "; // std::cout << "power: " << power << " "; // std::cout << "premtion: " << preemption().getX() << " " << preemption().getY() << " " << preemption().getZ() << " "; // std::cout << "\n"; m_object->run(frameRate); }
Board makeBoard(Group* group, Move move){ // Make Board from Group and Move Board board; int x,y; for(x=0;x<3;x++){ for(y=0;y<4;y++){ board.tile[x][y].x = x; board.tile[x][y].y = y; board.tile[x][y].occupied = getTile(x,y,*group); board.tile[x][y].enemyNum = 0; board.tile[x][y].myNum = 0; // Initialize Board with Group info } } if(move.dirc==PLACE){ board.tile[move.prevX][move.prevY].occupied = move.type; group->animal[group->num] = newAnimal(move.type, move.prevX, move.prevY); group->num++; // Apply Placement }else{ x = moveX(move.prevX,move.dirc); y = moveY(move.prevY,move.dirc); *group = moveGroup(*group, move.prevX, move.prevY, x, y); board.tile[move.prevX][move.prevY].occupied = 'o'; board.tile[x][y].occupied = move.type; // Apply Movement } return board; }
void moveDown() { if(face == 0 && flip == 1) { moveZ(1); } else if(face == 0 && flip == -1) { moveZ(-1); } else if(face == 2 && flip == 1) { moveX(-1); } else if(face == 2 && flip == -1) { moveX(1); } }
void Pnj::IA() { if (id == 3) { if (gpJeu->getJoueur()->getAvancement()==4) { if (y<30*16) {direction=N; moveY(1);} else if (x>28*16) {direction=N; moveX(-1);} } else if (x>=gpJeu->getJoueur()->getX()) direction=O; else direction=E; } if (id == 15 && !immo && gpJeu->getZone()==9 && gpJeu->getJoueur()->getAvancement()==6) { if (x>74*16-8) {direction=O; x-=1;} else if (y<22*16) {direction=S; y+=1;} else if (x>66*16-8) {direction=O; x-=1;} else {gpJeu->getJoueur()->setImmo(false); vie=0;gpJeu->getJoueur()->setAvancement(7); gpJeu->getMonde()->setValeur(64*16, 20*16, 923, -1, LIBRE, 0); gpJeu->getMonde()->setValeur(65*16, 20*16, 924, -1, LIBRE, 0); gpJeu->getMonde()->setValeur(64*16, 21*16, 925, -1, LIBRE, 0); gpJeu->getMonde()->setValeur(65*16, 21*16, 926, -1, LIBRE, 0); } return; } if (immo) return; if (parle()) return; if (typeIA==IA_SUIT) suit(); if (typeIA==IA_RANDOM) bouge(); }
void Engine::checkKeys(void) { if(keys['r']) { initPlayer(); } if(keys['4']) { turnCamera(0.002); } if(keys['5']) { zoomCamera(0.01); } if(keys['6']) { turnCamera(-0.002); } if(keys['8']) { zoomCamera(-0.01); } if(keys[playerKeys->keyUp()]) { moveX(player->GetxyS()); } if(keys[playerKeys->keyDown()]) { moveX(-player->GetxyS()); } if(keys[playerKeys->keyLeft()]) { moveY(player->GetxyS()); } if(keys[playerKeys->keyRight()]){ moveY(-player->GetxyS()); } //if(keys[playerKeys->keyJump()]) { if(state == 0) { index = player->GetZ() + 10; } } //if(index - player->GetZ() > 0.02) //{ player->SetZ(player->GetZ() + player->GetzS()); index-=player->GetzS(); } //else { player->SetZ(player->GetZ() - player->GetzS()); } }
void applyMy(char type, int prevX, int prevY, int dirc, Board* board){ // Apply my range to tile in the direction. int x = moveX(prevX,dirc), y = moveY(prevY,dirc); if(isInBoard(x,y)==0) return; board->tile[x][y].myReach[board->tile[x][y].myNum] = type; board->tile[x][y].myNum++; }
void goForwards() { moveX(10); moveY(30); while(!digitalInput(0)) { delayMs(50); } moveY(0); }
void moveRight() { while(1) { moveY(0); moveX(30); while(digitalInput(0)) { delayMs(50); if(analog(0) >127) { return; } } moveX(0); moveY3(25); while(!digitalInput(0)) { delayMs(50); } } }
void goRightNoSuper() { moveXAdjusted(30); moveY(0); while(analog(0) < 127) { delayMs(50); } moveY(0); moveX(0); }
void motorTest() { clearScreen(); printString("motor test"); buttonWait(); clearScreen(); printString("forwards"); moveY(10); delayMs(2000); moveY(0); buttonWait(); clearScreen(); printString("right"); moveX(10); delayMs(2000); moveX(0); clearScreen(); printString("done"); }
void moveUp() { if(face == 0 && flip == 1) { if(!moveZ(-1)) coi[1] += 5; } else if(face == 0 && flip == -1) { if(!moveZ(1)) coi[1] += 5; } else if(face == 2 && flip == 1) { if(!moveX(1)) coi[1] += 5; } else if(face == 2 && flip == -1) { if(!moveX(-1)) coi[1] += 5; } }
void Mogh::collision(gen::Sprite* other, gen::World* w){ if(Troll* ch = dynamic_cast<Troll*>(other)){ damaged = true; setCurrentAnimationVector("DAMAGED"); setHealth(getHealth() - 10); setTimer( SDL_GetTicks() + 2000 ); setCollidable(false); setVelocityX(getVelocityX()*2); setVelocityY(getVelocityY()*2); } else if(gen::Object* o = dynamic_cast<gen::Object*>(other)){ std::string direction = getKeyOfCurrentAnimationVector(); if(direction == "LEFT"){ setMovementX(getVelocityX()); moveX(w); } else if(direction == "RIGHT"){ setMovementX(-getVelocityX()); moveX(w); } else if(direction == "BACK"){ setMovementY(getVelocityY()); moveY(w); } else if(direction == "FRONT"){ setMovementY(-getVelocityY()); moveY(w); } } else if(SeaStar* s = dynamic_cast<SeaStar*>(other)){ damaged = true; setCurrentAnimationVector("DAMAGED"); setHealth(getHealth() - s->getDamage()); setTimer( SDL_GetTicks() + 2000 ); setCollidable(false); setVelocityX(getVelocityX()*2); setVelocityY(getVelocityY()*2); } }
void Pnj::bouge() { int randomValue = (int)((float)rand() / RAND_MAX * (100)); switch (randomValue) { case 1 : moveX(-1);direction=O; break; case 2 : moveX(1); direction=E; break; case 3 : moveY(-1);direction=N; break; case 4 : moveY(1); direction=S; break; case 5 : case 6 : case 7 : case 8 : break; default : switch (direction) { case N : moveY(-1); break; case S : moveY(1); break; case O : moveX(-1); break; case E : moveX(1); break; } break; } }
void mov_pacman_jogo(int passo) { encontra_pacman(); switch(direcao)//up { case 1: moveX(1); break; case 2://down moveX(2); break; case 3://left moveY(3); break; case 4://Right moveY(4); break; } glutPostRedisplay(); glutTimerFunc(50,mov_pacman_jogo,1); }
void FpsCamera::updateCameraView(float dt) { if(isKeyLeftPressed) { moveX(dt*speed); } if(isKeyRightPressed) { moveX(-dt*speed); } if(isKeyFrontPressed) { moveZ(dt*speed); } if(isKeyBackPressed) { moveZ(-dt*speed); } }
void FpsCamera::updateCameraView(float invFrameRate) { if(isKeyLeftPressed) { moveX(invFrameRate*speed); } if(isKeyRightPressed) { moveX(-invFrameRate*speed); } if(isKeyFrontPressed) { moveZ(invFrameRate*speed); } if(isKeyBackPressed) { moveZ(-invFrameRate*speed); } }
int animalCanFlee(Board board, int x, int y, int type){ int i, tileToFlee = 0; for(i=0; i<animalDirectionCount[type]; i++){ int dirc = animalDirections[type][i]; int myX = moveX(x, dirc); int myY = moveY(y, dirc); if(myX>3 || myX<0 || myY>4 || myY<0) continue; if(board.tile[myX][myY].occupied == 'o') tileToFlee = 1; if(isEnemy(board.tile[myX][myY].occupied) && board.tile[myX][myY].myNum == 1) return 0; } return tileToFlee; }
int getPlaceDanger(Board board, Animal enemy){ int i; int type = charToAnimalnum(enemy.type); for(i=0; i<animalDirectionCount[type]; i++){ int dirc = animalDirections[type][i]; int x = moveX(enemy.x, dirc); int y = moveY(enemy.y, dirc); if(x>=3 || x<0 || y>=4 || y<0) continue; char myType = charToAnimalnum(board.tile[x][y].occupied); if(!isMine(myType)) continue; if(!animalCanFlee(board, x, y, myType)) return typeToScore(board.tile[x][y].occupied)/2; } return 0; }
void collectBackwards() { // Really slow moveY(-8); //moveX(0); while(1) { // if (analog(0) > 80) if (digitalInput(1)) // bump sensor is tripped { moveX(0); moveY(0); break; } delayMs(50); } }
void Gib::act(std::vector< Object * > * others, World * world, std::vector< Object * > * add){ if (fade > 0){ fade += 2; if (fade > 255){ setHealth(-1); } } else { moveX(dx); moveY(dy); moveZ(dz); dy -= 0.1; if ( getY() <= 0 ){ dy = -dy / 2; dx = dx / 2; dz = dz / 2; if ( fade == 0 && fabs( dy ) < 0.1 ){ fade = 1; } } double gibAmount = Configuration::getProperty(GibProperty, 5) / 5.0; for (int i = 0; i < Util::rnd((int)(2 * gibAmount)) + 2; i++){ int x = getRX() + Util::rnd(5) - 2; int y = getRY() + Util::rnd(5) - 2; blood.push_back(Point(x, y, Util::rnd(10) + 5)); } for (std::vector< Point >::iterator it = blood.begin(); it != blood.end(); /**/){ Point & p = *it; p.life -= 1; if (p.life <= 0){ it = blood.erase(it); } else { it++; } } angle += (int) sqrt(dx * dx + dy * dy) * 3; } }
void Monsters::moveToPlayer(Player* p){ int dx = (p->position().x > position().x)? 1:-1; int dy = (p->position().y > position().y)? 1:-1; point2D moveX(position().x+dx,position().y); point2D moveY(position().x, position().y+dy); if (p->position() == moveX || p->position() == moveY) { attack(p); return; } if (position().x == p->position().x){ moveToPoint(moveY); return; } if (position().y == p->position().y) { moveToPoint(moveX); return; } if (moveToPoint(moveX)) { return; } else{ moveToPoint(moveY); } }
void BuddyPlayer::act( vector< Object * > * others, World * world, vector< Object * > * add ){ Character::act(others, world, add); if (show_life > getHealth()){ show_life--; } if (show_life < getHealth()){ show_life++; } vector<Object *> enemies; if (getStatus() != Status_Ground && getStatus() != Status_Jumping){ return; } filterEnemies(enemies, others); if (animation_current->Act()){ animation_current->reset(); // nextTicket(); // animation_current = movements[ "idle" ]; animation_current = getMovement("idle"); animation_current->reset(); } if (animation_current == getMovement("idle") || animation_current == getMovement("walk") ){ if (enemies.empty() && want_x == -1 && want_z == -1 && Util::rnd(15) == 0){ // want_x = Util::rnd( 100 ) - 50 + furthestFriend( others, getAlliance(), this ); want_x = Util::rnd(100) - 50 + (int) leader->getX(); want_z = Util::rnd(world->getMinimumZ(), world->getMaximumZ()); } else if (! enemies.empty()){ const Object * main_enemy = findClosest(enemies); if ( main_enemy->getX() > getX() ){ want_x = (int)(main_enemy->getX() - 20 - Util::rnd(20)); } else { want_x = (int)(main_enemy->getX() + 20 + Util::rnd(20)); } if (want_x < 1){ want_x = Util::rnd(100) - 50 + (int) leader->getX(); } want_z = (int)(Util::rnd(3) - 1 + main_enemy->getZ()); faceObject(main_enemy); if (Util::rnd(35) == 0){ vector<Util::ReferenceCount<Animation> > attacks; for (map<string, Util::ReferenceCount<Animation> >::const_iterator it = getMovements().begin(); it != getMovements().end(); it++){ Util::ReferenceCount<Animation> maybe = (*it).second; if (maybe->isAttack() && maybe->getStatus() == Status_Ground && maybe->getName() != "special"){ attacks.push_back(maybe); } } double attack_range = fabs( getX() - main_enemy->getX() ); double zdistance = ZDistance( main_enemy ); for (vector<Util::ReferenceCount<Animation> >::iterator it = attacks.begin(); it != attacks.end(); /**/){ Util::ReferenceCount<Animation> maybe = *it; if (attack_range > maybe->getRange() || zdistance > maybe->getMinZDistance()){ it = attacks.erase(it); } else { it++; } } if (!attacks.empty()){ animation_current = attacks[Util::rnd(attacks.size())]; world->addMessage(animationMessage()); nextTicket(); animation_current->reset(); return; } else { } } } if (want_x != -1 && want_z != -1){ bool walk = false; if (want_x < 1){ want_x = 1; } if (want_z < world->getMinimumZ()){ want_z = world->getMinimumZ() + 1; } if (want_z >= world->getMaximumZ()){ want_z = world->getMaximumZ() - 1; } if (getX() - want_x < -2){ moveX(getSpeed()); setFacing(FACING_RIGHT); walk = true; } else if (getX() - want_x > 2){ setFacing(FACING_LEFT); moveX(getSpeed()); walk = true; } if (getZ() < want_z){ moveZ(getSpeed()); walk = true; } else if (getZ() > want_z){ moveZ(-getSpeed()); walk = true; } if (walk){ animation_current = getMovement("walk"); } if (fabs(getX() - want_x) <= 2 && fabs(getZ() - want_z) <= 2){ want_x = -1; want_z = -1; animation_current = getMovement("idle"); } } } }
void PlayableCharacter::moveRight() { direction = RIGHT; if(animate()) { moveX(++x); } }
void PlayableCharacter::moveLeft() { direction = LEFT; if(animate()) { moveX(--x); } }