From ff431a385d3ca8383765ae6db9ab9c407d744268 Mon Sep 17 00:00:00 2001 From: Petr Sykora Date: Sat, 1 Sep 2007 14:25:23 +0200 Subject: [PATCH] Refactoring --- CMakeLists.txt | 2 +- ebulanci.c | 84 ++++++++++++++++++++-------------------------------------- map.c | 14 ++++++++++ map.h | 21 +++++++++++++++ 4 files changed, 65 insertions(+), 56 deletions(-) create mode 100644 map.c create mode 100644 map.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 23aeb32..eead5e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ MESSAGE("CAIRO:${CAIRO_INCLUDE_DIR}") LINK_DIRECTORIES(${SDL_LIBRARY_DIR} ${CAIRO_LIBRARY_DIR}) INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIR} ${CAIRO_INCLUDE_DIR}) -ADD_EXECUTABLE(ebulanci ebulanci.c geometry.c gr.c config.c) +ADD_EXECUTABLE(ebulanci ebulanci.c geometry.c gr.c config.c map.c) ADD_EXECUTABLE(kolize kolize.c geometry.c ) SET_TARGET_PROPERTIES(kolize PROPERTIES LINK_FLAGS "-lm") SET_TARGET_PROPERTIES(ebulanci PROPERTIES LINK_FLAGS "${SDL_LINK_FLAGS} ${CAIRO_LINK_FLAGS} -lsvg -lsvg-cairo -lm -lGL -lGLU") diff --git a/ebulanci.c b/ebulanci.c index c0f08bd..c6fc70e 100644 --- a/ebulanci.c +++ b/ebulanci.c @@ -4,6 +4,7 @@ #include "util.h" #include "config.h" #include "gr.h" +#include "map.h" //typedef int Uint8; // We use seconds for measuring time, meters for measuring distance @@ -64,21 +65,6 @@ typedef struct{ double VFuzzy; // Fuzzy factor for traveling 0-1 :) }TBullet; -typedef struct{ - Area **FArea; //forbidden Area - int noFArea; //no used FArea -}TMapLayer; - -typedef struct{ - TMapLayer **Layer; - int noLayer; - Area *BoundingArea; // ALL OBJECTS MUST BE IN THIS POLY - double XX,YY; //margins for random placement - double X,Y; //left top corner MUST be != [0,0] - int noSprites; - Sprite **Sprites; - Vect *SpritePos; -}TMap; typedef struct{ TMap *Map; //where we are playing @@ -115,18 +101,6 @@ int InitBase(){ return 0; } -int AreaInMap(TMap *m, Area *p, int FromLayer, int ToLayer){ //returns 0 if p collides with something in m otherwise 1 - int i,j; - if(!AreaInAreaComp(m->BoundingArea, p)){ - return 0; - } - for(i = FromLayer; i < m->noLayer && i <= ToLayer; i++){ - for(j=0; j < m->Layer[i]->noFArea; j++) - if(AreaInArea(p, m->Layer[i]->FArea[j])) - return 0; - } - return 1; -} void SpawnLilanek(Game *g, int lid){ Vect Pos; int tries; @@ -584,32 +558,6 @@ Game *testgame(){ //return testing game, function for use before we have some me g->Weapon[i].Shape = 0; } - g->noWID=2; - g->WeaponTemplate = malloc(sizeof(TWeapon)*g->noWID); - p = NewRect(0,0,0.5,0.5); - a = NewArea(); - AddToArea(a, p); - FreePoly(p); - g->WeaponTemplate[0].Shape = a; - g->WeaponTemplate[0].WID = 0; - g->WeaponTemplate[0].Exists = 1; - g->WeaponTemplate[0].Ammo = 50; - g->WeaponTemplate[0].MaxAmmo = 150; - g->WeaponTemplate[0].ReloadTime = 0.2; - g->WeaponTemplate[0].Burst = 24; - - p = NewRect(0,0,0.5,0.5); - a = NewArea(); - AddToArea(a, p); - FreePoly(p); - g->WeaponTemplate[1].Shape = a; - g->WeaponTemplate[1].WID = 1; - g->WeaponTemplate[1].Exists = 1; - g->WeaponTemplate[1].Ammo = 3; - g->WeaponTemplate[1].MaxAmmo = 6; - g->WeaponTemplate[1].ReloadTime = 0.5; - g->WeaponTemplate[1].Burst = 1; - g->noLilaneks = 2; g->Lilanek = malloc(sizeof(TLilanek) * g->noLilaneks); memset(g->Lilanek, 0, sizeof(TLilanek) * g->noLilaneks); @@ -672,6 +620,20 @@ Game *testgame(){ //return testing game, function for use before we have some me g->Lilanek[1].ActiveWeapon = 0; SpawnLilanek(g, 1); + g->noWID=2; + g->WeaponTemplate = malloc(sizeof(TWeapon)*g->noWID); + p = NewRect(0,0,0.5,0.5); + a = NewArea(); + AddToArea(a, p); + FreePoly(p); + g->WeaponTemplate[0].Shape = a; + g->WeaponTemplate[0].WID = 0; + g->WeaponTemplate[0].Exists = 1; + g->WeaponTemplate[0].Ammo = 50; + g->WeaponTemplate[0].MaxAmmo = 250; + g->WeaponTemplate[0].ReloadTime = 2.1; + g->WeaponTemplate[0].Burst = 10; + g->BulletTemplate = malloc(sizeof(TBullet) * g->noWID); p = NewRect(0,0,0.1,0.1); a = NewArea(); @@ -680,8 +642,20 @@ Game *testgame(){ //return testing game, function for use before we have some me g->BulletTemplate[0].Shape = a; g->BulletTemplate[0].WID = 0; g->BulletTemplate[0].Speed = 20; - g->BulletTemplate[0].SFuzzy = 0.20; - g->BulletTemplate[0].VFuzzy = 0.15; + g->BulletTemplate[0].SFuzzy = 0.040; + g->BulletTemplate[0].VFuzzy = 0.000; + + p = NewRect(0,0,0.5,0.5); + a = NewArea(); + AddToArea(a, p); + FreePoly(p); + g->WeaponTemplate[1].Shape = a; + g->WeaponTemplate[1].WID = 1; + g->WeaponTemplate[1].Exists = 1; + g->WeaponTemplate[1].Ammo = 3; + g->WeaponTemplate[1].MaxAmmo = 6; + g->WeaponTemplate[1].ReloadTime = 0.5; + g->WeaponTemplate[1].Burst = 1; p = NewRect(0,0,0.5,0.5); a = NewArea(); diff --git a/map.c b/map.c new file mode 100644 index 0000000..1f80254 --- /dev/null +++ b/map.c @@ -0,0 +1,14 @@ +#include "map.h" + +int AreaInMap(TMap *m, Area *p, int FromLayer, int ToLayer){ //returns 0 if p collides with something in m otherwise 1 + int i,j; + if(!AreaInAreaComp(m->BoundingArea, p)){ + return 0; + } + for(i = FromLayer; i < m->noLayer && i <= ToLayer; i++){ + for(j=0; j < m->Layer[i]->noFArea; j++) + if(AreaInArea(p, m->Layer[i]->FArea[j])) + return 0; + } + return 1; +} diff --git a/map.h b/map.h new file mode 100644 index 0000000..f31f3dd --- /dev/null +++ b/map.h @@ -0,0 +1,21 @@ +#pragma once +#include "geometry.h" +#include "gr.h" + +typedef struct{ + Area **FArea; //forbidden Area + int noFArea; //no used FArea +}TMapLayer; + +typedef struct{ + TMapLayer **Layer; + int noLayer; + Area *BoundingArea; // ALL OBJECTS MUST BE IN THIS POLY + double XX,YY; //margins for random placement + double X,Y; //left top corner MUST be != [0,0] + int noSprites; + Sprite **Sprites; + Vect *SpritePos; +}TMap; + +int AreaInMap(TMap *m, Area *p, int FromLayer, int ToLayer); //returns 0 if p collides with something in m otherwise 1 -- 2.11.4.GIT