Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Max rotation in left flipper, Pinball 2d Tier 2

Author
Message
JasonM20
User Offline
Joined: 14th May 2024
Location:
Posted: 15th May 2024 14:16
hello good morning

I am making a game from the AppGameKit classic guide, the pinball game.
Following the steps of this guide I created the logic for the flippers, but when running the game the left flipper does not respect the maximum rotation, the right flipper works fine, it stops when it reaches the maximum rotation indicated.
I attach the code and project, I hope you can help me, thanks.


#include "Flipper.h"
#include "agk.h"

const float Flipper::ROTATION_SPEED = 720.0f;
const float Flipper::BASE_ROTATION = 50.0f;
const float Flipper::MAX_ROTATION = 80.0f;

Flipper::Flipper(unsigned int image, float x, float y, bool mirror)
{
sprite = agk::CreateSprite(image);
agk::SetSpriteOffset(sprite, 13.0f, 13.0f);
agk::SetSpritePositionByOffset(sprite, x, y);
agk::SetSpriteAngle(sprite, mirror ? BASE_ROTATION : -BASE_ROTATION);
agk::SetSpriteFlip(sprite, mirror ? 1 : 0, 0);
agk::SetSpritePhysicsOn(sprite, 3);
agk::SetSpritePhysicsRestitution(sprite, 0.8f);
agk::SetSpriteShape(sprite, 3);

rotation_direction = mirror ? 1.0f : -1.0f;
active = false;
}

void Flipper::activate()
{
active = true;
}

void Flipper::desactivate()
{
active = false;
}

void Flipper::update() {
float const max_rotation_this_frame = agk::GetFrameTime() * ROTATION_SPEED;
float const current_angle = agk::GetSpriteAngle(sprite) * rotation_direction;

if (active)
{
float max_rotate = BASE_ROTATION + MAX_ROTATION;
if (max_rotate != current_angle)
{
float const angle_after_move = current_angle + max_rotation_this_frame;
float const new_angle = angle_after_move < max_rotate ? angle_after_move : max_rotate;
agk::SetSpriteAngle(sprite, new_angle * rotation_direction);
}
}
else
{
if (BASE_ROTATION != current_angle)
{
float const angle_after_move = current_angle - max_rotation_this_frame;
float const new_angle = angle_after_move > BASE_ROTATION ? angle_after_move : BASE_ROTATION;
agk::SetSpriteAngle(sprite, new_angle * rotation_direction);
}
}
}

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-11-17 22:22:47
Your offset time is: 2024-11-17 22:22:47