diff --git a/CollisionDefines.h b/CollisionDefines.h new file mode 100644 index 0000000..73155da --- /dev/null +++ b/CollisionDefines.h @@ -0,0 +1,16 @@ +#pragma once + +#define GRAVITATION 0.3 +#define DRAGGING 0.999999 +#define BOUNCE 0.5 +#define FRICTION 0.1 + +#define WORLD_LEFT 0 +#define WORLD_TOP 0 +#define WORLD_RIGHT 800 +#define WORLD_BOTTOM 600 + + +#define COLLISION_NONE 0 +#define COLLISION_AXIS 1 +#define COLLISION_OTHER 2 \ No newline at end of file diff --git a/Edges.h b/Edges.h new file mode 100644 index 0000000..f2f68e9 --- /dev/null +++ b/Edges.h @@ -0,0 +1,8 @@ +#pragma once + + + +#define EDGE_ID_OFF 0 +#define EDGE_ID_INTERESTING 1 +#define EDGE_ID_SOLID 2 + diff --git a/EditMap.sln b/EditMap.sln new file mode 100644 index 0000000..bd3d593 --- /dev/null +++ b/EditMap.sln @@ -0,0 +1,20 @@ +п»ї +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "EditMap", "EditMap.vcproj", "{E9423B38-C119-40D9-93B1-858DB43B8CA5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E9423B38-C119-40D9-93B1-858DB43B8CA5}.Debug|Win32.ActiveCfg = Debug|Win32 + {E9423B38-C119-40D9-93B1-858DB43B8CA5}.Debug|Win32.Build.0 = Debug|Win32 + {E9423B38-C119-40D9-93B1-858DB43B8CA5}.Release|Win32.ActiveCfg = Release|Win32 + {E9423B38-C119-40D9-93B1-858DB43B8CA5}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/EditMap.suo b/EditMap.suo new file mode 100644 index 0000000..5548559 Binary files /dev/null and b/EditMap.suo differ diff --git a/GraphicDynamicObject.cpp b/GraphicDynamicObject.cpp new file mode 100644 index 0000000..db36074 --- /dev/null +++ b/GraphicDynamicObject.cpp @@ -0,0 +1,122 @@ +#include "GraphicDynamicObject.h" + +GraphicDynamicObject::GraphicDynamicObject() +: GraphicObject() +{ + TYPE_ID = GRAPHIC_DYNAMIC_OBJECT_ID; + + this->old_pos = pos; + speed = max_speed = 0; + + tile = NULL; +} + +GraphicDynamicObject::GraphicDynamicObject(const char *texture_name, hgeVector pos, short xw, short yw, short layer) +: GraphicObject(texture_name, pos, xw, yw, layer) +{ + TYPE_ID = GRAPHIC_DYNAMIC_OBJECT_ID; + + this->old_pos = pos; + speed = max_speed = 0; + + tile = NULL; + +} + +GraphicDynamicObject::~GraphicDynamicObject() +{ +} + +void GraphicDynamicObject::Verlet() +{ + float d = DRAGGING; + float g = GRAVITATION; + + float px, py; + + float ox = old_pos.x; //we can't swap buffers since mcs/sticks point directly to vector2s.. + float oy = old_pos.y; + + old_pos.x = px = pos.x; //get vector values + old_pos.y = py = pos.y; //pos = position + //old_pos = old position + + //integrate + pos.x += (d*px) - (d*ox); + pos.y += (d*py) - (d*oy) + g; +} + +//(px,py) is projection vector, (dx,dy) is surface normal +void GraphicDynamicObject::ReportCollision(float px, float py, float dx, float dy, TileMap *tile) +{ + //calc velocity + float vx = pos.x - old_pos.x; + float vy = pos.y - old_pos.y; + + //find component of velocity parallel to collision normal + float dp = (vx*dx + vy*dy); + float nx = dp*dx;//project velocity onto collision normal + + float ny = dp*dy;//nx,ny is normal velocity + + float tx = vx-nx;//px,py is tangent velocity + float ty = vy-ny; + + //we only want to apply collision response forces if the object is travelling into, and not out of, the collision + float b,bx,by,f,fx,fy; + if(dp < 0) + { + f = FRICTION; + fx = tx * f; + fy = ty * f; + + b = 1 + BOUNCE;//this bounce constant should be else where, i.e inside the object/tile/etc.. + + bx = (nx * b); + by = (ny * b); + } + else + { + //moving out of collision, do not apply forces + bx = by = fx = fy = 0; + } + + pos.x += px;//project object out of collision + pos.y += py; + + old_pos.x += px + bx + fx;//apply bounce+friction impulses which alter velocity + old_pos.y += py + by + fy; +} + +void GraphicDynamicObject::Move(int move) +{ + float fx = 0; + float fy = 0; + + switch (move) + { + case MOVE_LEFT: + fx -= speed; + break; + + case MOVE_RIGHT: + fx += speed; + break; + + case MOVE_UP: + fy -= speed + GRAVITATION; + break; + + case MOVE_DOWN: + fy += speed; + break; + } + + float vx = pos.x - old_pos.x; + float newx = min(max_speed, max(-max_speed, vx+fx)); + pos.x = old_pos.x + newx; + + float vy = pos.y - old_pos.y; + float newy = min(max_speed, max(-max_speed, vy+fy)); + pos.y = old_pos.y + newy; +} \ No newline at end of file diff --git a/GraphicDynamicObject.h b/GraphicDynamicObject.h new file mode 100644 index 0000000..7f61215 --- /dev/null +++ b/GraphicDynamicObject.h @@ -0,0 +1,40 @@ +#pragma once + +#include "GraphicObject.h" +#include "CollisionDefines.h" + +#define MOVE_LEFT 1 +#define MOVE_RIGHT 2 +#define MOVE_UP 3 +#define MOVE_DOWN 4 + +class TileMap; +class World; + +class GraphicDynamicObject: public GraphicObject +{ + friend World; +public: + GraphicDynamicObject(); + GraphicDynamicObject(const char *texture_name, hgeVector pos, short xw, short yw, short layer); + virtual ~GraphicDynamicObject(); + + virtual void Verlet(); + virtual void ReportCollision(float px, float py, float dx, float dy, TileMap *tile); + + virtual void Move(int move); + + virtual void Render() = 0; + + void SetSpeed(float speed) { this->speed = this->max_speed = speed; } + void SetSpeed(float speed, float max_speed) { this->speed = speed; this->max_speed = max_speed; } + + virtual int Update() = 0; + +protected: + hgeVector old_pos; + float speed, max_speed; + + TileMap *tile; + //TileMap *prev_tile; +}; diff --git a/GraphicObject.cpp b/GraphicObject.cpp new file mode 100644 index 0000000..91665bb --- /dev/null +++ b/GraphicObject.cpp @@ -0,0 +1,46 @@ +#include "GraphicObject.h" + + + +HGE *GraphicObject::hge = NULL; +hgeResourceManager *GraphicObject::resources_manager = NULL; + +GraphicObject::GraphicObject() + +: xw(0) +, yw(0) +{ + TYPE_ID = GRAPHIC_OBJECT_ID; + hge = hgeCreate(HGE_VERSION); + + layer = 0; + + pos.x = 0; + pos.y = 0; +} + +GraphicObject::GraphicObject(const char *texture_name, hgeVector pos, short xw, short yw, short layer) +{ + if (texture_name) + { + resource_name = texture_name; + } + + TYPE_ID = GRAPHIC_OBJECT_ID; + hge = hgeCreate(HGE_VERSION); + + this->layer = layer; + + this->pos = pos; + this->xw = abs(xw); + this->yw = abs(yw); +} + +GraphicObject::~GraphicObject() +{ + hge->Release(); + + // world->RemoveObject(this); + + resource_name.clear(); +} diff --git a/GraphicObject.h b/GraphicObject.h new file mode 100644 index 0000000..5673ae6 --- /dev/null +++ b/GraphicObject.h @@ -0,0 +1,52 @@ +#pragma once + +#include "Object.h" + +#include +#include +#include +#include + +class GraphicObject: public Object +{ +public: + GraphicObject(); + GraphicObject(const char *resource_name, hgeVector pos, short xw, short yw, short layer); + + virtual ~GraphicObject(); + + void SetResName(char *name) { resource_name = name; } + const char *GetResName() { return resource_name.c_str(); } + + void SetPos(hgeVector pos) { this->pos = pos; } + void SetPos(float x, float y) { this->pos.x = x; this->pos.y = y; } + hgeVector GetPos() { return pos; } + + void SetWidth(short width) { this->xw = width; } + short GetWidth() const { return xw; } + + void SetHeight(short height) { this->yw = height; } + short GetHeight() const { return yw; } + + void SetLayer(short layer) { this->layer = layer; } + short GetLayer() { return layer; } + + + virtual void UpdateGraphic() { /*empty*/ } + + virtual void Render() = 0; + + static void SetResourceManager(hgeResourceManager *rm) { resources_manager = rm; } + +protected: + hgeVector pos; + short xw, yw; + short layer; //уровень рисования и столкновения + + std::string resource_name; + + static HGE *hge; + + static hgeResourceManager *resources_manager; + +}; diff --git a/InitCombo.h b/InitCombo.h new file mode 100644 index 0000000..91b2cb0 --- /dev/null +++ b/InitCombo.h @@ -0,0 +1,212 @@ +#include +#include "Map.h" + +extern HWND hCB_ObjType; +extern HWND hCB_SprName; +extern HWND hCB_AnimName; +extern HWND hCB_TileType; +extern HWND hCB_PS1; +extern HWND hCB_PS2; +extern HWND hCB_ResType; + +void InitComboBoxTiles() +{ + LRESULT index = SendMessage(hCB_ObjType, CB_ADDSTRING, 0, (LPARAM)"undefined"); + SendMessage(hCB_ObjType, CB_SETITEMDATA, index, (LPARAM)-1); + SendMessage(hCB_ObjType, CB_SETCURSEL, 0, 0); + + index = SendMessage(hCB_ObjType, CB_ADDSTRING, 0, (LPARAM)"TileMap"); + SendMessage(hCB_ObjType, CB_SETITEMDATA, index, (LPARAM)TILE_MAP_ID); + + + index = SendMessage(hCB_ObjType, CB_ADDSTRING, 0, (LPARAM)"TileMapEx"); + SendMessage(hCB_ObjType, CB_SETITEMDATA, index, (LPARAM)TILE_MAP_EXTENDED_ID); + + index = SendMessage(hCB_ObjType, CB_ADDSTRING, 0, (LPARAM)"TileMapAnimation"); + SendMessage(hCB_ObjType, CB_SETITEMDATA, index, (LPARAM)TILE_MAP_ANIMATION_ID); + + index = SendMessage(hCB_ObjType, CB_ADDSTRING, 0, (LPARAM)"TileMapAnimationEx"); + SendMessage(hCB_ObjType, CB_SETITEMDATA, index, (LPARAM)TILE_MAP_ANIMATION_EX_ID); + + index = SendMessage(hCB_ObjType, CB_ADDSTRING, 0, (LPARAM)"TileMapParticle"); + SendMessage(hCB_ObjType, CB_SETITEMDATA, index, (LPARAM)TILE_MAP_PARTICLE_ID); + + index = SendMessage(hCB_ObjType, CB_ADDSTRING, 0, (LPARAM)"TileMapResource"); + SendMessage(hCB_ObjType, CB_SETITEMDATA, index, (LPARAM)TILE_MAP_RESOURCE_ID); + +} + +void InitComboBox1() +{ + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"undefined"); + SendMessage(hCB_SprName, CB_SETCURSEL, 0, 0); + + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"empty"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"g_1_1"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"g_1_2"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"g_1_3_1"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"g_1_3_2"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"g_1_4_1"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"g_1_4_2"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"g_1_5"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"g_1_6"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"g_1_7"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"g_1_8"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"g_1_9"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"g_1_10"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"g_1_11"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"g_1_12"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"g_1_13"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"g_1_14_1"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"g_1_14_2"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"g_1_15"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"g_1_16"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"g_1_17"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"g_1_18"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"g_1_19"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"tree1_1"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"tree1_2"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"tree1_3"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"tree1_4"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"tree1_5"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"tree1_6"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"tree1_7"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"tree1_8"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"tree1_9"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"fence1_1"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"fence1_2"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"fence1_3"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"fence1_4"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"fence1_5"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"fence1_6"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"fence1_7"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"fence1_8"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"stone1_1"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"stone1_2"); + + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"stone2_1"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"stone2_2"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"stone2_3"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"stone2_4"); + + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"grass1"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"grass2"); + + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"stone3"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"stone4"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"stone5"); + + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"stub1_1"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"stub1_2"); + + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"grass3_1"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"grass3_2"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"grass3_3"); + + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"bush1_1"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"bush1_2"); + + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"bush2_1"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"bush2_2"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"bush2_3"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"bush2_4"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"bush2_5"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"bush2_6"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"bush2_7"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"bush2_8"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"bush2_9"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"bush2_10"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"bush2_11"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"bush2_12"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"bush2_13"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"bush2_14"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"bush2_15"); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)"bush2_16"); + + for (int i = 1; i <= 18; i++) + { + char str[256] = {0}; + sprintf(str, "tree2_%d", i); + SendMessage(hCB_SprName, CB_ADDSTRING, 0, (LPARAM)str); + } +} + +void InitComboBox2() +{ + SendMessage(hCB_AnimName, CB_ADDSTRING, 0, (LPARAM)"undefined"); + SendMessage(hCB_AnimName, CB_SETCURSEL, 0, (LPARAM)-1); + SendMessage(hCB_AnimName, CB_SETCURSEL, 0, 0); + + SendMessage(hCB_AnimName, CB_ADDSTRING, 0, (LPARAM)"hard"); +} + +void InitComboBox3() +{ + LRESULT index = 0; + + SendMessage(hCB_TileType, CB_ADDSTRING, 0, (LPARAM)"undefined"); + SendMessage(hCB_TileType, CB_SETITEMDATA, index, (LPARAM)-1); + SendMessage(hCB_TileType, CB_SETCURSEL, 0, 0); + + index = SendMessage(hCB_TileType, CB_ADDSTRING, 0, (LPARAM)"TILE_TYPE_EMPTY"); + SendMessage(hCB_TileType, CB_SETITEMDATA, index, (LPARAM)TILE_TYPE_EMPTY); + + index = SendMessage(hCB_TileType, CB_ADDSTRING, 0, (LPARAM)"TILE_TYPE_FULL"); + SendMessage(hCB_TileType, CB_SETITEMDATA, index, (LPARAM)TILE_TYPE_FULL); + + index = SendMessage(hCB_TileType, CB_ADDSTRING, 0, (LPARAM)"TILE_TYPE_45DEGREE_pn"); + SendMessage(hCB_TileType, CB_SETITEMDATA, index, (LPARAM)TILE_TYPE_45DEGREE_pn); + + index = SendMessage(hCB_TileType, CB_ADDSTRING, 0, (LPARAM)"TILE_TYPE_45DEGREE_nn"); + SendMessage(hCB_TileType, CB_SETITEMDATA, index, (LPARAM)TILE_TYPE_45DEGREE_nn); + + index = SendMessage(hCB_TileType, CB_ADDSTRING, 0, (LPARAM)"TILE_TYPE_45DEGREE_np"); + SendMessage(hCB_TileType, CB_SETITEMDATA, index, (LPARAM)TILE_TYPE_45DEGREE_np); + + index = SendMessage(hCB_TileType, CB_ADDSTRING, 0, (LPARAM)"TILE_TYPE_45DEGREE_pp"); + SendMessage(hCB_TileType, CB_SETITEMDATA, index, (LPARAM)TILE_TYPE_45DEGREE_pp); + + index = SendMessage(hCB_TileType, CB_ADDSTRING, 0, (LPARAM)"TILE_TYPE_22DEGREE_pn"); + SendMessage(hCB_TileType, CB_SETITEMDATA, index, (LPARAM)TILE_TYPE_22DEGREE_pn); + + index = SendMessage(hCB_TileType, CB_ADDSTRING, 0, (LPARAM)"TILE_TYPE_22DEGREE_nn"); + SendMessage(hCB_TileType, CB_SETITEMDATA, index, (LPARAM)TILE_TYPE_22DEGREE_nn); + + index = SendMessage(hCB_TileType, CB_ADDSTRING, 0, (LPARAM)"TILE_TYPE_22DEGREE_np"); + SendMessage(hCB_TileType, CB_SETITEMDATA, index, (LPARAM)TILE_TYPE_22DEGREE_np); + + index = SendMessage(hCB_TileType, CB_ADDSTRING, 0, (LPARAM)"TILE_TYPE_22DEGREE_pp"); + SendMessage(hCB_TileType, CB_SETITEMDATA, index, (LPARAM)TILE_TYPE_22DEGREE_pp); +} + +void InitComboBoxPS1() +{ + LRESULT index = 0; + + SendMessage(hCB_PS1, CB_ADDSTRING, 0, (LPARAM)"undefined"); + SendMessage(hCB_PS1, CB_SETCURSEL, 0, 0); +} + +void InitComboBoxPS2() +{ + LRESULT index = 0; + + SendMessage(hCB_PS2, CB_ADDSTRING, 0, (LPARAM)"undefined"); + SendMessage(hCB_PS2, CB_SETCURSEL, 0, 0); +} + +void InitComboBoxTileRes() +{ + LRESULT index = 0; + + index = SendMessage(hCB_ResType, CB_ADDSTRING, 0, (LPARAM)"RESOURCE_TYPES::LIFES"); + SendMessage(hCB_ResType, CB_SETITEMDATA, index, (LPARAM)RESOURCE_TYPES::LIFES); + + index = SendMessage(hCB_ResType, CB_ADDSTRING, 0, (LPARAM)"RESOURCE_TYPES::AID"); + SendMessage(hCB_ResType, CB_SETITEMDATA, index, (LPARAM)RESOURCE_TYPES::AID); + + index = SendMessage(hCB_ResType, CB_ADDSTRING, 0, (LPARAM)"RESOURCE_TYPES::ARMOUR"); + SendMessage(hCB_ResType, CB_SETITEMDATA, index, (LPARAM)RESOURCE_TYPES::ARMOUR); + + SendMessage(hCB_ResType, CB_SETCURSEL, 0, 0); +} \ No newline at end of file diff --git a/Initiate.cpp b/Initiate.cpp new file mode 100644 index 0000000..e3c738d --- /dev/null +++ b/Initiate.cpp @@ -0,0 +1,14 @@ +#include "Initiate.h" + +#include + +#include "GraphicObject.h" +#include "GraphicDynamicObject.h" + + +hgeResourceManager* CreateResourceManager() +{ + hgeResourceManager *rm = new hgeResourceManager; + GraphicObject::SetResourceManager(rm); + return rm; +} diff --git a/Initiate.h b/Initiate.h new file mode 100644 index 0000000..b9d5bd6 --- /dev/null +++ b/Initiate.h @@ -0,0 +1,7 @@ +#pragma once + +class hgeResourceManager; +class World; + +hgeResourceManager* CreateResourceManager(); +World* InitiateWorld(); \ No newline at end of file diff --git a/Map.cpp b/Map.cpp new file mode 100644 index 0000000..0b46a34 --- /dev/null +++ b/Map.cpp @@ -0,0 +1,912 @@ +#include + +#include "Map.h" + +Map::Map(size_t layers, size_t rows, size_t cols, int screen_width, int screen_hight, short tile_width, short tile_hight) +{ + TYPE_ID = MAP_ID; + + this->layers = layers; + + this->rows = rows; + this->cols = cols; + + this->screen_width = screen_width; + this->screen_hight = screen_hight; + + this->tile_width = tile_width; + this->tile_hight = tile_hight; + + this->offset_x = 0; + this->offset_y = 0; + + grid.resize(layers); + + for (size_t l = 0; l < layers; l++) + { + grid[l].resize(rows); + for (size_t i = 0; i < rows; i++) + { + grid[l][i].resize(cols); + } + } + + tile = NULL; +} + +Map::~Map() +{ + Free(); +} + +void Map::Free() +{ + for (size_t l = 0; l < layers; l++) + { + for (size_t i = 0; i < rows; i++) + { + for (size_t j = 0; j < cols; j++) + { + if (grid[l][i][j] != NULL) + { +/* + if (TILE_MAP_ID == grid[l][i][j]->GetObjectType()) + delete ((TileMap *)grid[l][i][j]); + else if (TILE_MAP_EXTENDED_ID == grid[l][i][j]->GetObjectType()) + delete ((TileMapEx *)grid[l][i][j]); + else if (TILE_MAP_ANIMATION_ID == grid[l][i][j]->GetObjectType()) + delete ((TileMapAnimation *)grid[l][i][j]); + else if (TILE_MAP_PARTICLE_ID == grid[l][i][j]->GetObjectType()) + delete ((TileMapParticle *)grid[l][i][j]); +*/ + + delete grid[l][i][j]; + + grid[l][i][j] = NULL; + } + } + } + } + grid.clear(); +} + +void Map::InsertTile(int row, int col, TileMap *tile) +{ + size_t layer = tile->GetLayer(); + + grid[layer][row][col] = tile; +} + +void Map::DeleteTile(int layer, int row, int col) +{ + TileMap *t = grid[layer][row][col]; + + if (t == tile) + { + tile = NULL; + } + + if (t != NULL) + { + delete t; + t = NULL; + } + + grid[layer][row][col] = NULL; +} + +TileMap* Map::GetTile(int layer, const hgeVector *pos) +{ + return GetTile(layer, pos->x, pos->y); +} + +TileMap* Map::GetTile(int layer, float x, float y) +{ + int row = (int)floor((y + offset_y) / tile_hight); + int col = (int)floor((x + offset_x) / tile_width); + + return grid[layer][row][col]; +} + +TileMap* Map::GetTile(int layer, int row, int col) +{ + return grid[layer][row][col]; +} + +void Map::GetTileIndex(const hgeVector *pos, int &row, int &col) +{ + row = (int)floor((pos->y + offset_y) / tile_hight); + col = (int)floor((pos->x + offset_x) / tile_width); +} + +void Map::HorizontalScroll(int offset_x) +{ + if (0 < offset_x) + { + if (((this->offset_x + offset_x) + screen_width) < ((tile_width * cols))) + this->offset_x += offset_x; + else + this->offset_x = (cols * tile_width) - screen_width; + } + else if (0 > offset_x) + { + if ((this->offset_x + offset_x) > 0) + this->offset_x += offset_x; + else + this->offset_x = 0; + } +} + +void Map::VerticalScroll(int offset_y) +{ + if (0 < offset_y) + { + if (((this->offset_y + offset_y) + screen_hight) < ((tile_hight * rows))) + this->offset_y += offset_y; + else + this->offset_y = (rows * tile_hight) - screen_hight; + } + else if (0 > offset_y) + { + if ((this->offset_y + offset_y) > 0) + this->offset_y += offset_y; + else + this->offset_y = 0; + } +} + + +void Map::Render(int layer) +{ + hgeVector temp; + + size_t row = floor(offset_y / tile_hight); + size_t col = floor(offset_x / tile_width); + size_t n = (size_t)ceil((float)((screen_hight + offset_y) / tile_hight)); + size_t m = (size_t)ceil((float)((screen_width + offset_x) / tile_width)); + + float temp_x = (tile_width / 2) - ((int)offset_x % tile_width); + float temp_y = (tile_hight / 2) - ((int)offset_y % tile_hight); + float x = temp_x; + float y = temp_y; + + size_t l = layer; + + for (size_t i = row; i < n; i++) + { + for (size_t j = col; j < m; j++) + { + if (grid[l][i][j] != NULL) + { + temp = grid[l][i][j]->pos; + + grid[l][i][j]->pos.x = x; + grid[l][i][j]->pos.y = y; + + int object_type = grid[l][i][j]->GetObjectType(); + + switch( object_type ) + { + case TILE_MAP_ID: + ((TileMap *)grid[l][i][j])->Render(); + break; + + case TILE_MAP_EXTENDED_ID: + ((TileMapEx *)grid[l][i][j])->Render(); + break; + + case TILE_MAP_ANIMATION_ID: + ((TileMapAnimation *)grid[l][i][j])->Render(); + break; + + case TILE_MAP_PARTICLE_ID: + ((TileMapParticle *)grid[l][i][j])->GetParticle()->MoveTo(x, y, true); + ((TileMapParticle *)grid[l][i][j])->Render(); + break; + + case TILE_MAP_ANIMATION_EX_ID: + ((TileMapAnimationEx *)grid[l][i][j])->MoveParticle(x, y, true); + ((TileMapAnimationEx *)grid[l][i][j])->Render(); + break; + + case TILE_MAP_RESOURCE_ID: + ((TileMapResource *)grid[l][i][j])->MoveParticle(x, y, true); + ((TileMapResource *)grid[l][i][j])->Render(); + break; + } + + grid[l][i][j]->pos = temp; + } + + x += tile_width; + } + x = temp_x; + y += tile_hight; + } +} + +TileMap *Map::SelectTile(short layer, hgeVector &p) +{ + if (tile) + tile->ShowTileQuad(false); + + tile = this->GetTile(layer, &p); + + if (tile) + tile->ShowTileQuad(true); + + return tile; +} + +void Map::Save(const char *file_name) +{ + std::ofstream f(file_name, std::ios::binary); + if (f.is_open()) + { + int ce = 7;//кол-во сущностей + + f.write((const char *)&ce, sizeof(int)); + + std::string next_level = "level2.lev"; + int l = next_level.size(); + f.write((const char *)&l, sizeof(int)); + f.write(next_level.c_str(), l); + + f.write((const char *)&layers, sizeof(size_t)); + f.write((const char *)&rows, sizeof(size_t)); + f.write((const char *)&cols, sizeof(size_t)); + + for (size_t l = 0; l < layers; l++) + { + for (size_t i = 0; i < rows; i++) + { + for (size_t j = 0; j < cols; j++) + { + + if (grid[l][i][j] == NULL) + { + short null_tile = -1; + f.write((const char *)&null_tile, sizeof(short)); + } + else + { + short object_type = grid[l][i][j]->GetObjectType(); + + f.write((const char *)&object_type, sizeof(object_type)); + + switch (object_type) + { + + case TILE_MAP_ID: + ((TileMap *)grid[l][i][j])->Save(&f); + break; + + case TILE_MAP_EXTENDED_ID: + ((TileMapEx *)grid[l][i][j])->Save(&f); + break; + + case TILE_MAP_ANIMATION_ID: + ((TileMapAnimation *)grid[l][i][j])->Save(&f); + break; + + case TILE_MAP_PARTICLE_ID: + ((TileMapParticle *)grid[l][i][j])->Save(&f); + break; + + case TILE_MAP_ANIMATION_EX_ID: + ((TileMapAnimationEx *)grid[l][i][j])->Save(&f); + break; + + case TILE_MAP_RESOURCE_ID: + ((TileMapResource *)grid[l][i][j])->Save(&f); + break; + } + } + f.flush(); + } + } + } + f.close(); + } +} + +void Map::Load(const char *file_name) +{ + Free(); + + std::ifstream f(file_name, std::ios::binary); + + if (f.is_open()) + { + short object_type = 0; + + + int ce = 0;//кол-во сущностей + + f.read((char *)&ce, sizeof(int)); + + int l = 0; + char *buffer = NULL; + f.read((char *)&l, sizeof(int)); + buffer = new char[l]; + f.read((char *)buffer, l); + buffer[l] = '\0'; + //next_level = buffer; + //delete[] buffer; + + f.read((char *)&layers, sizeof(size_t)); + f.read((char *)&rows, sizeof(size_t)); + f.read((char *)&cols, sizeof(size_t)); + + + + grid.resize(layers); + + for (size_t l = 0; l < layers; l++) + { + grid[l].resize(rows); + for (size_t i = 0; i < rows; i++) + { + grid[l][i].resize(cols); + } + } + + for (size_t l = 0; l < layers; l++) + { + for (size_t i = 0; i < rows; i++) + { + for (size_t j = 0; j < cols; j++) + { + f.read((char *)&object_type, sizeof(short)); + + switch(object_type) + { + case -1: + grid[l][i][j] = NULL; + break; + + case TILE_MAP_ID: + grid[l][i][j] = new TileMap(); + grid[l][i][j]->Load(&f); + break; + + case TILE_MAP_EXTENDED_ID: + grid[l][i][j] = new TileMapEx(); + ((TileMapEx *)grid[l][i][j])->Load(&f); + break; + + case TILE_MAP_ANIMATION_ID: + grid[l][i][j] = new TileMapAnimation(); + ((TileMapAnimation *)grid[l][i][j])->Load(&f); + break; + + case TILE_MAP_PARTICLE_ID: + grid[l][i][j] = new TileMapParticle(); + ((TileMapParticle *)grid[l][i][j])->Load(&f); + break; + + case TILE_MAP_ANIMATION_EX_ID: + grid[l][i][j] = new TileMapAnimationEx(); + ((TileMapAnimationEx *)grid[l][i][j])->Load(&f); + break; + + case TILE_MAP_RESOURCE_ID: + grid[l][i][j] = new TileMapResource(); + ((TileMapResource *)grid[l][i][j])->Load(&f); + break; + + } + } + } + } + f.close(); + } + + +} + +void Map::UpdateGraphic() +{ + size_t row = floor(offset_y / tile_hight); + size_t col = floor(offset_x / tile_width); + size_t n = (size_t)ceil((float)((screen_hight + offset_y) / tile_hight)); + size_t m = (size_t)ceil((float)((screen_width + offset_x) / tile_width)); + + for (size_t l = 0; l < layers; l++) + { + for (size_t i = row; i < n; i++) + { + for (size_t j = col; j < m; j++) + { + if (grid[l][i][j] != NULL) + { + grid[l][i][j]->UpdateGraphic(); + } + } + } + } +} + + + +void Map::UpdateEdges(int layer) +{ + size_t l = layer; + + for (size_t i = 1; i < rows - 1; i++) + { + for (size_t j = 1; j < cols - 1; j++) + { + TileMapEx *tile; + TileMapEx *tile_next;//Соседний tile + + tile = (TileMapEx *)grid[l][i][j]; + tile_next = (TileMapEx *)grid[l][i - 1][j]; + + + if(tile->tile_type == TILE_TYPE_EMPTY) + { + if(tile_next->tile_type == TILE_TYPE_EMPTY) + { + tile->edge_up = EDGE_ID_OFF; + } + else if(tile_next->tile_type == TILE_TYPE_FULL) + { + tile->edge_up = EDGE_ID_SOLID; + } + else if(((tile_next->signy * -1) <= 0)) + { + tile->edge_up = EDGE_ID_INTERESTING; + } + else + { + tile->edge_up = EDGE_ID_SOLID; + } + } + else if(tile->tile_type == TILE_TYPE_FULL) + { + if(tile_next->tile_type == TILE_TYPE_FULL) + { + tile->edge_up = EDGE_ID_OFF; + } + else if(tile_next->tile_type == TILE_TYPE_EMPTY) + { + tile->edge_up = EDGE_ID_OFF; + } + else if((tile_next->signy * -1) <= 0) + { + tile->edge_up = EDGE_ID_INTERESTING; + } + else + { + tile->edge_up = EDGE_ID_OFF; + } + } + else + { + if(0 <= (tile->signy * -1)) + { + if(tile_next->tile_type == TILE_TYPE_EMPTY) + { + tile->edge_up = EDGE_ID_OFF; + } + else if(tile_next->tile_type == TILE_TYPE_FULL) + { + tile->edge_up = EDGE_ID_SOLID; + } + else if((tile->signy * -1) <= 0) + { + tile->edge_up = EDGE_ID_INTERESTING; + } + else + { + tile->edge_up = EDGE_ID_SOLID; + } + } + else + { + + if(tile_next->tile_type == TILE_TYPE_FULL) + { + tile->edge_up = EDGE_ID_OFF; + } + else if(tile_next->tile_type == TILE_TYPE_EMPTY) + { + tile->edge_up = EDGE_ID_OFF; + } + else if((tile_next->signy * -1) <= 0) + { + tile->edge_up = EDGE_ID_INTERESTING; + } + else + { + tile->edge_up = EDGE_ID_OFF; + } + + } + } + + + tile_next = (TileMapEx *)grid[l][i + 1][j];//Соседний tile + + + if(tile->tile_type == TILE_TYPE_EMPTY) + { + if(tile_next->tile_type == TILE_TYPE_EMPTY) + { + tile->edge_down = EDGE_ID_OFF; + } + else if(tile_next->tile_type == TILE_TYPE_FULL) + { + tile->edge_down = EDGE_ID_SOLID; + } + else if((tile_next->signy * 1) <= 0) + { + tile->edge_down = EDGE_ID_INTERESTING; + } + else + { + tile->edge_down = EDGE_ID_SOLID; + } + } + else if(tile->tile_type == TILE_TYPE_FULL) + { + if(tile_next->tile_type == TILE_TYPE_FULL) + { + tile->edge_down = EDGE_ID_OFF; + } + else if(tile_next->tile_type == TILE_TYPE_EMPTY) + { + tile->edge_down = EDGE_ID_OFF; + } + else if((tile_next->signy * 1) <= 0) + { + tile->edge_down = EDGE_ID_INTERESTING; + } + else + { + tile->edge_down = EDGE_ID_OFF; + } + } + else + { + if(0 <= (tile->signy * 1)) + { + if(tile_next->tile_type == TILE_TYPE_EMPTY) + { + tile->edge_down = EDGE_ID_OFF; + } + else if(tile_next->tile_type == TILE_TYPE_FULL) + { + tile->edge_down = EDGE_ID_SOLID; + } + else if((tile_next->signy * 1) <= 0) + { + tile->edge_down = EDGE_ID_INTERESTING; + } + else + { + tile->edge_down = EDGE_ID_SOLID; + } + } + else + { + if(tile_next->tile_type == TILE_TYPE_FULL) + { + tile->edge_down = EDGE_ID_OFF; + } + else if(tile_next->tile_type == TILE_TYPE_EMPTY) + { + tile->edge_down = EDGE_ID_OFF; + } + else if((tile_next->signy * 1) <= 0) + { + tile->edge_down = EDGE_ID_INTERESTING; + } + else + { + tile->edge_down = EDGE_ID_OFF; + } + } + } + + tile_next = (TileMapEx *)grid[l][i][j + 1]; + + if(tile->tile_type == TILE_TYPE_EMPTY) + { + if(tile_next->tile_type == TILE_TYPE_EMPTY) + { + tile->edge_right = EDGE_ID_OFF; + } + else if(tile_next->tile_type == TILE_TYPE_FULL) + { + tile->edge_right = EDGE_ID_SOLID; + } + else if((tile_next->signx * 1) <= 0 || tile_next->tile_type == TILE_TYPE_22DEGREE_pn || tile_next->tile_type == TILE_TYPE_22DEGREE_pp) + { + tile->edge_right = EDGE_ID_INTERESTING; + } + else + { + tile->edge_right = EDGE_ID_SOLID; + } + } + else if(tile->tile_type == TILE_TYPE_FULL) + { + if(tile_next->tile_type == TILE_TYPE_FULL) + { + tile->edge_right = EDGE_ID_OFF; + } + else if(tile_next->tile_type == TILE_TYPE_EMPTY) + { + tile->edge_right = EDGE_ID_OFF; + } + else if((tile_next->signx * 1) <= 0 || tile_next->tile_type == TILE_TYPE_22DEGREE_pn || tile_next->tile_type == TILE_TYPE_22DEGREE_pp) + { + tile->edge_right = EDGE_ID_INTERESTING; + } + else + { + tile->edge_right = EDGE_ID_OFF; + } + } + else + { + if(0 <= (tile->signx*1)) + { + if(tile_next->tile_type == TILE_TYPE_EMPTY) + { + tile->edge_right = EDGE_ID_OFF; + } + else if(tile_next->tile_type == TILE_TYPE_FULL) + { + tile->edge_right = EDGE_ID_SOLID; + } + else if((tile_next->signx * 1) <= 0 || tile_next->tile_type == TILE_TYPE_22DEGREE_pn || tile_next->tile_type == TILE_TYPE_22DEGREE_pp) + { + tile->edge_right = EDGE_ID_INTERESTING; + } + else + { + tile->edge_right = EDGE_ID_SOLID; + } + } + else + { + if(tile->tile_type == TILE_TYPE_22DEGREE_nn || tile->tile_type == TILE_TYPE_22DEGREE_np) + { + + if(tile_next->tile_type == TILE_TYPE_EMPTY) + { + tile->edge_right = EDGE_ID_OFF; + } + else if(tile_next->tile_type == TILE_TYPE_FULL) + { + tile->edge_right = EDGE_ID_SOLID; + } + else if((tile_next->signx*1) <= 0 || tile_next->tile_type == TILE_TYPE_22DEGREE_pn || tile_next->tile_type == TILE_TYPE_22DEGREE_pp) + { + tile->edge_right = EDGE_ID_INTERESTING; + } + else if(tile_next->tile_type == TILE_TYPE_FULL || (0 < (tile_next->signx * 1)) ) + { + tile->edge_right = EDGE_ID_SOLID; + } + else + { + tile->edge_right = EDGE_ID_OFF; + } + + } + else + { + if(tile_next->tile_type == TILE_TYPE_FULL) + { + tile->edge_right = EDGE_ID_OFF; + } + else if(tile_next->tile_type == TILE_TYPE_EMPTY) + { + tile->edge_right = EDGE_ID_OFF; + } + else if((tile_next->signx * 1) <= 0 || tile_next->tile_type == TILE_TYPE_22DEGREE_pn || tile_next->tile_type == TILE_TYPE_22DEGREE_pp) + { + tile->edge_right = EDGE_ID_INTERESTING; + } + else + { + tile->edge_right = EDGE_ID_OFF; + } + } + } + } + + tile_next = (TileMapEx *)grid[l][i][j - 1];//Соседний tile + + if(tile->tile_type == TILE_TYPE_EMPTY) + { + if(tile_next->tile_type == TILE_TYPE_EMPTY) + { + tile->edge_left = EDGE_ID_OFF; + } + else if(tile_next->tile_type == TILE_TYPE_FULL) + { + tile->edge_left= EDGE_ID_SOLID; + } + else if((tile_next->signx*-1) <= 0 || tile_next->tile_type == TILE_TYPE_22DEGREE_nn || tile_next->tile_type == TILE_TYPE_22DEGREE_np) + { + tile->edge_left= EDGE_ID_INTERESTING; + } + else + { + tile->edge_left= EDGE_ID_SOLID; + } + } + else if(tile->tile_type == TILE_TYPE_FULL) + { + if(tile_next->tile_type == TILE_TYPE_FULL) + { + tile->edge_left = EDGE_ID_OFF; + } + else if(tile_next->tile_type == TILE_TYPE_EMPTY) + { + tile->edge_left = EDGE_ID_OFF; + } + else if((tile_next->signx * -1) <= 0 || tile_next->tile_type == TILE_TYPE_22DEGREE_nn || tile_next->tile_type == TILE_TYPE_22DEGREE_np) + { + tile->edge_left= EDGE_ID_INTERESTING; + } + else + { + tile->edge_left= EDGE_ID_OFF; + } + } + else + { + if(0 <= (tile->signx * -1)) + { + if(tile_next->tile_type == TILE_TYPE_EMPTY) + { + tile->edge_left= EDGE_ID_OFF; + } + else if(tile_next->tile_type == TILE_TYPE_FULL) + { + tile->edge_left= EDGE_ID_SOLID; + } + else if((tile_next->signx * -1) <= 0 || tile_next->tile_type == TILE_TYPE_22DEGREE_nn || tile_next->tile_type == TILE_TYPE_22DEGREE_np) + { + tile->edge_left= EDGE_ID_INTERESTING; + } + else + { + tile->edge_left= EDGE_ID_SOLID; + } + } + else + { + if(tile->tile_type == TILE_TYPE_22DEGREE_pn || tile->tile_type == TILE_TYPE_22DEGREE_pp) + { + if(tile_next->tile_type == TILE_TYPE_EMPTY) + { + tile->edge_left= EDGE_ID_OFF; + } + else if(tile_next->tile_type == TILE_TYPE_FULL) + { + tile->edge_left= EDGE_ID_SOLID; + } + else if((tile_next->signx*-1) <= 0 || tile_next->tile_type == TILE_TYPE_22DEGREE_nn || tile_next->tile_type == TILE_TYPE_22DEGREE_np) + { + tile->edge_left= EDGE_ID_INTERESTING; + } + else if(0 < (tile_next->signx*-1) || tile_next->tile_type == TILE_TYPE_FULL) + { + tile->edge_left= EDGE_ID_SOLID; + } + else + { + tile->edge_left= EDGE_ID_OFF; + } + } + else + { + if(tile_next->tile_type == TILE_TYPE_FULL) + { + tile->edge_left= EDGE_ID_OFF; + } + else if(tile_next->tile_type == TILE_TYPE_EMPTY) + { + tile->edge_left= EDGE_ID_OFF; + } + else if((tile_next->signx*-1) <= 0 || tile_next->tile_type == TILE_TYPE_22DEGREE_nn || tile_next->tile_type == TILE_TYPE_22DEGREE_np) + { + tile->edge_left= EDGE_ID_INTERESTING; + } + else + { + tile->edge_left= EDGE_ID_OFF; + } + } + } + } + } + } +} + +bool Map::QueryPoint(int layer, float x, float y) +{ + TileMap *tile = this->GetTile(layer, x, y); + return TestPointTile(x, y, tile); +} + +bool Map::TestPointTile(float x, float y, TileMap *t) +{ + if (t) + { + x += offset_x; + y += offset_y; + + switch (t->GetTileType()) + { + case TILE_TYPE_EMPTY: + return false; + break; + + case TILE_TYPE_FULL: + return TestPointVsTileFull(x, y, t); + break; + + case TILE_TYPE_45DEGREE_pn: + case TILE_TYPE_45DEGREE_nn: + case TILE_TYPE_45DEGREE_np: + case TILE_TYPE_45DEGREE_pp: + return TestPointVsTile45Degree(x, y, (TileMapEx *)t); + break; + + case TILE_TYPE_22DEGREE_pn: + case TILE_TYPE_22DEGREE_nn: + case TILE_TYPE_22DEGREE_np: + case TILE_TYPE_22DEGREE_pp: + return TestPointVsTile22Degree(x, y, (TileMapEx *)t); + break; + + default: + return false; + break; + } + } + + return false; +} + +bool Map::TestPointVsTileFull(float x, float y, TileMap *t) +{ + return true; +} + +bool Map::TestPointVsTile45Degree(float x, float y, TileMapEx *t) +{ + float dx = x - t->pos.x; + float dy = y - t->pos.y; + if (dx * t->sx + dy * t->sy <= 0) + { + return true; + } + else + { + return false; + } +} + +bool Map::TestPointVsTile22Degree(float x, float y, TileMapEx *t) +{ + hgeVector pos = t->GetPos(); + float dx = x - (pos.x + t->signx * t->xw); + float dy = y - (pos.y - t->signy * t->yw); + if (dx * t->sx + dy * t->sy <= 0) + { + return true; + } + else + { + return false; + } +} diff --git a/Map.h b/Map.h new file mode 100644 index 0000000..a26ce75 --- /dev/null +++ b/Map.h @@ -0,0 +1,69 @@ +#pragma once + +#include "Object.h" +#include "TileMap.h" +#include "TileMapEx.h" +#include "TileMapAnimation.h" +#include "TileMapParticle.h" +#include "TileMapAnimationEx.h" +#include "TileMapResource.h" + +#include + + +class Map: public Object +{ +public: + Map(size_t layers, size_t rows, size_t cols, int screen_width, int screen_hight, short tile_width, short tile_hight); + virtual ~Map(); + + void Free(); + + void InsertTile(int row, int col, TileMap *tile); + void DeleteTile(int layer, int row, int col); + + TileMap* GetTile(int layer, const hgeVector *pos); + TileMap* GetTile(int layer, float x, float y); + TileMap* GetTile(int layer, int row, int col); + + float GetOffsetX() { return offset_x; } + float GetOffsetY() { return offset_y; } + + void SetOffsetX(float offset) { offset_x = offset;} + void SetOffsetY(float offset) { offset_y = offset;} + + void GetTileIndex(const hgeVector *pos, int &row, int &col); + + void HorizontalScroll(int offset_x); + void VerticalScroll(int offset_y); + + void Render(int layer); + + TileMap *SelectTile(short layer, hgeVector &p); + + void Save(const char *file_name); + void Load(const char *file_name); + + void UpdateGraphic(); + + void UpdateEdges(int layer); + + bool QueryPoint(int layer, float x, float y); + + bool TestPointTile(float x, float y, TileMap *t); + bool TestPointVsTileFull(float x, float y, TileMap *t); + bool TestPointVsTile45Degree(float x, float y, TileMapEx *t); + bool TestPointVsTile22Degree(float x, float y, TileMapEx *t); + +protected: + float offset_x, offset_y; + short tile_width, tile_hight; + int screen_width, screen_hight; + + size_t rows, cols; + size_t layers; + + TileMap *tile; + + std::vector< std::vector< std::vector > > grid; +}; diff --git a/Object.cpp b/Object.cpp new file mode 100644 index 0000000..178941c --- /dev/null +++ b/Object.cpp @@ -0,0 +1,10 @@ +#include "Object.h" + +Object::Object() +{ + TYPE_ID = OBJECT_ID; +} + +Object::~Object() +{ +} diff --git a/Object.h b/Object.h new file mode 100644 index 0000000..ad5456a --- /dev/null +++ b/Object.h @@ -0,0 +1,32 @@ +#pragma once + +#include "options.h" + +#define OBJECT_ID 1 +#define GRAPHIC_OBJECT_ID 2 +#define GRAPHIC_DYNAMIC_OBJECT_ID 10 + +#define TILE_MAP_ID 20 +#define TILE_MAP_EXTENDED_ID 21 +#define TILE_MAP_ANIMATION_ID 22 +#define TILE_MAP_PARTICLE_ID 23 +#define TILE_MAP_ANIMATION_EX_ID 24 +#define TILE_MAP_RESOURCE_ID 25 + +#define MAP_ID 34 + + + + +class Object +{ +public: + Object(); + virtual ~Object(); + + virtual inline int GetObjectType() const + { return TYPE_ID; } + +protected: + short TYPE_ID; +}; diff --git a/Tables.cpp b/Tables.cpp new file mode 100644 index 0000000..eec4d7b --- /dev/null +++ b/Tables.cpp @@ -0,0 +1,88 @@ +#include "Tables.h" + + +#include "Object.h" + +#include "TileMapEx.h" +#include "TileMapResource.h" + + +const char *GetTilesObjectName(int id) +{ + switch(id) + { + case TILE_MAP_ID: + return "TileMap"; + + case TILE_MAP_EXTENDED_ID: + return "TileMapEx"; + + case TILE_MAP_ANIMATION_ID: + return "TileMapAnimation"; + + case TILE_MAP_ANIMATION_EX_ID: + return "TileMapAnimationEx"; + + case TILE_MAP_PARTICLE_ID: + return "TileMapParticle"; + + case TILE_MAP_RESOURCE_ID: + return "TileMapResource"; + } + + return ""; +} + +const char *GetTileMapTypeName(int id) +{ + switch (id) + { + case TILE_TYPE_EMPTY: + return "TILE_TYPE_EMPTY"; + + case TILE_TYPE_FULL: + return "TILE_TYPE_FULL"; + + case TILE_TYPE_22DEGREE_nn: + return "TILE_TYPE_22DEGREE_nn"; + + case TILE_TYPE_22DEGREE_np: + return "TILE_TYPE_22DEGREE_np"; + + case TILE_TYPE_22DEGREE_pn: + return "TILE_TYPE_22DEGREE_pn"; + + case TILE_TYPE_22DEGREE_pp: + return "TILE_TYPE_22DEGREE_pp"; + + case TILE_TYPE_45DEGREE_nn: + return "TILE_TYPE_45DEGREE_nn"; + + case TILE_TYPE_45DEGREE_np: + return "TILE_TYPE_45DEGREE_np"; + + case TILE_TYPE_45DEGREE_pn: + return "TILE_TYPE_45DEGREE_pn"; + + case TILE_TYPE_45DEGREE_pp: + return "TILE_TYPE_45DEGREE_pp"; + } + + return ""; +} + + +const char *GetTileMapNameResType(int id) +{ + + switch (id) + { + case RESOURCE_TYPES::AID: + return "RESOURCE_TYPES::AID"; + case RESOURCE_TYPES::ARMOUR: + return "RESOURCE_TYPES::AID"; + case RESOURCE_TYPES::LIFES: + return "RESOURCE_TYPES::LIFES"; + } + return ""; +} \ No newline at end of file diff --git a/Tables.h b/Tables.h new file mode 100644 index 0000000..d7306ba --- /dev/null +++ b/Tables.h @@ -0,0 +1,6 @@ +#pragma once + + +const char *GetTilesObjectName(int id); +const char *GetTileMapTypeName(int id); +const char *GetTileMapNameResType(int id); \ No newline at end of file diff --git a/TileMap.cpp b/TileMap.cpp new file mode 100644 index 0000000..3df69ea --- /dev/null +++ b/TileMap.cpp @@ -0,0 +1,167 @@ +#include + +#include "TileMap.h" + + + +TileMap::TileMap() +: GraphicObject() +{ + TYPE_ID = TILE_MAP_ID; + + edge_up = edge_down = edge_left = edge_right = EDGE_ID_OFF; + + layer = 0; + SetTileType(TILE_TYPE_EMPTY); + + show_tile_quad = false; +} + +TileMap::TileMap(char *resurce_name, hgeVector pos, short xw, short yw, short layer) +: GraphicObject(resurce_name, pos, xw, yw, layer) +{ + TYPE_ID = TILE_MAP_ID; + + edge_up = edge_down = edge_left = edge_right = EDGE_ID_OFF; + + layer = 0; + SetTileType(TILE_TYPE_EMPTY); + + show_tile_quad = false; +} + +TileMap::~TileMap() +{ +} + +void TileMap::SetTileType(short type) +{ + this->tile_type = type; +} + +void TileMap::Render() +{ + float x0, y0, x1, y1, x2, y2, x3, y3; + + x0 = pos.x - xw; y0 = pos.y - yw; + x1 = pos.x + xw; y1 = pos.y - yw; + x2 = pos.x + xw; y2 = pos.y + yw; + x3 = pos.x - xw; y3 = pos.y + yw; + + switch (tile_type) + { + case TILE_TYPE_EMPTY: + case TILE_TYPE_FULL: + { + if (!resource_name.empty()) + { + hgeSprite *sprite = resources_manager->GetSprite(resource_name.c_str()); + + if (sprite) + { + sprite->Render4V(x0, y0, x1, y1, x2, y2, x3, y3); + } + + RenderTileQuad(); + } + break; + } + } +} + +void TileMap::Save(std::ofstream *f) +{ + if (f) + { + size_t l = 0; + + f->write((const char *)&tile_type, sizeof(short)); + f->write((const char *)&pos.x, sizeof(float)); + f->write((const char *)&pos.y, sizeof(float)); + f->write((const char *)&xw, sizeof(short)); + f->write((const char *)&yw, sizeof(short)); + f->write((const char *)&layer, sizeof(short)); + + l = resource_name.size(); + + f->write((const char *)&l, sizeof(size_t)); + f->write(resource_name.c_str(), l*sizeof(char)); + } +} + +void TileMap::Load(std::ifstream *f) +{ + if (f) + { + size_t l = 0; + + f->read((char *)&tile_type, sizeof(short)); + f->read((char *)&pos.x, sizeof(float)); + f->read((char *)&pos.y, sizeof(float)); + f->read((char *)&xw, sizeof(short)); + f->read((char *)&yw, sizeof(short)); + f->read((char *)&layer, sizeof(short)); + + f->read((char *)&l, sizeof(size_t)); + + resource_name.clear(); + resource_name.resize(l); + + char *name = new char[l+1]; + + f->read(name, l*sizeof(char)); + name[l] = '\0'; + resource_name = name; + + delete[] name; + } +} + +void TileMap::InsertObject(GraphicDynamicObject *obj) +{ + for (size_t i = 0; i < objects.size(); i++) + { + if (obj == objects[i]) + return; + } + + objects.push_back(obj); +} + +void TileMap::RemoveObject(GraphicDynamicObject *obj) +{ + std::vector::iterator i = objects.begin(); + + while (i != objects.end()) + { + if (*i == obj) + { + objects.erase(i); + break; + } + i++; + } +} + +void TileMap::RenderTileQuad() +{ + if (show_tile_quad) + { + float x0, y0, x1, y1, x2, y2, x3, y3; + + x0 = pos.x - xw; y0 = pos.y - yw; + x1 = pos.x + xw; y1 = pos.y - yw; + x2 = pos.x + xw; y2 = pos.y + yw; + x3 = pos.x - xw; y3 = pos.y + yw; + + hge->Gfx_RenderLine(x0, y0, x1, y1, ARGB(255, 255, 0, 0)); + hge->Gfx_RenderLine(x1, y1, x2, y2, ARGB(255, 255, 0, 0)); + hge->Gfx_RenderLine(x2, y2, x3, y3, ARGB(255, 255, 0, 0)); + hge->Gfx_RenderLine(x3, y3, x0, y0, ARGB(255, 255, 0, 0)); + } +} + +void TileMap::ShowTileQuad(bool show) +{ + show_tile_quad = show; +} \ No newline at end of file diff --git a/TileMap.h b/TileMap.h new file mode 100644 index 0000000..24a4ba6 --- /dev/null +++ b/TileMap.h @@ -0,0 +1,51 @@ +#pragma once + + +#include + +#include "CollisionDefines.h" +#include "GraphicObject.h" +#include "Edges.h" + +#include + +#define TILE_TYPE_EMPTY 0 +#define TILE_TYPE_FULL 1 + +class Map; +class GraphicDynamicObject; + +class TileMap: public GraphicObject +{ + friend Map; + +public: + TileMap(); + TileMap(char *sprite_name, hgeVector pos, short xw, short yw, short layer); + + virtual ~TileMap(); + + virtual void SetTileType(short type); + short GetTileType() { return tile_type; } + + virtual void Render(); + + virtual void RenderTileQuad(); + virtual void ShowTileQuad(bool show); + + + virtual void Save(std::ofstream *file); + virtual void Load(std::ifstream *file); + + void InsertObject(GraphicDynamicObject *obj); + void RemoveObject(GraphicDynamicObject *obj); + +protected: + short tile_type; + bool show_tile_quad; + +public: + std::vector objects; //временно + short edge_up, edge_down, edge_left, edge_right; + +}; diff --git a/TileMapAnimation.cpp b/TileMapAnimation.cpp new file mode 100644 index 0000000..b4598ed --- /dev/null +++ b/TileMapAnimation.cpp @@ -0,0 +1,79 @@ +#include "TileMapAnimation.h" + +TileMapAnimation::TileMapAnimation() +: TileMap() +, animation(NULL) +{ + TYPE_ID = TILE_MAP_ANIMATION_ID; +} + +TileMapAnimation::TileMapAnimation(char *res_name, hgeVector pos, short xw, short yw, short layer) +: TileMap(res_name, pos, xw, yw, layer) +{ + TYPE_ID = TILE_MAP_ANIMATION_ID; + + if (res_name != NULL) + { + animation = new hgeAnimation( *(resources_manager->GetAnimation(resource_name.c_str())) ); + + animation->Play(); + } +} + +TileMapAnimation::~TileMapAnimation() +{ + if (animation) + { + delete animation; + animation = NULL; + } +} + +void TileMapAnimation::Render() +{ + float x0, y0, x1, y1, x2, y2, x3, y3; + + x0 = pos.x - xw; y0 = pos.y - yw; + x1 = pos.x + xw; y1 = pos.y - yw; + x2 = pos.x + xw; y2 = pos.y + yw; + x3 = pos.x - xw; y3 = pos.y + yw; + + if (animation) + { + animation->Render4V(x0, y0, x1, y1, x2, y2, x3, y3); + } + + RenderTileQuad(); +} + +void TileMapAnimation::Save(std::ofstream *file) +{ + TileMap::Save(file); +} + +void TileMapAnimation::Load(std::ifstream *file) +{ + TileMap::Load(file); + + if (animation != NULL) + delete animation; + + animation = new hgeAnimation( *(resources_manager->GetAnimation( resource_name.c_str())) ); + animation->Play(); +} + +void TileMapAnimation::UpdateGraphic() +{ + float dt = hge->Timer_GetDelta(); + animation->Update(dt); +} + +void TileMapAnimation::Stop() +{ + animation->Stop(); +} + +void TileMapAnimation::Play() +{ + animation->Play(); +} \ No newline at end of file diff --git a/TileMapAnimation.h b/TileMapAnimation.h new file mode 100644 index 0000000..9926c0c --- /dev/null +++ b/TileMapAnimation.h @@ -0,0 +1,26 @@ +#pragma once + +#include + +#include "TileMap.h" + +class TileMapAnimation: public TileMap +{ +public: + TileMapAnimation(); + TileMapAnimation(char *res_name, hgeVector pos, short xw, short yw, short layer); + virtual ~TileMapAnimation(); + + virtual void Render(); + + virtual void Save(std::ofstream *file); + virtual void Load(std::ifstream *file); + + virtual void UpdateGraphic(); + + virtual void Play(); + virtual void Stop(); + +protected: + hgeAnimation *animation; +}; diff --git a/TileMapAnimationEx.cpp b/TileMapAnimationEx.cpp new file mode 100644 index 0000000..125e99f --- /dev/null +++ b/TileMapAnimationEx.cpp @@ -0,0 +1,120 @@ +#include "TileMapAnimationEx.h" + +TileMapAnimationEx::TileMapAnimationEx() +: TileMapAnimation() +{ + Object::TYPE_ID = TILE_MAP_ANIMATION_EX_ID; + ps_name = ""; + ps = NULL; +} + +TileMapAnimationEx::TileMapAnimationEx(char *animation_name, char *particle_name, hgeVector pos, short xw, short yw, short layer) +: TileMapAnimation(animation_name, pos, xw, yw, layer) +{ + Object::TYPE_ID = TILE_MAP_ANIMATION_EX_ID; + + if (particle_name != NULL) + { + ps_name = particle_name; + + ps = new hgeParticleSystem( *(resources_manager->GetParticleSystem( ps_name.c_str() )) ); + + ps->FireAt(pos.x, pos.y); + } + else + { + ps = NULL; + } +} + +TileMapAnimationEx::~TileMapAnimationEx() +{ + if (ps) + { + delete ps; + ps = NULL; + } + + ps_name.clear(); +} + +void TileMapAnimationEx::Play() +{ + TileMapAnimation::Play(); + if (ps) + ps->Fire(); + +} + +void TileMapAnimationEx::Stop() +{ + TileMapAnimation::Stop(); + if (ps) + ps->Stop(); +} + +void TileMapAnimationEx::Render() +{ + TileMapAnimation::Render(); + + if (ps) + { + ps->Render(); + } +} + +void TileMapAnimationEx::Save(std::ofstream *f) +{ + TileMapAnimation::Save(f); + + size_t l = ps_name.length(); + + f->write((const char *)&l, sizeof(size_t)); + f->write(ps_name.c_str(), l*sizeof(char)); +} + +void TileMapAnimationEx::Load(std::ifstream *f) +{ + TileMapAnimation::Load(f); + + ps_name.clear(); + + size_t l = 0; + f->read((char *)&l, sizeof(size_t)); + + char *name = new char[l]; + f->read(name, l*sizeof(char)); + name[l] = '\0'; + + ps_name = name; + + + if (ps) + { + delete ps; + ps = NULL; + } + + if (!ps_name.empty()) + { + ps = new hgeParticleSystem( *(resources_manager->GetParticleSystem( ps_name.c_str() )) ); + ps->Fire(); + } + + +} + +void TileMapAnimationEx::MoveParticle(float x, float y, bool move) +{ + if (ps) + ps->MoveTo(x, y, move); +} + +void TileMapAnimationEx::UpdateGraphic() +{ + TileMapAnimation::UpdateGraphic(); + + float dt = hge->Timer_GetDelta(); + if (ps) + ps->Update(dt); +} \ No newline at end of file diff --git a/TileMapAnimationEx.h b/TileMapAnimationEx.h new file mode 100644 index 0000000..eca87c6 --- /dev/null +++ b/TileMapAnimationEx.h @@ -0,0 +1,31 @@ +#pragma once + +#include "TileMapAnimation.h" +#include "TileMapParticle.h" + +class TileMapAnimationEx: public TileMapAnimation +{ +public: + TileMapAnimationEx(); + TileMapAnimationEx(char *animation_name, char *particle_name, hgeVector pos, short xw, short yw, short layer); + virtual ~TileMapAnimationEx(); + + virtual void Render(); + + virtual void Save(std::ofstream *file); + virtual void Load(std::ifstream *file); + + virtual void UpdateGraphic(); + + hgeParticleSystem * GetParticle() const { return ps; } + + virtual void Play(); + virtual void Stop(); + virtual void MoveParticle(float x, float y, bool move); + + const char * GetPSName() { return ps_name.c_str(); } + +protected: + hgeParticleSystem *ps; + std::string ps_name; +}; diff --git a/TileMapEx.cpp b/TileMapEx.cpp new file mode 100644 index 0000000..c1d490d --- /dev/null +++ b/TileMapEx.cpp @@ -0,0 +1,167 @@ +#include +#include "TileMapEx.h" + +TileMapEx::TileMapEx() +: TileMap() +{ + TYPE_ID = TILE_MAP_EXTENDED_ID; +} + +TileMapEx::TileMapEx(char *texture_name, hgeVector pos, short xw, short yw, short layer) +: TileMap(texture_name, pos, xw, yw, layer) +{ + TYPE_ID = TILE_MAP_EXTENDED_ID; +} + +TileMapEx::~TileMapEx() +{ +} + +void TileMapEx::SetTileType(short type) +{ + tile_type = type; + switch (tile_type) + { + case TILE_TYPE_EMPTY: + case TILE_TYPE_FULL: + { + signx = 0; + signy = 0; + sx = 0; + sy = 0; + } + break; + + case TILE_TYPE_45DEGREE_pn: + { + signx = 1; + signy = -1; + sx = signx / sqrt(2.0f);//get slope unit normal + sy = signy / sqrt(2.0f);//since normal is (1,-1), length is sqrt(1*1 + -1*-1) = sqrt(2) + } + break; + + case TILE_TYPE_45DEGREE_nn: + { + signx = -1; + signy = -1; + sx = signx / sqrt(2.0f);//get slope unit normal + sy = signy / sqrt(2.0f);//since normal is (1,-1), length is sqrt(1*1 + -1*-1) = sqrt(2) + } + break; + + case TILE_TYPE_45DEGREE_np: + { + signx = -1; + signy = 1; + sx = signx / sqrt(2.0f);//get slope unit normal + sy = signy / sqrt(2.0f);//since normal is (1,-1), length is sqrt(1*1 + -1*-1) = sqrt(2) + } + break; + + case TILE_TYPE_45DEGREE_pp: + { + signx = 1; + signy = 1; + sx = signx / sqrt(2.0f);//get slope unit normal + sy = signy / sqrt(2.0f);//since normal is (1,-1), length is sqrt(1*1 + -1*-1) = sqrt(2) + } + break; + + case TILE_TYPE_22DEGREE_pn: + { + signx = 1; + signy = -1; + float slen = sqrt(2.0f*2.0f + 1.0f*1.0f); + sx = (signx * 1) / slen; + sy = (signy * 2) / slen; + } + break; + + case TILE_TYPE_22DEGREE_nn: + { + signx = -1; + signy = -1; + float slen = sqrt(2.0f*2.0f + 1.0f*1.0f); + sx = (signx * 1) / slen; + sy = (signy * 2) / slen; + } + break; + + case TILE_TYPE_22DEGREE_np: + { + signx = -1; + signy = 1; + float slen = sqrt(2.0f*2.0f + 1.0f*1.0f); + sx = (signx * 1) / slen; + sy = (signy * 2) / slen; + } + break; + + case TILE_TYPE_22DEGREE_pp: + { + signx = 1; + signy = 1; + float slen = sqrt(2.0f*2.0f + 1.0f*1.0f); + sx = (signx * 1) / slen; + sy = (signy * 2) / slen; + } + break; + } +} + +//TODO: render +void TileMapEx::Render() +{ + switch (tile_type) + { + case TILE_TYPE_EMPTY: + case TILE_TYPE_FULL: + { + TileMap::Render(); + } + break; + + default: + + TileMap::Render(); + float x0, y0, x1, y1, x2, y2, x3, y3; + + x0 = pos.x - xw; y0 = pos.y - yw; + x1 = pos.x + xw; y1 = pos.y - yw; + x2 = pos.x + xw; y2 = pos.y + yw; + x3 = pos.x - xw; y3 = pos.y + yw; + + hgeSprite *sprite = resources_manager->GetSprite(resource_name.c_str()); + if (sprite) + { + sprite->Render4V(x0, y0, x1, y1, x2, y2, x3, y3); + } + RenderTileQuad(); + + break; + } + +} + +void TileMapEx::Save(std::ofstream *f) +{ + TileMap::Save(f); + + f->write((const char *)&signx, sizeof(float)); + f->write((const char *)&signy, sizeof(float)); + f->write((const char *)&sx, sizeof(float)); + f->write((const char *)&sy, sizeof(float)); + +} + +void TileMapEx::Load(std::ifstream *f) +{ + TileMap::Load(f); + + f->read((char *)&signx, sizeof(float)); + f->read((char *)&signy, sizeof(float)); + f->read((char *)&sx, sizeof(float)); + f->read((char *)&sy, sizeof(float)); + +} \ No newline at end of file diff --git a/TileMapEx.h b/TileMapEx.h new file mode 100644 index 0000000..83a9930 --- /dev/null +++ b/TileMapEx.h @@ -0,0 +1,33 @@ +#pragma once + +#include "TileMap.h" + +#define TILE_TYPE_45DEGREE_pn 2//45-degree triangle, whose normal is (+ve,-ve) +#define TILE_TYPE_45DEGREE_nn 3//(+ve,+ve) +#define TILE_TYPE_45DEGREE_np 4//(-ve,+ve) +#define TILE_TYPE_45DEGREE_pp 5//(-ve,-ve) + +#define TILE_TYPE_22DEGREE_pn 6 +#define TILE_TYPE_22DEGREE_nn 7 +#define TILE_TYPE_22DEGREE_np 8 +#define TILE_TYPE_22DEGREE_pp 9 + + +class TileMapEx: public TileMap +{ +public: + TileMapEx(); + TileMapEx(char *sprite_name, hgeVector pos, short xw, short yw, short layer); + virtual ~TileMapEx(); + + virtual void SetTileType(short type); + + virtual void Save(std::ofstream *file); + virtual void Load(std::ifstream *file); + + virtual void Render(); + +public: + float signx, signy; + float sx, sy; +}; diff --git a/TileMapParticle.cpp b/TileMapParticle.cpp new file mode 100644 index 0000000..ce89216 --- /dev/null +++ b/TileMapParticle.cpp @@ -0,0 +1,100 @@ +#include "TileMapParticle.h" + +TileMapParticle::TileMapParticle() +: TileMap() +, ps(NULL) +{ + TYPE_ID = TILE_MAP_PARTICLE_ID; + + ps_name = ""; + ps = NULL; +} + + +TileMapParticle::TileMapParticle(char *texture_name, char *name_particle, hgeVector pos, short xw, short yw, short layer) +: TileMap(texture_name, pos, xw, yw, layer) +{ + TYPE_ID = TILE_MAP_PARTICLE_ID; + + ps_name = name_particle; + + ps = new hgeParticleSystem( *(resources_manager->GetParticleSystem( ps_name.c_str() )) ); + + ps->FireAt(pos.x, pos.y); +} + +TileMapParticle::~TileMapParticle() +{ + if (ps) + { + delete ps; + ps = NULL; + } + + ps_name.clear(); +} + + +void TileMapParticle::Render() +{ + TileMap::Render(); + + if (ps) + { + ps->Render(); + } +} + +void TileMapParticle::Save(std::ofstream *f) +{ + TileMap::Save(f); + + size_t l = ps_name.length(); + + f->write((const char *)&l, sizeof(size_t)); + f->write(ps_name.c_str(), l*sizeof(char)); + +} + +void TileMapParticle::Load(std::ifstream *f) +{ + TileMap::Load(f); + ps_name.clear(); + + size_t l = 0; + f->read((char *)&l, sizeof(size_t)); + + char *name = new char[l]; + f->read(name, l*sizeof(char)); + + ps_name = name; + + if (ps) + { + delete ps; + } + + ps = new hgeParticleSystem( *(resources_manager->GetParticleSystem( ps_name.c_str() )) ); + ps->Fire(); +} + +void TileMapParticle::UpdateGraphic() +{ + float dt = hge->Timer_GetDelta(); + ps->Update(dt); +} + +void TileMapParticle::Play() +{ + ps->Fire(); +} + +void TileMapParticle::Stop() +{ + ps->Stop(); +} + +void TileMapParticle::MoveParticle(float x, float y, bool move) +{ + ps->MoveTo(x, y, move); +} \ No newline at end of file diff --git a/TileMapParticle.h b/TileMapParticle.h new file mode 100644 index 0000000..34b07fd --- /dev/null +++ b/TileMapParticle.h @@ -0,0 +1,32 @@ +#pragma once + +#include + +#include "TileMap.h" + +class TileMapParticle: public TileMap +{ +public: + TileMapParticle(); + TileMapParticle(char *texture_name, char *particle_name, hgeVector pos, short xw, short yw, short layer); + virtual ~TileMapParticle(); + + virtual void Render(); + + virtual void Save(std::ofstream *file); + virtual void Load(std::ifstream *file); + + virtual void UpdateGraphic(); + + hgeParticleSystem * GetParticle() const { return ps; } + + virtual void Play(); + virtual void Stop(); + void MoveParticle(float x, float y, bool move); + + const char * GetPSName() { return ps_name.c_str(); } + +protected: + hgeParticleSystem *ps; + std::string ps_name; +}; diff --git a/TileMapResource.cpp b/TileMapResource.cpp new file mode 100644 index 0000000..d6cb6ae --- /dev/null +++ b/TileMapResource.cpp @@ -0,0 +1,146 @@ +#include "TileMapResource.h" + +TileMapResource::TileMapResource() +: TileMapAnimationEx() +{ + Object::TYPE_ID = TILE_MAP_RESOURCE_ID; + + used_name_ps = ""; + ps_used = NULL; + + resource_type = 0; +} + +TileMapResource::TileMapResource(char *animation_name, char *particle_name, char *particle_used_name, hgeVector pos, short xw, short yw, short layer) +: TileMapAnimationEx(animation_name, particle_name, pos, xw, yw, layer) +{ + Object::TYPE_ID = TILE_MAP_RESOURCE_ID; + + if (particle_used_name != NULL) + { + used_name_ps = particle_used_name; + + ps_used = new hgeParticleSystem( *(resources_manager->GetParticleSystem( particle_used_name )) ); + } + else + { + ps_used = NULL; + } + + used = false; + + resource_type = 0; +} + +TileMapResource::~TileMapResource() +{ +} + + +void TileMapResource::UpdateGraphic() +{ + if (!used) + { + TileMapAnimationEx::UpdateGraphic(); + } + else + { + float dt = hge->Timer_GetDelta(); + if (ps_used) + ps_used->Update(dt); + } +} + +void TileMapResource::Render() +{ + if (!used) + { + TileMapAnimationEx::Render(); + } + else + { + ps_used->Render(); + } +} + +void TileMapResource::MoveParticle(float x, float y, bool move) +{ + if (!used) + { + TileMapAnimationEx::MoveParticle(x, y, move); + } + else + { + if (ps_used) + ps_used->MoveTo(x, y, move); + } +} + +void TileMapResource::Used(bool used) +{ + this->used = used; + + if (!used) + { + animation->Play(); + + if (ps_used) + ps_used->Stop(); + + if (ps) + ps->Fire(); + } + else + { + animation->Stop(); + + if (ps) + ps->Stop(); + + if (ps_used) + ps_used->Fire(); + } +} + +void TileMapResource::Save(std::ofstream *f) +{ + TileMapAnimationEx::Save(f); + + size_t l = used_name_ps.length(); + + f->write((const char *)&resource_type, sizeof(int)); + + f->write((const char *)&l, sizeof(size_t)); + f->write(used_name_ps.c_str(), l*sizeof(char)); +} + +void TileMapResource::Load(std::ifstream *f) +{ + TileMapAnimationEx::Load(f); + + used_name_ps.clear(); + + f->read((char *)&resource_type, sizeof(int)); + + size_t l = 0; + f->read((char *)&l, sizeof(size_t)); + + char *name = new char[l]; + f->read(name, l*sizeof(char)); + name[l] = '\0'; + + used_name_ps = name; + + if (ps_used) + { + delete ps_used; + ps_used = NULL; + } + + if (!used_name_ps.empty()) + { + ps_used = new hgeParticleSystem( *(resources_manager->GetParticleSystem( used_name_ps.c_str() )) ); + } + + used = false; +} \ No newline at end of file diff --git a/TileMapResource.h b/TileMapResource.h new file mode 100644 index 0000000..2a37caf --- /dev/null +++ b/TileMapResource.h @@ -0,0 +1,47 @@ +#pragma once + +#include "TileMapAnimationEx.h" + +enum RESOURCE_TYPES +{ + LIFES = 1, + AID = 2, + ARMOUR = 3 +}; + +class Entity; + +class TileMapResource: public TileMapAnimationEx +{ +public: + TileMapResource(); + TileMapResource(char *animation_name, char *particle_name, char *particle_used_name, hgeVector pos, short xw, short yw, short layer); + ~TileMapResource(); + + inline void SetResourceType(int type) { resource_type = type; } + inline int GetResourceType() const { return resource_type; } + + inline bool IsUsed() const { return used; } + inline void Used(bool used); + virtual void UpdateGraphic(); + + virtual void Render(); + + void MoveParticle(float x, float y, bool move); + + virtual void Save(std::ofstream *file); + virtual void Load(std::ifstream *file); + + const char* GetUsedPSName() { return used_name_ps.c_str(); } + +protected: + int resource_type; + + bool used; + + float time; + float timer; + + hgeParticleSystem *ps_used; + std::string used_name_ps; +}; diff --git a/hge.dll b/hge.dll new file mode 100644 index 0000000..222a0fd Binary files /dev/null and b/hge.dll differ diff --git a/level1.lev b/level1.lev new file mode 100644 index 0000000..a5be909 Binary files /dev/null and b/level1.lev differ diff --git a/level2.lev b/level2.lev new file mode 100644 index 0000000..82637bc Binary files /dev/null and b/level2.lev differ diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..3384924 --- /dev/null +++ b/main.cpp @@ -0,0 +1,517 @@ +#include +#include + +#include "Map.h" +#include "Initiate.h" +#include "Tables.h" +#include "InitCombo.h" + +#pragma comment(lib, "hge.lib") +#pragma comment(lib, "hgehelp.lib") + + +HGE* hge = NULL; +hgeResourceManager *resource_manager = NULL; + + + +HWND hwndHGE = 0; + +HWND hCB_ObjType = 0; +HWND hCB_SprName = 0; +HWND hCB_AnimName = 0; +HWND hCB_TileType = 0; +HWND hCB_PS1 = 0; +HWND hCB_PS2 = 0; +HWND hCB_ResType = 0; + +HWND hEdit = 0; +HWND hEditLoad = 0; +HWND hEditSave = 0; + +HWND hButtonOk = 0; +HWND hButtonDel = 0; +HWND hButtonSave = 0; +HWND hButtonLoad = 0; + +hgeVector mouse_pos(0, 0); +hgeRect hge_rect(0, 0, 800, 768); + + +Map *map = NULL; + + +TileMap *tile = NULL; +int layer = 0; +int row = 0, col = 0; + +// #define LAYER 3 +#define LAYERS 7 + + +LRESULT CALLBACK HGEProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); + + +void InitMap() +{ + size_t rows = 20; + size_t cols = 250; + map = new Map(LAYERS, rows, cols, 800, 768, 64, 64); + + TileMap *tile = NULL; + hgeVector pos(32, 32); + + for (size_t i = 0; i < rows; i++) + { + for (size_t j = 0; j < cols; j++) + { + tile = new TileMap("empty", pos, 32, 32, 3); + tile->SetTileType(TILE_TYPE_EMPTY); + pos.x += 64; + + map->InsertTile(i, j, tile); + } + pos.x = 32; + pos.y += 64; + } +} + + + +bool FrameFunc() +{ + POINT p; + GetCursorPos(&p); + + ScreenToClient(hwndHGE, &p); + + mouse_pos.x = (float)p.x; + mouse_pos.y = (float)p.y; + + if (map) + map->UpdateGraphic(); + + if (hge->Input_GetKeyState(HGEK_LBUTTON) && hge_rect.TestPoint(mouse_pos.x, mouse_pos.y)) + { + int n = GetWindowTextLength(hEdit)+1; + char *buf = new char[n]; + GetWindowText(hEdit, buf, n); + layer = atoi(buf); + delete[] buf; + + if (tile) + tile->ShowTileQuad(false); + + tile = map->SelectTile(layer, mouse_pos); + map->GetTileIndex(&mouse_pos, row, col); + + if (!tile) + { + SendMessage(hCB_ObjType, CB_SETCURSEL, 0, 0); + SendMessage(hCB_SprName, CB_SETCURSEL, 0, 0); + SendMessage(hCB_AnimName, CB_SETCURSEL, 0, 0); + SendMessage(hCB_TileType, CB_SETCURSEL, 0, 0); + } + else + { + SendMessage(hCB_ObjType, CB_SETCURSEL, 0, 0); + SendMessage(hCB_SprName, CB_SETCURSEL, 0, 0); + SendMessage(hCB_AnimName, CB_SETCURSEL, 0, 0); + SendMessage(hCB_TileType, CB_SETCURSEL, 0, 0); + + tile->ShowTileQuad(true); + + LRESULT index = SendMessage(hCB_ObjType, CB_FINDSTRING, -1, (LPARAM)GetTilesObjectName(tile->GetObjectType())); + if (index != -1) + SendMessage(hCB_ObjType, CB_SETCURSEL, index, 0); + + if (tile->GetObjectType() == TILE_MAP_RESOURCE_ID) + { + TileMapResource *tr = (TileMapResource *)tile; + index = SendMessage(hCB_ResType, CB_FINDSTRING, -1, (LPARAM)GetTileMapNameResType(tr->GetResourceType())); + if (index != -1) + SendMessage(hCB_ResType, CB_SETCURSEL, index, 0); + + index = SendMessage(hCB_PS2, CB_FINDSTRING, -1, (LPARAM)((TileMapResource *)tile)->GetUsedPSName()); + if (index != -1) + SendMessage(hCB_PS2, CB_SETCURSEL, index, 0); + } + + index = SendMessage(hCB_SprName, CB_FINDSTRING, -1, (LPARAM)tile->GetResName()); + if (index != -1) + SendMessage(hCB_SprName, CB_SETCURSEL, index, 0); + + if (tile->GetObjectType() == TILE_MAP_ANIMATION_EX_ID || tile->GetObjectType() == TILE_MAP_PARTICLE_ID) + { + if (tile->GetObjectType() == TILE_MAP_ANIMATION_EX_ID) + { + index = SendMessage(hCB_PS1, CB_FINDSTRING, -1, (LPARAM)((TileMapAnimationEx *)tile)->GetPSName()); + } + else if (tile->GetObjectType() == TILE_MAP_PARTICLE_ID) + { + index = SendMessage(hCB_PS1, CB_FINDSTRING, -1, (LPARAM)((TileMapParticle *)tile)->GetPSName()); + } + if (index != -1) + { + SendMessage(hCB_PS1, CB_SETCURSEL, index, 0); + } + } + + + if (tile->GetObjectType() == TILE_MAP_ANIMATION_ID || + tile->GetObjectType() == TILE_MAP_ANIMATION_EX_ID || + tile->GetObjectType() == TILE_MAP_RESOURCE_ID) + { + index = SendMessage(hCB_AnimName, CB_FINDSTRING, -1, (LPARAM)tile->GetResName()); + if (index != -1) + SendMessage(hCB_AnimName, CB_SETCURSEL, index, 0); + } + + + index = SendMessage(hCB_TileType, CB_FINDSTRING, -1, (LPARAM)GetTileMapTypeName(tile->GetTileType())); + if (index != -1) + SendMessage(hCB_TileType, CB_SETCURSEL, index, 0); + } + } + + + int offset = 4; + if (hge->Input_GetKeyState(HGEK_S)) + { + map->VerticalScroll(offset); + } + if (hge->Input_GetKeyState(HGEK_W)) + { + map->VerticalScroll(offset*-1); + } + if (hge->Input_GetKeyState(HGEK_D)) + { + map->HorizontalScroll(offset); + } + if (hge->Input_GetKeyState(HGEK_A)) + { + map->HorizontalScroll(offset*-1); + } + + + return false; +} + + +bool RenderFunc() +{ + hge->Gfx_BeginScene(); + hge->Gfx_Clear(0); + + for (int i = 0; i < LAYERS; i++) + { + map->Render(i); + } + + hge->Gfx_EndScene(); + return false; +} + + +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR, int iCmdShow) +{ + MSG msg; + WNDCLASS wndclass; + char szHGEName[] = "HGE Workspace"; + + wndclass.style = CS_HREDRAW|CS_VREDRAW; + wndclass.lpfnWndProc = HGEProc; + wndclass.cbClsExtra = 0; + wndclass.cbWndExtra = 0; + wndclass.hInstance = hInstance; + wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); + wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); + wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);; + wndclass.lpszMenuName = NULL; + wndclass.lpszClassName = szHGEName; + + if ( !RegisterClass(&wndclass) ) + { + MessageBox(NULL, "Unable to open the HGE window!", szHGEName, MB_ICONERROR); + return 0; + } + + hwndHGE = CreateWindowEx(WS_EX_CLIENTEDGE, + szHGEName, + szHGEName, + WS_OVERLAPPEDWINDOW|WS_VISIBLE, + 15,128, + 1024,768, + NULL, + NULL, + hInstance, + NULL + ); + + if (hwndHGE == NULL) + { + MessageBox(NULL, "HGE Window Creation Failed!", "Error!", MB_ICONEXCLAMATION|MB_OK); + return 0; + } + + hButtonOk = CreateWindow("BUTTON", "OK", WS_VISIBLE|WS_CHILD|WS_TABSTOP|BS_DEFPUSHBUTTON, 808,250,80,30, hwndHGE, NULL, hInstance, NULL); + + hButtonDel = CreateWindow("BUTTON", "DELETE", WS_VISIBLE|WS_CHILD|WS_TABSTOP|BS_DEFPUSHBUTTON, 914,250,80,30, hwndHGE, NULL, hInstance, NULL); + hButtonLoad = CreateWindow("BUTTON", "Load", WS_VISIBLE|WS_CHILD|WS_TABSTOP|BS_DEFPUSHBUTTON, 937,610,60,30, hwndHGE, NULL, hInstance, NULL); + hButtonSave = CreateWindow("BUTTON", "Save", WS_VISIBLE|WS_CHILD|WS_TABSTOP|BS_DEFPUSHBUTTON, 937,640,60,30, hwndHGE, NULL, hInstance, NULL); + + hCB_ObjType = CreateWindowEx(WS_EX_CLIENTEDGE, "COMBOBOX", "", WS_VISIBLE|WS_CHILD|WS_TABSTOP|WS_VSCROLL|CBS_AUTOHSCROLL|CBS_DROPDOWNLIST, 804,10,200,500, hwndHGE, NULL, hInstance, NULL); + hCB_SprName = CreateWindowEx(WS_EX_CLIENTEDGE, "COMBOBOX", "", WS_VISIBLE|WS_CHILD|WS_TABSTOP|WS_VSCROLL|CBS_AUTOHSCROLL|CBS_DROPDOWNLIST, 804,40,200,500, hwndHGE, NULL, hInstance, NULL); + hCB_AnimName = CreateWindowEx(WS_EX_CLIENTEDGE, "COMBOBOX", "", WS_VISIBLE|WS_CHILD|WS_TABSTOP|WS_VSCROLL|CBS_AUTOHSCROLL|CBS_DROPDOWNLIST, 804,70,200,500, hwndHGE, NULL, hInstance, NULL); + hCB_TileType = CreateWindowEx(WS_EX_CLIENTEDGE, "COMBOBOX", "", WS_VISIBLE|WS_CHILD|WS_TABSTOP|WS_VSCROLL|CBS_AUTOHSCROLL|CBS_DROPDOWNLIST, 804,100,200,500, hwndHGE, NULL, hInstance, NULL); + hCB_PS1 = CreateWindowEx(WS_EX_CLIENTEDGE, "COMBOBOX", "", WS_VISIBLE|WS_CHILD|WS_TABSTOP|WS_VSCROLL|CBS_AUTOHSCROLL|CBS_DROPDOWNLIST, 804,130,200,500, hwndHGE, NULL, hInstance, NULL); + hCB_PS2 = CreateWindowEx(WS_EX_CLIENTEDGE, "COMBOBOX", "", WS_VISIBLE|WS_CHILD|WS_TABSTOP|WS_VSCROLL|CBS_AUTOHSCROLL|CBS_DROPDOWNLIST, 804,160,200,500, hwndHGE, NULL, hInstance, NULL); + hCB_ResType = CreateWindowEx(WS_EX_CLIENTEDGE, "COMBOBOX", "", WS_VISIBLE|WS_CHILD|WS_TABSTOP|WS_VSCROLL|CBS_AUTOHSCROLL|CBS_DROPDOWNLIST, 804,190,200,500, hwndHGE, NULL, hInstance, NULL); + + hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",WS_VISIBLE|WS_CHILD|WS_TABSTOP|ES_AUTOHSCROLL|ES_NUMBER, 870,300,80,30, hwndHGE, NULL, hInstance, NULL); + hEditLoad = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",WS_VISIBLE|WS_CHILD|WS_TABSTOP|ES_AUTOHSCROLL, 804,610,128,30, hwndHGE, NULL, hInstance, NULL); + hEditSave = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",WS_VISIBLE|WS_CHILD|WS_TABSTOP|ES_AUTOHSCROLL, 804,640,128,30, hwndHGE, NULL, hInstance, NULL); + + InitComboBoxTiles(); + InitComboBox1(); + InitComboBox2(); + InitComboBox3(); + InitComboBoxPS1(); + InitComboBoxPS2(); + InitComboBoxTileRes(); + + SetWindowText(hEdit, "0"); + + ShowWindow(hwndHGE, iCmdShow); + UpdateWindow(hwndHGE); + + RECT hgeClient; + GetClientRect(hwndHGE, &hgeClient); + + hge = hgeCreate(HGE_VERSION); + + hge->System_SetState(HGE_FRAMEFUNC, FrameFunc); + hge->System_SetState(HGE_RENDERFUNC, RenderFunc); + hge->System_SetState(HGE_USESOUND, false); + hge->System_SetState(HGE_WINDOWED, true); + hge->System_SetState(HGE_SCREENWIDTH, 800); + hge->System_SetState(HGE_SCREENHEIGHT, 768); + hge->System_SetState(HGE_SCREENBPP, 32); + hge->System_SetState(HGE_HIDEMOUSE, false); + hge->System_SetState(HGE_HWNDPARENT, hwndHGE ); + + if (hge->System_Initiate() ) + { + resource_manager = CreateResourceManager(); + resource_manager->ChangeScript("resource.rs"); + + InitMap(); + + while (true) + { + if(hge->System_GetState(HGE_HWND)) + hge->System_Start(); + + if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) + { + if(msg.message == WM_QUIT) + break; + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + } + + delete map; + + hge->System_Shutdown(); + hge->Release(); + + return 0; +} + +LRESULT CALLBACK HGEProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + HDC hdc; + PAINTSTRUCT ps; + + + switch (msg) + { + case WM_CREATE: + return 0; + + case WM_PAINT: + hdc = BeginPaint(hwnd, &ps); + EndPaint(hwnd, &ps); + return 0; + + case WM_DESTROY: + return 0; + + case WM_COMMAND: + if ((HWND)lParam == hButtonSave) + { + char *path = NULL; + int len = GetWindowTextLength(hEditSave)+1; + path = new char[len]; + GetWindowText(hEditSave, path, len); + map->Save(path); + delete[] path; + } + else if ((HWND)lParam == hButtonLoad) + { + char *path = NULL; + int len = GetWindowTextLength(hEditLoad)+1; + path = new char[len]; + GetWindowText(hEditLoad, path, len); + map->Load(path); + delete[] path; + } + else if ((HWND)lParam == hButtonOk) + { + char *spr_name = NULL, *anim_name = NULL, *ps_name1 = NULL, *ps_name2 = NULL; + int res_type = 0; + + int len = 0; + LRESULT tile_type = -1; + LRESULT obj_type = -1; + LRESULT cur_index = -1; + + cur_index = SendMessage(hCB_ObjType, CB_GETCURSEL, 0, 0); + obj_type = SendMessage(hCB_ObjType, CB_GETITEMDATA, cur_index, 0); + + cur_index = SendMessage(hCB_TileType, CB_GETCURSEL, 0, 0); + tile_type = SendMessage(hCB_TileType, CB_GETITEMDATA, cur_index, 0); + + len = GetWindowTextLength(hCB_SprName)+1; + spr_name = new char[len]; + + GetWindowText(hCB_SprName, spr_name, len); + if (strcmp("undefined", spr_name) == 0) + { + delete[] spr_name; + spr_name = NULL; + } + + if (obj_type == TILE_MAP_ANIMATION_ID || obj_type == TILE_MAP_ANIMATION_EX_ID || obj_type == TILE_MAP_RESOURCE_ID) + { + len = GetWindowTextLength(hCB_AnimName)+1; + anim_name = new char[len]; + GetWindowText(hCB_AnimName, anim_name, len); + if (strcmp("undefined", anim_name) == 0) + { + delete[] anim_name; + anim_name = NULL; + } + } + + if (obj_type == TILE_MAP_ANIMATION_EX_ID || obj_type == TILE_MAP_PARTICLE_ID || obj_type == TILE_MAP_RESOURCE_ID) + { + len = GetWindowTextLength(hCB_PS1)+1; + ps_name1 = new char[len]; + GetWindowText(hCB_PS1, ps_name1, len); + if (strcmp("undefined", ps_name1) == 0) + { + delete[] ps_name1; + ps_name1 = NULL; + } + } + + if (obj_type == TILE_MAP_RESOURCE_ID) + { + len = GetWindowTextLength(hCB_PS2)+1; + ps_name2 = new char[len]; + GetWindowText(hCB_PS2, ps_name2, len); + if (strcmp("undefined", ps_name2) == 0) + { + delete[] ps_name2; + ps_name2 = NULL; + } + } + + + if (obj_type == TILE_MAP_RESOURCE_ID) + { + len = GetWindowTextLength(hCB_ResType)+1; + char *str = new char[len]; + GetWindowText(hCB_ResType, str, len); + + if (strcmp(str, "RESOURCE_TYPES::LIFES") == 0) + { + res_type = RESOURCE_TYPES::LIFES; + } + else if (strcmp(str, "RESOURCE_TYPES::AID") == 0) + { + res_type = RESOURCE_TYPES::AID; + } + else if (strcmp(str, "RESOURCE_TYPES::ARMOUR") == 0) + { + res_type = RESOURCE_TYPES::ARMOUR; + } + } + + + hgeVector pos(32, 32); + pos.x += col*64; + pos.y += row*64; + + if (obj_type != -1) + { + map->DeleteTile(layer, row, col); + tile = NULL; + } + + switch (obj_type) + { + case TILE_MAP_ID: + tile = new TileMap(spr_name, pos, 32, 32, layer); + break; + case TILE_MAP_EXTENDED_ID: + tile = new TileMapEx(spr_name, pos, 32, 32, layer); + break; + case TILE_MAP_ANIMATION_ID: + tile = new TileMapAnimation(anim_name, pos, 32, 32, layer); + break; + case TILE_MAP_PARTICLE_ID: + tile = new TileMapParticle(spr_name, ps_name1, pos, 32, 32, layer); + break; + case TILE_MAP_ANIMATION_EX_ID: + tile = new TileMapAnimationEx(anim_name, ps_name1, pos, 32, 32, layer); + break; + case TILE_MAP_RESOURCE_ID: + tile = new TileMapResource(anim_name, ps_name1, ps_name2, pos, 32, 32, layer); + ((TileMapResource *)tile)->SetResourceType(res_type); + break; + } + + if (tile && -1 < tile_type) + { + tile->SetTileType(tile_type); + } + + if (tile) + { + tile->ShowTileQuad(true); + map->InsertTile(row, col, tile); + } + + delete[] spr_name; + delete[] anim_name; + delete[] ps_name1; + delete[] ps_name2; + } + break; + + case WM_LBUTTONDOWN: + mouse_pos.x = LOWORD(lParam); + mouse_pos.y = HIWORD(lParam); + break; + + default: + return DefWindowProc(hwnd, msg, wParam, lParam); + + } + + return 0; +} \ No newline at end of file diff --git a/options.h b/options.h new file mode 100644 index 0000000..e69de29