Skip to content

Commit

Permalink
Fixing the character update requests for keyboard input.
Browse files Browse the repository at this point in the history
	modified:   SFML with RakNet/main.cpp
	modified:   SFML with RakNet/serverclient.cpp
  • Loading branch information
Chibin committed Dec 15, 2013
1 parent 19bb91c commit 77398c9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
1 change: 1 addition & 0 deletions SFML with RakNet/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ int main()
if (event.type == sf::Event::Closed) window.close();
}
}
user->requestsToServer();
//------------
// Client stuff for drawing
//------------
Expand Down
43 changes: 25 additions & 18 deletions SFML with RakNet/serverclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class serverclient{
RakNet::SocketDescriptor* sd;
packetManager packet_manager;
Player* player;
std::map<std::string, Player> otherPlayers;
ServerDataContainer* serverData; //Should only 1 that exist
//From main
bool isUp,isDown,isLeft,isRight, repeat, isShiftDown, isChatting;
Expand Down Expand Up @@ -143,10 +144,33 @@ class serverclient{

void drawManager(sf::RenderWindow &window){
//std::cout << player->getName() << std::endl;
std::map<std::string, Player>::iterator it;
for (it = otherPlayers.begin(); it !=otherPlayers.end(); it++){
it->second.draw(window);
}
if(player != NULL){
player->draw(window);
}
}
void requestsToServer(){
//-----------
//character calculations: Request to move the character
//------------
if(isUp) printf("UP!\n");
if(isDown) printf("isDown!\n");
if(isLeft) printf("isLeft!\n");
if(isRight) printf("isRight!\n");
if( (isUp==true) || (isDown==true) || (isLeft==true) || (isRight==true) ) {//player.move(0,-3);
BitStream bsOut;
bsOut.Write((RakNet::MessageID)REQUEST_FOR_PLAYER_TO_MOVE);
std::string playerName = player->getName().c_str();
unsigned short strlength = (unsigned short)strlen(playerName.c_str());
bsOut.Write(strlength);
bsOut.Write(playerName.c_str(),strlength);
bsOut.Write(isUp); bsOut.Write(isDown); bsOut.Write(isLeft); bsOut.Write(isRight);
peer->Send(&bsOut,HIGH_PRIORITY,RELIABLE_ORDERED,0,RakNet::UNASSIGNED_SYSTEM_ADDRESS,true);
}
}
void inputHandler(sf::Event &event, sf::RenderWindow &window){
int y;
if (event.type == sf::Event::KeyReleased){
Expand Down Expand Up @@ -192,23 +216,6 @@ class serverclient{
else if(event.key.code == sf::Keyboard::Right){ isRight = true; y = 1; }
else std::cout << event.type << " " <<keypressToChar(event.key.code) << std::endl;
}
//-----------
//character calculations: Request to move the character
//------------
if(isUp) printf("UP!\n");
if(isDown) printf("isDown!\n");
if(isLeft) printf("isLeft!\n");
if(isRight) printf("isRight!\n");
if(isUp==true || isDown==true || isLeft==true || isRight==true) {//player.move(0,-3);
BitStream bsOut;
bsOut.Write((RakNet::MessageID)REQUEST_FOR_PLAYER_TO_MOVE);
std::string playerName = player->getName().c_str();
unsigned short strlength = (unsigned short)strlen(playerName.c_str());
bsOut.Write(strlength);
bsOut.Write(playerName.c_str(),strlength);
bsOut.Write(isUp); bsOut.Write(isDown); bsOut.Write(isLeft); bsOut.Write(isRight);
peer->Send(&bsOut,HIGH_PRIORITY,RELIABLE_ORDERED,0,RakNet::UNASSIGNED_SYSTEM_ADDRESS,true);
}
}
void packetManager(){
RakNet::Packet *packet = NULL;
Expand All @@ -227,4 +234,4 @@ class serverclient{
}
}
};
#endif
#endif

0 comments on commit 77398c9

Please sign in to comment.