134 lines
3.1 KiB
C++
134 lines
3.1 KiB
C++
#ifndef PINBALL_ENTITIES_H
|
|
#define PINBALL_ENTITIES_H
|
|
|
|
#include "gint/defs/types.h"
|
|
#include "gint/display-cg.h"
|
|
#include "stdint-gcc.h"
|
|
#include "utilities.h"
|
|
#include "vector2D.h"
|
|
#include <num/num.h>
|
|
|
|
#include <vector>
|
|
|
|
|
|
enum
|
|
{
|
|
LEFT = 0,
|
|
RIGHT = 1,
|
|
};
|
|
|
|
class Ball {
|
|
public:
|
|
Ball(libnum::num32 radius, libnum::num32 mass, Vector2D pos, Vector2D vel,
|
|
libnum::num32 restitution, uint16_t color) {
|
|
this->radius = radius;
|
|
this->mass = mass;
|
|
this->pos = pos.Clone();
|
|
this->vel = vel.Clone();
|
|
this->restitution = restitution;
|
|
this->color = color;
|
|
}
|
|
|
|
~Ball() {}
|
|
|
|
void Simulate(libnum::num32 dt, Vector2D gravity) {
|
|
this->vel.Add(gravity, dt);
|
|
this->pos.Add(this->vel, dt);
|
|
}
|
|
|
|
libnum::num32 radius, mass, restitution;
|
|
Vector2D pos, vel;
|
|
uint16_t color;
|
|
};
|
|
|
|
|
|
class Obstacle {
|
|
public:
|
|
Obstacle(libnum::num32 radius, Vector2D pos, libnum::num32 pushVel, uint16_t color, uint16_t points) {
|
|
this->radius = radius;
|
|
this->pos = pos.Clone();
|
|
this->pushVel = pushVel;
|
|
this->color = color;
|
|
this->points = points;
|
|
}
|
|
|
|
Obstacle() {}
|
|
|
|
libnum::num32 radius, pushVel;
|
|
Vector2D pos;
|
|
uint16_t color;
|
|
uint16_t points;
|
|
};
|
|
|
|
|
|
class Flipper {
|
|
public:
|
|
Flipper(libnum::num32 radius, Vector2D pos, libnum::num32 length,
|
|
libnum::num32 restAngle, libnum::num32 maxRotation,
|
|
libnum::num32 angularVelocity, libnum::num32 restitution, uint8_t side, uint16_t color ) {
|
|
this->radius = radius;
|
|
this->pos = pos.Clone();
|
|
this->length = length;
|
|
this->restAngle = restAngle;
|
|
this->maxRotation = ABS(maxRotation);
|
|
this->sign = SIGN(maxRotation);
|
|
this->angularVelocity = angularVelocity;
|
|
this->rotation = libnum::num32(0);
|
|
this->currentAngularVelocity = libnum::num32(0);
|
|
this->touchIdentifier = libnum::num32(-1);
|
|
this->side=side;
|
|
this->color=color;
|
|
}
|
|
|
|
void Simulate(libnum::num32 dt) {
|
|
libnum::num32 prevRotation = this->rotation;
|
|
bool pressed = this->touchIdentifier >= 0;
|
|
if (pressed)
|
|
this->rotation = MIN(this->rotation + dt * this->angularVelocity, this->maxRotation);
|
|
else
|
|
this->rotation = MAX(this->rotation - dt * this->angularVelocity, libnum::num(0.0) );
|
|
this->currentAngularVelocity = this->sign * (this->rotation - prevRotation) / dt;
|
|
}
|
|
|
|
Vector2D getTip()
|
|
{
|
|
libnum::num32 angle = this->restAngle + this->sign * this->rotation;
|
|
Vector2D D( COS(angle) , SIN(angle) );
|
|
|
|
Vector2D tip = this->pos.Clone();
|
|
tip.Add(D, this->length);
|
|
return tip;
|
|
}
|
|
|
|
libnum::num32 radius;
|
|
Vector2D pos;
|
|
libnum::num32 length;
|
|
libnum::num32 restAngle;
|
|
libnum::num32 maxRotation;
|
|
libnum::num32 sign;
|
|
libnum::num32 angularVelocity;
|
|
libnum::num32 rotation;
|
|
libnum::num32 currentAngularVelocity;
|
|
libnum::num32 touchIdentifier;
|
|
uint8_t side;
|
|
uint16_t color;
|
|
};
|
|
|
|
|
|
|
|
struct Scene
|
|
{
|
|
Vector2D gravity;
|
|
libnum::num32 dt;
|
|
uint32_t score;
|
|
bool pause;
|
|
std::vector<Vector2D> borders;
|
|
std::vector<Ball> balls;
|
|
std::vector<Obstacle> obstacles;
|
|
std::vector< std::vector<Vector2D> > islands;
|
|
std::vector<Flipper> flippers;
|
|
bopti_image_t *sideimage;
|
|
};
|
|
|
|
|
|
#endif |