1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
// (_||_/
// ( ) Classe Sprite
// ( o 0 )
//-OOO--(_)---OOO---------------------------------------
// Copyright (C) 2006 By Dominique Roux-Serret
// .OOOo oOOO. roux-serret@ifrance.com
//-( )------( )---------------------------------------
// ( ( ) / Le 3/04/2006
// (_) (_/
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 or version 3 of the License.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <iostream>
using namespace std;
#include <stdio.h>
#include <stdlib.h>
#include "preference.h"
#include "utils.h"
#include "tableau.h"
/*** Constructeurs ***/
/*********************/
Tableau::Tableau(void) : N(0)
{
int i;
for(i=0;i<MAX_N_LEVEL_IN_MEMORY;i++) Clear(i);
}
Tableau::~Tableau(void)
{
}
/*** Charge les tableaux ***/
/***************************/
bool Tableau::Load(void)
{
unsigned char *Buf;
long L,P=2;
int i,j;
char NameLevelFile[512]="levels.dat";
GetPath(NameLevelFile);
L=ChargeFichier(NameLevelFile,Buf);
if(L<=0) return false;
// Charge les tableaux
N=(int)(Buf[0])*256+(int)(Buf[1]);
for(i=0;i<N;i++) {
for(j=0;j<LT*HT;j++) T[i].T[j]=Buf[P++];
T[i].DepX=(int)(Buf[P])*256+(int)(Buf[P+1]);
T[i].DepY=(int)(Buf[P+2])*256+(int)(Buf[P+3]);
T[i].DepDir=(int)(Buf[P+4])*256+(int)(Buf[P+5]);
T[i].NDeco=(int)(Buf[P+6])*256+(int)(Buf[P+7]);
P+=8;
for(j=0;j<T[i].NDeco;j++) {
T[i].Deco[j].NumSpr=(int)(Buf[P])*256+(int)(Buf[P+1]);
T[i].Deco[j].x=(int)(Buf[P+2])*256+(int)(Buf[P+3]);
T[i].Deco[j].y=(int)(Buf[P+4])*256+(int)(Buf[P+5]);
P+=6;
}
}
delete [] Buf;
return true;
}
/*** Sauve les tableaux ***/
/**************************/
bool Tableau::Save(void)
{
unsigned char *Buf;
long P=2;
int i,j;
char NameLevelFile[512]="levels.dat";
// Alloue la mmoire
Buf=new unsigned char [sizeof(s_Tableau)*N+sizeof(int)+1];
if(Buf<=0) return false;
// Charge les tableaux
Buf[0]=N/256;
Buf[1]=N%256;
for(i=0;i<N;i++) {
for(j=0;j<LT*HT;j++) Buf[P++]=T[i].T[j];
Buf[P]=T[i].DepX/256;
Buf[P+1]=T[i].DepX%256;
Buf[P+2]=T[i].DepY/256;
Buf[P+3]=T[i].DepY%256;
Buf[P+4]=T[i].DepDir/256;
Buf[P+5]=T[i].DepDir%256;
Buf[P+6]=T[i].NDeco/256;
Buf[P+7]=T[i].NDeco%256;
P+=8;
for(j=0;j<T[i].NDeco;j++) {
Buf[P]=T[i].Deco[j].NumSpr/256;
Buf[P+1]=T[i].Deco[j].NumSpr%256;
Buf[P+2]=T[i].Deco[j].x/256;
Buf[P+3]=T[i].Deco[j].x%256;
Buf[P+4]=T[i].Deco[j].y/256;
Buf[P+5]=T[i].Deco[j].y%256;
P+=6;
}
}
// Sauve les tableaux
GetPath(NameLevelFile);
if(SauveFichier(NameLevelFile,(char*)Buf,P)==false) {
delete [] Buf;
return false;
}
delete [] Buf;
return true;
}
/*** Efface un Tableau ***/
/*************************/
void Tableau::Del(int Num)
{
int i,j;
if(Num<N) {
for(i=Num;i<N-1;i++) {
for(j=0;j<LT*HT;j++) T[i].T[j]=T[i+1].T[j];
T[i].DepX=T[i+1].DepX;
T[i].DepY=T[i+1].DepY;
T[i].DepDir=T[i+1].DepDir;
T[i].NDeco=T[i+1].NDeco;
for(j=0;j<T[i].NDeco;j++) {
T[i].Deco[j].x=T[i+1].Deco[j].x;
T[i].Deco[j].y=T[i+1].Deco[j].y;
T[i].Deco[j].NumSpr=T[i+1].Deco[j].NumSpr;
}
}
N--;
}
}
/*** Insert un Tableau ***/
/*************************/
void Tableau::Ins(int Num)
{
int i,j;
if(Num<N) {
for(i=N;i>Num;i--) {
for(j=0;j<LT*HT;j++) T[i].T[j]=T[i-1].T[j];
T[i].DepX=T[i-1].DepX;
T[i].DepY=T[i-1].DepY;
T[i].DepDir=T[i-1].DepDir;
T[i].NDeco=T[i-1].NDeco;
for(j=0;j<T[i].NDeco;j++) {
T[i].Deco[j].x=T[i-1].Deco[j].x;
T[i].Deco[j].y=T[i-1].Deco[j].y;
T[i].Deco[j].NumSpr=T[i-1].Deco[j].NumSpr;
}
}
Clear(Num);
N++;
}
}
/*** Vide un tableau ***/
/***********************/
void Tableau::Clear(int Num)
{
int i;
for(i=0;i<LT*HT;i++) T[Num].T[i]=C_None;
T[Num].DepX=LT/2;
T[Num].DepY=HT/2;
T[Num].NDeco=0;
}
|