Example #1
0
/**
 * \brief Hurts the enemy.
 *
 * Updates its state, its sprite and plays the sound.
 *
 * \param source the entity attacking the enemy (often the hero)
 */
void Enemy::hurt(MapEntity& source) {

  uint32_t now = System::now();

  // update the enemy state
  being_hurt = true;
  set_movement_events_enabled(false);

  can_attack = false;
  can_attack_again_date = now + 300;

  // graphics and sounds
  set_animation("hurt");
  play_hurt_sound();

  // stop any movement
  clear_movement();

  // push the enemy back
  if (pushed_back_when_hurt) {
    double angle = source.get_angle(*this);
    StraightMovement* movement = new StraightMovement(false, true);
    movement->set_max_distance(24);
    movement->set_speed(120);
    movement->set_angle(angle);
    set_movement(movement);
  }

  stop_hurt_date = now + 300;
}
Example #2
0
/**
 * \brief Notifies this enemy that it should restart his movement.
 *
 * This function is called when the enemy needs to restart its movement
 * because something happened (for example the enemy has just been created,
 * or it was just hurt).
 * By default, the "walking" animation is set on the enemy's sprites.
 */
void Enemy::restart() {

  if (is_immobilized()) {
    stop_immobilized();
  }
  set_animation("walking");
  get_lua_context().enemy_on_restarted(*this);
}
/* ----------------------------------------------------------------------------
 * Closes up and gets ready for a conversion.
 */
void converter::close() {
    fsm.set_state(CONVERTER_STATE_CLOSING);
    set_animation(
        get_animation_nr_from_base_and_group(
            CONVERTER_ANIM_CLOSING, N_CONVERTER_ANIMS, current_type_nr
        )
    );
    cur_base_anim_nr = CONVERTER_ANIM_CLOSING;
    auto_conversion_timer.stop();
}
Example #4
0
void animation_previous()
{
    stop_animation();
    if (current_animation == animation_type_o_matic)
        current_animation = animation_LAST;
    current_animation = (animation_names)decrement(current_animation, 1, 0, animation_LAST);
    dprintf("animation_previous: %u\n", current_animation);

    set_animation(current_animation);
    start_animation();
}
Example #5
0
void animation_next()
{
    stop_animation();

    current_animation = (animation_names)increment(current_animation, 1, 0, animation_LAST);
    if (current_animation == animation_LAST)
        current_animation = animation_type_o_matic;
    dprintf("animation_next: %u\n", current_animation);

    set_animation(current_animation);
    start_animation();
}
Example #6
0
/* ----------------------------------------------------------------------------
 * Creates a treasure.
 */
treasure::treasure(
    const float x, const float y, treasure_type* type,
    const float angle, const string &vars
) :
    mob(x, y, type, angle, vars),
    tre_type(type),
    buried(s2f(get_var_value(vars, "buried", "0"))) {
    
    become_carriable(true);
    
    set_animation(ANIM_IDLING);
    
}
Example #7
0
void animation_toggle(void)
{
    dprintf("animation_toggle\r\n");

    if (animation_is_running())
    {
        stop_animation();
        return;
    }

    set_animation(current_animation);
    start_animation();
}
void Magma::set_image()
{
	RECT magma[8];
	magma[0] = help_set_rect(0, 336, 336, 800);
	magma[1] = help_set_rect(0, 672, 336, 800);
	magma[2] = help_set_rect(0, 1008, 336, 800);
	magma[3] = help_set_rect(0, 1344, 336, 800);
	magma[4] = help_set_rect(0, 1680, 336, 800);
	magma[5] = help_set_rect(0, 2016, 336, 800);
	magma[6] = help_set_rect(0, 2352, 336, 800);
	magma[7] = help_set_rect(0, 2688, 336, 800);

	set_animation(magma);
}
// The player is dead
	void
dead(Player * me)
{

	InputState * is;

	is = me->is;

	set_animation(me->body, (char *) "dead");

	if (key_down(is, SDLK_RETURN))
	{
		stop(me->halter);
	}

}
Example #10
0
/* ----------------------------------------------------------------------------
 * Changes to the next type in the list, if applicable.
 */
void converter::change_type() {
    current_type_nr =
        sum_and_wrap(
            current_type_nr, 1,
            con_type->available_pikmin_types.size()
        );
    current_type = con_type->available_pikmin_types[current_type_nr];
    
    set_animation(
        get_animation_nr_from_base_and_group(
            cur_base_anim_nr, N_CONVERTER_ANIMS, current_type_nr
        ),
        true, false
    );
    
    type_change_timer.start();
}
Example #11
0
static int process_command(usb_dev_handle *handle, char *cmd) {
	int tube = 0;
	int value = 0;
	int anim = 0;
	int speed = 0;
	int r = 0;
	int g = 0;
	int b = 0;
	if (sscanf(cmd, "t%d:%d", &tube, &value) == 2 && tube >= 0 && value >= 0) {
		printf("Setting nixie tube %u to %u.\n", tube, value);
		return set_tube(handle, tube, value);
	} else if (sscanf(cmd, "l%d:%d/%d/%d", &tube, &r, &g, &b) == 4 && tube >= 0) {
		printf("Setting nixie LED %u to %u/%u/%u.\n", tube, r, g, b);
		return set_led(handle, tube, r, g, b);
	} else if (sscanf(cmd, "anim:%d:%d", &anim, &speed) == 2 && anim >= 0 && anim >= 0) {
		printf("Setting animation style %u with speed %u.\n", anim, speed);
		return set_animation(handle, anim, speed);
	} else if (sscanf(cmd, "lnum:%d", &value) == 1 && value >= 0) {
		printf("Setting number %u\n", value);
		return set_number(handle, value, 1);
	} else if (sscanf(cmd, "num:%d", &value) == 1 && value >= 0) {
		printf("Setting number %u\n", value);
		return set_number(handle, value, 0);
	} else if (sscanf(cmd, "color:%d/%d/%d", &r, &g, &b) == 3) {
		printf("Setting color %u/%u/%u\n", r, g, b);
		return set_color(handle, r, g, b);
	} else if (strcmp(cmd, "off") == 0) {
		printf("Turning off all tubes...\n");
		return tubes_off(handle);
	} else if (strcmp(cmd, "read") == 0) {
		printf("Reading commands from stdin...\n");
		return read_cmds(handle, 0);
	} else if (strcmp(cmd, "readf") == 0) {
		printf("Reading commands from stdin (autofail)...\n");
		return read_cmds(handle, 1);
	} else {
		fprintf(stderr, "Unable to parse command: %s\n", cmd);
		return 2;
	}
	return 0;

}
Example #12
0
/**
 * \brief Initialize the item.
 */
void ptb::honeypot::build()
{
  super::build();

  level_variables::set_object_count
        ( get_level(), "honeypot",
          level_variables::get_object_count( get_level(), "honeypot" ) + 1);
  m_id = level_variables::get_object_count( get_level(), "honeypot" );

  std::ostringstream s;
  s << "honeypot " << m_id;
  std::string name(s.str());

  create_level_bonus(name);

  level_variables::set_honeypot_found
    ( get_level(), m_id, game_variables::get_level_object_state
      (game_variables::get_main_level_name(), name ));

  game_variables::set_level_object_state
    (name, level_variables::get_honeypot_found(get_level(), m_id));
  game_variables::set_level_object_filename
    (name, "gfx/ui/bonus-icons/bonus-icons.png");
  game_variables::set_level_object_name(name, name);

  set_animation
    ( get_level_globals().get_animation("animation/shiny-honey-jar.canim") );

  if ( level_variables::get_honeypot_found(get_level(), m_id) )
    {
      get_rendering_attributes().set_intensity( 0.25, 0.25, 1 );
      get_rendering_attributes().set_opacity( 0.5 );
    }

  set_size( 64, 64 );
} // honeypot::build()
Example #13
0
void set_and_start_animation(animation_names animation_by_name)
{
    stop_animation();
    set_animation(animation_by_name);
    start_animation();
}
Example #14
0
/**
 * \brief Starts a custom animation of the hero's sprites.
 *
 * All sprites of the hero that have an animation with this name take the
 * animation. The ones that don't have such an animation are not displayed.
 * Many simple animations can be started with this function.
 * More complex one have dedicated functions.
 *
 * \param animation Name of the animation to give to the hero's sprites.
 */
void HeroSprites::set_animation(const std::string& animation) {

  set_animation(animation, ScopedLuaRef());
}
Example #15
0
/**
 * \brief Updates the enemy.
 */
void Enemy::update() {

  MapEntity::update();

  if (is_suspended() || !is_enabled()) {
    return;
  }

  uint32_t now = System::now();

  if (being_hurt) {

    // see if we should stop the animation "hurt"
    if (now >= stop_hurt_date) {
      being_hurt = false;
      set_movement_events_enabled(true);

      if (life <= 0) {
        kill();
      }
      else if (is_immobilized()) {
        clear_movement();
        set_animation("immobilized");
        notify_immobilized();
      }
      else {
        clear_movement();
        restart();
      }
    }
  }

  if (life > 0 && invulnerable && now >= vulnerable_again_date && !being_hurt) {
    invulnerable = false;
  }

  if (life > 0 && !can_attack && !is_immobilized()
      && can_attack_again_date != 0 && now >= can_attack_again_date) {
    can_attack = true;
  }

  if (is_immobilized() && !is_killed() && now >= end_shaking_date &&
      get_sprite().get_current_animation() == "shaking") {

    restart();
  }

  if (is_immobilized() && !is_killed() && !is_being_hurt() && now >= start_shaking_date &&
      get_sprite().get_current_animation() != "shaking") {

    end_shaking_date = now + 2000;
    set_animation("shaking");
  }

  if (exploding) {
    uint32_t now = System::now();
    if (now >= next_explosion_date) {

      // create an explosion
      Rectangle xy;
      xy.set_x(get_top_left_x() + Random::get_number(get_width()));
      xy.set_y(get_top_left_y() + Random::get_number(get_height()));
      get_entities().add_entity(new Explosion("", LAYER_HIGH, xy, false));
      Sound::play("explosion");

      next_explosion_date = now + 200;
      nb_explosions++;

      if (nb_explosions >= 15) {
        exploding = false;
      }
    }
  }

  if (is_killed() && is_dying_animation_finished()) {

    // Create the pickable treasure if any.
    get_entities().add_entity(Pickable::create(get_game(),
        "", get_layer(), get_x(), get_y(),
        treasure, FALLING_HIGH, false));

    // Remove the enemy.
    remove_from_map();

    // Notify Lua that this enemy is dead.
    // We need to do this after remove_from_map() so that this enemy is
    // considered dead in functions like map:has_entities(prefix).
    notify_dead();
  }

  get_lua_context().enemy_on_update(*this);
}
// The player is alive
void
alive(Player * me)
{
	InputState * is;
	Camera * cam;
	EntitySet * others;
	Level world;

	unsigned int mousex;
	unsigned int mousey;

	float playerx, playery;

	float fake_lookx, fake_looky;
	float lookx, looky;
	unsigned int dir;

	float x, y;

	float dx = 0;
	float dy = 0;

	gboolean shoot;
	gboolean firing;

	Entity * target;

	is = me->is;
	cam = me->cam;
	others = me->others;
	world = me->world;

	firing = mouse_press(is);
	shoot = expired(me->attack_timer); 

	// Get the mouse position
	mouse_position(is, &mousex, &mousey);

	// Get the mouse position with regards to the level.
	camera_inverse_transform(cam, mousex, mousey, &fake_lookx, &fake_looky);
	lookx = fake_lookx / square_size;
	looky = fake_looky / square_size;

	entity_position(me->body, &playerx, &playery);

	dir = look(playerx, playery, lookx, looky);

	// Set the direction of the player with regards to key presses
	if (key_down(is, SDLK_a) || key_down(is, SDLK_LEFT))
	{
		dx = -1;
	} else if (key_down(is, SDLK_d) || key_down(is, SDLK_RIGHT))
	{
		dx = 1;
	}

	if (key_down(is, SDLK_w) || key_down(is, SDLK_UP))
	{
		dy = -1;
	} else if (key_down(is, SDLK_s) || key_down(is, SDLK_DOWN))
	{
		dy = 1;
	}

	entity_set_direction(me->body, dx, dy);

	// Try to shoot a KITTY!
	if (firing)
	{
		if (shoot)
		{
			play_wav(me->fire);

			entity_position(me->body, &x, &y);

			if (can_see(world, x, y, lookx, looky))
			{
				target = collision(me->body, lookx, looky, others);



				if (target)
				{
					entity_destroy(target);
					me->score ++;
				}
			}
		}


		if (dx != 0 || dy != 0)
		{
			if (dir == LEFT)
			{
				set_animation(me->body, (char *) "shoot_walk_left");
			}
			else if (dir == RIGHT)
			{
				set_animation(me->body, (char *) "shoot_walk_right");
			}
			else if (dir == UP)
			{
				set_animation(me->body, (char *) "shoot_walk_up");
			}
			else if (dir == DOWN)
			{
				set_animation(me->body, (char *) "shoot_walk_down");
			}
		}
		else
		{
			if (dir == LEFT)
			{
				set_animation(me->body, (char *) "shoot_idle_left");
			}
			else if (dir == RIGHT)
			{
				set_animation(me->body, (char *) "shoot_idle_right");
			}
			else if (dir == UP)
			{
				set_animation(me->body, (char *) "shoot_idle_up");
			}
			else if (dir == DOWN)
			{
				set_animation(me->body, (char *) "shoot_idle_down");
			}

		}
	}
	else
	{
		if (dx != 0 || dy != 0)
		{
			if (dir == LEFT)
			{
				set_animation(me->body, (char *) "walk_left");
			}
			else if (dir == RIGHT)
			{
				set_animation(me->body, (char *) "walk_right");
			}
			else if (dir == UP)
			{
				set_animation(me->body, (char *) "walk_up");
			}
			else if (dir == DOWN)
			{
				set_animation(me->body, (char *) "walk_down");
			}
		}
		else
		{
			if (dir == LEFT)
			{
				set_animation(me->body, (char *) "idle_left");
			}
			else if (dir == RIGHT)
			{
				set_animation(me->body, (char *) "idle_right");
			}
			else if (dir == UP)
			{
				set_animation(me->body, (char *) "idle_up");
			}
			else if (dir == DOWN)
			{
				set_animation(me->body, (char *) "idle_down");
			}

		}

	}

}
Example #17
0
void voxel_model::process_animation(GLfloat advance)
{
	if(!anim_) {
		return;
	}

	if(anim_->duration > 0 && anim_time_ > anim_->duration) {
		set_animation("stand");
	}

	anim_time_ += advance;

	const GLfloat TransitionTime = 0.5f;
	GLfloat ratio = 1.0f;

	if(old_anim_) {
		if(anim_time_ >= TransitionTime) {
			old_anim_.reset();
			old_anim_time_ = 0.0f;
		} else {
			old_anim_time_ += advance;
			if(old_anim_->duration > 0.0f && old_anim_time_ > old_anim_->duration) {
				old_anim_time_ = old_anim_->duration;
			}
			ratio = anim_time_ / TransitionTime;
		}
	}

	clear_transforms();

	game_logic::map_formula_callable_ptr callable(new game_logic::map_formula_callable);

	if(old_anim_) {
		callable->add("time", variant(decimal(old_anim_time_)));

		for(const AnimationTransform& transform : old_anim_->transforms) {
			glm::vec3 translate;
			if(transform.translation_formula) {
				const variant result = transform.translation_formula->execute(*callable);
				translate = variant_to_vec3(result)*(1.0f - ratio);
			}

			GLfloat rotation = 0.0;
			if(transform.rotation_formula) {
				rotation = transform.rotation_formula->execute(*callable).as_decimal().as_float();
			}

			get_child(transform.layer)->accumulate_rotation(transform.pivot_src, transform.pivot_dst, rotation*(1.0-ratio), translate, transform.children_only);
		}
	}

	callable->add("time", variant(decimal(anim_time_)));

	for(const AnimationTransform& transform : anim_->transforms) {
		glm::vec3 translate;
		if(transform.translation_formula) {
			const variant result = transform.translation_formula->execute(*callable);
			translate = variant_to_vec3(result) * ratio;
		}

		GLfloat rotation = 0.0;
		if(transform.rotation_formula) {
			rotation = transform.rotation_formula->execute(*callable).as_decimal().as_float();
		}

		get_child(transform.layer)->accumulate_rotation(transform.pivot_src, transform.pivot_dst, rotation*ratio, translate, transform.children_only);
	}

	generate_geometry();
}
Example #18
0
void voxel_model::set_animation(const std::string& anim_str)
{
	boost::shared_ptr<Animation> anim = animations_[anim_str];
	ASSERT_LOG(anim, "Could not find animation " << anim_str);
	set_animation(anim);
}
Example #19
0
 JNIEXPORT void JNICALL Java_org_geuz_onelab_Gmsh_setAnimation
 (JNIEnv *, jobject, jint animation)
 {
   set_animation(animation);
 }
// This is the kitten's callback,
// all its actions take place here
void
kitten_move(gpointer kittyp)
{
	Kitten * kitty;
	Entity * player;
	Level world;
	TimeTracker * time;
	EntitySet * others;

	float x, y;
	float px, py;
	float dx, dy;

	unsigned int dir;
	
	Entity * body;

	Player * dude;

	kitty = (Kitten *) kittyp;
	player = kitty->player;
	world = kitty->world;
	time = kitty->time;
	others = kitty->others;
	body = kitty->body;

	entity_position(body, &x, &y);
	entity_position(player, &px, &py);

	dir = look(x, y, px, py);

	dx = px - x;
	dy = py - y;

	entity_set_direction(body, dx, dy);
	entity_move(body, world, time, others);

	entity_get_direction(body, &dx, &dy);

	if (collision(body, x + dx, y + dy, others) == player)
	{
		if (expired(kitty->claw_timer))
		{
			play_wav(kitty->claw);
		}

		if (expired(kitty->attack_timer))
		{
			dude = entity_user_data(player);
			player_hurt(dude);
		}
		if (dir == LEFT)
		{
			set_animation(body, "attack_left");
		}
		else if (dir == RIGHT)
		{
			set_animation(body, "attack_right");
		}
		else if (dir == UP)
		{
			set_animation(body, "attack_up");
		}
		else if (dir == DOWN)
		{
			set_animation(body, "attack_down");
		}

	}
	else if (dir == LEFT)
	{
		set_animation(body, "left");
	}
	else if (dir == RIGHT)
	{
		set_animation(body, "right");
	}
	else if (dir == UP)
	{
		set_animation(body, "up");
	}
	else if (dir == DOWN)
	{
		set_animation(body, "down");
	}



}
Example #21
0
void AnimatedSprite::play(const StringName &p_animation) {

	if (p_animation)
		set_animation(p_animation);
	_set_playing(true);
}
void AnimationPlayer::play(const Animation& animation)
{
  if (get_animation() != &animation)
    set_animation(animation);
  play();
}