First working multiplayer version

This commit is contained in:
Phew
2026-02-11 23:20:46 +01:00
parent 08686e0fd6
commit a11da1b3d8
7 changed files with 284 additions and 163 deletions

View File

@@ -3,38 +3,54 @@
class Player
{
public:
Player(int[3], int, int);
Player(int, int, int);
int Id() const;
int Lives() const;
void Lives(int);
int Lives();
bool Alive() const;
void Kill();
bool Alive();
void moveto(int);
void setColor(int, int, int);
void moveby(int);
int color[3];
int position;
bool attacking;
int last_attack;
void moveto(int);
void Spawn(int);
void updateState(bool tilted, bool wobbled, int time);
void startAttack(int time);
int _lastState; // 0-> idle; 1-> move; 2 -> attack
// public variables
int position;
int speed;
bool attacking;
bool captured;
int last_attack;
int color[3];
private:
int _id;
int _lives;
int _state;
int _lastState; // 0-> idle; 1-> move; 2 -> attack
int _attackDuration;
};
Player::Player(int player_color[3], int lives, int attackDuration){
Player::Player(int id, int lives, int attackDuration){
_lives = lives;
_id = id;
attacking = false;
color[0] = player_color[0];
color[1] = player_color[1];
color[2] = player_color[2];
_attackDuration = attackDuration;
_lastState = 0; // start as idle;
captured = false;
}
void Player::setColor(int r, int g, int b){
color[0] = r;
color[1] = g;
color[2] = b;
}
int Player::Id() const
{
return _id;
}
void Player::updateState(bool tilted, bool wobbled, int time) {
@@ -65,16 +81,23 @@ void Player::Lives(int n){
_lives = n;
}
bool Player::Alive(){
bool Player::Alive() const{
return _lives > 0;
}
void Player::Kill(){
captured = true;
_lives--;
if (_lives < 0) _lives = 0;
}
int Player::Lives(){
void Player::Spawn(int pos){
captured = false;
moveto(pos);
}
int Player::Lives() const{
return _lives;
}