Added tiles and sprites, creating arenaGUI
@ -1,27 +1,34 @@
|
||||
#include "arenaEngine.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "fileHandler.h"
|
||||
#include "logHelper.h"
|
||||
#include "main.h"
|
||||
#include "arenaEngine.h"
|
||||
|
||||
|
||||
/*
|
||||
* Arena generate functions
|
||||
*/
|
||||
TILE* createTileList(void) {
|
||||
TILE* origin = NULL;
|
||||
|
||||
return origin;
|
||||
}
|
||||
|
||||
ARENA_H_TILE* createHTile(ARENA_H_TILE* prevHTile) {
|
||||
ARENA_H_TILE* tile_h = NULL;
|
||||
|
||||
if (prevHTile == NULL) {
|
||||
tile_h = calloc(1,sizeof(ARENA_H_TILE)); //Using calloc because of resetting all memory allocated to 0
|
||||
tile_h->type_id = 0;
|
||||
tile_h->playerOnTile = NULL;
|
||||
//tile_h->playerOnTile = NULL;
|
||||
tile_h->nextRow = NULL;
|
||||
tile_h->nextColumn = NULL;
|
||||
} else if (prevHTile != NULL) {
|
||||
tile_h = calloc(1,sizeof(ARENA_H_TILE));
|
||||
prevHTile->nextRow = tile_h;
|
||||
tile_h->type_id = 0;
|
||||
tile_h->playerOnTile = NULL;
|
||||
//tile_h->playerOnTile = NULL;
|
||||
tile_h->nextRow = NULL;
|
||||
tile_h->nextColumn = NULL;
|
||||
}
|
||||
@ -36,7 +43,7 @@ ARENA_W_TILE* createWTile(ARENA_H_TILE* prevHTile, ARENA_W_TILE* prevWTile) {
|
||||
tile_w = calloc(1,sizeof(ARENA_W_TILE));
|
||||
prevHTile->nextColumn = tile_w;
|
||||
tile_w->type_id = 0;
|
||||
tile_w->playerOnTile = NULL;
|
||||
//tile_w->playerOnTile = NULL;
|
||||
tile_w->nextColumn = NULL;
|
||||
|
||||
return tile_w;
|
||||
@ -44,7 +51,7 @@ ARENA_W_TILE* createWTile(ARENA_H_TILE* prevHTile, ARENA_W_TILE* prevWTile) {
|
||||
tile_w = calloc(1,sizeof(ARENA_W_TILE));
|
||||
prevWTile->nextColumn = tile_w;
|
||||
tile_w->type_id = 0;
|
||||
tile_w->playerOnTile = NULL;
|
||||
//tile_w->playerOnTile = NULL;
|
||||
tile_w->nextColumn = NULL;
|
||||
}
|
||||
|
||||
@ -114,6 +121,8 @@ int getTileTypeID(ARENA_H_TILE* arena, int coord_x, int coord_y) {
|
||||
int type_id = -1;
|
||||
int i;
|
||||
|
||||
if (coord_x > A_WIDTH || coord_y > A_HEIGHT) return -1;
|
||||
|
||||
if (coord_y == 0) {
|
||||
ARENA_H_TILE* tile_h = NULL;
|
||||
|
||||
@ -148,3 +157,11 @@ int getTileTypeID(ARENA_H_TILE* arena, int coord_x, int coord_y) {
|
||||
|
||||
return type_id;
|
||||
}
|
||||
|
||||
int isPlayerAdjacent(PLAYER* p1, PLAYER* p2) {
|
||||
int adjPlayer = -1;
|
||||
|
||||
if ((p1->PositionX-1 || p1->PositionX+1) == p2->PositionX && (p1->PositionY-1 || p1->PositionY+1) == p2->PositionY) adjPlayer = 1;
|
||||
|
||||
return adjPlayer;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "playerInterface.h"
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#ifndef ARENAENGINE_H_
|
||||
#define ARENAENGINE_H_
|
||||
@ -17,26 +18,28 @@ typedef struct items{
|
||||
|
||||
typedef struct tileType{
|
||||
int type_id;
|
||||
//texture?
|
||||
SDL_Surface texture;
|
||||
int isGround;
|
||||
int canBeMined;
|
||||
struct tileType *nextTile;
|
||||
}TILE;
|
||||
|
||||
typedef struct arena_h_tile{ //Rows chained list
|
||||
int type_id;
|
||||
PLAYER* playerOnTile;
|
||||
//PLAYER* playerOnTile;
|
||||
struct arena_h_tile *nextRow;
|
||||
struct arena_w_tile *nextColumn;
|
||||
}ARENA_H_TILE;
|
||||
|
||||
typedef struct arena_w_tile{ //Columns chained list
|
||||
int type_id;
|
||||
PLAYER* playerOnTile;
|
||||
//PLAYER* playerOnTile;
|
||||
struct arena_w_tile *nextColumn;
|
||||
}ARENA_W_TILE;
|
||||
|
||||
|
||||
//Generation functions
|
||||
TILE* createTileList(void);
|
||||
ARENA_H_TILE* genNewArena(int size_h, int size_w);
|
||||
void deleteArena(ARENA_H_TILE* arena);
|
||||
|
||||
|
22
arenaGUI.c
@ -1,3 +1,23 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "SDL2/SDL.h"
|
||||
#include "logHelper.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include <SDL2/SDL_ttf.h>
|
||||
#include "arenaGUI.h"
|
||||
|
||||
void displayArena(ARENA_H_TILE* arena, SDL_Window* window, SDL_Surface *res, int size_h, int size_w, int tile_size) {
|
||||
SDL_Rect tmp_tile_coord;
|
||||
int i,j;
|
||||
|
||||
for (i=0; i<size_h; i++) {
|
||||
for (j=0; j<size_w; j++) {
|
||||
tmp_tile_coord.x = i * tile_size;
|
||||
tmp_tile_coord.y = j * tile_size;
|
||||
|
||||
SDL_BlitSurface(res, NULL, SDL_GetWindowSurface(window), &tmp_tile_coord);
|
||||
|
||||
SDL_UpdateWindowSurface(window);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
#include "main.h"
|
||||
#include "arenaEngine.h"
|
||||
|
||||
#ifndef ARENAGUI_H_
|
||||
#define ARENAGUI_H_
|
||||
|
||||
|
||||
void displayArena(ARENA_H_TILE* arena, SDL_Window* windows, SDL_Surface *res, int size_h, int size_w, int tile_size);
|
||||
|
||||
#endif
|
||||
|
BIN
data/icon_ia.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
data/sprite_ia_1.png
Normal file
After Width: | Height: | Size: 3.2 KiB |
BIN
data/sprite_player_1.png
Normal file
After Width: | Height: | Size: 3.2 KiB |
BIN
data/tile_gold.png
Normal file
After Width: | Height: | Size: 3.1 KiB |
BIN
data/tile_grass.png
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
data/tile_rock.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
data/tile_tree.png
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
data/tile_water.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
70
main.c
@ -1,23 +1,17 @@
|
||||
/*
|
||||
* main.c
|
||||
*
|
||||
* Created on: 17 juin 2018
|
||||
* Author: isen
|
||||
*/
|
||||
|
||||
//#include "IAEngine.h"
|
||||
#include "playerInterface.h"
|
||||
#include "SDL2/SDL.h"
|
||||
#include "main.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "logHelper.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_thread.h>
|
||||
#include <SDL2/SDL_mutex.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include <SDL2/SDL_ttf.h>
|
||||
//#include <SDL2/SDL_thread.h>
|
||||
//#include <SDL2/SDL_mutex.h>
|
||||
#include "arenaEngine.h"
|
||||
#include "arenaGUI.h"
|
||||
//#include "IAEngine.h"
|
||||
#include "playerInterface.h"
|
||||
|
||||
#define A_HEIGHT 100
|
||||
#define A_WIDTH 100
|
||||
|
||||
void initDisplayLib() {
|
||||
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
||||
@ -27,22 +21,35 @@ void initDisplayLib() {
|
||||
}
|
||||
}
|
||||
|
||||
void initResources() {
|
||||
//resOpen();
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
ARENA_H_TILE* arena = NULL;
|
||||
|
||||
// Création de la fenêtre
|
||||
SDL_Window* pWindow = NULL;
|
||||
pWindow = SDL_CreateWindow("Arena Survival Tournament",SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,640,480,SDL_WINDOW_SHOWN);
|
||||
|
||||
addLogInfo("Starting game...");
|
||||
addLogInfo("Try init SDL libs...");
|
||||
initDisplayLib();
|
||||
initResources();
|
||||
|
||||
addLogInfo("Load ressources in memory...");
|
||||
SDL_Surface *tile_grass = NULL, *tile_rock = NULL, *tile_tree = NULL, *tile_water = NULL, *sprite_player_act = NULL, *sprite_ia_act = NULL;
|
||||
SDL_Surface *ressource[6] = {tile_grass, tile_rock, tile_tree, tile_water, sprite_player_act, sprite_ia_act};
|
||||
SDL_Surface *sprite_player[4] = {NULL}, *sprite_ia[4] = {NULL};
|
||||
tile_grass = IMG_Load("data/tile_grass.png");
|
||||
tile_rock = IMG_Load("data/tile_rock.png");
|
||||
tile_tree = IMG_Load("data/tile_tree.png");
|
||||
tile_water = IMG_Load("data/tile_water.png");
|
||||
|
||||
sprite_player[DOWN] = IMG_Load("data/sprite_player_1.png");
|
||||
//sprite_player[UP] = IMG_Load("data/sprite_player_2.png");
|
||||
//sprite_player[LEFT] = IMG_Load("data/sprite_player_3.png");
|
||||
//sprite_player[RIGHT] = IMG_Load("data/sprite_player_4.png");
|
||||
|
||||
sprite_ia[DOWN] = IMG_Load("data/sprite_ia_1.png");
|
||||
//sprite_ia[UP] = IMG_Load("data/sprite_ia_2.png");
|
||||
//sprite_ia[LEFT] = IMG_Load("data/sprite_ia_3.png");
|
||||
//sprite_ia[RIGHT] = IMG_Load("data/sprite_ia_4.png");
|
||||
|
||||
addLogInfo("Create SDL windows instance...");
|
||||
SDL_Window* gameWindows = SDL_CreateWindow("Arena Survival Tournament - alpha 0.2", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WINDOWS_WIDTH, WINDOWS_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
|
||||
|
||||
addLogInfo("Creating new arena...");
|
||||
ARENA_H_TILE* arena = NULL;
|
||||
arena = genNewArena(A_HEIGHT, A_WIDTH);
|
||||
if (arena == NULL) {
|
||||
addLogCritical("Error with arena generator !");
|
||||
@ -50,11 +57,20 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
addLogInfo("Successfully created arena.");
|
||||
|
||||
addLogInfo("Display arena GUI...");
|
||||
sprite_player_act = sprite_player[DOWN];
|
||||
sprite_ia_act = sprite_ia[DOWN];
|
||||
displayArena(arena, gameWindows, tile_grass, A_HEIGHT, A_WIDTH, TILE_SIZE);
|
||||
|
||||
|
||||
|
||||
|
||||
deleteArena(arena);
|
||||
addLogInfo("Cleared arena.");
|
||||
|
||||
|
||||
|
||||
SDL_Delay(5000);
|
||||
addLogInfo("Unload SDL libs...");
|
||||
SDL_Quit();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
14
main.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef MAIN_H_
|
||||
#define MAIN_H_
|
||||
|
||||
#define A_WIDTH 20
|
||||
#define A_HEIGHT 20
|
||||
|
||||
#define TILE_SIZE 32
|
||||
#define WINDOWS_WIDTH TILE_SIZE * A_WIDTH
|
||||
#define WINDOWS_HEIGHT TILE_SIZE * A_HEIGHT
|
||||
|
||||
enum {DOWN, UP, LEFT, RIGHT};
|
||||
enum {GRASS_T, ROCK_T, TREE_T, WATER_T, PLAYER_S, IA_S};
|
||||
|
||||
#endif
|