示例#1
0
void TestState::update() {
	_scene.beginUpdate();

	_input.sync();

	// ppm <=> Player Puppet Master
	MoveComponent* ppm = static_cast<MoveComponent*>(_obj->getComponent(MOVE_COMPONENT_ID));

//	Vec2i tileSize = _scene.level().tileMap().tileSize();
//	Tile tile = _scene.level().getTile(geom.pos.x() / tileSize.x(),
//	                                   geom.pos.y() / tileSize.y(), 0);
//	bool coll = _scene.level().tileCollision(tile);
	/*
	CollisionInfo info;
	Boxf objBox = _obj->worldBox();
	bool coll = _scene.level().collide(0, objBox, &info);
	_obj->sprite->setTileIndex(coll? 0: 1);
	if(coll) {
		_game->log("Collision: ", info.flags, " - ", info.penetration.transpose());
	}*/
	
	// moves
	if(_obj->isEnabled()) {
		if(_input.isPressed(_left))  ppm->walk(LEFT);
		if(_input.isPressed(_right)) ppm->walk(RIGHT);
		if(_input.isPressed(_up))    ppm->jump();
//		if(_input.isPressed(_down))  /* TODO: Duck ! */;
	}
	
//	if(_input.justPressed(_use)) _obj->setEnabled(!_obj->isEnabled());
	if(_input.justPressed(_use)) {
		LogicComponent* cmp =  _obj->getComponent(MOVE_COMPONENT_ID);
		cmp->setEnabled(!cmp->isEnabled());
	}

	_scene.updateLogic(MOVE_COMPONENT_ID);

	// sounds
	static bool was_moving = false;
	bool is_moving = _input.isPressed(_left) || _input.isPressed(_right)
		|| _input.isPressed(_up) || _input.isPressed(_down);

	if(is_moving && !was_moving) {
		_mchannel = _game->sounds()->playSound(_msound, -1);
	} else if (!is_moving && was_moving) {
		_game->sounds()->haltSound(_mchannel);
	}
	was_moving = is_moving;

	if(_input.justPressed(_use)) _game->sounds()->playSound(_jsound, 0);
}