- First commit
This commit is contained in:
301
habitacions.cpp
Normal file
301
habitacions.cpp
Normal file
@@ -0,0 +1,301 @@
|
||||
#include "habitacions.h"
|
||||
|
||||
//uses
|
||||
// uMain;
|
||||
|
||||
// THab
|
||||
|
||||
// THab - Constructor
|
||||
|
||||
THab::THab(std::string p_FitxerMapa)
|
||||
{
|
||||
Jump = false;
|
||||
//VGA = p_VGA;
|
||||
//Grafx = p_Grafx;
|
||||
FitxerMapa = p_FitxerMapa;
|
||||
HabitacioActual = START_ROOM;
|
||||
Animacio = 0;
|
||||
LoadMap;
|
||||
Grafx.Items[GFX_TILES].Picture.LoadFromFile(PATH+Habitacions[HabitacioActual].BMP);
|
||||
Grafx.Items[GFX_TILES].Restore;
|
||||
}
|
||||
|
||||
|
||||
// THab - Destructor
|
||||
|
||||
THab::~THab()
|
||||
{
|
||||
// pumba pumba pinyau catacroc!!!
|
||||
};
|
||||
|
||||
|
||||
// { THab - Private }
|
||||
|
||||
void THab::LoadMap()
|
||||
{
|
||||
FILE *f;
|
||||
f = fopen(FitxerMapa.c_str(), "rb");
|
||||
for (int i=0; i<MAX_HABITACIONS; ++i) {
|
||||
char buffer[33];
|
||||
fread(buffer, 33, 1, f);
|
||||
for (int j=0; j<buffer[0]; ++j) Habitacions[i].Nom[j] = buffer[i+1];
|
||||
Habitacions[i].Zona = fgetc(f);
|
||||
fread(Habitacions[i].Mapa, MAX_X*MAX_Y*MAX_Z, 1, f);
|
||||
fread(Habitacions[i].Flags, MAX_X*MAX_Y*MAX_Z, 1, f);
|
||||
fread(buffer, 33, 1, f);
|
||||
for (int j=0; j<buffer[0]; ++j) Habitacions[i].BMP[j] = buffer[i+1];
|
||||
fread(Habitacions[i].Portes, 6, 1, f);
|
||||
fread(Habitacions[i].Actors, sizeof(TActor)*MAX_ACTORS, 1, f);
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
|
||||
//{ THab - Public }
|
||||
|
||||
void THab::PintaMapa()
|
||||
{
|
||||
Llums : array[0..10] of TActor;
|
||||
|
||||
uint8_t NumLlums = 0;
|
||||
|
||||
// Pintem el fondo
|
||||
Grafx.Items[GFX_FONDO].Draw(VGA.Surface,0,0,0);
|
||||
|
||||
// Comencem els bucles locos
|
||||
for (int c_i=0; c_i<MAX_X; c_i++)
|
||||
{
|
||||
int c_x = c_i; int c_y = 0;
|
||||
do {
|
||||
for (int c_z=0; c_z<MAX_Z; c_z++)
|
||||
{
|
||||
int x = (144)-(c_x << 4)+(c_y << 4);
|
||||
int y = (42) +(c_x << 3)+(c_y << 3) - (c_z*TILE_Z);
|
||||
int z = (Habitacions[HabitacioActual].Flags[c_x][c_y][c_z] & FLAG_ANIMAT == FLAG_ANIMAT) ? Animacio : 0;
|
||||
if (Habitacions[HabitacioActual].Mapa[c_x][c_y][c_z] > 2)
|
||||
Grafx.Items[GFX_TILES].Draw(VGA.Surface,x,y,Habitacions[HabitacioActual].Mapa[c_x][c_y][c_z]+z);
|
||||
|
||||
for (int ActorPointer=0; ActorPointer<MAX_ACTORS; ActorPointer++)
|
||||
{
|
||||
if ((Sombres[ActorPointer].TileX == c_x) &&
|
||||
(Sombres[ActorPointer].TileY == c_y) &&
|
||||
(Sombres[ActorPointer].TileZ == c_z) )
|
||||
Grafx.Items[GFX_SPRITES].DrawAlpha(VGA.Surface,Rect(Sombres[ActorPointer].X-2,Sombres[ActorPointer].Y-4,Sombres[ActorPointer].X+30,Sombres[ActorPointer].Y+28),Sombres[ActorPointer].Frame,100);
|
||||
|
||||
if (Sprites[ActorPointer].TileX = c_x) and
|
||||
(Sprites[ActorPointer].TileY = c_y) and
|
||||
(Sprites[ActorPointer].TileZ = c_z) then
|
||||
{
|
||||
Grafx.Items[GFX_SPRITES].Draw(VGA.Surface,Sprites[ActorPointer].X,Sprites[ActorPointer].Y-4,Sprites[ActorPointer].Frame+FRAMES_ACTORS[Sprites[ActorPointer].Tipus]);
|
||||
if (Habitacions[HabitacioActual].Flags[c_x,c_y,c_z-1] and FLAG_SOMBRA = FLAG_SOMBRA) then
|
||||
Grafx.Items[GFX_SPRITES].DrawSub(VGA.Surface,Rect(Sprites[ActorPointer].X,Sprites[ActorPointer].Y-4,Sprites[ActorPointer].X+32,Sprites[ActorPointer].Y+28),Sprites[ActorPointer].Frame+FRAMES_ACTORS[Sprites[ActorPointer].Tipus],150);
|
||||
};
|
||||
};
|
||||
{ If (Habitacions[HabitacioActual].Mapa[c_x,c_y,c_z] = 55) then
|
||||
{
|
||||
Llums[NumLlums].x = x; Llums[NumLlums].y = y;
|
||||
inc(NumLlums);
|
||||
};}
|
||||
};
|
||||
dec(c_x); inc(c_y);
|
||||
} while ( (c_x != -1) || (c_y != c_i+1) );
|
||||
};
|
||||
|
||||
// Comencem els bucles locos
|
||||
For c_i = 1 to MAX_Y-1 do
|
||||
{
|
||||
c_x = MAX_X-1; c_y = c_i;
|
||||
repeat
|
||||
For c_z = 0 to MAX_Z-1 do
|
||||
{
|
||||
X = (144)-(c_x shl 4)+(c_y shl 4);
|
||||
Y = (42) +(c_x shl 3)+(c_y shl 3) - (c_z*TILE_Z);
|
||||
if (Habitacions[HabitacioActual].Flags[c_x,c_y,c_z] and FLAG_ANIMAT = FLAG_ANIMAT) then z = Animacio else z = 0;
|
||||
if (Habitacions[HabitacioActual].Mapa[c_x,c_y,c_z] > 2) then
|
||||
Grafx.Items[GFX_TILES].Draw(VGA.Surface,x,y,Habitacions[HabitacioActual].Mapa[c_x,c_y,c_z]+z);
|
||||
|
||||
for ActorPointer = 0 to MAX_ACTORS do
|
||||
{
|
||||
if (Sombres[ActorPointer].TileX = c_x) and
|
||||
(Sombres[ActorPointer].TileY = c_y) and
|
||||
(Sombres[ActorPointer].TileZ = c_z) then
|
||||
Grafx.Items[GFX_SPRITES].DrawAlpha(VGA.Surface,Rect(Sombres[ActorPointer].X-2,Sombres[ActorPointer].Y-4,Sombres[ActorPointer].X+30,Sombres[ActorPointer].Y+28),Sombres[ActorPointer].Frame,100);
|
||||
|
||||
if (Sprites[ActorPointer].TileX = c_x) and
|
||||
(Sprites[ActorPointer].TileY = c_y) and
|
||||
(Sprites[ActorPointer].TileZ = c_z) then
|
||||
{
|
||||
Grafx.Items[GFX_SPRITES].Draw(VGA.Surface,Sprites[ActorPointer].X,Sprites[ActorPointer].Y-4,Sprites[ActorPointer].Frame+FRAMES_ACTORS[Sprites[ActorPointer].Tipus]);
|
||||
if (Habitacions[HabitacioActual].Flags[c_x,c_y,c_z-1] and FLAG_SOMBRA = FLAG_SOMBRA) then
|
||||
Grafx.Items[GFX_SPRITES].DrawSub(VGA.Surface,Rect(Sprites[ActorPointer].X,Sprites[ActorPointer].Y-4,Sprites[ActorPointer].X+32,Sprites[ActorPointer].Y+28),Sprites[ActorPointer].Frame+FRAMES_ACTORS[Sprites[ActorPointer].Tipus],150);
|
||||
};
|
||||
};
|
||||
|
||||
{ If (Habitacions[HabitacioActual].Mapa[c_x,c_y,c_z] = 55) then
|
||||
{
|
||||
Llums[NumLlums].x = x; Llums[NumLlums].y = y;
|
||||
inc(NumLlums);
|
||||
};}
|
||||
};
|
||||
dec(c_x); inc(c_y);
|
||||
until (c_x = c_i-1) and (c_y = MAX_Y);
|
||||
};
|
||||
|
||||
// if NumLlums > 0 then For i = 0 to NumLlums-1 do
|
||||
// Grafx.Items[GFX_SPRITES].DrawAdd(VGA.Surface,Rect(Llums[i].x,Llums[i].y-8,Llums[i].x+32,Llums[i].y+24),17,150);
|
||||
|
||||
try
|
||||
VGA.Surface.Canvas.Brush.Style = bsClear;
|
||||
VGA.Surface.Canvas.Font.Color = $FFFFFF;
|
||||
// VGA.Surface.Canvas.TextOut(20,10,inttostr(Sprites[0].TileX)+','+inttostr(Sprites[0].TileY)+','+inttostr(Sprites[0].TileZ));
|
||||
// VGA.Surface.Canvas.TextOut(20,20,inttostr(Sprites[0].TPixX)+','+inttostr(Sprites[0].TPixY)+','+inttostr(Sprites[0].TPixZ));
|
||||
VGA.Surface.Canvas.TextOut(20,10,inttostr(Form1.PatMan.GetInfo.TileX)+','+inttostr(Form1.PatMan.GetInfo.TileY)+','+inttostr(Form1.PatMan.GetInfo.TileZ));
|
||||
VGA.Surface.Canvas.TextOut(20,20,inttostr(Form1.PatMan.GetInfo.TPixX)+','+inttostr(Form1.PatMan.GetInfo.TPixY)+','+inttostr(Form1.PatMan.GetInfo.TPixZ));
|
||||
VGA.Surface.Canvas.TextOut(20,220,'PatMan v'+NUM_VERSIO);
|
||||
finally
|
||||
VGA.Surface.Canvas.Release;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
void THab::{Update;
|
||||
var
|
||||
i : byte;
|
||||
{
|
||||
if Animacio = 3 then Animacio = 0 else inc(Animacio);
|
||||
for i = 0 to MAX_ACTORS do
|
||||
{
|
||||
Sprites[i].TileX = 20;
|
||||
Sprites[i].TileY = 20;
|
||||
Sprites[i].TileZ = 20;
|
||||
Sprites[i].X = 0;
|
||||
Sprites[i].Y = 0;
|
||||
Sprites[i].Frame = 0;
|
||||
};
|
||||
};
|
||||
|
||||
void THab::}Update;
|
||||
var
|
||||
temp : TSpriteInfo;
|
||||
punter : byte;
|
||||
menor : byte;
|
||||
i,j : byte;
|
||||
{
|
||||
// ordenem en Z
|
||||
for i = 0 to MAX_ACTORS do
|
||||
{
|
||||
punter = i; menor = i;
|
||||
for j = i to MAX_ACTORS do if Sprites[menor].TileZ > Sprites[j].TileZ then menor = j;
|
||||
temp = Sprites[punter]; Sprites[punter] = Sprites[menor]; Sprites[menor] = temp;
|
||||
};
|
||||
|
||||
// ordenem en X
|
||||
for i = 0 to MAX_ACTORS do
|
||||
{
|
||||
punter = i; menor = i;
|
||||
for j = i to MAX_ACTORS do if Sprites[menor].TileX > Sprites[j].TileX then menor = j;
|
||||
temp = Sprites[punter]; Sprites[punter] = Sprites[menor]; Sprites[menor] = temp;
|
||||
};
|
||||
|
||||
// ordenem en Y
|
||||
for i = 0 to MAX_ACTORS do
|
||||
{
|
||||
punter = i; menor = i;
|
||||
for j = i to MAX_ACTORS do if Sprites[menor].TileY > Sprites[j].TileY then menor = j;
|
||||
temp = Sprites[punter]; Sprites[punter] = Sprites[menor]; Sprites[menor] = temp;
|
||||
};
|
||||
Jump = false;
|
||||
|
||||
For i = 0 to MAX_ACTORS do
|
||||
{
|
||||
//i = 0;
|
||||
Sombres[i] = Sprites[i];
|
||||
Sombres[i].Frame = 16;
|
||||
while (Habitacions[HabitacioActual].Mapa[Sombres[i].TileX, Sombres[i].TileY, Sombres[i].TileZ-1] = 0) and not(Sombres[i].TileZ-1 = 0) and ((Form1.Actors.CheckMalos(Sombres[i])<14) or (Form1.Actors.CheckMalos(Sombres[i])>23)) do
|
||||
{
|
||||
dec(Sombres[i].TileZ); inc(Sombres[i].Y,7);
|
||||
};
|
||||
if Sombres[i].TPixZ mod 4 <> 0 then inc(Sombres[i].Y,4);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
void THab::EnviaInfoSprite(num: byte; Info: TSpriteInfo);
|
||||
{
|
||||
Sprites[num] = Info;
|
||||
if num <> 0 then exit;
|
||||
if (Sprites[0].TileX = 0) and (Habitacions[HabitacioActual].Portes[1] <> 0) then
|
||||
{
|
||||
HabitacioActual = Habitacions[HabitacioActual].Portes[1];
|
||||
Grafx.Items[GFX_TILES].Picture.LoadFromFile(PATH+Habitacions[HabitacioActual].BMP);
|
||||
Grafx.Items[GFX_TILES].Restore;
|
||||
Jump = true;
|
||||
};
|
||||
if (Sprites[0].TileX = 11) and (Habitacions[HabitacioActual].Portes[4] <> 0) then
|
||||
{
|
||||
HabitacioActual = Habitacions[HabitacioActual].Portes[4];
|
||||
Grafx.Items[GFX_TILES].Picture.LoadFromFile(PATH+Habitacions[HabitacioActual].BMP);
|
||||
Grafx.Items[GFX_TILES].Restore;
|
||||
Jump = true;
|
||||
};
|
||||
if (Sprites[0].TileY = 0) and (Habitacions[HabitacioActual].Portes[5] <> 0) then
|
||||
{
|
||||
HabitacioActual = Habitacions[HabitacioActual].Portes[5];
|
||||
Grafx.Items[GFX_TILES].Picture.LoadFromFile(PATH+Habitacions[HabitacioActual].BMP);
|
||||
Grafx.Items[GFX_TILES].Restore;
|
||||
Jump = true;
|
||||
};
|
||||
if (Sprites[0].TileY = 11) and (Habitacions[HabitacioActual].Portes[2] <> 0) then
|
||||
{
|
||||
HabitacioActual = Habitacions[HabitacioActual].Portes[2];
|
||||
Grafx.Items[GFX_TILES].Picture.LoadFromFile(PATH+Habitacions[HabitacioActual].BMP);
|
||||
Grafx.Items[GFX_TILES].Restore;
|
||||
Jump = true;
|
||||
};
|
||||
if (Sprites[0].TileZ = 0) and (Habitacions[HabitacioActual].Portes[3] <> 0) then
|
||||
{
|
||||
HabitacioActual = Habitacions[HabitacioActual].Portes[3];
|
||||
Grafx.Items[GFX_TILES].Picture.LoadFromFile(PATH+Habitacions[HabitacioActual].BMP);
|
||||
Grafx.Items[GFX_TILES].Restore;
|
||||
Jump = true;
|
||||
};
|
||||
if (Sprites[0].TileZ = 9) and (Habitacions[HabitacioActual].Portes[0] <> 0) then
|
||||
{
|
||||
HabitacioActual = Habitacions[HabitacioActual].Portes[0];
|
||||
Grafx.Items[GFX_TILES].Picture.LoadFromFile(PATH+Habitacions[HabitacioActual].BMP);
|
||||
Grafx.Items[GFX_TILES].Restore;
|
||||
Jump = true;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
function THab::PucPasar(x, y, z: byte): boolean;
|
||||
{
|
||||
Result = true;
|
||||
if (Habitacions[HabitacioActual].Mapa[x,y,z] <> 0) or
|
||||
(Habitacions[HabitacioActual].Mapa[x,y,Min(z+1,9)] <> 0) or
|
||||
(Habitacions[HabitacioActual].Mapa[x,y,Min(z+2,9)] <> 0) or
|
||||
(Habitacions[HabitacioActual].Mapa[x,y,Min(z+3,9)] <> 0) then result = false;
|
||||
};
|
||||
|
||||
|
||||
function THab::DonamElsFlags(x, y, z: byte): byte;
|
||||
{
|
||||
result = Habitacions[HabitacioActual].Flags[x,y,z-1];
|
||||
};
|
||||
|
||||
|
||||
function THab::GetHabitacioActual: byte;
|
||||
{
|
||||
result = HabitacioActual;
|
||||
};
|
||||
|
||||
|
||||
function THab::GetActorsInfo : TActors;
|
||||
{
|
||||
result = Habitacions[HabitacioActual].Actors;
|
||||
};
|
||||
|
||||
|
||||
}.
|
||||
Reference in New Issue
Block a user