void GoldBomb::active_update(float elapsed_time) { if(tstate == STATE_TICKING) { ticking->set_position(get_pos()); if(sprite->animation_done()) { kill_fall(); } else if (!grabbed) { movement = physic.get_movement(elapsed_time); } return; } if(grabbed) return; WalkingBadguy::active_update(elapsed_time); }
void BadGuy::kill_squished(GameObject& object) { sound_manager->play("sounds/squish.wav", get_pos()); physic.enable_gravity(true); physic.set_velocity_x(0); physic.set_velocity_y(0); set_state(STATE_SQUISHED); set_group(COLGROUP_MOVING_ONLY_STATIC); Player* player = dynamic_cast<Player*>(&object); if (player) { player->bounce(*this); } // start dead-script run_dead_script(); }
void LifeForm::move_to(const WorldPosition &new_position) { auto world = m_world.lock(); if (!world) { return; } auto old_loc = world->location(get_pos()); auto new_loc = world->location(new_position); if (new_loc != old_loc && m_unvisited_tiles.count(new_loc)) { m_unvisited_tiles.erase(new_loc); m_visited_tiles.insert(new_loc); } m_pos_x = new_position.x; m_pos_y = new_position.y; }
void FlipLevelTransformer::transform_sector(Sector* sector) { float height = sector->get_height(); for(auto& object : sector->get_objects()) { auto tilemap = dynamic_cast<TileMap*>(object.get()); if(tilemap) { transform_tilemap(height, *tilemap); } auto player = dynamic_cast<Player*>(object.get()); if(player) { Vector pos = player->get_pos(); pos.y = height - pos.y - player->get_bbox().get_height(); player->move(pos); continue; } auto badguy = dynamic_cast<BadGuy*>(object.get()); if(badguy) { transform_badguy(height, *badguy); } auto flower = dynamic_cast<Flower*>(object.get()); if(flower) { transform_flower(*flower); } auto platform = dynamic_cast<Platform*>(object.get()); if(platform) { transform_platform(height, *platform); } auto block = dynamic_cast<Block*>(object.get()); if(block) { transform_block(height, *block); } auto mobject = dynamic_cast<MovingObject*>(object.get()); if(mobject) { transform_moving_object(height, *mobject); } } for(auto& spawnpoint : sector->m_spawnpoints) { transform_spawnpoint(height, *spawnpoint); } if(sector->m_camera != nullptr && sector->m_player != nullptr) sector->m_camera->reset(sector->m_player->get_pos()); }
void Rock::collision_solid(const CollisionHit& hit) { if(grabbed) { return; } if(hit.top || hit.bottom) physic.set_velocity_y(0); if(hit.left || hit.right) physic.set_velocity_x(0); if(hit.crush) physic.set_velocity(0, 0); if(hit.bottom && !on_ground && !grabbed) { SoundManager::current()->play(ROCK_SOUND, get_pos()); on_ground = true; } }
void Path_Map::print(FILE* out) { Point p(0, 0, level); for (unsigned int j = 0; j <= height; j++) { for (unsigned int i = 0; i <= width; i++) { p.x = i; p.y = j; Node* node = table[get_pos(&p)]; if (node == NULL || node->g == HUGE_VAL || node->g < 0) fprintf(out, " "); else if (node->check_state(WAITING) || node->check_state(FRINGE)) fprintf(out, "%4.1f_ ", node->g); else fprintf(out, "%4.1f ", node->g); } fprintf(out, "\n"); } }
void Totem::jump_on(Totem* target) { if (target->carrying) { log_warning << "target is already carrying someone" << std::endl; return; } target->carrying = this; this->carried_by = target; this->initialize(); bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); SoundManager::current()->play( LAND_ON_TOTEM_SOUND , get_pos()); this->synchronize_with(target); }
void Block::update(float elapsed_time) { if(!bouncing) return; float offset = original_y - get_pos().y; if(offset > BOUNCY_BRICK_MAX_OFFSET) { bounce_dir = BOUNCY_BRICK_SPEED; movement = Vector(0, bounce_dir * elapsed_time); } else if(offset < BOUNCY_BRICK_SPEED * elapsed_time && bounce_dir > 0) { movement = Vector(0, offset); bounce_dir = 0; bouncing = false; } else { movement = Vector(0, bounce_dir * elapsed_time); } }
Bomb::Bomb(const Vector& pos, Direction dir_, std::string custom_sprite /*= "images/creatures/mr_bomb/mr_bomb.sprite"*/ ) : BadGuy( pos, dir_, custom_sprite ), state(), grabbed(false), grabber(NULL), ticking() { state = STATE_TICKING; set_action(dir_ == LEFT ? "ticking-left" : "ticking-right", 1); countMe = false; ticking = SoundManager::current()->create_sound_source("sounds/fizz.wav"); ticking->set_position(get_pos()); ticking->set_looping(true); ticking->set_gain(2.0); ticking->set_reference_distance(32); ticking->play(); }
HitResponse Snowman::collision_bullet(Bullet& bullet, const CollisionHit& hit) { if(bullet.get_type() == FIRE_BONUS) { // fire bullets destroy snowman's body loose_head(); SoundManager::current()->play("sounds/pop.ogg", get_pos()); // this could be a different sound bullet.remove_me(); return ABORT_MOVE; } else { // in all other cases, bullets ricochet bullet.ricochet(*this, hit); return FORCE_MOVE; } }
void BadGuy::kill_fall() { if (!is_active()) return; SoundManager::current()->play("sounds/fall.wav", get_pos()); physic.set_velocity_y(0); physic.set_acceleration_y(0); physic.enable_gravity(true); set_state(STATE_FALLING); // Set the badguy layer to be the foremost, so that // this does not reveal secret tilemaps: layer = Sector::current()->get_foremost_layer() + 1; // start dead-script run_dead_script(); }
HitResponse Player::collision(GameObject& other, const CollisionHit& ) { Bullet* bullet = dynamic_cast<Bullet*> (&other); if(bullet) { return FORCE_MOVE; } if(other.get_flags() & FLAG_PORTABLE) { Portable* portable = dynamic_cast<Portable*> (&other); assert(portable != NULL); if(portable && grabbed_object == NULL && controller->hold(Controller::ACTION) /*&& fabsf(hit.normal.x) > .9*/) { grabbed_object = portable; grabbed_object->grab(*this, get_pos(), dir); return CONTINUE; } } #ifdef DEBUG assert(dynamic_cast<MovingObject*> (&other) != NULL); #endif MovingObject* moving_object = static_cast<MovingObject*> (&other); if(moving_object->get_group() == COLGROUP_TOUCHABLE) { TriggerBase* trigger = dynamic_cast<TriggerBase*> (&other); if(trigger) { if(controller->pressed(Controller::UP)) trigger->event(*this, TriggerBase::EVENT_ACTIVATE); } return FORCE_MOVE; } BadGuy* badguy = dynamic_cast<BadGuy*> (&other); if(badguy != NULL) { if(safe_timer.started() || invincible_timer.started()) return FORCE_MOVE; return CONTINUE; } return FORCE_MOVE; }
int main(int argc, char *argv[]) { char src[MAX_STR_LEN] = DEFAULT_STR; char dst[MAX_STR_LEN] = { 0 }; if(argc == 2) { strcpy(src, argv[1]); } char *src_bk = src; char *dst_bk = dst; get_pos(src_bk, dst_bk); printf("src:%s\n", src); printf("dst:%s\n", dst); return 0; }
HitResponse Jumpy::hit(const CollisionHit& chit) { if(chit.bottom) { if (!groundhit_pos_set) { pos_groundhit = get_pos(); groundhit_pos_set = true; } physic.set_velocity_y(JUMPSPEED); // TODO create a nice sound for this... //sound_manager->play("sounds/skid.wav"); } else if(chit.top) { physic.set_velocity_y(0); } return CONTINUE; }
HitResponse Jumpy::hit(const CollisionHit& chit) { if(chit.bottom) { if (!groundhit_pos_set) { pos_groundhit = get_pos(); groundhit_pos_set = true; } physic.set_velocity_y((frozen || get_state() == STATE_FALLING) ? 0 : JUMPYSPEED); // TODO create a nice sound for this... //SoundManager::current()->play("sounds/skid.wav"); } else if(chit.top) { physic.set_velocity_y(0); } return CONTINUE; }
int work(const int score) { int change = 0; for (int i=0; i<len; i++) status[i] = get_pos(i, len, score); memset(count , 0, sizeof(count )); memset(maxcnt, 0, sizeof(maxcnt)); for (int i=0; i<len; i++) { count[status[i]][word[i]-'a'] ++; if (count[status[i]][word[i]-'a'] > maxcnt[status[i]]) { maxcnt[status[i]] = count[status[i]][word[i]-'a']; maxwrd[status[i]] = word[i]; } } for (int i=0; i<len; i++) if (word[i] != maxwrd[status[i]]) change ++; return change; }
void Player::update_stand() { if(controller.button_was_pressed(USE_BUTTON)) { Entity* obj = find_useable_entity(); if (obj) obj->use(); return; } if(controller.button_was_pressed(JUMP_BUTTON) && controller.get_axis_state(Y_AXIS) > 1.0f) { set_jump_up_begin(); } else if (controller.button_was_pressed(AIM_BUTTON)) { // TODO remove me later, just here for testing Grenade* grenade = new Grenade(); grenade->set_pos(get_pos() + Vector(50, -300)); grenade->set_velocity(Vector(20, -10)); Sector::current()->add(grenade); sprite.set_action("PullGun"); state = PULL_GUN; } else if (controller.get_axis_state(X_AXIS) < 0) { if(get_direction() == WEST) set_walk(WEST); else set_turnaround(); } else if (controller.get_axis_state(X_AXIS) > 0) { if(get_direction() == EAST) set_walk(EAST); else set_turnaround(); } }
HitResponse Jumpy::hit(const CollisionHit& chit) { // hit floor? if(chit.normal.y < -.5) { if (!groundhit_pos_set) { pos_groundhit = get_pos(); groundhit_pos_set = true; } physic.set_velocity_y(JUMPSPEED); // TODO create a nice sound for this... //sound_manager->play("sounds/skid.wav"); } else if(chit.normal.y < .5) { // bumped on roof physic.set_velocity_y(0); } return CONTINUE; }
static int vidc_init(int arg) { int i; if (vidc_started && arg == 0) return (0); vidc_started = 1; #ifdef TERM_EMU /* Init terminal emulator */ end_term(); get_pos(&curx, &cury); curs_move(&curx, &cury, curx, cury); fg_c = DEFAULT_FGCOLOR; bg_c = DEFAULT_BGCOLOR; #endif for (i = 0; i < 10 && vidc_ischar(); i++) (void)vidc_getchar(); return (0); /* XXX reinit? */ }
void Fish::active_update(float elapsed_time) { BadGuy::active_update(elapsed_time); // waited long enough? if(waiting.check()) { jump(); } // set sprite sprite->set_action(physic.get_velocity_y() > 0 ? "normal" : "down"); // we can't afford flying out of the tilemap, 'cause the engine would remove us. if ((get_pos().y - 31.8) < 0) // too high, let us fall { physic.set_velocity_y(0); physic.enable_gravity(true); } }
Firefly::Firefly(const Reader& lisp) : MovingSprite(lisp, "images/objects/resetpoints/default-resetpoint.sprite", LAYER_TILES, COLGROUP_TOUCHABLE), activated(false), initial_position() { initial_position = get_pos(); if( !lisp.get( "sprite", sprite_name ) ){ reactivate(); return; } if( sprite_name == "" ){ sprite_name = "images/objects/resetpoints/default-resetpoint.sprite"; reactivate(); return; } //Replace sprite sprite = sprite_manager->create( sprite_name ); bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); reactivate(); }
//TODO: Add launching velocity to certain badguys bool Dispenser::collision_squished(GameObject& object) { //Cannon launching MrRocket can be broken by jumping on it //other dispensers are not that fragile. if (broken || type != DT_ROCKETLAUNCHER) { return false; } sprite->set_action(dir == LEFT ? "broken-left" : "broken-right"); dispense_timer.start(0); set_colgroup_active(COLGROUP_MOVING_STATIC); // Tux can stand on broken cannon. Player* player = dynamic_cast<Player*>(&object); if (player){ player->bounce(*this); } SoundManager::current()->play("sounds/squish.wav", get_pos()); broken = true; return true; }
void Snail::collision_solid(const CollisionHit& hit) { if (m_frozen) { WalkingBadguy::collision_solid(hit); return; } switch (state) { case STATE_NORMAL: WalkingBadguy::collision_solid(hit); return; case STATE_KICKED: if (hit.left || hit.right) { SoundManager::current()->play("sounds/iceblock_bump.wav", get_pos()); if ( ( m_dir == Direction::LEFT && hit.left ) || ( m_dir == Direction::RIGHT && hit.right) ){ m_dir = (m_dir == Direction::LEFT) ? Direction::RIGHT : Direction::LEFT; m_sprite->set_action(m_dir == Direction::LEFT ? "flat-left" : "flat-right"); m_physic.set_velocity_x(-m_physic.get_velocity_x()); } } BOOST_FALLTHROUGH; case STATE_FLAT: case STATE_KICKED_DELAY: if (hit.top || hit.bottom) { m_physic.set_velocity_y(0); } break; case STATE_GRABBED: break; } update_on_ground_flag(hit); }
bool Stumpy::collision_squished(GameObject& object) { // if we're still invincible, we ignore the hit if (mystate == STATE_INVINCIBLE) { SoundManager::current()->play("sounds/mr_treehit.ogg", get_pos()); Player* player = dynamic_cast<Player*>(&object); if (player) player->bounce(*this); return true; } // if we can die, we do if (mystate == STATE_NORMAL) { sprite->set_action(dir == LEFT ? "squished-left" : "squished-right"); set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); kill_squished(object); // spawn some particles // TODO: provide convenience function in MovingSprite or MovingObject? for (int i = 0; i < 25; i++) { Vector ppos = bbox.get_middle(); float angle = graphicsRandom.randf(-M_PI_2, M_PI_2); float velocity = graphicsRandom.randf(45, 90); float vx = sin(angle)*velocity; float vy = -cos(angle)*velocity; Vector pspeed = Vector(vx, vy); Vector paccel = Vector(0, Sector::current()->get_gravity()*10); Sector::current()->add_object(std::make_shared<SpriteParticle>("images/objects/particles/bark.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS-1)); } return true; } //TODO: exception? return true; }
// insert key into hash table void hash_put(hash_table *h, int key) { int index = get_pos(h, key); // disallow insertion of duplicates into the hash table if (h->table[index] != NULL) return; // create space for the new string h->table[index] = malloc(sizeof(int)); // copy string into hash table *h->table[index] = key; // record keeping :) h->size++; // expand the table if it's over half full if (h->size > h->capacity / 2) expand_table(h); }
void SpiderMite::active_update(float elapsed_time) { if(timer.check()) { if(mode == FLY_UP) { mode = FLY_DOWN; physic.set_velocity_y(-FLYSPEED); } else if(mode == FLY_DOWN) { mode = FLY_UP; physic.set_velocity_y(FLYSPEED); } timer.start(FLYTIME); } movement=physic.get_movement(elapsed_time); Player* player = this->get_nearest_player(); if (player) { dir = (player->get_pos().x > get_pos().x) ? RIGHT : LEFT; sprite->set_action(dir == LEFT ? "left" : "right"); } }
void LiveFire::kill_fall() { sound_manager->play(death_sound, get_pos()); // throw a puff of smoke Vector ppos = bbox.get_middle(); Vector pspeed = Vector(0, -150); Vector paccel = Vector(0,0); Sector::current()->add_object(new SpriteParticle("images/objects/particles/smoke.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_BACKGROUNDTILES+2)); // extinguish the flame sprite->set_action(dir == LEFT ? "extinguish-left" : "extinguish-right", 1); physic.set_velocity_y(0); physic.set_acceleration_y(0); physic.enable_gravity(false); lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE)); lightsprite->set_color(Color(0.5f, 0.4f, 0.3f)); set_group(COLGROUP_DISABLED); // start dead-script run_dead_script(); }
bool tick() { if(age-- <= 0) return false; vec_t p = get_pos(); p.x += dir.x; if((p.x<legal.a.x)||(p.x>legal.b.x)) { dir.x = -dir.x; p.x += dir.x; } p.y += dir.y; if((p.y<legal.a.y)||(p.y>legal.b.y)) { dir.y = -dir.y; p.y += dir.y; } p.z += dir.z; if((p.z<legal.a.z)||(p.z>legal.b.z)) { dir.z = -dir.z; p.z += dir.z; } set_pos(p); return true; }
void Candle::draw(DrawingContext& context) { // draw regular sprite sprite->draw(context, get_pos(), layer); // draw on lightmap if (burning) { //Vector pos = get_pos() + (bbox.get_size() - candle_light_1->get_size()) / 2; context.push_target(); context.set_target(DrawingContext::LIGHTMAP); // draw approx. 1 in 10 frames darker. Makes the candle flicker if (gameRandom.rand(10) != 0 || !flicker) { //context.draw_surface(candle_light_1, pos, layer); candle_light_1->draw(context, get_bbox().get_middle(), 0); } else { //context.draw_surface(candle_light_2, pos, layer); candle_light_2->draw(context, get_bbox().get_middle(), 0); } context.pop_target(); } }
// isolates the path sorrounding the city void isolate_city(pos_t start, cell_type env[][WIDTH]) { pos_t curr; direction_e camefrom = L; curr.row = start.row; curr.column = start.column; do { env[curr.row][curr.column] = G; pos_t check; direction_e next_d = camefrom; do { next_d = clock(next_d); check = get_pos(curr, next_d); } while (env[check.row][check.column] == S || \ (check.row == curr.row && check.column == curr.column)); camefrom = get_opposite(next_d); curr = check; } while (curr.row != start.row || \ curr.column != start.column); }