diff --git a/Game.cpp b/Game.cpp index 3d00564..3bea1f9 100644 --- a/Game.cpp +++ b/Game.cpp @@ -421,6 +421,11 @@ bool LGame::initObjs() printf("Failed to load ash texture!\n"); return false; } + if (!window.loadTexture(ash2Texture, "resources/ash2.bmp")) + { + printf("Failed to load ash2 texture!\n"); + return false; + } if (!window.loadTexture(dogTexture, "resources/dog.png")) { printf("Failed to load dog texture!\n"); @@ -437,6 +442,7 @@ bool LGame::initObjs() LTexture *icecreamAnimationTexture = new LTexture(); LTexture *tennisAnimationTexture = new LTexture(); LTexture *basketBallAnimationTexture = new LTexture(); + LTexture *footBallAnimationTexture = new LTexture() ; if (!window.loadTexture(*sleepingAnimationTexture, "resources/sleeping.png")) { printf("Failed to load sleeping texture!\n"); @@ -467,13 +473,17 @@ bool LGame::initObjs() printf("Failed to load basketball texture!\n"); return false; } + if( !window.loadTexture(*footBallAnimationTexture , "resources/football.png")){ + printf("Failed to load football texture!\n"); + return false; + } sleepingAnimation = new Animation(*sleepingAnimationTexture, 32, 32); burgerAnimation = new Animation(*burgerAnimationTexture, 32, 32); hotDogAnimation = new Animation(*hotdogAnimationTexture, 32, 32); icecreamAnimation = new Animation(*icecreamAnimationTexture, 32, 32); basketballAnimation = new Animation(*basketBallAnimationTexture, 32, 32); tennisAnimation = new Animation(*tennisAnimationTexture, 32, 32); - + footballAnimation = new Animation(*footBallAnimationTexture,32,32) ; Player ash(ashTexture, *this, 32, 32, 3, 1, 2, 0); players.push_back(ash); int numberOfNPCs = 5; @@ -485,7 +495,7 @@ bool LGame::initObjs() NPCs.push_back(prof); } - Player opponent(ashTexture, *this, 32, 32, 3, 1, 2, 0); + Player opponent(ash2Texture, *this, 32, 32, 3, 1, 2, 0); players.push_back(opponent); camera = {0, 0, window.getWidth() - tasksVPWidth, window.getHeight() - 3 * gyRenderOffset - 5 * gyPadding}; @@ -859,8 +869,27 @@ void LGame::initEntities() { displayText = "shop"; }); Entity sac("sac", [&](Player &player, std::string &displayText) { displayText = "sac"; }); - Entity foot("foot", [&](Player &player, std::string &displayText) - { displayText = "foot"; }); + Entity foot("foot", getTextPromptFunc("PRESS F to PLAY FOOTBALL") , + [&](SDL_Event &e, Player &player) + { + if (e.type == SDL_KEYDOWN && e.key.repeat == 0) + { + switch (e.key.keysym.sym) + { + case SDLK_f: + player.setTaskText("playing basketball... "); + player.setTaskAnimation(player.getGame().footballAnimation); + player.setCurrentTaskTime(3000); + player.getCurrentTaskTimer().start(); + player.setUpdateStateParameters({-5, + 0, + 0, + 10}); + break; + } + } + } + ); Entity basketball("basketball", getTextPromptFunc("PRESS B TO PLAY BASKTEBALL"), [&](SDL_Event &e, Player &player) { diff --git a/Game.h b/Game.h index 5403a90..c162389 100644 --- a/Game.h +++ b/Game.h @@ -58,6 +58,7 @@ class LGame : public LScreen LTexture ashTexture; LTexture dogTexture; LTexture profTexture; + LTexture ash2Texture; TileAtlas tileAtlas; @@ -111,6 +112,7 @@ class LGame : public LScreen Animation *hotDogAnimation; Animation *tennisAnimation; Animation *basketballAnimation; + Animation* footballAnimation ; LTimer getTimer(); Mix_Music *backGroundMusic; Mix_Chunk *introMusic; diff --git a/Makefile b/Makefile index a749eb9..c581a69 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ OBJS = Button.o collision.o Game.o main.o MainMenu.o MessageStructs.o MyTexture. COMPILER_FLAGS = -g #LINKER_FLAGS specifies the libraries we're linking against -LINKER_FLAGS = -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer -lSDL2_net +LINKER_FLAGS = -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer #OBJ_NAME specifies the name of our exectuable OBJ_NAME = experiment.out @@ -28,7 +28,7 @@ Game.o: Tile.h Player.h MyTexture.h TileAtlas.h TileAtlas.h Renderable.h Entity. main.o: MyWindow.h Game.h MainMenu.h -MainMenu.o: Screen.h Game.h TextInput.h SearchOpponent.h MyWindow.h Button.h +MainMenu.o: Screen.h Game.h TextInput.h MyWindow.h Button.h MessageStructs.o: MessageStructs.h @@ -40,8 +40,6 @@ Player.o: Tile.h MyTexture.h Renderable.h MyWindow.h SoundEffect.h Timer.h utili Screen.o: MyWindow.h -#SearchOpponent.o: MyWindow.h MessageStructs.h Game.h Screen.h - Text.o: MyTexture.h MyWindow.h TextInput.o: MyWindow.h diff --git a/MyWindow.cpp b/MyWindow.cpp index f36f1d2..a246cf3 100644 --- a/MyWindow.cpp +++ b/MyWindow.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include @@ -233,11 +232,6 @@ bool LWindow::initLibs() } Mix_AllocateChannels(32); - if (SDLNet_Init() < 0) - { - fprintf(stderr, "SDLNet_Init: %s\n", SDLNet_GetError()); - return false; - } return true; } diff --git a/SearchOpponent.cpp b/SearchOpponent.cpp deleted file mode 100644 index 23d69d8..0000000 --- a/SearchOpponent.cpp +++ /dev/null @@ -1,185 +0,0 @@ -#include "SearchOpponent.h" -#include "MyWindow.h" -#include "MessageStructs.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "Game.h" - -SearchOpponent::SearchOpponent(LWindow &window, std::string playerName) : LScreen(window), playerName(playerName) -{ - // if (!(sd = SDLNet_UDP_Open(2000))) - // { - // fprintf(stderr, "SDLNet_UDP_Open: %s\n", SDLNet_GetError()); - // } - - // if (!(p = SDLNet_AllocPacket(512))) - // { - // fprintf(stderr, "SDLNet_AllocPacket: %s\n", SDLNet_GetError()); - // } - - // if (SDLNet_ResolveHost(&broadcastAdd, "192.168.227.102", 2001)) - // { - // fprintf(stderr, "SDLNet_ResolveHost: %s\n", SDLNet_GetError()); - // } - - // memset(&hints, 0, sizeof hints); - // hints.ai_family = AF_INET; // set to AF_INET to use IPv4 - // hints.ai_socktype = SOCK_DGRAM; - // hints.ai_flags = AI_PASSIVE; // use my IP - - // if ((rv = getaddrinfo(NULL, "2000", &hints, &servinfo)) != 0) - // { - // fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv)); - // } - - // for (p = servinfo; p != NULL; p = p->ai_next) - // { - // if ((sockfd = socket(p->ai_family, p->ai_socktype, - // p->ai_protocol)) == -1) - // { - // perror("listener: socket"); - // continue; - // } - - // if (bind(sockfd, p->ai_addr, p->ai_addrlen) == -1) - // { - // close(sockfd); - // perror("listener: bind"); - // continue; - // } - - // break; - // } - - if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) - { - perror("socket creation failed"); - } - - fcntl(sockfd, F_SETFL, O_NONBLOCK); - - // int broadcast = 1; - // if (setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &broadcast, - // sizeof(broadcast)) == -1) - // { - // perror("setsockopt (SO_BROADCAST)"); - // } - - memset(&myAddr, 0, sizeof(myAddr)); - memset(&theirAddr, 0, sizeof(theirAddr)); - - myAddr.sin_family = AF_INET; // IPv4 - myAddr.sin_addr.s_addr = INADDR_ANY; - myAddr.sin_port = htons(2000); - - theirAddr.sin_family = AF_INET; - theirAddr.sin_port = htons(8080); - // theirAddr.sin_addr.s_addr = INADDR_ANY; - inet_pton(AF_INET, "192.168.227.10", &(theirAddr.sin_addr.s_addr)); - - // if (bind(sockfd, (const struct sockaddr *)&myAddr, sizeof(myAddr)) < 0) - // { - // perror("bind failed"); - // } - - // if (p == NULL) - // { - // fprintf(stderr, "listener: failed to bind socket\n"); - // } - - // addr_len = sizeof their_addr; - - NewClientMessage newClientMsg; - newClientMsg.name = playerName; - int bytesUsed = serialize(&newClientMsg, buf); - sendto(sockfd, buf, bytesUsed, 0, (const struct sockaddr *)&theirAddr, - sizeof(theirAddr)); - - // sockaddr_in sendAddr; - // memset(&sendAddr, '\0', sizeof(sendAddr)); - // sendAddr.sin_family = AF_INET; - // sendAddr.sin_port = 2000; - // inet_pton(AF_INET, "255.255.255.255", &sendAddr.sin_addr); - - // if ((numbytes = sendto(sockfd, data, bytesUsed, 0, - // (const struct sockaddr *)sendAddr, p->ai_addrlen)) == -1) - // { - // perror("talker: sendto"); - // } - - // p->address.host = broadcastAdd.host; - // p->address.port = broadcastAdd.port; - // p->len = bytesUsed; - // int j = 4; - // while (p->data[j] != 0) - // { - // std::cout << p->data[j]; - // j++; - // } - // SDLNet_UDP_Send(sd, -1, p); -} - -void SearchOpponent::handleEvent(SDL_Event &e) -{ - switch (e.type) - { - case SDL_KEYUP: - if (e.key.keysym.sym == SDLK_s) - { - LGame *myGame = new LGame(window); - window.setCurrScreen(myGame); - } - break; - default: - break; - } -} - -void SearchOpponent::update() -{ - // int numbytes = 0; - // unsigned int len; - // if ((numbytes = recvfrom(sockfd, buf, sizeof(buf) - 1, 0, - // (struct sockaddr *)&theirAddr, &len)) != -1) - // { - // // NewClientMessage newClientMsg; - // // deserialize((char *)buf, &newClientMsg); - // // std::cout << newClientMsg.name << std::endl; - // // perror("recvfrom"); - // } - - // if (SDLNet_UDP_Recv(sd, p)) - // { - // // int j = 4; - // // while (p->data[j] != 0) - // // { - // // std::cout << p->data[j]; - // // j++; - // // } - // } -} - -void SearchOpponent::render(SDL_Renderer *renderer) -{ - SDL_SetRenderDrawColor(renderer, 3, 211, 252, 255); - SDL_RenderClear(renderer); -} - -void SearchOpponent::cleanUp() -{ - // SDLNet_FreePacket(p); - - // freeaddrinfo(servinfo); - close(sockfd); -} \ No newline at end of file diff --git a/SearchOpponent.h b/SearchOpponent.h deleted file mode 100644 index f51b4c7..0000000 --- a/SearchOpponent.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef SEARCH_OPPONENT -#define SEARCH_OPPONENT - -#include "Screen.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class SearchOpponent : public LScreen -{ -private: - std::string playerName; - // UDPsocket sd; - // UDPpacket *p; - // IPaddress broadcastAdd; - int sockfd; - struct sockaddr_in myAddr, theirAddr; - char buf[512]; - -public: - SearchOpponent(LWindow &window, std::string playerName); - void handleEvent(SDL_Event &e); - void update(); - void render(SDL_Renderer *renderer); - void cleanUp(); -}; - -#endif \ No newline at end of file