Modification de l'affichage des action de jeu

origin/fixingSettings
marouault 3 years ago
parent ec52ebd10c
commit 14f93ae622

@ -52,15 +52,21 @@ int main(int argc, char const *argv[]) {
int windowH;
SDL_GetWindowSize(window, &windowW, &windowH);
size_t nbPlayers = 0;
Players* players;
bool crashed = gameCreationMenu(renderer, &generalState, &fontHandler, windowW, windowH, &players, &nbPlayers);
if (crashed) {
fprintf(stderr,"sorry");
exit(-1);
}
gameView(&generalState, window, renderer, &fontHandler, players, nbPlayers);
gameCreationMenu(renderer, &generalState, &fontHandler, windowW, windowH);
endGameMenu(&generalState, window, renderer, &fontHandler, players, nbPlayers);
break;
}
case GS_Game: {
size_t nbPlayers = 0;
Player* players = NULL;//...;
endGameMenu(&generalState, window, renderer, &fontHandler, players, nbPlayers);
break;
}
}

@ -11,6 +11,7 @@
#include <SDL2/SDL.h>
#include <stdbool.h>
#include "model/Board.h"
#include "model/Coord.h"
/**
* \brief Draw the board (water, islands and bridges)
@ -23,7 +24,9 @@
* \param water Texture for water
* \return true I don't know what to return
*/
bool drawBoard(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Board* board, SDL_Texture* island, SDL_Texture* bridge, SDL_Texture* water);
bool drawFullBoard(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Board* board, SDL_Texture* island, SDL_Texture* bridge, SDL_Texture* water);
void drawRemoveBridge(SDL_Renderer* renderer, const SDL_Rect* boardRect, SDL_Texture* water, const Coord* coordBridge);
#endif

@ -7,4 +7,7 @@
void drawPiecesPlayer(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Piece arrPieces[], const size_t nbPieces, const size_t numPlayer, SDL_Texture* piece);
#endif //PIECES_DRAWER_INCLUDED
void drawMovePiece(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Island* startMove, const Island* endMove, SDL_Texture* pieceTexture, SDL_Texture* islandTexture);
#endif //PIECES_DRAWER_INCLUDED

@ -1,12 +1,44 @@
#include "view/BoardDrawer.h"
bool drawBoard(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Board* board, SDL_Texture* island, SDL_Texture* bridge, SDL_Texture* water)
SDL_Rect coordToRect(const SDL_Rect* boardRect, const Coord* coord) {
const int w = boardRect->w/9;
const int h = boardRect->h/9;
SDL_Rect r = {
.x = boardRect->x + w*coord->x,
.y = boardRect->y + h*coord->y,
.w = w,
.h = h
};
return r;
}
void drawRemoveBridge(SDL_Renderer* renderer, const SDL_Rect* boardRect, SDL_Texture* water, const Coord* coordBridge) {
const SDL_Rect destRect = coordToRect(boardRect, coordBridge);
SDL_RenderCopy(renderer, water, &destRect, boardRect);
}
bool drawFullBoard(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Board* board, SDL_Texture* island, SDL_Texture* bridge, SDL_Texture* water)
{
int h = boardRect->h / 9;
int w = boardRect->w / 9;
SDL_RenderCopy(renderer, water, NULL, boardRect);
//Water (Possible to optimize)
for (size_t y = 0; y < 9; ++y)
{
for (size_t x = 0; x < 9; ++x)
{
const SDL_Rect destRect = {
.x = boardRect->x+x*w,
.y = boardRect->y+y*h,
.w = w,
.h = h,
};
SDL_RenderCopy(renderer, water, NULL, &destRect);
}
}
//Islands
for (int y=0; y<9; y+=2) {

@ -1,7 +1,7 @@
#include <SDL2/SDL.h>
#include <stdio.h>
#include <stdbool.h>
#include "engine/InputProcessor.h"
#include "engine/GameInputProcessor.h"
#include "engine/InputElement.h"
#include "engine/TextureHandler.h"
#include "model/Game.h"
@ -9,49 +9,30 @@
#include "model/arrayCoord.h"
#include "debug/printer.h"
int main(int argc, char* argv[])
{
SDL_Window* window = NULL;
SDL_Rect windowSize = {10, 10, 600, 600};
SDL_Renderer* renderer = NULL;
int statut = EXIT_FAILURE;
if(SDL_Init(SDL_INIT_VIDEO) != 0) {
fprintf(stderr, "Error : %s\n", SDL_GetError());
goto Quit;
}
SDL_Rect boardRectFromWindowSize(int windowW, int windowH) {
SDL_Rect boardRect = {.x=windowW/10.0, .y=windowH/10, .w=windowW*8.0/10.0, .h=windowH*8.0/10.0};
window = SDL_CreateWindow("Pontu",windowSize.x, windowSize.y, windowSize.w, windowSize.h, SDL_WINDOW_SHOWN);
if (!window)
{
fprintf(stderr, "Error : %s\n", SDL_GetError());
goto Quit;
}
return boardRect;
}
renderer = SDL_CreateRenderer(window,-1,SDL_RENDERER_ACCELERATED);
if(!renderer)
{
fprintf(stderr, "Erreur : %s", SDL_GetError());
goto Quit;
void gameView(GeneralState* generalState, SDL_Window* window, SDL_Renderer* renderer, Player players[], size_t nbPlayers)
{
if (*generalState != GS_Game) {
return ;
}
InputProcessor inputProcessor = createInputProcessor();
GameInputProcessor inputProcessor = createGameInputProcessor();
struct array_Coord interactiveCases = array_Coord_Create();
int wBoardRect=99*3, hBoardRect=99*3;
SDL_Rect boardRect = {.x=windowSize.w/2 - wBoardRect/2, .y=windowSize.h/2 - hBoardRect/2, .w=wBoardRect, .h=99*3};
const char* pseudos[] = {"Azerty","Bépo"};
Game game = newGame(2, pseudos);
Game game = newGame(players, nbPlayers);
TextureHandler textureHandler = newTextureHandler(renderer);
bool quit = false;
while(!quit)
while(*generalState == GS_Game)
{
// Event handling
InputElement inputElement;
while (InputType_None != (inputElement = proccessInput(&inputProcessor, &boardRect)).type) {
while (InputType_None != (inputElement = proccessGameInput(&inputProcessor, &boardRect)).type) {
switch (inputElement.type)
{
@ -59,7 +40,7 @@ int main(int argc, char* argv[])
switch (inputElement.data.uiAction)
{
case UIAction_Quit:
quit = true;
*generalState = GS_Quit;
break;
case UIAction_Validate:
break;
@ -75,6 +56,8 @@ int main(int argc, char* argv[])
fprintf(stderr, "To (%d; %d)\n", inputElement.data.move.end.x, inputElement.data.move.end.y);
moveOnBoard(inputElement.data.move.start, inputElement.data.move.end, &game);
drawMovePiece
break;
case InputType_ClickGame:
fprintf(stderr, "Clic on board (%d; %d)\n", inputElement.data.coord.x, inputElement.data.coord.y);
@ -114,17 +97,9 @@ int main(int argc, char* argv[])
SDL_Delay(20);
}
statut = EXIT_SUCCESS;
Quit:
freeTextureHandler(&textureHandler);
array_Coord_Free(&interactiveCases);
if(renderer != NULL) {
SDL_DestroyRenderer(renderer);
}
if(window != NULL) {
SDL_DestroyWindow(window);
}
SDL_Quit();
return statut;

@ -3,12 +3,12 @@
//Don't put this in model
SDL_Rect islandToRect(const SDL_Rect* boardRect, const Island island) {
SDL_Rect islandToRect(const SDL_Rect* boardRect, const Island* island) {
const int w = boardRect->w/9;
const int h = boardRect->h/9;
SDL_Rect r = {
.x = boardRect->x + w*(island.x*2),
.y = boardRect->y + h*(island.y*2),
.x = boardRect->x + w*(island->x*2),
.y = boardRect->y + h*(island->y*2),
.w = w,
.h = h
};
@ -21,8 +21,17 @@ void drawPiecesPlayer(SDL_Renderer* renderer, const SDL_Rect* boardRect, const P
for (size_t i = 0; i < nbPieces; ++i)
{
if (arrPieces[i].idJ == numPlayer) {
const SDL_Rect rDest = islandToRect(boardRect, arrPieces[i].island);
const SDL_Rect rDest = islandToRect(boardRect, &arrPieces[i].island);
SDL_RenderCopy(renderer, piece, NULL, &rDest);
}
}
}
void drawMovePiece(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Island* startMove, const Island* endMove, SDL_Texture* pieceTexture, SDL_Texture* islandTexture) {
SDL_Rect rDest = islandToRect(boardRect, startMove);
SDL_RenderCopy(renderer, islandTexture, NULL, &rDest);
rDest = islandToRect(boardRect, endMove);
SDL_RenderCopy(renderer, pieceTexture, NULL, &rDest);
}

Loading…
Cancel
Save