221 lines
5.8 KiB
C
221 lines
5.8 KiB
C
/*
|
|
* main.c
|
|
*
|
|
* Created on: 17 juin 2018
|
|
* Author: isen
|
|
*/
|
|
|
|
//#include "IAEngine.h"
|
|
#include "playerInterface.h"
|
|
#include "fileHandler.h"
|
|
#include "arenaEngine.h"
|
|
|
|
#include "SDL2/SDL.h"
|
|
#include "SDL2/SDL_image.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#define BLOC_SIZE 32 // Taille d'un bloc (carré) en pixels
|
|
#define NB_BLOCS_LARGEUR 20
|
|
#define NB_BLOCS_HAUTEUR 20
|
|
#define LARGEUR_FENETRE BLOC_SIZE * NB_BLOCS_LARGEUR
|
|
#define HAUTEUR_FENETRE BLOC_SIZE * NB_BLOCS_HAUTEUR
|
|
|
|
enum {HAUT, BAS, GAUCHE, DROITE};
|
|
enum {GRASS, ROCK, TREE,FIRSTPLAYER, IA1}; //Définit quel type de case il s'agit
|
|
|
|
int main(void)
|
|
{
|
|
|
|
SDL_Init(SDL_INIT_VIDEO);
|
|
|
|
if (SDL_Init(SDL_INIT_VIDEO) != 0 )
|
|
{
|
|
fprintf(stdout,"Échec de l'initialisation de la SDL (%s)\n",SDL_GetError());
|
|
return -1;
|
|
}
|
|
else
|
|
{
|
|
int continuer = 1;
|
|
int action;
|
|
|
|
ARENA_H_TILE* arena = NULL; //Déclaration de l'arène
|
|
|
|
SDL_Surface *player[4] = {NULL}; // 4 surfaces pour 4 directions de mario
|
|
SDL_Surface *IA1[4] = {NULL}; // 4 surfaces pour 4 directions de mario
|
|
SDL_Surface *grass = NULL;
|
|
SDL_Surface *rock = NULL, *tree = NULL, *river = NULL,*actualPlayer = NULL, *actualIA1 = NULL;
|
|
SDL_Rect position, positionJoueur;
|
|
|
|
|
|
|
|
|
|
int i = 0, j = 0;
|
|
int carte[NB_BLOCS_LARGEUR][NB_BLOCS_HAUTEUR] = {0};
|
|
|
|
//SDL_WM_SetIcon(IMG_Load("adventurer_resize.png"),NULL); //Définit l'icone de la fenêtre
|
|
|
|
// Création de la fenêtre
|
|
SDL_Window* pWindow = NULL;
|
|
pWindow = SDL_CreateWindow("Arena Survival Tournament",SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,LARGEUR_FENETRE,HAUTEUR_FENETRE,SDL_WINDOW_SHOWN);
|
|
|
|
//Génération de la nouvelle arène à partir du fichier
|
|
arena = genNewArena(NB_BLOCS_HAUTEUR, NB_BLOCS_LARGEUR);
|
|
|
|
if (arena == NULL)
|
|
{
|
|
printf("Erreur de la génération de l'arène\n");
|
|
}
|
|
// Chargement des sprites (décors, personnage...)
|
|
grass = IMG_Load("Landscape/grass_green_32x32.png");
|
|
rock = IMG_Load("Landscape/stone_green_32x32.png");
|
|
tree = IMG_Load("Landscape/tree_green_32x32.png");
|
|
river = IMG_Load("Landscape/river_green_32x32.png");
|
|
|
|
player[BAS] = IMG_Load("Adventurer/adventurer1_32x32.png");
|
|
player[HAUT] = IMG_Load("Adventurer/adventurer_back_32x32.png");
|
|
player[DROITE] = IMG_Load("Adventurer/adventurer1_right_32x32.png");
|
|
player[GAUCHE] = IMG_Load("Adventurer/adventurer1_left_32x32.png");
|
|
|
|
IA1[BAS] = IMG_Load("IA1/adventurer2_32x32.png");
|
|
IA1[HAUT] = IMG_Load("IA1/adventurer2_back_32x32.png");
|
|
IA1[DROITE] = IMG_Load("IA1/adventurer2_right_32x32.png");
|
|
IA1[GAUCHE] = IMG_Load("IA1/adventurer2_left_32x32.png");
|
|
|
|
actualPlayer = player[BAS];
|
|
actualIA1 = IA1[BAS];
|
|
|
|
SDL_Surface* Sprites[5]= {grass,rock,tree,actualPlayer,actualIA1};
|
|
|
|
// Chargement du niveau pour le tableau (Phase de test)
|
|
/*if (!chargerNiveau(carte))
|
|
{
|
|
printf("Niveau non chargé\n");// On arrête le jeu si on n'a pas pu charger le niveau
|
|
}*/
|
|
|
|
/*
|
|
//Cette fonction peut être utile pour rechercher un joueur ( Pour la detection)
|
|
// Recherche de la position de Mario au départ
|
|
for (i = 0 ; i < NB_BLOCS_LARGEUR ; i++)
|
|
{
|
|
for (j = 0 ; j < NB_BLOCS_HAUTEUR ; j++)
|
|
{
|
|
if (carte[i][j] == MARIO) // Si Mario se trouve à cette position
|
|
{
|
|
positionJoueur.x = i;
|
|
positionJoueur.y = j;
|
|
carte[i][j] = VIDE;
|
|
}
|
|
}
|
|
}
|
|
*/
|
|
|
|
// Placement des objets à l'écran à la création de l'arène
|
|
drawArena(pWindow,arena,Sprites);
|
|
|
|
|
|
SDL_Event event; // Cette variable servira plus tard à gérer les événements
|
|
|
|
if( pWindow )
|
|
{
|
|
SDL_UpdateWindowSurface(pWindow); //Rafaichis la fenetre
|
|
|
|
//SDL_Delay(3000); /* Attendre trois secondes, que l'utilisateur voie la fenêtre */
|
|
while (continuer)
|
|
{
|
|
|
|
|
|
action = PlayerInterface(pWindow,arena,Sprites);
|
|
|
|
if (action == -1)
|
|
{
|
|
continuer = 0;
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
|
|
|
|
}
|
|
//SDL_DestroyWindow(pWindow);
|
|
}
|
|
else
|
|
{
|
|
fprintf(stderr,"Erreur de création de la fenêtre: %s\n",SDL_GetError());
|
|
}
|
|
}
|
|
|
|
//IAEngine();
|
|
|
|
SDL_Quit();
|
|
//PlayerInterface();
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
int drawArena(SDL_Window* pWindow,ARENA_H_TILE* arena,SDL_Surface **Sprites)
|
|
{
|
|
SDL_Rect position;
|
|
int ID;
|
|
for (int i = 0 ; i < NB_BLOCS_LARGEUR ; i++)
|
|
{
|
|
for (int j = 0 ; j < NB_BLOCS_HAUTEUR ; j++)
|
|
{
|
|
position.x = i * BLOC_SIZE;
|
|
position.y = j * BLOC_SIZE;
|
|
|
|
ID = getTileTypeID( arena, i, j);
|
|
switch(ID)
|
|
{
|
|
case GRASS:
|
|
SDL_BlitSurface(Sprites[GRASS], NULL, SDL_GetWindowSurface(pWindow), &position);
|
|
|
|
break;
|
|
case ROCK:
|
|
SDL_BlitSurface(Sprites[ROCK], NULL, SDL_GetWindowSurface(pWindow), &position);
|
|
break;
|
|
case TREE:
|
|
SDL_BlitSurface(Sprites[TREE], NULL, SDL_GetWindowSurface(pWindow), &position);
|
|
break;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/*//Fonction draw avec un tableau. A servi de test pour le graphique
|
|
int drawArena(SDL_Window* pWindow,int carte[NB_BLOCS_LARGEUR][NB_BLOCS_HAUTEUR],SDL_Surface **Sprites)
|
|
{
|
|
SDL_Rect position;
|
|
for (int i = 0 ; i < NB_BLOCS_LARGEUR ; i++)
|
|
{
|
|
for (int j = 0 ; j < NB_BLOCS_HAUTEUR ; j++)
|
|
{
|
|
position.x = i * BLOC_SIZE;
|
|
position.y = j * BLOC_SIZE;
|
|
|
|
|
|
switch(carte[i][j])
|
|
{
|
|
case GRASS:
|
|
SDL_BlitSurface(Sprites[GRASS], NULL, SDL_GetWindowSurface(pWindow), &position);
|
|
|
|
break;
|
|
case ROCK:
|
|
SDL_BlitSurface(Sprites[ROCK], NULL, SDL_GetWindowSurface(pWindow), &position);
|
|
break;
|
|
case TREE:
|
|
SDL_BlitSurface(Sprites[TREE], NULL, SDL_GetWindowSurface(pWindow), &position);
|
|
break;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
*/
|
|
|
|
|