made some changes in the input
This commit is contained in:
parent
c6174a62db
commit
fc3a09036b
94
main.c
94
main.c
@ -6,6 +6,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct{
|
||||
t_dude dude1;
|
||||
@ -19,7 +20,7 @@ t_action orange_update(void* my_info, void* com_data, int my_id);
|
||||
int get_purple_size();
|
||||
int get_orange_size();
|
||||
|
||||
void initWorld(){
|
||||
void initWorld(int width, int height){
|
||||
int i;
|
||||
|
||||
// allocations
|
||||
@ -44,17 +45,17 @@ void initWorld(){
|
||||
teams[i].spawn_food = 10;
|
||||
teams[i].spawn_count = 0;
|
||||
}
|
||||
map = (t_pixel**)malloc(sizeof(t_pixel*)*WIDTH);
|
||||
for(i=0; i<WIDTH; i++)
|
||||
map[i] = (t_pixel*)malloc(sizeof(t_pixel)*HEIGHT);
|
||||
map = (t_pixel**)malloc(sizeof(t_pixel*)*width);
|
||||
for(i=0; i<width; i++)
|
||||
map[i] = (t_pixel*)malloc(sizeof(t_pixel)*height);
|
||||
|
||||
// generate map
|
||||
printf("Generating map...\n");
|
||||
create_map(WIDTH, HEIGHT);
|
||||
create_map(width, height);
|
||||
|
||||
// create image from map
|
||||
printf("Creating image from map...\n");
|
||||
generateImg();
|
||||
generateImg(width, height);
|
||||
}
|
||||
|
||||
void addFight(t_dude dude, t_dude other_dude){
|
||||
@ -171,19 +172,22 @@ void handleAction(t_action action, t_dude* dude){
|
||||
}
|
||||
}
|
||||
|
||||
void generateImg(){
|
||||
void generateImg(int width, int height){
|
||||
int i, j;
|
||||
for(i=0; i<WIDTH; i++){
|
||||
for(j=0; j<HEIGHT; j++){
|
||||
for(i=0; i<width; i++){
|
||||
for(j=0; j<height; j++){
|
||||
putpixel(img, i, j, getColor(map[i][j]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void initSDL()
|
||||
void initSDL(int width, int height, int fullscreen)
|
||||
{
|
||||
srand(time(NULL));
|
||||
img = SDL_SetVideoMode(WIDTH, HEIGHT, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
|
||||
if(fullscreen)
|
||||
img = SDL_SetVideoMode(width, height, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN);
|
||||
else
|
||||
img = SDL_SetVideoMode(width, height, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
|
||||
SDL_WM_SetCaption("Pixel Wars", NULL);
|
||||
SDL_FillRect(img, NULL, SDL_MapRGB(img->format, 255, 255, 255));
|
||||
if (SDL_Init(SDL_INIT_VIDEO) == -1)
|
||||
@ -193,28 +197,72 @@ void initSDL()
|
||||
}
|
||||
}
|
||||
|
||||
int MAIN( int argc, char** argv )
|
||||
int MAIN
|
||||
{
|
||||
Uint8 *keystate = SDL_GetKeyState(NULL);
|
||||
SDL_Event event;
|
||||
int i;
|
||||
int over = 0;
|
||||
Uint32 temps;
|
||||
int wait_time = 100;
|
||||
int fullscreen = 0;
|
||||
int width = DEFAULT_WIDTH;
|
||||
int height = DEFAULT_HEIGHT;
|
||||
|
||||
printf("Starting Pixel Wars on %s\n", OS);
|
||||
initSDL();
|
||||
initWorld();
|
||||
#ifndef _WIN32
|
||||
argv++;
|
||||
while(argc > 1){ // pas initialisé sur windows
|
||||
printf("%s\n", argv[0]);
|
||||
switch(argv[0][0]){
|
||||
case 'f' :
|
||||
fullscreen = 1;
|
||||
break;
|
||||
case 't' :
|
||||
wait_time = atoi(argv[0]+2);
|
||||
break;
|
||||
case 'w' :
|
||||
width = atoi(argv[0]+2);
|
||||
break;
|
||||
case 'h' :
|
||||
height = atoi(argv[0]+2);
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
argv++;
|
||||
}
|
||||
#endif
|
||||
|
||||
initSDL(width, height, fullscreen);
|
||||
initWorld(width, height);
|
||||
SDL_Flip(img);
|
||||
|
||||
printf("Launching simulation... press ESCAPE to stop.\n");
|
||||
printf("Launching simulation...\n");
|
||||
|
||||
while (!keystate[SDLK_ESCAPE] && !over){
|
||||
temps = SDL_GetTicks();
|
||||
SDL_PumpEvents();
|
||||
int i;
|
||||
while (!over){
|
||||
while(SDL_PollEvent(&event)){
|
||||
switch (event.type){
|
||||
case SDL_KEYDOWN:
|
||||
switch(event.key.keysym.sym) {
|
||||
case SDLK_ESCAPE :
|
||||
over = 1;
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
over = 1;
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
spawnDudes();
|
||||
for(i=0; i<NB_TEAMS; i++)
|
||||
updateTeam(teams[i]);
|
||||
resolve_moves();
|
||||
if(SDL_GetTicks()-temps < MAX_FPS) SDL_Delay(MAX_FPS+temps-SDL_GetTicks());
|
||||
|
||||
SDL_Delay(wait_time);
|
||||
SDL_Flip(img);
|
||||
}
|
||||
SDL_FreeSurface(img);
|
||||
|
12
main.h
12
main.h
@ -5,17 +5,15 @@
|
||||
#include <SDL/SDL.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define MAIN WinMain
|
||||
#define OS "Windows"
|
||||
#include <windows.h>
|
||||
#define MAIN APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
|
||||
#else
|
||||
#define MAIN main
|
||||
#define OS "Linux"
|
||||
#define MAIN main(int argc, char** argv)
|
||||
#endif
|
||||
|
||||
#define MAX_FPS 4
|
||||
#define MAX_DUDES 50
|
||||
#define WIDTH 400
|
||||
#define HEIGHT 250
|
||||
#define DEFAULT_WIDTH 400
|
||||
#define DEFAULT_HEIGHT 250
|
||||
|
||||
// Teams
|
||||
enum{
|
||||
|
Loading…
x
Reference in New Issue
Block a user