119 lines
2.5 KiB
C++
119 lines
2.5 KiB
C++
#include "remoteplayer.h"
|
|
#include <iostream>
|
|
#include <cstring>
|
|
#include "texture.h"
|
|
#include <thread>
|
|
#include <queue>
|
|
|
|
|
|
|
|
RemotePlayer::RemotePlayer(netprot::PlayerInfo pinfo) : m_pinfo(pinfo), m_aminacc(0.0f), m_animstate(Anim::STILL), m_team_id(0), current(), previous(), m_texture_front(), Player(Vector3f(0, 0, 0), 0, 0) {
|
|
|
|
LoadTexture(m_texture_front, TEXTURE_PATH "AssetOtherPlayer/FinalPNGStanding/BlueFrontRight.png", false, false);
|
|
|
|
}
|
|
|
|
|
|
//RemotePlayer::RemotePlayer()
|
|
//{
|
|
//
|
|
//}
|
|
|
|
RemotePlayer::~RemotePlayer()
|
|
{
|
|
}
|
|
|
|
void RemotePlayer::Init() {
|
|
|
|
}
|
|
|
|
void RemotePlayer::Feed(const netprot::Output out) {
|
|
|
|
current.position = out.position;
|
|
current.direction = out.direction;
|
|
current.states = out.states;
|
|
current.id = out.id;
|
|
|
|
//a revoir pour le jump et le shoot en meme temps lorsque les test seront possible
|
|
|
|
if (current.position != previous.position)
|
|
{
|
|
Vector3f positionDelta = current.position - previous.position;
|
|
m_position = current.position + positionDelta;
|
|
m_direction = current.direction;
|
|
|
|
}
|
|
|
|
if(current.direction != previous.direction)
|
|
{
|
|
m_direction = current.direction;
|
|
current.direction = current.direction;
|
|
}
|
|
|
|
if (current.states.shooting) {
|
|
//true;
|
|
m_animstate = Anim::SHOOTING;
|
|
}
|
|
else if (current.states.jumping) {
|
|
//true;
|
|
m_animstate = Anim::JUMPING;
|
|
}
|
|
else if (current.states.dead) {
|
|
//true;
|
|
m_animstate = Anim::DEAD;
|
|
}
|
|
else if(current.states.powerup){
|
|
//true;
|
|
m_animstate = Anim::POWERUP;
|
|
}
|
|
else if (current.states.still) {
|
|
//true;
|
|
m_animstate = Anim::STILL;
|
|
}
|
|
else if (current.states.running) {
|
|
//true;
|
|
m_animstate = Anim::RUNNING;
|
|
}
|
|
|
|
|
|
previous.direction = current.direction;
|
|
previous.position = current.position;
|
|
previous.states = current.states;
|
|
previous.id = current.id;
|
|
|
|
|
|
|
|
}
|
|
|
|
void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, float elapsedTime)
|
|
{
|
|
shader.Use();
|
|
//m_texture_front.Bind();
|
|
|
|
|
|
float u, v, w, h;
|
|
atlas.Bind();
|
|
atlas.TextureIndexToCoord(0, u, v, w, h);
|
|
glBegin(GL_QUADS);
|
|
glTexCoord2f(u, v); glVertex3f(0, 50., 0);
|
|
glTexCoord2f(u+w, v); glVertex3f(50., 50., 0);
|
|
glTexCoord2f(u+w, v+h); glVertex3f(50., 0, 0);
|
|
glTexCoord2f(u, v+h); glVertex3f(0, 0, 0);
|
|
glEnd();
|
|
shader.Disable();
|
|
}
|
|
|
|
bool RemotePlayer::LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps, bool stopOnError)
|
|
{
|
|
texture.Load(filename, useMipmaps);
|
|
if (!texture.IsValid()) {
|
|
std::cerr << "Unable to load texture (" << filename << ")" << std::endl;
|
|
if (stopOnError)
|
|
return false;
|
|
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|