bool Player::set_bonus(BonusType type, bool animate) { if(player_status->bonus == NO_BONUS) { if (!adjust_height(62.8)) { printf("can't adjust\n"); return false; } if(animate) growing_timer.start(GROWING_TIME); } if ((type == NO_BONUS) || (type == GROWUP_BONUS)) { if ((player_status->bonus == FIRE_BONUS) && (animate)) { // visually lose helmet Vector ppos = Vector((bbox.p1.x + bbox.p2.x) / 2, bbox.p1.y); Vector pspeed = Vector(((dir==LEFT) ? +100 : -100), -300); Vector paccel = Vector(0, 1000); std::string action = (dir==LEFT)?"left":"right"; Sector::current()->add_object(new SpriteParticle("images/objects/particles/firetux-helmet.sprite", action, ppos, ANCHOR_TOP, pspeed, paccel, LAYER_OBJECTS-1)); } player_status->max_fire_bullets = 0; player_status->max_ice_bullets = 0; } if (type == FIRE_BONUS) player_status->max_fire_bullets++; if (type == ICE_BONUS) player_status->max_ice_bullets++; player_status->bonus = type; return true; }
static void gradient(SRC_NODE *node, int isPeGrad) { int dev, type, *val; double v, *fval; char **vlabel, **flabel; FILE *fd; COMMON_NODE *comnode; vlabel = NULL; val = NULL; dev = node->device; if (dev < GRADDEV) return; if (chY[dev] == 0.0) { if (node->power == 0.0) return; if (node->xetime <= node->xstime) return; } fd = fds[dev]; if (fd == NULL) return; type = GRAD; comnode = (COMMON_NODE *) &node->node.common_node; fval = comnode->fval; flabel = comnode->flabel; if (isPeGrad) { val = comnode->val; vlabel = comnode->vlabel; if (fval[1] != 0.0) type = PEGRAD; else isPeGrad = 0; } print_item(dev, ITEM, type, node->fname); fprintf(fd, "#info Level: %s = %g\n",flabel[0], node->power); if (isPeGrad) { if (flabel[1] != NULL) fprintf(fd, "#info Step: %s = %g\n", flabel[1],fval[1]); if (vlabel[0] != NULL) fprintf(fd, "#info Mult: %s = %d\n", vlabel[0], val[1]); print_size(dev, 5); } else print_size(dev, 3); v = adjust_height(node); fprintf(fd, "%.3f %g %g 0 0 1\n", node->xstime, chY[dev], chY[dev]); if (isPeGrad) fprintf(fd, "%.3f 0 0 0 0 1\n", node->xstime); fprintf(fd, "%.3f %g %g 0 0 1\n", node->xstime, v, v); fprintf(fd, "%.3f %g %g 0 0 1\n", node->xetime, v, v); chY[dev] = v; if (isPeGrad) { fprintf(fd, "%.3f 0 0 0 0 1\n", node->xetime); chY[dev] = 0.0; } chX[dev] = node->xetime; }
static void rf_shapepulse(SRC_NODE *node) { int dev, k; double t, vx, tx, v1, v2; double *amp, *phase; SHAPE_NODE *sh_node; FILE *fd; dev = node->device; fd = fds[dev]; if (fd == NULL) return; sh_node = node->shapeData; if (sh_node == NULL || sh_node->dataSize < 2) { dummy_shapepulse(fd, node); return; } t = node->xstime; tx = (node->xetime - node->xstime) / (double) (sh_node->dataSize - 1); patch_channel(dev, t); if (node->type == GRPPULSE) print_item(dev, ITEM, GRPPULSE, node->fname); else print_item(dev, ITEM, SHPUL, node->fname); if (sh_node->name != NULL) print_item(dev, PATTERN, 0, sh_node->name); if (sh_node->filename != NULL) print_item(dev, FILENAME,0, sh_node->filename); fprintf(fd, "#duration %g\n", node->xetime - node->xstime); vx = adjust_height(node); vx = vx / 1024.0; amp = sh_node->amp; phase = sh_node->phase; print_size(dev, sh_node->dataSize + 2); fprintf(fd, "%.3f 0.0 0.0 0 0 1\n", t); for (k = 0; k < sh_node->dataSize; k++) { v1 = *amp * vx; v2 = *phase * vx; fprintf(fd, "%.3f %g %g %g %g 1\n", t, v1, v2, *amp, *phase); t += tx; amp++; phase++; } t = t - tx; fprintf(fd, "%.3f 0.0 0.0 0 0 1\n", t); chX[dev] = t; chY[dev] = 0.0; }
void Player::do_duck() { if (duck) return; if (!is_big()) return; if (physic.get_velocity_y() != 0) return; if (!on_ground()) return; if (adjust_height(31.8)) { duck = true; unduck_hurt_timer.stop(); } else { // FIXME: what now? } }
/* Kill Player! */ void Player::kill(bool completely) { if(dying || deactivated) return; if(!completely && safe_timer.started() || invincible_timer.started()) return; sound_manager->play("sounds/hurt.wav"); physic.set_velocity_x(0); if(!completely && is_big()) { if(player_status->bonus == FIRE_BONUS || player_status->bonus == ICE_BONUS) { safe_timer.start(TUX_SAFE_TIME); set_bonus(GROWUP_BONUS, true); } else { //growing_timer.start(GROWING_TIME); safe_timer.start(TUX_SAFE_TIME /* + GROWING_TIME */); adjust_height(30.8); duck = false; set_bonus(NO_BONUS, true); } } else { for (int i = 0; (i < 5) && (i < player_status->coins); i++) { // the numbers: starting x, starting y, velocity y Sector::current()->add_object(new FallingCoin(get_pos() + Vector(systemRandom.rand(5), systemRandom.rand(-32,18)), systemRandom.rand(-100,100))); } physic.enable_gravity(true); physic.set_acceleration(0, 0); physic.set_velocity(0, -700); player_status->coins -= 25; set_bonus(NO_BONUS, true); dying = true; dying_timer.start(3.0); set_group(COLGROUP_DISABLED); DisplayEffect* effect = new DisplayEffect(); effect->fade_out(3.0); Sector::current()->add_object(effect); sound_manager->stop_music(3.0); } }
bool Player::set_bonus(BonusType type, bool animate) { if((player_status->bonus == NO_BONUS) && (type != NO_BONUS)) { if (!adjust_height(BIG_TUX_HEIGHT)) { log_debug << "Can't adjust Tux height" << std::endl; return false; } if(animate) { growing = true; sprite->set_action((dir == LEFT)?"grow-left":"grow-right", 1); } if (climbing) stop_climbing(*climbing); } if (type == NO_BONUS) { if (does_buttjump) does_buttjump = false; } if ((type == NO_BONUS) || (type == GROWUP_BONUS)) { if ((player_status->bonus == FIRE_BONUS) && (animate)) { // visually lose helmet Vector ppos = Vector((bbox.p1.x + bbox.p2.x) / 2, bbox.p1.y); Vector pspeed = Vector(((dir==LEFT) ? +100 : -100), -300); Vector paccel = Vector(0, 1000); std::string action = (dir==LEFT)?"left":"right"; Sector::current()->add_object(std::make_shared<SpriteParticle>("images/objects/particles/firetux-helmet.sprite", action, ppos, ANCHOR_TOP, pspeed, paccel, LAYER_OBJECTS-1)); if (climbing) stop_climbing(*climbing); } if ((player_status->bonus == ICE_BONUS) && (animate)) { // visually lose cap Vector ppos = Vector((bbox.p1.x + bbox.p2.x) / 2, bbox.p1.y); Vector pspeed = Vector(((dir==LEFT) ? +100 : -100), -300); Vector paccel = Vector(0, 1000); std::string action = (dir==LEFT)?"left":"right"; Sector::current()->add_object(std::make_shared<SpriteParticle>("images/objects/particles/icetux-cap.sprite", action, ppos, ANCHOR_TOP, pspeed, paccel, LAYER_OBJECTS-1)); if (climbing) stop_climbing(*climbing); } player_status->max_fire_bullets = 0; player_status->max_ice_bullets = 0; } if (type == FIRE_BONUS) player_status->max_fire_bullets++; if (type == ICE_BONUS) player_status->max_ice_bullets++; player_status->bonus = type; return true; }
void Player::do_standup() { if (!duck) return; if (!is_big()) return; if (backflipping) return; if (adjust_height(63.8)) { duck = false; unduck_hurt_timer.stop(); } else { // if timer is not already running, start it. if (unduck_hurt_timer.get_period() == 0) { unduck_hurt_timer.start(UNDUCK_HURT_TIME); } else if (unduck_hurt_timer.check()) { kill(false); } } }
void Player::do_duck() { if (duck) return; if (!is_big()) return; if (physic.get_velocity_y() != 0) return; if (!on_ground()) return; if (does_buttjump) return; if (adjust_height(DUCKED_TUX_HEIGHT)) { duck = true; growing = false; unduck_hurt_timer.stop(); } else { // FIXME: what now? } }
static void update_height(SRC_NODE *node) { int dev; double v; FILE *fd; while (node != NULL) { dev = node->device; fd = fds[dev]; if (fd == NULL) return; print_dummy(dev); print_size(dev, 2); fprintf(fd, "%.3f %g %g 0 0 1\n", node->xstime, chY[dev], chY[dev]); v = adjust_height(node); fprintf(fd, "%.3f %g %g 0 0 1\n", node->xstime, v, v); chY[dev] = v; chX[dev] = node->xstime; node = node->bnode; } }
static void pulse(SRC_NODE *node) { int dev; double v; FILE *fd; while (node != NULL) { if (node->ptime > 0.0 && node->power != 0.0) { dev = node->device; fd = fds[dev]; if (fd == NULL) return; patch_channel(dev, node->xstime); fprintf(fd, "#duration %g\n", node->xetime - node->xstime); fprintf(fd, "#info Duration: %g usec\n", node->xetime - node->xstime); if (dev < GRADDEV) { if (node->type == GRPPULSE) print_item(dev, ITEM, GRPPULSE, node->fname); else print_item(dev, ITEM, PULSE, node->fname); fprintf(fd, "#info Level: %g dB\n", node->power); } else { print_item(dev, ITEM, GRAD, node->fname); fprintf(fd, "#info Power: %g dB\n", node->power); } print_size(dev, 4); fprintf(fd, "%.3f 0.0 0.0 0 0 1\n", node->xstime); v = adjust_height(node); fprintf(fd, "%.3f %g %g 0 0 1\n", node->xstime, v, v); fprintf(fd, "%.3f %g %g 0 0 1\n", node->xetime, v, v); fprintf(fd, "%.3f 0.0 0.0 0 0 1\n", node->xetime); chY[dev] = 0.0; chX[dev] = node->xetime; } node = node->bnode; } }
/* *gets the number of neighbours given a specific cell */ int number_of_neighbours(int board[][COL], int rowCoord, int colCoord){ int count = 0; /*circle around cell*/ for (int row = -1; row <= 1; row++) { for (int col = -1; col <= 1; col++) { /*exclude case where row = col = 0 (-> position of the cell being circled)*/ if (row || col) { /*count only living neighbours (value = 1)*/ if (board[adjust_height(rowCoord, row)][adjust_width(colCoord, col)]) { count++; } } } } return count; }
/* Kill Player! */ void Player::kill(bool completely) { if(dying || deactivated || is_winning() ) return; if(!completely && (safe_timer.started() || invincible_timer.started())) return; growing = false; if (climbing) stop_climbing(*climbing); physic.set_velocity_x(0); sprite->set_angle(0.0f); if(!completely && is_big()) { SoundManager::current()->play("sounds/hurt.wav"); if(player_status->bonus == FIRE_BONUS || player_status->bonus == ICE_BONUS) { safe_timer.start(TUX_SAFE_TIME); set_bonus(GROWUP_BONUS, true); } else if(player_status->bonus == GROWUP_BONUS) { safe_timer.start(TUX_SAFE_TIME /* + GROWING_TIME */); adjust_height(SMALL_TUX_HEIGHT); duck = false; backflipping = false; sprite->set_angle(0.0f); set_bonus(NO_BONUS, true); } else if(player_status->bonus == NO_BONUS) { safe_timer.start(TUX_SAFE_TIME); adjust_height(SMALL_TUX_HEIGHT); duck = false; } } else { SoundManager::current()->play("sounds/kill.wav"); // do not die when in edit mode if (edit_mode) { set_ghost_mode(true); return; } if (player_status->coins >= 25 && !GameSession::current()->get_reset_point_sectorname().empty()) { for (int i = 0; i < 5; i++) { // the numbers: starting x, starting y, velocity y Sector::current()->add_object(std::make_shared<FallingCoin>(get_pos() + Vector(graphicsRandom.rand(5), graphicsRandom.rand(-32,18)), graphicsRandom.rand(-100,100))); } player_status->coins -= std::max(player_status->coins/10, 25); } else { GameSession::current()->set_reset_point("", Vector()); } physic.enable_gravity(true); physic.set_gravity_modifier(1.0f); // Undo jump_early_apex safe_timer.stop(); invincible_timer.stop(); physic.set_acceleration(0, 0); physic.set_velocity(0, -700); set_bonus(NO_BONUS, true); dying = true; dying_timer.start(3.0); set_group(COLGROUP_DISABLED); // TODO: need nice way to handle players dying in co-op mode Sector::current()->effect->fade_out(3.0); SoundManager::current()->stop_music(3.0); } }
static void grad_shapepulse(SRC_NODE *node) { int dev, k, num, repeats; double t, t0, vx, tx, v0, v1; double *amp; SHAPE_NODE *sh_node; FILE *fd; dev = node->device; fd = fds[dev]; if (fd == NULL) return; sh_node = node->shapeData; if (sh_node == NULL || sh_node->dataSize < 2) { dummy_shapepulse(fd, node); return; } t = node->xstime; if (node->updateLater <= 0) patch_channel(dev, t); vx = adjust_height(node); // v1 = 32767.0; v1 = fabs(sh_node->maxData); if (fabs(sh_node->minData) > v1) v1 = fabs(sh_node->minData); vx = vx / v1; amp = sh_node->amp; t0 = t; tx = (node->xetime - node->xstime) / (double) (sh_node->dataSize - 1); v0 = *amp - 0.1; num = 0; repeats = 0; for (k = 0; k < sh_node->dataSize; k++) { if (v0 != *amp) { num++; if (repeats > 0) { num++; repeats = 0; } v0 = *amp; } else repeats++; amp++; } amp = sh_node->amp; v0 = *amp; v1 = v0 * vx; update_shaped_gradient(node, v1, v0); if (node->type == DPESHGR) print_item(dev, ITEM, DPESHGR, node->fname); else if (node->type == DPESHGR2) print_item(dev, ITEM, DPESHGR2, node->fname); else print_item(dev, ITEM, SHGRAD, node->fname); if (sh_node->name != NULL) print_item(dev, PATTERN, 0, sh_node->name); if (sh_node->filename != NULL) print_item(dev, FILENAME,0, sh_node->filename); fprintf(fd, "#duration %g\n", node->xetime - node->xstime); // print_size(dev, sh_node->dataSize + 2); print_size(dev, num); // fprintf(fd, "%.3f 0.0 0.0 0 0 1\n", t); v0 = *amp - 0.1; repeats = 0; for (k = 0; k < sh_node->dataSize; k++) { if (v0 != *amp) { if (repeats > 0) { v1 = v0 * vx; fprintf(fd, "%.3f %g 0 %g 0 1\n", t - tx, v1, v0); repeats = 0; } v0 = *amp; v1 = v0 * vx; fprintf(fd, "%.3f %g 0 %g 0 1\n", t, v1, v0); } else repeats++; t += tx; amp++; } t = t - tx; // fprintf(fd, "%.3f 0.0 0.0 0 0 1\n", t); chX[dev] = t; chY[dev] = v1; chY2[dev] = v0; }