Implementats actors en Windows
This commit is contained in:
52
main.cpp
52
main.cpp
@@ -97,17 +97,23 @@ int StrToInt(const char* str) {
|
|||||||
|
|
||||||
#define UndoInc(var) (var = (var+1)%UNDO_MAX)
|
#define UndoInc(var) (var = (var+1)%UNDO_MAX)
|
||||||
#define UndoDec(var) (var = (var-1+UNDO_MAX)%UNDO_MAX)
|
#define UndoDec(var) (var = (var-1+UNDO_MAX)%UNDO_MAX)
|
||||||
void Undo_Create() {
|
void Undo_Create(const bool actor) {
|
||||||
unsigned char* dest = undo + (map_width*map_height*undo_pointer);
|
unsigned char* dest = undo + ((map_width*map_height+1)*undo_pointer);
|
||||||
memcpy(dest, map, map_width*map_height);
|
*dest = actor ? 1 : 0;
|
||||||
|
dest++;
|
||||||
|
unsigned char* src = actor ? map + (map_width*map_height) : map;
|
||||||
|
memcpy(dest, src, map_width*map_height);
|
||||||
}
|
}
|
||||||
void Undo_Restore() {
|
void Undo_Restore() {
|
||||||
unsigned char* src = undo + (map_width*map_height*undo_pointer);
|
unsigned char* src = undo + ((map_width*map_height+1)*undo_pointer);
|
||||||
memcpy(map, src, map_width*map_height);
|
const bool actor = (*src == 1);
|
||||||
|
src++;
|
||||||
|
unsigned char* dest = actor ? map + (map_width*map_height) : map;
|
||||||
|
memcpy(dest, src, map_width*map_height);
|
||||||
}
|
}
|
||||||
void Undo_Op() {
|
void Undo_Op(const bool actor = false) {
|
||||||
UndoInc(undo_pointer);
|
UndoInc(undo_pointer);
|
||||||
Undo_Create();
|
Undo_Create(actor);
|
||||||
undo_max = undo_pointer;
|
undo_max = undo_pointer;
|
||||||
if (undo_pointer == undo_min) UndoInc(undo_min);
|
if (undo_pointer == undo_min) UndoInc(undo_min);
|
||||||
}
|
}
|
||||||
@@ -211,22 +217,24 @@ void Init() {
|
|||||||
stbi_image_free(buffer);
|
stbi_image_free(buffer);
|
||||||
|
|
||||||
f = fopen(GetPath(map_filename), "rb");
|
f = fopen(GetPath(map_filename), "rb");
|
||||||
map = (unsigned char*)malloc(map_width*map_height);
|
map = (unsigned char*)calloc(map_width*map_height*2, 1);
|
||||||
undo = (unsigned char*)malloc(map_width*map_height*UNDO_MAX);
|
undo = (unsigned char*)malloc((map_width*map_height*UNDO_MAX)+UNDO_MAX);
|
||||||
if (f) {
|
if (f) {
|
||||||
int old_map_width = 0, old_map_height = 0;
|
int old_map_width = 0, old_map_height = 0;
|
||||||
fread(&old_map_width, 1, 1, f);
|
fread(&old_map_width, 1, 1, f);
|
||||||
fread(&old_map_height, 1, 1, f);
|
fread(&old_map_height, 1, 1, f);
|
||||||
if (old_map_width == map_width && old_map_height == map_height) {
|
if (old_map_width == map_width && old_map_height == map_height) {
|
||||||
fread(map, map_width*map_height, 1, f);
|
fread(map, map_width*map_height*2, 1, f);
|
||||||
} else {
|
} else {
|
||||||
unsigned char* old_map = (unsigned char*)malloc(old_map_width*old_map_height);
|
unsigned char* old_map = (unsigned char*)malloc(old_map_width*old_map_height);
|
||||||
fread(old_map, old_map_width*old_map_height, 1, f);
|
fread(old_map, old_map_width*old_map_height*2, 1, f);
|
||||||
for (int y = 0; y < map_height; y++) {
|
for (int y = 0; y < map_height; y++) {
|
||||||
for (int x = 0; x < map_width; x++) {
|
for (int x = 0; x < map_width; x++) {
|
||||||
map[x + y*map_width] = 0;
|
map[x + y*map_width] = 0;
|
||||||
|
map[(x + y*map_width)+(map_width*map_height)] = 0;
|
||||||
if (old_map_width > x && old_map_height > y && (x + y*map_width) < (old_map_width*old_map_height)) {
|
if (old_map_width > x && old_map_height > y && (x + y*map_width) < (old_map_width*old_map_height)) {
|
||||||
map[x + y*map_width] = old_map[x + y*(map_width)];
|
map[x + y*map_width] = old_map[x + y*(old_map_width)];
|
||||||
|
map[(x + y*map_width)+(map_width*map_height)] = old_map[(x + y*(old_map_width))+(old_map_width*old_map_height)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -238,7 +246,7 @@ void Init() {
|
|||||||
if (!f) { error = 3; return; }
|
if (!f) { error = 3; return; }
|
||||||
fwrite(&map_width, 1, 1, f);
|
fwrite(&map_width, 1, 1, f);
|
||||||
fwrite(&map_height, 1, 1, f);
|
fwrite(&map_height, 1, 1, f);
|
||||||
fwrite(map, map_width*map_height, 1, f);
|
fwrite(map, map_width*map_height*2, 1, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
dialog = 1;
|
dialog = 1;
|
||||||
}
|
}
|
||||||
@@ -448,6 +456,8 @@ void DoTileMap() {
|
|||||||
for (int x = 0; x < width_in_tiles; x++) {
|
for (int x = 0; x < width_in_tiles; x++) {
|
||||||
unsigned char tile = map[(map_x + x) + (map_y + y) * map_width];
|
unsigned char tile = map[(map_x + x) + (map_y + y) * map_width];
|
||||||
Draw(sdlTilesTexture, x*tile_width, y*tile_height, (tile % pal_width_in_tiles)*tile_width, (tile / pal_width_in_tiles)*tile_height, tile_width, tile_height);
|
Draw(sdlTilesTexture, x*tile_width, y*tile_height, (tile % pal_width_in_tiles)*tile_width, (tile / pal_width_in_tiles)*tile_height, tile_width, tile_height);
|
||||||
|
unsigned char sprite = map[((map_x + x) + (map_y + y) * map_width)+(map_width*map_height)];
|
||||||
|
if (sprite != 0 ) Draw(sdlTilesTexture, x*tile_width, y*tile_height, (sprite % pal_width_in_tiles)*tile_width, (sprite / pal_width_in_tiles)*tile_height, tile_width, tile_height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -471,7 +481,19 @@ void DoTileMap() {
|
|||||||
|
|
||||||
if (mouse.mouse_down[MOUSE_BUTTON_LEFT] || mouse.mouse_down[MOUSE_BUTTON_RIGHT]) { Undo_Op(); }
|
if (mouse.mouse_down[MOUSE_BUTTON_LEFT] || mouse.mouse_down[MOUSE_BUTTON_RIGHT]) { Undo_Op(); }
|
||||||
if (mouse.buttons[MOUSE_BUTTON_RIGHT]) { map[(map_x + cur_x) + (map_y + cur_y)*map_width] = tile_back; }
|
if (mouse.buttons[MOUSE_BUTTON_RIGHT]) { map[(map_x + cur_x) + (map_y + cur_y)*map_width] = tile_back; }
|
||||||
if (mouse.buttons[MOUSE_BUTTON_LEFT]) { map[(map_x + cur_x) + (map_y + cur_y)*map_width] = tile_sel; }
|
if (mouse.buttons[MOUSE_BUTTON_LEFT]) {
|
||||||
|
const int pos = (map_x + cur_x) + (map_y + cur_y)*map_width;
|
||||||
|
if (keyboard[CTRL]) {
|
||||||
|
ignoreMouse = true;
|
||||||
|
if (map[pos + (map_width*map_height)] == 0) {
|
||||||
|
map[pos + (map_width*map_height)] = tile_sel;
|
||||||
|
} else {
|
||||||
|
map[pos + (map_width*map_height)] = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
map[pos] = tile_sel;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (mouse.buttons[MOUSE_BUTTON_MIDDLE]) { tile_sel = map[(map_x + cur_x) + (map_y + cur_y)*map_width]; }
|
if (mouse.buttons[MOUSE_BUTTON_MIDDLE]) { tile_sel = map[(map_x + cur_x) + (map_y + cur_y)*map_width]; }
|
||||||
|
|
||||||
if (keyJustPressed == SDL_SCANCODE_Z && keyboard[CTRL]) { Undo_Undo(); }
|
if (keyJustPressed == SDL_SCANCODE_Z && keyboard[CTRL]) { Undo_Undo(); }
|
||||||
@@ -485,7 +507,7 @@ void DoTileMap() {
|
|||||||
FILE* f = fopen(GetPath(map_filename), "wb");
|
FILE* f = fopen(GetPath(map_filename), "wb");
|
||||||
fwrite(&map_width, 1, 1, f);
|
fwrite(&map_width, 1, 1, f);
|
||||||
fwrite(&map_height, 1, 1, f);
|
fwrite(&map_height, 1, 1, f);
|
||||||
fwrite(map, map_width*map_height, 1, f);
|
fwrite(map, map_width*map_height*2, 1, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
menu = false; ignoreMouse = true;
|
menu = false; ignoreMouse = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,7 +94,7 @@
|
|||||||
<ResourceCompile Include="res.rc" />
|
<ResourceCompile Include="res.rc" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Image Include="..\..\..\Users\Raimon\Dropbox\jailgames2016\Rise of the Bal1\utils\mappy\mappy.ico" />
|
<Image Include="..\..\..\Users\Raimon\Dropbox\jailgames2016\volcano\utils\mappy\mappy.ico" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
</ResourceCompile>
|
</ResourceCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Image Include="..\..\..\Users\Raimon\Dropbox\jailgames2016\Rise of the Bal1\utils\mappy\mappy.ico">
|
<Image Include="..\..\..\Users\Raimon\Dropbox\jailgames2016\volcano\utils\mappy\mappy.ico">
|
||||||
<Filter>Resource Files</Filter>
|
<Filter>Resource Files</Filter>
|
||||||
</Image>
|
</Image>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user