MCPcopy Create free account
hub / github.com/atraczyk/2d-engine / draw

Method draw

engine/src/entity.cpp:407–458  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

405Player::~Player() {}
406
407void Player::draw(Camera* camera)
408{
409 ScreenRect srcRect = getFrame()->sourceRectangle;
410 int flashsmall =
411 (health < 2 && hit > 59) ? (hit % 3 ? 1 : 0) : (health < 2 ? 1 : 0);
412 srcRect.y += flashsmall * srcRect.h;
413 if (direction == -1)
414 {
415 srcRect.x += srcRect.w;
416 srcRect.w *= -1;
417 }
418
419 ScreenRect dstRect((int)position.x, (int)position.y, size.x, size.y);
420 glBindTexture(GL_TEXTURE_2D, *(atlas->texture));
421 glBegin(GL_QUADS);
422 {
423 glTexCoord2d(srcRect.fLeft(), srcRect.fTop());
424 glVertex2f(dstRect.fLeft(), dstRect.fBottom());
425 glTexCoord2d(srcRect.fRight(), srcRect.fTop());
426 glVertex2f(dstRect.fRight(), dstRect.fBottom());
427 glTexCoord2d(srcRect.fRight(), srcRect.fBottom());
428 glVertex2f(dstRect.fRight(), dstRect.fTop());
429 glTexCoord2d(srcRect.fLeft(), srcRect.fBottom());
430 glVertex2f(dstRect.fLeft(), dstRect.fTop());
431 if (swimming && !crouching &&
432 (currentState == CS_JUMPING || currentState == CS_FALLING))
433 {
434 srcRect = getFrame()->sourceRectangle;
435 if (direction == -1)
436 {
437 srcRect.w *= -1;
438 dstRect = ScreenRect((int)position.x + size.x, (int)position.y,
439 size.x, size.y);
440 }
441 else
442 {
443 srcRect.x -= srcRect.w;
444 dstRect = ScreenRect((int)position.x - size.x, (int)position.y,
445 size.x, size.y);
446 }
447 glTexCoord2d(srcRect.fLeft(), srcRect.fTop());
448 glVertex2f(dstRect.fLeft(), dstRect.fBottom());
449 glTexCoord2d(srcRect.fRight(), srcRect.fTop());
450 glVertex2f(dstRect.fRight(), dstRect.fBottom());
451 glTexCoord2d(srcRect.fRight(), srcRect.fBottom());
452 glVertex2f(dstRect.fRight(), dstRect.fTop());
453 glTexCoord2d(srcRect.fLeft(), srcRect.fBottom());
454 glVertex2f(dstRect.fLeft(), dstRect.fTop());
455 }
456 }
457 glEnd();
458}
459
460void Player::reinitialize(float x, float y)
461{

Callers

nothing calls this directly

Calls 5

ScreenRectClass · 0.85
fLeftMethod · 0.80
fTopMethod · 0.80
fBottomMethod · 0.80
fRightMethod · 0.80

Tested by

no test coverage detected