elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: AIO elhacker.NET 2021 Compilación herramientas análisis y desinfección malware


  Mostrar Mensajes
Páginas: [1]
1  Programación / Programación C/C++ / Re: Juego SDL en: 20 Agosto 2016, 02:30 am
Gracias, ahí lo solucione, con crear un par de vectores era suficiente jeje. Les dejo el código si alguien lo necesita.
Código
  1. #include <SDL/SDL.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. /* ********************************
  6.    *          .:La nave:.         *
  7.    *                              *
  8.    * Author: Joaquin Cortes       *
  9.    * Version: 0.0.1               *
  10.    * Name: La nave                *
  11.    * Language: C/C++              *
  12.    * Library: SDL                 *
  13.    *                              *
  14.    ******************************** */
  15.  
  16. #define WIDTH 800
  17. #define HEIGHT 600
  18. #define BTS 16
  19.  
  20. void iniciarSDL();
  21. void iniciarVideo();
  22. void transparencia();
  23. void imgFondo();
  24. void drawNave();
  25. void moverNave();
  26. void drawEnemiga();
  27. void moverEnemigo();
  28. void Colision();
  29.  
  30. /* Declaracion de variables */
  31. SDL_Surface *screen;
  32. SDL_Surface *nave;
  33. SDL_Surface *enemigo;
  34. SDL_Surface *fondo;
  35.  
  36. SDL_Rect destino;
  37. SDL_Rect destinoe[2];
  38. SDL_Rect destinoNave;
  39.  
  40. /* Posicion incial */
  41. int xNave = 320, yNave = 400;
  42. int xEne[2] = {320, 230};
  43. int yEne[2] = {40, 30};
  44.  
  45. /* Activar las teclas */
  46. Uint8* teclas;
  47.  
  48. int main(int argc, char *argv[])
  49. {
  50.    int terminado = 0;
  51.    SDL_Event suceso;
  52.    /*SDL_Rect clip_rect;*/
  53.  
  54.    iniciarSDL();
  55.  
  56.    /* Imagenes a mostrar */
  57.    fondo = SDL_LoadBMP("fondo.bmp");
  58.    nave = SDL_LoadBMP("nave.bmp");
  59.    enemigo = SDL_LoadBMP("enemigo.bmp");
  60.  
  61.    iniciarVideo();
  62.    transparencia();
  63.  
  64.    /* Cambiar titulo de la ventana (titulo, icono) */
  65.    SDL_WM_SetCaption("Joaquin Cortes", NULL);
  66.  
  67.    /* Gameloop, mientras que terminar sea igual a 0 hacer todo esto */
  68.    while(terminado == 0)
  69.    {
  70.  
  71.        imgFondo();
  72.        /*clip_rect.x = 100;
  73.         clip_rect.y = 100;
  74.         clip_rect.w = 300;
  75.         clip_rect.h = 580;
  76.  
  77.         [Sirve para crear un rectangulo en la pantalla]
  78.         SDL_SetClipRect(screen, &clip_rect);*/
  79.        drawNave();
  80.        drawEnemiga();
  81.  
  82.        Colision();
  83.        /* Actualizamos la pantalla */
  84.        SDL_Flip(screen);
  85.  
  86.        /* Miramos si hay algun suceso pendiente,
  87.             entre ellos, peticion de abandonar el programa
  88.             (pulsar la X de la ventana) o tecla ESC */
  89.        while(SDL_PollEvent(&suceso)){
  90.            if(suceso.type == SDL_QUIT)
  91.                terminado = 1;
  92.            if(suceso.type == SDL_KEYDOWN)
  93.                if(suceso.key.keysym.sym == SDLK_ESCAPE) terminado = 1;
  94.        }
  95.  
  96.        moverNave();
  97.        moverEnemigo();
  98.  
  99.        /* Esperamos 50 ms antes de repetir */
  100.        SDL_Delay(10);
  101.    }
  102.  
  103.    /* Finalmente, preparamos para salir */
  104.    SDL_Quit();
  105.    return 0;
  106. }
  107.  
  108. void iniciarSDL()
  109. {
  110.    /* Inicializamos la Biblioteca SDL */
  111.    if(SDL_Init(SDL_INIT_VIDEO) < 0){
  112.        printf("No se pudo inicializar SDL: %s\n", SDL_GetError());
  113.        exit(1);
  114.    }
  115. }
  116.  
  117. void iniciarVideo()
  118. {
  119.    /* Si todo va bien, hacemos esto:
  120.         entrar a modo grafico y cambiar el titulo de la ventana */
  121.    screen = SDL_SetVideoMode(WIDTH, HEIGHT, BTS, SDL_HWSURFACE);
  122.    if(screen == NULL){
  123.        printf("Error al entrar a modo grafico: %s\n", SDL_GetError());
  124.        SDL_Quit();
  125.    }
  126. }
  127.  
  128. void transparencia()
  129. {
  130.    /* transparencia nave */
  131.    SDL_SetColorKey(nave, SDL_SRCCOLORKEY,
  132.                    SDL_MapRGB(nave->format, 0,0,0));
  133.  
  134.    /* transparencia enemigo */
  135.    SDL_SetColorKey(enemigo, SDL_SRCCOLORKEY,
  136.                    SDL_MapRGB(enemigo->format, 0,0,0));
  137. }
  138.  
  139. void imgFondo()
  140. {
  141.    /*Dibujamos la imagen de fondo
  142.         Como tiene 207x211 pixeles, la repetimos varias veces */
  143.    int i, j;
  144.  
  145.    for(i=0; i<5; i++)
  146.    {
  147.        for(j=0; j<3; j++)
  148.        {
  149.            destino.x=207*i;
  150.            destino.y=211*j;
  151.            SDL_BlitSurface(fondo, NULL, screen, &destino);
  152.        }
  153.    }
  154. }
  155.  
  156. void drawNave()
  157. {
  158.    /* Dibujamos el nave */
  159.    destinoNave.x = xNave;
  160.    destinoNave.y = yNave;
  161.    destinoNave.w = 35;
  162.    destinoNave.h = 58;
  163.    SDL_BlitSurface(nave, NULL, screen, &destinoNave);
  164. }
  165.  
  166. void moverNave()
  167. {
  168.    /* Vemos el estado individual de las demas teclas */
  169.    teclas = SDL_GetKeyState(NULL);
  170.    if(teclas[SDLK_UP] && yNave > 0)
  171.        yNave -= 5;
  172.    if(teclas[SDLK_DOWN] && yNave < HEIGHT-45)
  173.        yNave += 5;
  174.    if(teclas[SDLK_LEFT] && xNave > 0)
  175.        xNave -= 5;
  176.    if(teclas[SDLK_RIGHT] && xNave < WIDTH-25)
  177.        xNave += 5;
  178. }
  179.  
  180. void drawEnemiga()
  181. {
  182.    int i;
  183.  
  184.    for(i=0; i<2; i++)
  185.    {
  186.        destinoe[i].w = 35;
  187.        destinoe[i].h = 58;
  188.        destinoe[i].x = xEne[i];
  189.        destinoe[i].y = yEne[i];
  190.        SDL_BlitSurface(enemigo, NULL, screen, &destinoe[i]);
  191.    }
  192. }
  193.  
  194. void moverEnemigo()
  195. {
  196.    int i;
  197.  
  198.    for(i=0; i<2; i++)
  199.    {
  200.        yEne[i] += 5;
  201.        if(destinoe[i].y == HEIGHT)
  202.            yEne[i] = 0;
  203.    }
  204. }
  205.  
  206. void Colision()
  207. {
  208.    int i;
  209.  
  210.    for(i=0; i<2; i++)
  211.    {
  212.        if(((destinoNave.x + destinoNave.w) > destinoe[i].x)
  213.            && ((destinoNave.y + destinoNave.h) > destinoe[i].y)
  214.            && ((destinoe[i].x + destinoe[i].w) > destinoNave.x)
  215.           && ((destinoe[i].y + destinoe[i].h) > destinoNave.y))
  216.        {
  217.            yEne[i] = 0;
  218.            yNave = 540;
  219.        }
  220.    }
  221. }

Otra cosa. ¿Algo que pueda mejorar? ya que arranque hace poco a programar videojuegos en C, y cualquier opinión sirve de ayuda.
2  Programación / Programación C/C++ / Juego SDL en: 19 Agosto 2016, 19:32 pm
Hola comunidad, esta programando el juego de la nave, pero no se me ocurre como aumentar las naves enemigas. Me puse a pensar y creo que puede ser creando una matriz, pero no se. Les dejo el código, talvez me puedan ayudar. Saludos.

Código
  1. #include <SDL/SDL.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. /* ********************************
  6.    *          .:La nave:.         *
  7.    *                              *
  8.    * Author: Joaquin Cortes       *
  9.    * Version: 0.0.1               *
  10.    * Name: La nave                *
  11.    * Language: C/C++              *
  12.    * Library: SDL                 *
  13.    *                              *
  14.    ******************************** */
  15.  
  16. #define WIDTH 800
  17. #define HEIGHT 600
  18. #define BTS 16
  19.  
  20. void iniciarSDL();
  21. void iniciarVideo();
  22. void transparencia();
  23. void imgFondo();
  24. void drawNave();
  25. void moverNave();
  26. void drawEnemiga();
  27. void moverEnemigo();
  28. void Colision();
  29.  
  30. /* Declaracion de variables */
  31. SDL_Surface *screen;
  32. SDL_Surface *nave;
  33. SDL_Surface *enemigo;
  34. SDL_Surface *fondo;
  35. SDL_Rect destino;
  36. SDL_Rect destinoe;
  37. SDL_Rect destinoNave;
  38.  
  39. /* Posicion incial */
  40. int xNave = 320, yNave = 400;
  41. int xEne = 320, yEne = 10;
  42.  
  43. /* Activar las teclas */
  44. Uint8* teclas;
  45.  
  46. int main(int argc, char *argv[])
  47. {
  48.    int terminado = 0;
  49.    SDL_Event suceso;
  50.    /*SDL_Rect clip_rect;*/
  51.  
  52.    iniciarSDL();
  53.  
  54.    /* Imagenes a mostrar */
  55.    fondo = SDL_LoadBMP("fondo.bmp");
  56.    nave = SDL_LoadBMP("nave.bmp");
  57.    enemigo = SDL_LoadBMP("enemigo.bmp");
  58.  
  59.    iniciarVideo();
  60.    transparencia();
  61.  
  62.    /* Cambiar titulo de la ventana (titulo, icono) */
  63.    SDL_WM_SetCaption("Joaquin Cortes", NULL);
  64.  
  65.    /* Gameloop, mientras que terminar sea igual a 0 hacer todo esto */
  66.    while(terminado == 0)
  67.    {
  68.  
  69.        imgFondo();
  70.        /*clip_rect.x = 100;
  71.         clip_rect.y = 100;
  72.         clip_rect.w = 300;
  73.         clip_rect.h = 580;
  74.  
  75.         [Sirve para crear un rectangulo en la pantalla]
  76.         SDL_SetClipRect(screen, &clip_rect);*/
  77.        drawNave();
  78.        drawEnemiga();
  79.  
  80.        Colision();
  81.        /* Actualizamos la pantalla */
  82.        SDL_Flip(screen);
  83.  
  84.        /* Miramos si hay algun suceso pendiente,
  85.             entre ellos, peticion de abandonar el programa
  86.             (pulsar la X de la ventana) o tecla ESC */
  87.        while(SDL_PollEvent(&suceso)){
  88.            if(suceso.type == SDL_QUIT)
  89.                terminado = 1;
  90.            if(suceso.type == SDL_KEYDOWN)
  91.                if(suceso.key.keysym.sym == SDLK_ESCAPE) terminado = 1;
  92.        }
  93.  
  94.        moverNave();
  95.        moverEnemigo();
  96.  
  97.        /* Esperamos 50 ms antes de repetir */
  98.        SDL_Delay(10);
  99.    }
  100.  
  101.    /* Finalmente, preparamos para salir */
  102.    SDL_Quit();
  103.    return 0;
  104. }
  105.  
  106. void iniciarSDL()
  107. {
  108.    /* Inicializamos la Biblioteca SDL */
  109.    if(SDL_Init(SDL_INIT_VIDEO) < 0){
  110.        printf("No se pudo inicializar SDL: %s\n", SDL_GetError());
  111.        exit(1);
  112.    }
  113. }
  114.  
  115. void iniciarVideo()
  116. {
  117.    /* Si todo va bien, hacemos esto:
  118.         entrar a modo grafico y cambiar el titulo de la ventana */
  119.    screen = SDL_SetVideoMode(WIDTH, HEIGHT, BTS, SDL_HWSURFACE);
  120.    if(screen == NULL){
  121.        printf("Error al entrar a modo grafico: %s\n", SDL_GetError());
  122.        SDL_Quit();
  123.    }
  124. }
  125.  
  126. void transparencia()
  127. {
  128.    /* transparencia nave */
  129.    SDL_SetColorKey(nave, SDL_SRCCOLORKEY,
  130.                    SDL_MapRGB(nave->format, 0,0,0));
  131.  
  132.    /* transparencia enemigo */
  133.    SDL_SetColorKey(enemigo, SDL_SRCCOLORKEY,
  134.                    SDL_MapRGB(enemigo->format, 0,0,0));
  135. }
  136.  
  137. void imgFondo()
  138. {
  139.    /*Dibujamos la imagen de fondo
  140.         Como tiene 207x211 pixeles, la repetimos varias veces */
  141.    int i, j;
  142.  
  143.    for(i=0; i<5; i++)
  144.    {
  145.        for(j=0; j<3; j++)
  146.        {
  147.            destino.x=207*i;
  148.            destino.y=211*j;
  149.            SDL_BlitSurface(fondo, NULL, screen, &destino);
  150.        }
  151.    }
  152. }
  153.  
  154. void drawNave()
  155. {
  156.    /* Dibujamos el nave */
  157.    destinoNave.x = xNave;
  158.    destinoNave.y = yNave;
  159.    destinoNave.w = 35;
  160.    destinoNave.h = 58;
  161.    SDL_BlitSurface(nave, NULL, screen, &destinoNave);
  162. }
  163.  
  164. void moverNave()
  165. {
  166.    /* Vemos el estado individual de las demas teclas */
  167.    teclas = SDL_GetKeyState(NULL);
  168.    if(teclas[SDLK_UP] && yNave > 0)
  169.        yNave -= 5;
  170.    if(teclas[SDLK_DOWN] && yNave < HEIGHT-45)
  171.        yNave += 5;
  172.    if(teclas[SDLK_LEFT] && xNave > 0)
  173.        xNave -= 5;
  174.    if(teclas[SDLK_RIGHT] && xNave < WIDTH-25)
  175.        xNave += 5;
  176. }
  177.  
  178. void drawEnemiga()
  179. {
  180.    destinoe.x = xEne;
  181.    destinoe.y = yEne;
  182.    destinoe.w = 35;
  183.    destinoe.h = 58;
  184.    SDL_BlitSurface(enemigo, NULL, screen, &destinoe);
  185. }
  186.  
  187. void moverEnemigo()
  188. {
  189.    yEne += 5;
  190.    if(destinoe.y == HEIGHT)
  191.        yEne = 0;
  192. }
  193.  
  194. void Colision()
  195. {
  196.    if(((destinoNave.x + destinoNave.w) > destinoe.x) && ((destinoNave.y + destinoNave.h) > destinoe.y) && ((destinoe.x + destinoe.w) > destinoNave.x) && ((destinoe.y + destinoe.h) > destinoNave.y))
  197.    {
  198.        yEne = 0;
  199.        yNave = 540;
  200.    }
  201. }
  202.  
3  Informática / Hardware / Mouse (Doble click) en: 4 Mayo 2016, 01:47 am
Hola, buenos dias. Tengo un problemas con mi mouse. Lo que sucede es que al hacer click el mouse como que hace 3 clicks más, estoy seguro que es un problema del mouse y no del software(razer synapse). Si alguien sabe lo que sucede me lo podría notificar y decir como se soluciona.

Desde ya muchas gracias :xD
4  Programación / Scripting / Re: ¿Como hago? [Python] en: 8 Enero 2016, 03:12 am
Mira, implemente el codigo ese, pero me marca que el archivo no se encuentra en el directorio, pero si esta el archivo .txt

Me marca la linea 10 y me tira este error:
Citar
IOError: [Errno 2] No such file or directory: 'Pastore.txt'

Código
  1. import os
  2.  
  3. while True:
  4.  
  5. path = 'C:\Users\Joaquin\Desktop\Programacion\Base\Jugadores'
  6. archivos= os.listdir(path)
  7. nombre=raw_input('Buscar:')+'.txt'
  8. os.system('cls')
  9. if nombre in archivos:
  10. mostrar = open(nombre, 'r')
  11. linea = mostrar.readline()
  12. while linea != '':
  13. print linea    
  14. linea = mostrar.readline()
  15. mostrar.close()
  16. else:
  17. print 'El jugador no se encuentra en el programa'



 Ya solucione el problema. Gracias.
5  Programación / Scripting / Re: ¿Como hago? [Python] en: 7 Enero 2016, 16:15 pm
No entiendo como hacer el for, hice esto mira.

Código
  1. import os
  2.  
  3. while True:
  4.  
  5. nombre = raw_input('Buscar: ')
  6. os.system('cls')
  7.  
  8. path = '/Jugadores/'
  9.  
  10. lstFiles = []
  11.  
  12. lstDir = os.walk(path)
  13.  
  14. for files in lstDir:
  15. for fichero in files:
  16. if nombre == lstDir:
  17. archi=open(fichero,'r')
  18. lineas=archi.readlines()
  19. for li in lineas:
  20. print li
  21. archi.close()
6  Programación / Scripting / ¿Como hago? [Python] en: 7 Enero 2016, 13:48 pm
Quisiera saber como hago para que al ingresar determinado nombre me busque el .txt que lleva ese nombre y me lo imprima en la pantalla. Les dejo el código que hice, lo quiero acortar para que directamente me busque el .txt que ingreso en la variable nombre.

Código
  1. import os
  2.  
  3. while True:
  4. nombre = raw_input('Buscar: ')
  5. os.system('cls')
  6. if nombre == 'J.Pastore':
  7. try:
  8. archi=open('Jugadores/Pastore.txt','r')
  9. lineas=archi.readlines()
  10. for li in lineas:
  11. print li
  12. archi.close()
  13. except IOError:
  14. print 'Ocurrio un error inesperado'
  15. elif nombre == 'C.Tevez':
  16. try:
  17. archi=open('Jugadores/Tevez.txt','r')
  18. lineas=archi.readlines()
  19. for li in lineas:
  20. print li
  21. archi.close()
  22. except IOError:
  23. print 'Ocurrio un error inesperado'
  24. elif nombre == 'L.Messi':
  25. try:
  26. archi=open('Jugadores/Messi.txt','r')
  27. lineas=archi.readlines()
  28. for li in lineas:
  29. print li
  30. archi.close()
  31. except IOError:
  32. print 'Ocurrio un error inesperado'
  33. elif nombre == 'E.Lavezzi':
  34. try:
  35. archi=open('Jugadores/Lavezzi.txt','r')
  36. lineas=archi.readlines()
  37. for li in lineas:
  38. print li
  39. archi.close()
  40. except IOError:
  41. print 'Ocurrio un error inesperado'
  42. elif nombre == 'Wanchope':
  43. try:
  44. archi=open('Jugadores/Wanchope.txt','r')
  45. lineas=archi.readlines()
  46. for li in lineas:
  47. print li
  48. archi.close()
  49. except IOError:
  50. print 'Ocurrio un error inesperado'
  51. elif nombre == 'exit':
  52. print "Gracias por utilizar nuestro programa"
  53. break
  54. else:
  55. print 'El jugador no se encuentra en el programa'
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines