commit d8e43ff04fc87b19a2e962306167c2f3b94cbc37 Author: anselme16 Date: Mon Jan 12 16:01:58 2015 +0100 initial commit diff --git a/Courier.ttf b/Courier.ttf new file mode 100755 index 0000000..6819f34 Binary files /dev/null and b/Courier.ttf differ diff --git a/SDL.dll b/SDL.dll new file mode 100755 index 0000000..69fd61e Binary files /dev/null and b/SDL.dll differ diff --git a/SDL_ttf.dll b/SDL_ttf.dll new file mode 100755 index 0000000..a8f1bcc Binary files /dev/null and b/SDL_ttf.dll differ diff --git a/main.c b/main.c new file mode 100755 index 0000000..d55605c --- /dev/null +++ b/main.c @@ -0,0 +1,254 @@ +#include "main.h" +#include "team.h" +#include +#include +#include +#include +#include +#include + +t_pixel** map; +t_teams* teams; +SDL_Surface* img; + +void initWorld(){ + int i, j; + // allocations + for(i=0; i 10 && map[team.spawn.x][team.spawn.y].type == SPAWN){ + team.spawn_food--; + + new_dude.pos = team.spawn; + new_dude.team = team.team; + new_dude.inventory = -1; + new_dude.ground = SPAWN; + new_dude.custom_data = malloc(team.dude_size); + memset(new_dude.custom_data, 0, dude_size); + new_dude.com_data = NULL; + + team.dudes[team.nb_dudes++] = new_dude; + } + } +} + +void handleAction(t_action action, t_dude dude){ + t_pixel target = getTile(dude.pos, action.dir); + switch(action.type){ + case MOVE : + if( target.type != WALL + && target.type != ROCK + && target.type != BEDROCK + && target.type != IRON_ORE + && target.type != DUDE + && target.type != TREE + ){ + map[dude.pos.x][dude.pos.y] = dude.ground; + dude.ground = target; + target.type = DUDE; + target.data = &dude; + } + break; + case ATTACK : + if(target.type == DUDE) + addFight(dude, *((dude*)(target.data))); + break; + case PICK : + + // TODO + break; + case PUT : + break; + case WORK : + break; + case WAIT : + break; + case COMMUNICATE : + break; + } +} + +void generateImg(){ + Uint32 color; + for(i=0; ipixels[j * WIDTH + i] = color; + } + } +} + +int min(int a, int b) +{ + if (ab) return a; + else return b; +} + +Uint32 getpixel(SDL_Surface *surface, int x, int y) +{ + int bpp = surface->format->BytesPerPixel; + Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; + switch (bpp) { + case 1: + return *p; + + case 2: + return *(Uint16 *)p; + case 3: + if (SDL_BYTEORDER == SDL_BIG_ENDIAN) + return p[0] << 16 | p[1] << 8 | p[2]; + else + return p[0] | p[1] << 8 | p[2] << 16; + case 4: + return *(Uint32 *)p; + + default: + return 0; + } +} + +void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) +{ + int bpp = surface->format->BytesPerPixel; + /* Here p is the address to the pixel we want to set */ + Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; + + switch(bpp) { + case 1: + *p = pixel; + break; + + case 2: + *(Uint16 *)p = pixel; + break; + + case 3: + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { + p[0] = (pixel >> 16) & 0xff; + p[1] = (pixel >> 8) & 0xff; + p[2] = pixel & 0xff; + } else { + p[0] = pixel & 0xff; + p[1] = (pixel >> 8) & 0xff; + p[2] = (pixel >> 16) & 0xff; + } + break; + + case 4: + *(Uint32 *)p = pixel; + break; + } +} + +void initSDL() +{ + srand(time(NULL)); + img = SDL_SetVideoMode(RESX, RESY, 32, SDL_HWSURFACE | SDL_DOUBLEBUF); + SDL_WM_SetCaption("Pixel Wars", NULL); + SDL_FillRect(img, NULL, SDL_MapRGB(img->format, 255, 255, 255)); + if(TTF_Init() == -1) + { + fprintf(stderr, "Erreur d'initialisation de TTF_Init : %s\n", TTF_GetError()); + exit(EXIT_FAILURE); + } + if (SDL_Init(SDL_INIT_VIDEO) == -1) + { + fprintf(stderr, "Erreur d'initialisation de la SDL"); + exit(EXIT_FAILURE); + } +} + +int MAIN( int argc, char** argv ) +{ + initSDL(); + initWorld(); + + while (!keystate[SDLK_ESCAPE] && !over){ + temps = SDL_GetTicks(); + SDL_PumpEvents(); + int i; + spawnDudes(); + for(i=0; iHEIGHT;j++){ + if (i == 0 || j == 0){ + map[i][j]=BEDROCK; + else{ + map[i][j] = generate(i,j); + } + } + } + + int spawns[NB_TEAMS]; + memset(spawns, 0, NB_TEAMS); + + for(int k=0;k 0 ? val : -val; +} diff --git a/team.h b/team.h new file mode 100644 index 0000000..123ce2d --- /dev/null +++ b/team.h @@ -0,0 +1,37 @@ +#ifndef TEAM_H +#define TEAM_H + +// Directions +enum{ + NORTH, SOUTH, EAST, WEST +}; + +// Tile types +enum{ + BEDROCK, GRASS, ROCK, IRON_ORE, TREE, BERRIES, // nature + FOOD, WOOD, STONE, IRON, // resources + CORPSE, DUDE, // humans + SPAWN, WALL, ROAD, SWORD, SIGN // buildings +}; + +// Action types +enum{ + MOVE, ATTACK, PICK, PUT, WORK, WAIT, COMMUNICATE +}; + +typedef struct{ + int x; + int y; +} t_coord; + +typedef struct{ + int type; + int dir; + void* data; +} t_action; + +int getInventory(); + +int getNear(int dir); + +#endif \ No newline at end of file