1
0
Fork 0
blockofighter/src/legoman.h

201 lines
3.9 KiB
C
Raw Permalink Normal View History

2014-02-16 14:32:28 +00:00
#ifndef __LEGOMAN_H_INCLUDED__
#define __LEGOMAN_H_INCLUDED__
class BodyPart;
class Sensor;
class Legoman;
class DamageVisual;
#include "object.h"
#include "world.h"
#define LEGHEIGHT 4
#define WAISTHEIGHT 1
#define TORSOHEIGHT 4
#define HANDHEIGHT 6
#define HEADHEIGHT 3
#define PLAYER1 1
#define PLAYER2 2
#define LEFTLEG 1
#define RIGHTLEG 2
#define LEFTHAND 4
#define RIGHTHAND 8
2015-06-03 12:29:34 +00:00
const char LEFTLEGASC[] = DATAPATH "blockolegscaled.asc";
const char RIGHTLEGASC[] = DATAPATH "blockolegscaled.asc";
const char WAISTASC[] = DATAPATH "blockowaistscaled.asc";
const char TORSOASC[] = DATAPATH "blockotorsoscaled.asc";
const char LEFTARMASC[] = DATAPATH "leftarm.asc";
const char RIGHTARMASC[] = DATAPATH "rightarm.asc";
const char LEFTPALMASC[] = DATAPATH "leftpalm.asc";
const char RIGHTPALMASC[] = DATAPATH "rightpalm.asc";
2014-02-16 14:32:28 +00:00
#define MODELSCALE 0.12
#define TORSOSCALE 0.115
2015-06-03 12:29:34 +00:00
class BodyPart : public Object {
2014-02-16 14:32:28 +00:00
private:
2015-06-03 12:29:34 +00:00
float energy;
float strength;
Legoman *parent;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
bool attached;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
int immortal;
2014-02-16 14:32:28 +00:00
bool isInContact();
2014-02-16 14:32:28 +00:00
public:
2015-06-03 12:29:34 +00:00
BodyPart(Legoman *parent, float strength);
2014-02-16 14:32:28 +00:00
inline bool isAttached() { return attached; }
2015-06-03 12:29:34 +00:00
void move(void);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void hitForce(float speed, float *speed2, Object *source);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void makeDamage(float amount);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void reset(void);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
friend class DamageVisual;
friend class Legoman;
2014-02-16 14:32:28 +00:00
};
2015-06-03 12:29:34 +00:00
class Sensor {
2014-02-16 14:32:28 +00:00
private:
2015-06-03 12:29:34 +00:00
float relativeposition[3];
Object *object;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
float position[3], oldposition[3];
float velocity[3], oldvelocity[3];
float acceleration[3];
2014-02-16 14:32:28 +00:00
public:
2015-06-03 12:29:34 +00:00
Sensor();
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void attach(Object *object, float *relativeposition);
void attach(Object *object);
void update(void);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void getPosition(float *target);
void getVelocity(float *target);
void getAcceleration(float *target);
2014-02-16 14:32:28 +00:00
};
2015-06-03 12:29:34 +00:00
class Legoman {
2014-02-16 14:32:28 +00:00
private:
2015-06-03 12:29:34 +00:00
int side;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
bool alive;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
BodyPart *head;
BodyPart *torso;
BodyPart *waist;
BodyPart *lefthand, *righthand;
BodyPart *leftleg, *rightleg;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
DamageVisual *headvisual;
DamageVisual *torsovisual;
DamageVisual *lefthandvisual, *righthandvisual;
DamageVisual *leftlegvisual, *rightlegvisual;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
ObjectLink *leftleglink, *rightleglink;
ObjectLink *lefthandlink, *righthandlink;
ObjectLink *lll, *rll;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
ObjectLink *leftleglinks[3], *rightleglinks[3];
ObjectLink *lefthandlinks[3], *righthandlinks[3];
ObjectLink *headlinks[3];
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
objectlist *harmfulobjects;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
Legoman *opponent;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
Sensor *headsensor, *torsosensor;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
int walkphase, walkdelay;
int jumpphase;
int hitside;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
bool jumpenabled;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
World *world;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void balance(void);
void updateLegs(void);
bool isStanding(void);
bool isOnGround(void);
float getInvMass(void);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void fallOff(void);
void releasePart(BodyPart *part);
void die(void);
2014-02-16 14:32:28 +00:00
public:
2015-06-03 12:29:34 +00:00
Legoman(int side);
2014-02-16 14:32:28 +00:00
inline Object *getMainObject() { return (Object *)torso; }
inline Object *getHead() { return (Object *)head; }
inline bool isBeheaded() { return not(Object *)head->isAttached(); }
bool isOutOfRing(void); // TK
2015-06-03 12:29:34 +00:00
void insertToWorld(World *world);
void heal(void);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void addHarmfulObject(Object *object);
bool isHarmfulObject(Object *object);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void addOpponent(Legoman *opponent);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
// Call once per frame
void update(void);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
// Lock both legs at the same time by calling
// lockLeg(LEFTLEG | RIGHTLEG);
void lockPart(int part);
void unlockPart(int part);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
// Relative movement
void move(float *movement);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void turn(float amount);
void walk(float amount);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void jump(void);
void hit(void);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
bool isAlive(void);
Legoman *getOpponent(void);
int hitcounter;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void drawVisuals();
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
friend class BodyPart;
friend void drawEnd(int framecount);
2014-02-16 14:32:28 +00:00
};
extern Texture *damageHead;
extern Texture *damageTorso;
extern Texture *damageHand;
extern Texture *damageLeg;
2015-06-03 12:29:34 +00:00
class DamageVisual {
2014-02-16 14:32:28 +00:00
private:
2015-06-03 12:29:34 +00:00
BodyPart *object;
float x1, y1, x2, y2;
float tx1, ty1, tx2, ty2;
Texture *texture;
2014-02-16 14:32:28 +00:00
public:
2015-06-03 12:29:34 +00:00
DamageVisual(BodyPart *object, Texture *texture, bool mirror, float x1,
float y1, float x2, float y2);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void draw(void);
2014-02-16 14:32:28 +00:00
};
#endif