es en esa linea pero el tamano es fijo.
for(int col = 0; col < map[row].length; col++)
for(int col = 0; col < mapheight; col++)
for(int col = 0; col < map[row].length; col++)
for(int col = 0; col < mapheight; col++)
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menú
TileMap(String s,int size)
{
tilesize = size;
try
{
BufferedReader br = new BufferedReader(new FileReader(s));
mapwidth = Integer.parseInt(br.readLine());
mapheight = Integer.parseInt(br.readLine());
System.out.printf("width [%d], height[%d]",mapwidth , mapheight);
map = new int[mapheight][mapwidth];
System.out.printf("Lenght [%d}",map.length);
String del = " ";
for(int row = 0;row < map.length ;row++ )
{
String line = br.readLine();
String[] tokens = line.split(del);
System.out.printf("Tokens [%s]\n", tokens);
///for(int col = 0; col < mapheight; col++)
for(int col = 0; col < map[row].length; col++)
{
System.out.printf("[%d],",Integer.parseInt(tokens[col]));
///eclipse me redirecciona aqui.
map[row][col] = Integer.parseInt(tokens[col]);
}
System.out.printf("\n");
}
br.close();
}catch(Exception e)
{
e.printStackTrace();
}
}
public void update()
{
}
public void draw(Graphics2D g)
{
for(int row = 0; row < map.length; row++)
{
for(int col= 0; col < map[row].length; col++)
{
int rc = map[row][col];
if(rc == 0)
{
g.setColor(Color.BLACK);
}
if(rc == 1)
{
g.setColor(Color.RED);
}
g.fillRect(x+col *tilesize, y + row * tilesize, tilesize, tilesize);
}
}
}
}
#include<SDL.h>
#include<cstdlib>
#include<ctime>
using namespace std;
void CopiarPantalla(SDL_Renderer *renderer, SDL_Rect start_pos[256],SDL_Texture *img)
{
for(unsigned int Drawers = 0; Drawers <255; Drawers++)
{
SDL_RenderCopy(renderer, img,NULL,&start_pos[Drawers]);
}
}
int main(int argc, char *argv[])
{
SDL_Rect player = {10,12,32,32};
SDL_Window *window = NULL;
SDL_Renderer *renderer = NULL;
int width = 0 ;
int height = 0 ;
bool Run = true;
SDL_Surface *unloaded = NULL;
SDL_Surface *opt_img = NULL;
SDL_Texture *img = NULL;
SDL_Event event;
SDL_DisplayMode mode;
unsigned int start = 0;
SDL_Rect start_pos[256];
SDL_Color color_pantalla = {0,0x12,0xa,0xff};
SDL_Rect fillRect;
if(SDL_Init(SDL_INIT_EVERYTHING) < 0 )
{
SDL_Log("Imposible Cargar SDL_INIT [%s]", SDL_GetError());
Run = false;
}
srand(time(NULL));
for(unsigned int initializer = 0; initializer <255; initializer++)
{
start_pos[initializer].x = 10 + rand() % width;
start_pos[initializer].y = 10 + rand() % height;
start_pos[initializer].w = 32;
start_pos[initializer].h = 32;
}
unloaded = SDL_LoadBMP("color.bmp");
if(unloaded == NULL)
{
SDL_Log("No se cargo el graficio");
Run = false;
}
else
{
opt_img = SDL_ConvertSurfaceFormat( unloaded, SDL_PIXELFORMAT_RGBA8888, NULL );
if(opt_img == NULL)
{
SDL_Log("Imposible optimizar");
Run = false;
}
}
if(Run == true)
{
//obtner el tamano de los valores de la pantalla.
if( SDL_GetCurrentDisplayMode( 0, &mode ) == 0 )
{
width = mode.w;
height = mode.h;
fillRect.w = width;
fillRect.h = height;
player.x = width /2;
player.y = height/2;
}
//crear la ventana SDL
window = SDL_CreateWindow("Neo.App",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,width, height, SDL_WINDOW_SHOWN);
if(window == NULL)
{
SDL_Log("Imposible crear la ventana ,[%s]", SDL_GetError());
Run = false;
}
else
{
Run = true;
}
if(Run == true)
{
renderer = SDL_CreateRenderer(window , -1 , SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if(renderer == NULL)
{
Run = false;
}
}
///Creamo la textura aqui.
SDL_SetColorKey(opt_img, SDL_TRUE, SDL_MapRGB(opt_img->format, 0,0,0));
img = SDL_CreateTextureFromSurface( renderer, opt_img);
///bucle principal.
while(Run)
{
start = SDL_GetTicks();
///pollEvent's
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
{
Run = false;
#ifdef _DEBUG_ENABLE
SDL_Log("se acabo");
#endif
}
if(event.type == SDL_KEYDOWN || event.type == SDL_FINGERDOWN)
{
if(event.type == SDL_FINGERDOWN)
{
color_pantalla.g +=32 ;
if(color_pantalla.g == 256)
{
color_pantalla.g = 0;
color_pantalla.r += 32;
color_pantalla.b += 64;
if(color_pantalla.r == 256)
color_pantalla.r = 0;
if(color_pantalla.b == 256)
color_pantalla.b = 0;
}
}
}
}//end event;
//update
for(unsigned int initializer = 0; initializer <255; initializer++)
{
start_pos[initializer].x = 10 + rand() % width;
start_pos[initializer].y = 10 + rand() % height;
start_pos[initializer].w = 32;
start_pos[initializer].h = 32;
}
//Draw
SDL_RenderClear(renderer);
SDL_SetRenderDrawColor( renderer, color_pantalla.r, color_pantalla.g, color_pantalla.b, color_pantalla.a);
SDL_RenderFillRect( renderer, &fillRect );
CopiarPantalla(renderer,start_pos,img);
SDL_RenderCopy(renderer, img,NULL,&player);
SDL_RenderPresent(renderer);
//FPS
}
}
return 0;
}
void Editor()
{
string filename;
cout <<"por favor ingrese el del fichero que va a editar"<<endl;
///analizar texto/
getline(cin , filename, '$');
for(string::iterator it =filename.begin(); it != filename.end(); it++)
{
if(*it == (char)13 || *it == (char)3)
cout <<"Salto de linea \n "<<endl;
else
cout << '\n' << *it <<endl; ///aqui me imprime todo los caracteres
///incluyendo los espacios y los enter
////solo es parte del codigo de la
//// asi que el nomnre lo pueden ignorar.....
}
}
void PrintSpace(unsgined int cnt)
{
for(auto e(0) : cnt )
cout <<( char ) 32;
}
#include...
////librerias esas estanbien incluida
///usare una funcion getTransaccionActual()
void CopiarFichero(){
int inFhandle;
int outFhandle;
int cnt;
int bytesLeidos;
int bytesEscrito;
TRAN_STRUCT stTran;
inFhandle = open("lect.dat", O_RDONLY);
outFhandle = open("lect.dat", O_WRONLY | O_CREAT);
if(inFhandle < 0 || outFhandle < 0)
{
LOG("Error abriendo el fichero");
/// si pudiera salir o hacer Ret ,aunque no hay salida en log
}
else
{
do{
bytesLeidos = read(inFhandle , (char *)&srTran, sizeof(srTran));
if(bytesLeidos == sizeof(srTran))
{
if(strcmp(srTran.code, "mivalor") != 0)
{
bytesEscritos = write(outFhandle , (char *)&srTran, sizeof(srTran));
}
else
{
////simplemente ignoro
}
}else
{
/////mas codigo para mostrar el error
}
}while(bytesLeidos == sizeof(srTran));
close(inFhandle);
close(outFhandle);'
}
////mas codgio
}