//movement and actions void move_left() { moving_left = 1; moving_right = 0; if(cur_level == 1) { if(pos_x != 0 && level1[pos_y][pos_x-1] != TILE && level1[pos_y-1][pos_x-1] != TILE && level1[pos_y+1][pos_x] != 0 && level1[pos_y+1][pos_x] != EXIT_COLOR) { if(level1[pos_y][pos_x-1] == GREEN) { player_HP--; } if(player_HP == 0) { reset(); } has_moved = 1; level1[pos_y][pos_x] = 0; level1[pos_y-1][pos_x] = 0; pos_x--; level1[pos_y][pos_x] = YELLOW; level1[pos_y-1][pos_x] = YELLOW; } else if(level1[pos_y+1][pos_x-1] == EXIT_COLOR) { next_level(); } else if(level1[pos_y+1][pos_x] == 0) { fall(); } } if(cur_level == 2) { if(pos_x != 0 && level2[pos_y][pos_x-1] != TILE && level2[pos_y-1][pos_x-1] != TILE && level2[pos_y+1][pos_x] != 0) { if(level2[pos_y][pos_x-1] == GREEN) { player_HP--; } if(player_HP == 0) { reset(); } has_moved = 1; level2[pos_y][pos_x] = 0; level2[pos_y-1][pos_x] = 0; pos_x--; level2[pos_y][pos_x] = YELLOW; level2[pos_y-1][pos_x] = YELLOW; } else if(level2[pos_y+1][pos_x] == 0) { fall(); } } }
void Character::update(InputManager& inputManager, b2World* world) { #ifdef __WIN32__ if (inputManager.isKeyPressed(SDLK_UP)) { jump(); } if (inputManager.isKeyPressed(SDLK_DOWN)) { slide(); } if (inputManager.isKeyReleased(SDLK_UP)) { fall(); } if (inputManager.isKeyReleased(SDLK_DOWN)) { stopSlide(); } #endif #ifdef __ANDROID__ if (inputManager.isKeyPressed(SDL_FINGERDOWN)) { jump(); } #endif }
//the keyboard callback to change the values to the transforms void keyboard(unsigned char key, int x, int y ) { // printf("%c pressed\n", key); switch( key ) { case 'w': moveForward(); break; case 's': moveBackward(); break; case 'a': strafeLeft(); break; case 'd': strafeRight(); break; case 32: // space rise(); break; case 'c': fall(); break; case 'n': g_shadeType = g_shadeType == NORMAL ? PHONG : NORMAL; break; case 'q': case 'Q' : exit( EXIT_SUCCESS ); break; } //glutPostRedisplay(); }
void Runner::moveStep(float delta) { Cell* cell = field->cell(x,y); if (!climbing) if (cell->growing() && ((GrowingCell*)cell)->solid()) { this->die(); return; } if (falling) { if (checkFall(delta)); catchBonus(); } if (climbing) { x = x + vx * delta; y = y + vy * delta; checkClimb(); } if (!busy()) { if (vx < 0) tryMoveLeft(delta); else if (vx > 0) tryMoveRight(delta); catchBonus(); if (!field->hasSurface(round(x), y)) fall(); } if (stopping) doStop(); if (fabs(x-field->grenadePutX)>0.3 || fabs(y-field->grenadePutY)>0.3) field->grenadePutX = 1000; }
char kongjumpright(char **map, char c, t_pict *pict) { int x, y; char sauv = c; x = 0; y = 0; while (map[x][y] != 'i' && map[x][y] != 'j') { if (map[x][y] == '\n') { y = 0; x++; } y++; } if (map[x - 1][y] != 'w' || map[x -1][y] == 'k') sauv = kongjumpright_2(x, y, c, map, pict); if (sauv == 'o' && (check_end(map) == 1)) donkey_win(pict->win); fall(map, pict); if (sauv == 'n' || sauv == 'm' || sauv == 'k') { if (c != 's') sauv = '.'; } return (sauv); }
void Enemy1::doActions(std::list<GameCharacter*> characters) { punched = false; moveDir = { true, true, true, true }; //collision(characters); currentCondition = STANDING; action = false; currentGoal = getGoalSquare(); if (player_punching()) { fall(); } else { animation("WALLKING"); if (currentGoal != currentSquare[0]) { moving(); } if (action) { frame++; } else punch_players(); } if (frame / FRAMES_DELIMITOR >= Clips.size()) { frame = firstclip; } prevTargetLocation = currentGoal; }
void BadGuy::action_bouncingsnowball(double frame_ratio) { static const float JUMPV = 4.5; fall(); // jump when on ground if(dying == DYING_NOT && issolid(base.x, base.y+32)) { physic.set_velocity_y(JUMPV); physic.enable_gravity(true); } else { mode = NORMAL; } // check for right/left collisions check_horizontal_bump(); physic.apply(frame_ratio, base.x, base.y); if(dying == DYING_NOT) collision_swept_object_map(&old_base, &base); // Handle dying timer: if (dying == DYING_SQUISHED && !timer.check()) { /* Remove it if time's up: */ remove_me(); return; } }
void GameStateManager::makeItemsDrop(const WorldCoords & wc) { Map::AlertMap new_alerts; auto interesting_blocks = m_map.blockAlerts().equal_range(wc + BLOCK_YPLUS); // if y == 127, we won't find anything. for (auto it = interesting_blocks.first; it != interesting_blocks.second; ) { if (it->second.type == Map::BlockAlert::CONTAINS_SPAWN_ITEM) { WorldCoords wbelow(wc); if (fall(wbelow)) { new_alerts.insert(std::make_pair(wbelow, it->second)); std::cout << "Item " << it->second.data << " must fall from " << wc << " to " << wbelow << "." << std::endl; } else { std::cout << "Item " << it->second.data << " falls from " << wc << " to its death." << std::endl; sendRawToAll(rawPacketSCDestroyEntity(it->second.data)); } m_map.blockAlerts().erase(it++); } else { ++it; } } m_map.blockAlerts().insert(new_alerts.begin(), new_alerts.end()); }
void step(){ energymean = 0; int i; int prog[INSTRUCTIONS]; repBlocks = 0; quantityMoved = 0; quantityKiled = 0; for(i = 0; i < INSTRUCTIONS; i++){ prog[i] = rand() % 8; } setBlock(rand() % X_SIZE,0, prog, NULL, 0, 50, 50, 0); for(i = 0; i < X_SIZE; i++){ memset(grid[i], NULL, sizeof(grid[i][0]) * Y_SIZE); } for(i = 0; i < lastBlock; i++){ blockList[i].verified = 0; blockList[i].moved = 0; grid[blockList[i].x][blockList[i].y] = &blockList[i]; } resoursesDistribuition(); for(i = 0; i < lastBlock; i++){ run(&blockList[i]); } fall(); resolveKileds(); resolveRep(); resolveMoves(); }
void Cat::update(Uint32 ticks) { //std::cout << ticks << std::endl; advanceFrame(ticks); if(t >= 0){ jump(ticks) ; } else if( t2 >= 0){ fall(ticks) ; } else{ Vector2f incr = getVelocity() * static_cast<float>(ticks) * 0.001; setPosition(getPosition() + incr); if ( Y() < 0) { velocityY( abs( velocityY() ) ); } if ( Y() > worldHeight-frameHeight) { velocityY( -abs( velocityY() ) ); } if ( X() < 0) { velocityX( abs( velocityX() ) ); } if ( X() > worldWidth-frameWidth) { velocityX( -abs( velocityX() ) ); } } }
/** @REAL_TIME */ void Player::update(const float& dt, ColisionSide& side ){ pCurrentSprite->update(dt); if( pIsFly ) { pVY = PLAYER_Y_VELOCITY; pAY = PLAYER_Y_ACCELERATION; pCurrentSprite = &pFlySprite; } /** Polozenie w poziomie */ //@TODO powiazac ilosc zycia z szybkoscia //@TODO usunac liczbe magiczna//@TODO przeniesc do przesuwania mapy if( pCurrentSprite != ( &pStandSprite ) ) { if( pX < ( LiveBar::getLiveAmount()*pMaxPlayerOnScreenX ) ) { pX += dt * 100; } else if( pX > ( LiveBar::getLiveAmount()*pMaxPlayerOnScreenX ) && pX > PLAYER_OFFSET_X ) { pX -= dt *100; } /** Polozenie w pionie */ float nextY = pY + ( (pVY+pAY) * (dt) * 15); if( side.up == true && nextY < pY ) { fall(); pY = side.pos_Y_px; return; } if( side.down == true && nextY > pY ) { pCurrentSprite = &pRunSprite; pY = side.pos_Y_px; return; } if( side.down != true && pY != MAX_Y_PLAYER && nextY > pY ) pCurrentSprite = &pFlySprite; if( nextY > PLAYER_MAX_Y_POS && nextY < MAX_Y_PLAYER ) { pY = nextY; } else if( nextY >= MAX_Y_PLAYER ) { // gracz laduje na ziemi pCurrentSprite = &pRunSprite; pY = MAX_Y_PLAYER; } if( pCurrentSprite != &pRunSprite ) pVY -= pAY * (dt*0.5); } }
void game::Click(int nx, int ny) { if(exchange==false) { exchange = true; x1 = nx; y1 = ny; } else if(exchange==true&&(((x1==nx)&&(y1==ny+1))||((x1==nx)&&(y1==ny-1))||((x1==nx+1)&&(y1==ny))||((x1==nx-1)&&(y1==ny)))) { x2 = nx; y2 = ny; int temp_sp,temp_c; qDebug()<<candytable[x1][y1]<<endl; qDebug()<<candytable[x2][y2]<<endl; temp_sp = candy_b[x1][y1]->spec; candy_b[x1][y1]->spec = candy_b[x2][y2]->spec; candy_b[x2][y2]->spec = temp_sp; temp_c = candytable[x1][y1]; candytable[x1][y1] = candytable[x2][y2]; candytable[x2][y2] = temp_c; if(candytable[x1][y1]=='z'||candytable[x2][y2]=='z') { chocolate = true; qDebug()<<"choco ok"<<endl; } while(check()==false) { clean(); fall(); generate(); //delete [] candy_b; deletearr(); //qDebug()<<"delete ok"<<endl; showcandy(); } if(checkchange()==false) { temp_sp = candy_b[x1][y1]->spec; candy_b[x1][y1]->spec = candy_b[x2][y2]->spec; candy_b[x2][y2]->spec = temp_sp; temp_c = candytable[x1][y1]; candytable[x1][y1] = candytable[x2][y2]; candytable[x2][y2] = temp_c; } exchange = false; chocolate = false; } else { x1 = nx; y1 = ny; } }
void BadGuy::action_stalactite(double frame_ratio) { Player& tux = *World::current()->get_tux(); static const int SHAKETIME = 800; static const int RANGE = 40; if(mode == NORMAL) { // start shaking when tux is below the stalactite and at least 40 pixels // near if(tux.base.x + 32 > base.x - RANGE && tux.base.x < base.x + 32 + RANGE && tux.base.y + tux.base.height > base.y) { timer.start(SHAKETIME); mode = STALACTITE_SHAKING; } } if(mode == STALACTITE_SHAKING) { base.x = old_base.x + (rand() % 6) - 3; // TODO this could be done nicer... if(!timer.check()) { mode = STALACTITE_FALL; } } else if(mode == STALACTITE_FALL) { fall(); /* Destroy if we collides with land */ if(issolid(base.x+base.width/2, base.y+base.height)) { timer.start(2000); dying = DYING_SQUISHED; mode = FLAT; set_sprite(img_stalactite_broken, img_stalactite_broken); } } else if(mode == FLAT) { fall(); } // move physic.apply(frame_ratio, base.x, base.y); if(dying == DYING_SQUISHED && !timer.check()) remove_me(); }
// remove the element that has the highest // priority from the priority queue // (highest priority might mean smallest value) ProcessPointer pqDequeue( PriorityQueuePointer pq ) { printPriorityQueue( pq ); ProcessPointer result = pq->data[1]; pq->data[1] = pq->data[pq->size]; pq->data[pq->size] = NULL; pq->size--; fall( pq, 1 ); return result; } // pqEnqueue()
void Golem::update() { if (!stan_flag) { move(); fall(); vector(); updateChara(); } if (stan_flag == true) { vec_.x() = 0.0f; } }
void BadGuy::action_snowball(double frame_ratio) { if (dying == DYING_NOT) check_horizontal_bump(); fall(); physic.apply(frame_ratio, base.x, base.y); if (dying != DYING_FALLING) collision_swept_object_map(&old_base,&base); }
void GameStateManager::spawnSomething(uint16_t type, uint8_t number, uint8_t damage, const WorldCoords & wc) { WorldCoords wbelow(wc); if (!fall(wbelow)) return; int32_t eid = GenerateEID(); m_map.blockAlerts().insert(std::make_pair(wbelow, Map::BlockAlert(Map::BlockAlert::CONTAINS_SPAWN_ITEM, eid))); m_map.items().insert(std::make_pair(eid, type)); // stub sendToAll(MAKE_CALLBACK(packetSCPickupSpawn, eid, type, number, damage, wc)); }
void Duck::act() { switch (state) { case DuckState::IDLE : break; case DuckState::FLYING_IN : flyIn(); break; case DuckState::FLYING_AROUND: flyAround(); break; case DuckState::SHOT : die(); break; case DuckState::FALLING : fall(); break; case DuckState::FLYING_OUT : flyOut(); break; default: throw std::invalid_argument("Duck state #" + boost::lexical_cast<std::string, int>(int(state)) + " not recognized!"); } updateShotBox(); prevstate = state; }
void Entity::updateFallState(double d, boolean flag) { if(flag) { if(fallDistance > 0.0F) { fall(fallDistance); fallDistance = 0.0F; } } else if(d < 0.0D) { fallDistance -= d; } }
void Slime::update() { ride_pos = pos + Vec2f(10, size.y()); ride_size = Vec2f(size.x()-20, 10); if (!stan_flag) { move(); fall(); vector(); updateChara(); directionControlEnemy(); } if (stan_flag == true) { vec_.x() = 0.0f; } }
void missile(int ydelta, int xdelta) { struct object *obj; struct linked_list *item, *nitem; /* * Get which thing we are hurling */ if ((item = get_item("throw", WEAPON)) == NULL) return; obj = (struct object *) ldata(item); if (!dropcheck(obj) || is_current(obj)) return; /* * Get rid of the thing. If it is a non-multiple item object, or * if it is the last thing, just drop it. Otherwise, create a new * item with a count of one. */ if (obj->o_count < 2) { detach(pack, item); inpack--; } else { obj->o_count--; if (obj->o_group == 0) inpack--; nitem = (struct linked_list *) new_item(sizeof *obj); obj = (struct object *) ldata(nitem); *obj = *((struct object *) ldata(item)); obj->o_count = 1; item = nitem; } do_motion(obj, ydelta, xdelta); /* * AHA! Here it has hit something. If it is a wall or a door, * or if it misses (combat) the mosnter, put it on the floor */ if (!ismons(CMVWINCH(mw, obj->o_pos.y, obj->o_pos.x)) || !hit_monster(unc(obj->o_pos), obj)) fall(item, TRUE); mvwaddrawch(cw, hero.y, hero.x, PLAYER); }
void circle::move(){ if(sDisp>0){ if(angle>TWO_PI)angle=0; }else if(sDisp<=0){ if(angle<0)angle=TWO_PI; } angle+=sDisp; if(fixing){ falling=false; antiFall(); } else if(falling){ fall(); }else{ pos.x=(pRad*cos(angle))+ofGetWidth()/2; pos.y=(pRad*sin(angle))+ofGetHeight()/2; } }
void BadGuy::action_jumpy(double frame_ratio) { const float vy = physic.get_velocity_y(); // XXX: These tests *should* use location from ground, not velocity if (fabsf(vy) > 5.6f) set_sprite(img_jumpy_left_down, img_jumpy_left_down); else if (fabsf(vy) > 5.3f) set_sprite(img_jumpy_left_middle, img_jumpy_left_middle); else set_sprite(img_jumpy_left_up, img_jumpy_left_up); Player& tux = *World::current()->get_tux(); static const float JUMPV = 6; fall(); // jump when on ground if(dying == DYING_NOT && issolid(base.x, base.y+32)) { physic.set_velocity_y(JUMPV); physic.enable_gravity(true); mode = JUMPY_JUMP; } else if(mode == JUMPY_JUMP) { mode = NORMAL; } // set direction based on tux if(tux.base.x > base.x) dir = RIGHT; else dir = LEFT; // move physic.apply(frame_ratio, base.x, base.y); if(dying == DYING_NOT) collision_swept_object_map(&old_base, &base); }
void updateBoard() { int fallFinished = fall(); int lineFilled; // this checks if the shape has reached the bottom of its decent if(fallFinished) { lineFilled = lockShape(); // FIXME: Line filled should just call findFilledLine(). lockShape() should return a 1 if there is a game over // this checks if there is a full line of blocks needing to be removed if (lineFilled >= 0) { destroyLines(); } } return; }
void BadGuy::action_spiky(double frame_ratio) { if (dying == DYING_NOT) check_horizontal_bump(); fall(); #if 0 // jump when we're about to fall if (physic.get_velocity_y() == 0 && !issolid(base.x+base.width/2, base.y + base.height)) { physic.enable_gravity(true); physic.set_velocity_y(2); } #endif physic.apply(frame_ratio, base.x, base.y); if (dying != DYING_FALLING) collision_swept_object_map(&old_base,&base); }
void Entity::checkCollisionsWithLevel(Level &lvl) { if (!isAnyFieldBelowMe(lvl)) int a = 0 ; // czy jednostka koliduje z czymœ od do³u if (isAnyFieldBelowMe(lvl)) playerOnGround(); // czy jednostka koliduje z czymœ od góry if(isAnyFieldAboveMe(lvl)) fall(); // czy jednostka koliduje z czymœ po lewej stronie if (isAnyFieldOnLeft(lvl)) moveRight(); // czy jednostka koliduje z czymœ po prawej stronie if (isAnyFieldOnRight(lvl)) moveLeft(); };
// -------- Begin of function RainSpot::draw_step -------// void RainSpot::draw_step(VgaBuf *vgabuf) { fall(); short x,y; /* x = center_x - step; y = center_y - step/2; vgabuf->draw_pixel(x,y,0x73); x = center_x - step/2; y = center_y - step; vgabuf->draw_pixel(x,y,0x73); x = center_x + step/2; y = center_y - step; vgabuf->draw_pixel(x,y,0x73); x = center_x + step; y = center_y - step/2; vgabuf->draw_pixel(x,y,0x73); */ // BUGHERE : didn't check ZOOM_X1,Y1,X2,Y2 x = center_x - step; y = center_y - step; // ##### begin Gilbert 8/5 ######// if( x >= ZOOM_X1 && x < ZOOM_X2 && y >= ZOOM_Y1 && y < ZOOM_Y2) vgabuf->draw_pixel(x,y,VGA_GRAY+12); x = center_x - step; y = center_y + step/2; if( x >= ZOOM_X1 && x < ZOOM_X2 && y >= ZOOM_Y1 && y < ZOOM_Y2) vgabuf->draw_pixel(x,y,VGA_GRAY+12); x = center_x + step; y = center_y - step; if( x >= ZOOM_X1 && x < ZOOM_X2 && y >= ZOOM_Y1 && y < ZOOM_Y2) vgabuf->draw_pixel(x,y,VGA_GRAY+12); x = center_x + step; y = center_y + step/2; if( x >= ZOOM_X1 && x < ZOOM_X2 && y >= ZOOM_Y1 && y < ZOOM_Y2) vgabuf->draw_pixel(x,y,VGA_GRAY+12); // ##### end Gilbert 8/5 ######// }
// move an element down in the tree // until the heap condition (value of each // node is less than the value of its children) // is restored void fall( PriorityQueuePointer pq, int i ) { // i is the index of a parent node in the heap // j and k are the indices of its children // choose the smaller of the children int j = 2 * i; int k = 2 * i + 1; if( k <= pq->size && compareElements( pq, k, j) < 0 ) { j = k; } // if // do not fall too far! // stop falling when heap condition has // been stored if( j <= pq->size && compareElements(pq, j, i) < 0 ) { swap( pq, i, j ); //int temp = pq->data[i]; //pq->data[i] = pq->data[j]; //pq->data[j] = temp; fall( pq, j ); } // if } // fall( PriorityQueuePointer, int )
void missile(int ydelta, int xdelta) { THING *obj; /* * Get which thing we are hurling */ if ((obj = get_item("throw", WEAPON)) == NULL) return; if (!dropcheck(obj) || is_current(obj)) return; obj = leave_pack(obj, TRUE, FALSE); do_motion(obj, ydelta, xdelta); /* * AHA! Here it has hit something. If it is a wall or a door, * or if it misses (combat) the monster, put it on the floor */ if (moat(obj->o_pos.y, obj->o_pos.x) == NULL || !hit_monster(unc(obj->o_pos), obj)) fall(obj, TRUE); }
void BadGuy::action_bomb(double frame_ratio) { static const int TICKINGTIME = 1000; static const int EXPLODETIME = 1000; fall(); if(mode == NORMAL) { mode = BOMB_TICKING; timer.start(TICKINGTIME); } else if(!timer.check()) { if(mode == BOMB_TICKING) { mode = BOMB_EXPLODE; set_sprite(img_mrbomb_explosion, img_mrbomb_explosion); dying = DYING_NOT; // now the bomb hurts timer.start(EXPLODETIME); /* play explosion sound */ // FIXME: is the stereo all right? maybe we should use player cordinates... if (base.x < scroll_x + screen->w/2 - 10) play_sound(sounds[SND_EXPLODE], SOUND_LEFT_SPEAKER); else if (base.x > scroll_x + screen->w/2 + 10) play_sound(sounds[SND_EXPLODE], SOUND_RIGHT_SPEAKER); else play_sound(sounds[SND_EXPLODE], SOUND_CENTER_SPEAKER); } else if(mode == BOMB_EXPLODE) { remove_me(); return; } } // move physic.apply(frame_ratio, base.x, base.y); collision_swept_object_map(&old_base,&base); }