コード例 #1
0
ushort cMobile::currentMountAction() const {
	// Try to translate the current action
	// We assume human bodytype for this
	if (bodyType() != HUMAN && bodyType() != EQUIPMENT) {
		return 0;
	}

	if (currentAction_ == 24) {
		return 1; // Running horse
	} else if (currentAction_ == 23) {
        return 0; // Walking horse
	} else {
		return 2; // Standing horse
	}
}
コード例 #2
0
unsigned char cMobile::getIdleAction() {
	if (this == Player && UoSocket && UoSocket->sequenceQueueLength() > 0) {
		return currentAction_;
	}

	switch (bodyType()) {
		case ANIMAL:
			return 2; // Animal animation for standing
		case MONSTER:
			return 1; // High detail critter animation for standing		
		case HUMAN:
		case EQUIPMENT:
			if (equipment[LAYER_MOUNT]) {
				return 25;
			} else if (warmode) {				
				if (!equipment[LAYER_RIGHTHAND] && equipment[LAYER_LEFTHAND]) {
					return 8; // Two handed attack stand
				} else {
					return 7; // One handed attack stand
				}
			}
		default:
			return 4; // Human animation for standing
	}
}
コード例 #3
0
ファイル: box2dbody.cpp プロジェクト: ElderOrb2k8/qml-box2d
void Box2DBody::setBodyType(BodyType _bodyType)
{
    if (bodyType() == _bodyType)
        return;
    if (mBody)
        mBody->SetType(static_cast<b2BodyType>(_bodyType));
    else
        mBodyDef.type = static_cast<b2BodyType>(_bodyType);

    emit bodyTypeChanged();
}
コード例 #4
0
ファイル: physicitem.cpp プロジェクト: sudnikand/QBox2D
void PhysicItem::createBody(b2World *const world){
    if(_body) {
        _bd.position = position();
        _bd.angle = rotation();
        _bd.type = bodyType();
        world->DestroyBody(_body);
    }
    _bd.allowSleep = true;
    _bd.awake = true;
    _body = world->CreateBody(&_bd);
}
コード例 #5
0
void cMobile::playMoveAnimation(uint duration, bool running) {
	uchar action = 0;

	if (bodyType() == HUMAN) {
		// Armed movement position
		if (equipment[LAYER_RIGHTHAND]) {
			action = running ? 3 : 1;
		} else if (running) {
			action = 2;
		}

		// Warmode only got a walking animation
		if (warmode && !running) {
			action = 15;
		}
	}

	// Mounted movement
	if (bodyType() == HUMAN && equipment[LAYER_MOUNT]) {
		action = running ? 24 : 23;
	}

	playAction(action, duration);
}
コード例 #6
0
void cMobile::draw(int cellx, int celly, int leftClip, int topClip, int rightClip, int bottomClip) {
	// Save the original cellx, celly for the greyed out stuff
	int orgCellX = cellx;
	int orgCellY = celly;
	static int cellXOffset = 0;
	static int cellYOffset = 0;

	if (Config->gameHideMobiles()) {
		return;
	}

	// Test for smoother player movement
	if (this == Player) {
		cellx = WorldView->x() + WorldView->width() / 2;
		celly = WorldView->y() + WorldView->height() / 2;
	}

	cellx += cellXOffset;
	celly += cellYOffset;

	// See if the current action expired
	if (currentActionEnd_ != 0 && currentActionEnd_ < Utilities::getTicks()) {
		// Don't cancel the movement action while we're still moving -or- have movement requests left
		if (this != Player || ((!WorldView->isMoving() || WorldView->isMovementBlocked()) && (!UoSocket || UoSocket->sequenceQueueLength() == 0))) {
			freeSequence(); // Free current surface
			currentActionEnd_ = 0; // Reset end time
			currentAction_ = getIdleAction();
		}
	}

	// Refresh the sequence
	if (!sequence_) {
		refreshSequence();
	}

	float alpha = 1.0f;

	// Modify cellx/celly based on the smooth move settings
	// Smooth move handling.
	if (smoothMoveEnd != 0) {
		int moveProgress = smoothMoveTime - (smoothMoveEnd - Utilities::getTicks());
		if (moveProgress < 0 || moveProgress >= (int)smoothMoveTime) {
			smoothMoveEnd = 0;
			World->removeEntity(this);
			World->addEntity(this);
		} else if (this != Player) {
			if (moveProgress <= 0) {
				cellx += drawxoffset;
				celly += drawyoffset;
			} else {
				float factor = 1.0f - (float)moveProgress / (float)smoothMoveTime;
				cellx += (int)(factor * (float)drawxoffset);
				celly += (int)(factor * (float)drawyoffset);
			}
		}
	}

	static bool inGreyDraw = false;
	static bool inBlurDraw = false;

	if (isHidden()) {
		glPushAttrib(GL_ENABLE_BIT);

		glEnable(GL_ALPHA_TEST); // Make sure that transparent pixels wont touch our stencil buffer
		glAlphaFunc(GL_GREATER, 0.0f);

		glEnable(GL_STENCIL_TEST); // Enable per-pixel stencil testing
		glStencilFunc(GL_EQUAL, 1, 1); // Draw if stencil buffer is not zero
		glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);

		if (!inGreyDraw) {
			glClearStencil(1);
			glClear(GL_STENCIL_BUFFER_BIT);
		}

		static uint nextPeak = 0;
		static uint lastPeak = 0;
		static bool peakDirection = false;

		uint time = Utilities::getTicks();

		if (time >= nextPeak) {
			lastPeak = Utilities::getTicks();
			nextPeak = lastPeak + 1500 + Random->randInt(1000);				
			peakDirection = !peakDirection;
		}

		alpha = (nextPeak - Utilities::getTicks()) / (float)(nextPeak - lastPeak);
		if (peakDirection) {
			alpha = 1.0f - alpha;
		}

		if (inGreyDraw) {			
			if (inBlurDraw) {
				alpha *= 0.5f;
			} else {
				alpha *= 0.8f;
			}
		} else {
			GLWidget->enableGrayShader();
			alpha = 0.8 * (1.0f - alpha); // Invert alpha value
		}
	}

	// Draw
	if (sequence_) {
		// Only advance to the next frame if we're not beyond the end of this action
		if (currentActionEnd_ != 0 && currentActionEnd_ >= Utilities::getTicks()) {
			// Skip to next frame
			if (nextFrame < Utilities::getTicks()) {
				if (++frame >= sequence_->frameCount()) {
					frame = 0;
				}
				nextFrame = Utilities::getTicks() + getFrameDelay();
			}
		}

		// The anims facing right are generated by flipping the ones facing left
		bool flip = (direction_ >= 0 && direction_ < 4);

		// Mounts come always first
		if (!isHidden()) {
			if ((bodyType() == HUMAN || bodyType() == EQUIPMENT) && equipment[LAYER_MOUNT] && equipmentSequences[LAYER_MOUNT]) {
				// Only advance to the next frame if we're not beyond the end of this action
				if (currentActionEnd_ != 0 && currentActionEnd_ >= Utilities::getTicks()) {
					// Skip to next frame
					if (nextMountFrame < Utilities::getTicks()) {
						if (++mountFrame >= equipmentSequences[LAYER_MOUNT]->frameCount()) {
							mountFrame = 0;
						}
						nextMountFrame = Utilities::getTicks() + getMountFrameDelay();
					}
				}
				
				mountFrame = frame; // Until something better is found
				equipmentSequences[LAYER_MOUNT]->draw(mountFrame, cellx, celly, flip, alpha);            
			}

			sequence_->draw(frame, cellx, celly, flip, alpha);
		}

		// Draw the equipment
		if (bodyType() == HUMAN || bodyType() == EQUIPMENT) {
			// Reverse the draw order if hidden
			if (isHidden()) {
				uint count = 0;
				const int *order = drawOrder[direction_ % 8];
				while (order[count] != -1) {
					count++;
				}

				for (int i = count - 1; i >= 0; --i) {
					enLayer layer = (enLayer)order[i];

					if (layer < LAYER_VISIBLECOUNT && equipmentSequences[layer]) {
						// Oh great OSI... Another exception from the rule *sigh*
						// Don't draw Hair if we're wearing a gm robe
						if (layer != LAYER_HAIR || !equipmentSequences[LAYER_OUTERTORSO] || equipmentSequences[LAYER_OUTERTORSO]->body() != 0x3db) {					
							equipmentSequences[layer]->draw(frame, cellx, celly, flip, alpha);
						}
					}
				}
			} else {
				const int *order = drawOrder[direction_ % 8];
				while (*order != -1) {
					enLayer layer = (enLayer)*order;
		
					if (layer < LAYER_VISIBLECOUNT && equipmentSequences[layer]) {
						// Oh great OSI... Another exception from the rule *sigh*
						// Don't draw Hair if we're wearing a gm robe
						if (layer != LAYER_HAIR || !equipmentSequences[LAYER_OUTERTORSO] || equipmentSequences[LAYER_OUTERTORSO]->body() != 0x3db) {					
							equipmentSequences[layer]->draw(frame, cellx, celly, flip, alpha);
						}				
					}
		
					++order; // Next layer
				}
			}
		}

		// If we're hidden, mount+body come last
		if (isHidden()) {
			sequence_->draw(frame, cellx, celly, flip, alpha);

			if ((bodyType() == HUMAN || bodyType() == EQUIPMENT) && equipment[LAYER_MOUNT] && equipmentSequences[LAYER_MOUNT]) {
				// Only advance to the next frame if we're not beyond the end of this action
				if (currentActionEnd_ != 0 && currentActionEnd_ >= Utilities::getTicks()) {
					// Skip to next frame
					if (nextMountFrame < Utilities::getTicks()) {
						if (++mountFrame >= equipmentSequences[LAYER_MOUNT]->frameCount()) {
							mountFrame = 0;
						}
						nextMountFrame = Utilities::getTicks() + getMountFrameDelay();
					}
				}
				
				mountFrame = frame; // Until something better is found
				equipmentSequences[LAYER_MOUNT]->draw(mountFrame, cellx, celly, flip, alpha);            
			}
		}
	}

	if (isHidden()) {
		glPopAttrib();
		if (!inGreyDraw) {
			GLWidget->disableGrayShader();
		}
	}

	drawx_ = cellx;
	drawy_ = celly;

	if (isHidden() && !inGreyDraw) {
		glClearStencil(1);
		glClear(GL_STENCIL_BUFFER_BIT);

		inGreyDraw = true;	
		inBlurDraw = true;
		cellXOffset = 1;
		draw(orgCellX, orgCellY, leftClip, topClip, rightClip, bottomClip);
		cellXOffset = -1;
		draw(orgCellX, orgCellY, leftClip, topClip, rightClip, bottomClip);
		cellXOffset = 0;
		cellYOffset = 1;
		draw(orgCellX, orgCellY, leftClip, topClip, rightClip, bottomClip);
		cellYOffset = -1;
		draw(orgCellX, orgCellY, leftClip, topClip, rightClip, bottomClip);
		cellYOffset = 0;
		inBlurDraw = false;
		draw(orgCellX, orgCellY, leftClip, topClip, rightClip, bottomClip);
		inGreyDraw = false;
	}
}