Editor De Mapas Src
Enviado por ASDFASCIIASDF • 28 de Mayo de 2013 • 3.225 Palabras (13 Páginas) • 385 Visitas
#include "allegro5/allegro_font.h"
#include "allegro5/allegro_ttf.h"
#include "allegro5/allegro_native_dialog.h"
#include "src/base.h"
#include "src/button.h"
#include "src/mapa.h"
/*#define bbox_collision(x1,y1,w1,h1,x2,y2,w2,h2) (!( ((x1)>=(x2)+(w2)) || ((x2)>=(x1)+(w1)) || \
((y1)>=(y2)+(h2)) || ((y2)>=(y1)+(h1)) )) */
using namespace std;
ALLEGRO_DISPLAY *display;
ALLEGRO_TIMER *timer;
ALLEGRO_EVENT_QUEUE *event_queue;
ALLEGRO_EVENT event;
ALLEGRO_BITMAP *screen;
ALLEGRO_BITMAP *bTexturasGame1[48];
ALLEGRO_BITMAP *_button[9];
ALLEGRO_BITMAP *bLetras[64];
//ALLEGRO_BITMAP *_numeros[10];
ALLEGRO_FONT *font;
//const int pixel = 32;
const int width = pixel*35;
const int height = pixel*21;
//const int columna = 40, fila = 25;
const int screenWidth = pixel*23;
const int screenHeight = pixel*18;
const char letra[65] = {"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNPOQRSTUVWXYZ:.0123456789"};
bool eliminar = 0, enter = 0, guardaMapa = 0,guardaImagen= 0;
void set_texturas_to_mapTexturas( MAP_TEXTURAS *map_texturas, ALLEGRO_BITMAP *bitmap[] ){
for(int i= 0; i < map_texturas->numTexts ; i++){
al_set_target_bitmap( map_texturas->textura[i] );
al_draw_bitmap(bitmap[i], 0, 0, 0);
}
al_set_target_bitmap(al_get_backbuffer(display) );
}
void resaltar_cursor_on_matriz( Coord mousePosition, Coord mapPosition, int col, int fil,int pix ){
int i = 0, j= 0;
if( mousePosition.x >= mapPosition.x && mousePosition.y >= mapPosition.y)
if( check_collision_mouse_with_map( mousePosition, mapPosition, col, fil,pix , j, i) ){
al_draw_rectangle( mapPosition.x + j*pix, mapPosition.y + i*pix,
(mapPosition.x + j*pix)+pix, (mapPosition.y + i*pix)+pix, al_map_rgb(200,0,0), 0);
}
}
void dibujar_cuadricula_matriz(int x, int y, int W, int H){
int i;
// Pinta lines Verticales
for( i = 0; i <= W; i++){
al_draw_line(pixel*i +x, 0+y, pixel*i+x, H*pixel+y , al_map_rgb(255, 255, 255),0 );
}
// Pinta lines horizontales
for( i = 0; i <= H; i++){
al_draw_line(0+x , pixel*i+y, W*pixel+x , pixel*i+ y, al_map_rgb(255, 255, 255),0 );
}
}
void copiar_imagen_a_escala(ALLEGRO_BITMAP *copia, ALLEGRO_BITMAP *pega, int escalaW, int escalaH ){
al_set_target_bitmap (pega);
al_draw_scaled_bitmap(copia, 0,0, al_get_bitmap_width(copia), al_get_bitmap_height(copia)
,0,0, escalaW, escalaH,0);
al_set_target_bitmap(al_get_backbuffer(display) );
}
void dibujar_mapa(const char tileMapa[fila][columna], const MAP_TEXTURAS texturasEditor, int textuValores[] ,int x = 0, int y = 0){
int i= 0, j = 0, k = 0;
for( i = 0; i < fila; i++){ // Se dibuja el mapa de tildes
for( j = 0; j < columna; j++){
for(k = 1; k < texturasEditor.fila *texturasEditor.columna+1; k++){
if(tileMapa[i][j] == k ){
if(textuValores[k-1] >= 0 && textuValores[k-1] < texturasEditor.fila*texturasEditor.columna ){
al_draw_bitmap(texturasEditor.textura[textuValores[k-1] ],x+ j*pixel, y+ i*pixel, 0 );
}
}
}
}
}
}
void SAVE_CURRENT_MAP_IMAGE (const char *dir_and_name, char currentMap[fila][columna],MAP_TEXTURAS currentTexturas, int textsValor[] ){
ALLEGRO_BITMAP *buffer = al_create_bitmap(columna*pixel, fila *pixel);
al_set_target_bitmap(buffer);
dibujar_mapa(currentMap, currentTexturas, textsValor);
al_save_bitmap(dir_and_name, buffer);
al_destroy_bitmap(buffer);
al_set_target_bitmap( al_get_backbuffer(display) );
};
void SAVE_CURRENT_MAP(const char *dir_and_name, char tileMapa[fila][columna] ){
std::ofstream fout(dir_and_name);
fout << columna<<" "<< fila ;
for(int i= 0; i < fila; i++){
fout << std::endl;
for(int j= 0; j < columna; j++){
fout << int (tileMapa[i][j] )<<" ";
}
}
}
class PALABRA{
public:
PALABRA( int _tam = 1);
~PALABRA();
void reiniciar(int _tam);
//friend void imprimir(const PALABRA);
//friend void ingresar(PALABRA &);
int tam, cont;
char *palabra;
};
PALABRA::PALABRA(int _tam ){
tam = _tam;
palabra = new char[tam];
cont = 0;
palabra[cont] = '_';
for(int j=1; j < tam; j++)
palabra[j] = char(8);
palabra[tam] = ' ';
}
PALABRA::~PALABRA(){
delete []palabra;
}
void PALABRA::reiniciar(int _tam){
delete []palabra;
tam = _tam;
palabra = new char[tam];
cont = 0;
palabra[cont] = '_';
for(int j=1; j < tam; j++)
palabra[j] = char(8);
palabra[tam] = ' ';
}
void ingresar_texto(PALABRA &texto , char caract ){
texto.palabra[texto.cont] = caract;
if( texto.cont+1 < texto.tam ) texto.cont++;
if( texto.cont < texto.tam-1)texto.palabra[texto.cont] = '_';
}
void ingresar_cadena(PALABRA &cadena, MAP_TEXTURAS *letras,MOUSE_STATE mouse,bool &bloqueado ,int x = 0, int y = 0){
bool finalizado = 0;
for(int i= 0; i <= cadena.tam; i++){
if(cadena.palabra[i] == '\0') finalizado = 1;
}
if(!finalizado){
letras->actualizar( mouse );
if(enter){
if(cadena.cont == cadena.tam-1 ) cadena.palabra[cadena.tam] = '\0';
else cadena.palabra[cadena.cont] = '\0';
}
else if(letras->sobre && mouse.button.IZQ && !bloqueado ){
ingresar_texto(cadena,
...