|
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. #include <SDL/SDL.h> #include <stdio.h> #include <stdlib.h> /* ******************************** * .:La nave:. * * * * Author: Joaquin Cortes * * Version: 0.0.1 * * Name: La nave * * Language: C/C++ * * Library: SDL * * * ******************************** */ #define WIDTH 800 #define HEIGHT 600 #define BTS 16 void iniciarSDL(); void iniciarVideo(); void transparencia(); void imgFondo(); void drawNave(); void moverNave(); void drawEnemiga(); void moverEnemigo(); void Colision(); /* Declaracion de variables */ SDL_Surface *screen; SDL_Surface *nave; SDL_Surface *enemigo; SDL_Surface *fondo; SDL_Rect destino; SDL_Rect destinoe[2]; SDL_Rect destinoNave; /* Posicion incial */ int xNave = 320, yNave = 400; int xEne[2] = {320, 230}; int yEne[2] = {40, 30}; /* Activar las teclas */ Uint8* teclas; int main(int argc, char *argv[]) { int terminado = 0; SDL_Event suceso; /*SDL_Rect clip_rect;*/ iniciarSDL(); /* Imagenes a mostrar */ fondo = SDL_LoadBMP("fondo.bmp"); nave = SDL_LoadBMP("nave.bmp"); enemigo = SDL_LoadBMP("enemigo.bmp"); iniciarVideo(); transparencia(); /* Cambiar titulo de la ventana (titulo, icono) */ SDL_WM_SetCaption("Joaquin Cortes", NULL); /* Gameloop, mientras que terminar sea igual a 0 hacer todo esto */ while(terminado == 0) { imgFondo(); /*clip_rect.x = 100; clip_rect.y = 100; clip_rect.w = 300; clip_rect.h = 580; [Sirve para crear un rectangulo en la pantalla] SDL_SetClipRect(screen, &clip_rect);*/ drawNave(); drawEnemiga(); Colision(); /* Actualizamos la pantalla */ SDL_Flip(screen); /* Miramos si hay algun suceso pendiente, entre ellos, peticion de abandonar el programa (pulsar la X de la ventana) o tecla ESC */ while(SDL_PollEvent(&suceso)){ if(suceso.type == SDL_QUIT) terminado = 1; if(suceso.type == SDL_KEYDOWN) if(suceso.key.keysym.sym == SDLK_ESCAPE) terminado = 1; } moverNave(); moverEnemigo(); /* Esperamos 50 ms antes de repetir */ SDL_Delay(10); } /* Finalmente, preparamos para salir */ SDL_Quit(); return 0; } void iniciarSDL() { /* Inicializamos la Biblioteca SDL */ if(SDL_Init(SDL_INIT_VIDEO) < 0){ printf("No se pudo inicializar SDL: %s\n", SDL_GetError ()); } } void iniciarVideo() { /* Si todo va bien, hacemos esto: entrar a modo grafico y cambiar el titulo de la ventana */ screen = SDL_SetVideoMode(WIDTH, HEIGHT, BTS, SDL_HWSURFACE); if(screen == NULL){ printf("Error al entrar a modo grafico: %s\n", SDL_GetError ()); SDL_Quit(); } } void transparencia() { /* transparencia nave */ SDL_SetColorKey(nave, SDL_SRCCOLORKEY, SDL_MapRGB(nave->format, 0,0,0)); /* transparencia enemigo */ SDL_SetColorKey(enemigo, SDL_SRCCOLORKEY, SDL_MapRGB(enemigo->format, 0,0,0)); } void imgFondo() { /*Dibujamos la imagen de fondo Como tiene 207x211 pixeles, la repetimos varias veces */ int i, j; for(i=0; i<5; i++) { for(j=0; j<3; j++) { destino.x=207*i; destino.y=211*j; SDL_BlitSurface(fondo, NULL, screen, &destino); } } } void drawNave() { /* Dibujamos el nave */ destinoNave.x = xNave; destinoNave.y = yNave; destinoNave.w = 35; destinoNave.h = 58; SDL_BlitSurface(nave, NULL, screen, &destinoNave); } void moverNave() { /* Vemos el estado individual de las demas teclas */ teclas = SDL_GetKeyState(NULL); if(teclas[SDLK_UP] && yNave > 0) yNave -= 5; if(teclas[SDLK_DOWN] && yNave < HEIGHT-45) yNave += 5; if(teclas[SDLK_LEFT] && xNave > 0) xNave -= 5; if(teclas[SDLK_RIGHT] && xNave < WIDTH-25) xNave += 5; } void drawEnemiga() { int i; for(i=0; i<2; i++) { destinoe[i].w = 35; destinoe[i].h = 58; destinoe[i].x = xEne[i]; destinoe[i].y = yEne[i]; SDL_BlitSurface(enemigo, NULL, screen, &destinoe[i]); } } void moverEnemigo() { int i; for(i=0; i<2; i++) { yEne[i] += 5; if(destinoe[i].y == HEIGHT) yEne[i] = 0; } } void Colision() { int i; for(i=0; i<2; i++) { if(((destinoNave.x + destinoNave.w) > destinoe[i].x) && ((destinoNave.y + destinoNave.h) > destinoe[i].y) && ((destinoe[i].x + destinoe[i].w) > destinoNave.x) && ((destinoe[i].y + destinoe[i].h) > destinoNave.y)) { yEne[i] = 0; yNave = 540; } } }
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. #include <SDL/SDL.h> #include <stdio.h> #include <stdlib.h> /* ******************************** * .:La nave:. * * * * Author: Joaquin Cortes * * Version: 0.0.1 * * Name: La nave * * Language: C/C++ * * Library: SDL * * * ******************************** */ #define WIDTH 800 #define HEIGHT 600 #define BTS 16 void iniciarSDL(); void iniciarVideo(); void transparencia(); void imgFondo(); void drawNave(); void moverNave(); void drawEnemiga(); void moverEnemigo(); void Colision(); /* Declaracion de variables */ SDL_Surface *screen; SDL_Surface *nave; SDL_Surface *enemigo; SDL_Surface *fondo; SDL_Rect destino; SDL_Rect destinoe; SDL_Rect destinoNave; /* Posicion incial */ int xNave = 320, yNave = 400; int xEne = 320, yEne = 10; /* Activar las teclas */ Uint8* teclas; int main(int argc, char *argv[]) { int terminado = 0; SDL_Event suceso; /*SDL_Rect clip_rect;*/ iniciarSDL(); /* Imagenes a mostrar */ fondo = SDL_LoadBMP("fondo.bmp"); nave = SDL_LoadBMP("nave.bmp"); enemigo = SDL_LoadBMP("enemigo.bmp"); iniciarVideo(); transparencia(); /* Cambiar titulo de la ventana (titulo, icono) */ SDL_WM_SetCaption("Joaquin Cortes", NULL); /* Gameloop, mientras que terminar sea igual a 0 hacer todo esto */ while(terminado == 0) { imgFondo(); /*clip_rect.x = 100; clip_rect.y = 100; clip_rect.w = 300; clip_rect.h = 580; [Sirve para crear un rectangulo en la pantalla] SDL_SetClipRect(screen, &clip_rect);*/ drawNave(); drawEnemiga(); Colision(); /* Actualizamos la pantalla */ SDL_Flip(screen); /* Miramos si hay algun suceso pendiente, entre ellos, peticion de abandonar el programa (pulsar la X de la ventana) o tecla ESC */ while(SDL_PollEvent(&suceso)){ if(suceso.type == SDL_QUIT) terminado = 1; if(suceso.type == SDL_KEYDOWN) if(suceso.key.keysym.sym == SDLK_ESCAPE) terminado = 1; } moverNave(); moverEnemigo(); /* Esperamos 50 ms antes de repetir */ SDL_Delay(10); } /* Finalmente, preparamos para salir */ SDL_Quit(); return 0; } void iniciarSDL() { /* Inicializamos la Biblioteca SDL */ if(SDL_Init(SDL_INIT_VIDEO) < 0){ printf("No se pudo inicializar SDL: %s\n", SDL_GetError ()); } } void iniciarVideo() { /* Si todo va bien, hacemos esto: entrar a modo grafico y cambiar el titulo de la ventana */ screen = SDL_SetVideoMode(WIDTH, HEIGHT, BTS, SDL_HWSURFACE); if(screen == NULL){ printf("Error al entrar a modo grafico: %s\n", SDL_GetError ()); SDL_Quit(); } } void transparencia() { /* transparencia nave */ SDL_SetColorKey(nave, SDL_SRCCOLORKEY, SDL_MapRGB(nave->format, 0,0,0)); /* transparencia enemigo */ SDL_SetColorKey(enemigo, SDL_SRCCOLORKEY, SDL_MapRGB(enemigo->format, 0,0,0)); } void imgFondo() { /*Dibujamos la imagen de fondo Como tiene 207x211 pixeles, la repetimos varias veces */ int i, j; for(i=0; i<5; i++) { for(j=0; j<3; j++) { destino.x=207*i; destino.y=211*j; SDL_BlitSurface(fondo, NULL, screen, &destino); } } } void drawNave() { /* Dibujamos el nave */ destinoNave.x = xNave; destinoNave.y = yNave; destinoNave.w = 35; destinoNave.h = 58; SDL_BlitSurface(nave, NULL, screen, &destinoNave); } void moverNave() { /* Vemos el estado individual de las demas teclas */ teclas = SDL_GetKeyState(NULL); if(teclas[SDLK_UP] && yNave > 0) yNave -= 5; if(teclas[SDLK_DOWN] && yNave < HEIGHT-45) yNave += 5; if(teclas[SDLK_LEFT] && xNave > 0) xNave -= 5; if(teclas[SDLK_RIGHT] && xNave < WIDTH-25) xNave += 5; } void drawEnemiga() { destinoe.x = xEne; destinoe.y = yEne; destinoe.w = 35; destinoe.h = 58; SDL_BlitSurface(enemigo, NULL, screen, &destinoe); } void moverEnemigo() { yEne += 5; if(destinoe.y == HEIGHT) yEne = 0; } void Colision() { 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)) { yEne = 0; yNave = 540; } }
|
|
|
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
|
|
|
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: IOError: [Errno 2] No such file or directory: 'Pastore.txt' import os while True: path = 'C:\Users\Joaquin\Desktop\Programacion\Base\Jugadores' archivos= os.listdir(path) nombre=raw_input('Buscar:')+'.txt' os.system('cls') if nombre in archivos: mostrar = open(nombre, 'r') linea = mostrar.readline() while linea != '': print linea linea = mostrar.readline() mostrar.close() else: 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. import os while True: nombre = raw_input('Buscar: ') os.system('cls') path = '/Jugadores/' lstFiles = [] lstDir = os.walk(path) for files in lstDir: for fichero in files: if nombre == lstDir: archi=open(fichero,'r') lineas=archi.readlines() for li in lineas: print li 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.import os while True: nombre = raw_input('Buscar: ') os.system('cls') if nombre == 'J.Pastore': try: archi=open('Jugadores/Pastore.txt','r') lineas=archi.readlines() for li in lineas: print li archi.close() except IOError: print 'Ocurrio un error inesperado' elif nombre == 'C.Tevez': try: archi=open('Jugadores/Tevez.txt','r') lineas=archi.readlines() for li in lineas: print li archi.close() except IOError: print 'Ocurrio un error inesperado' elif nombre == 'L.Messi': try: archi=open('Jugadores/Messi.txt','r') lineas=archi.readlines() for li in lineas: print li archi.close() except IOError: print 'Ocurrio un error inesperado' elif nombre == 'E.Lavezzi': try: archi=open('Jugadores/Lavezzi.txt','r') lineas=archi.readlines() for li in lineas: print li archi.close() except IOError: print 'Ocurrio un error inesperado' elif nombre == 'Wanchope': try: archi=open('Jugadores/Wanchope.txt','r') lineas=archi.readlines() for li in lineas: print li archi.close() except IOError: print 'Ocurrio un error inesperado' elif nombre == 'exit': print "Gracias por utilizar nuestro programa" break else: print 'El jugador no se encuentra en el programa'
|
|
|
|
|
|
|