hacker


Ingresar con nombre de usuario, contraseña y duración de la sesión
| Portal Hacker | Editorial | Descargas | Ezine |
Inicio Ayuda Ingresar Registrarse
14 de Octubre de 2008, 12:45:47
Noticias: Reporte de temas
Para ver este enlace Registrate o Inicia Sesion
> Aqui

+  Foros pOrtal Hacker
|-+  Programacion
| |-+  C / C++
| | |-+  Código Abierto (Moderadores: mycrox, TXS)
| | | |-+  Stick en Movimiento v2.0
0 Usuarios y 1 Visitante están viendo este tema. « anterior próximo »
Páginas: [1] Ir Abajo Imprimir
Autor Tema: Stick en Movimiento v2.0  (Leído 339 veces)
Grib_Jr.
NZ2
**
Desconectado Desconectado

Mensajes: 153


Querer es poder


Ver Perfil
« : 19 de Marzo de 2008, 12:19:04 »

Otro programa con SDL, si compilan el codigo no les va a funcionar, (necesita SDL.h, y tambien unas imagenes), por lo cual, les dejo el programa en Winrar, este incluye el exe, 2 dibujos que se usan en el programa, y el Archivo.cpp.



En este, trata de un personaje, de grafica de palo (stick), que simula estar en prision, y tu puedes moverlo con los botones izquierda y derecha, como solo camina, le puse lento el caminar, y varias imagenes para representar el movimiento.


EDIT:
NUEVA VERSION.-
 
Ya no es solo moverse en una habitacion, ahora es toda una historia, muchas mas imagenes, ya el primer enemigo y de todo, junto con un amigo vamos a agrandarlo y hacer un gran juego.

Se juega con las flechas y espacio para agarrar un objeto

Aun es corto pero vamos a mejorar!!!

PROGRAMACION:
Por Grib Jr.

DISEÑO:
Por GANSOxp


Code:
Código:

#include <stdio.h>
#include <SDL\SDL.h>
#include <windows.h>
#include <string.h>

void mov_pokebola(SDL_Surface *screen, SDL_Surface *ima, int x, int y, int *esena, int side, int *asdasd)
{
     
        if(side > 0)
        {
        x-=(*esena) * 10;
        if(x < -10)
        {
        (*asdasd) = 0;
        (*esena) = 0;
        }
        }
        else
        {
        x+=100;
        x+=(*esena) * 10;
        if(x > 630)
        {
        (*asdasd) = 0;
        (*esena) = 0;
        }
        }
       
        y+=(*esena)*2;
       
        (*esena)+=3;
        SDL_Rect rect = {x, y, 0, 0};
        SDL_BlitSurface(ima, NULL, screen, &rect);

void imprimir_sprite(SDL_Surface *screen, SDL_Surface *ima, int x, int y, int xtrozo, int ytrozo, int *esena)
{

        struct sprite {int x, y;}Sprite;
        if ((*esena) >= -40 && (*esena) < -30)
        {Sprite.x = xtrozo * 5 + 10;}
        if ((*esena) >= -30 && (*esena) < -20)
        {Sprite.x = xtrozo * 6 + 12;}
        if ((*esena) >= -20 && (*esena) < -10)
        {Sprite.x = xtrozo * 7 + 14;}
        if ((*esena) >= -10 && (*esena) < 0)
        {Sprite.x = xtrozo * 8 + 16;}
        if((*esena) == -1)
        (*esena)=-40;
        //
        if ((*esena) == 0)
        {Sprite.x = xtrozo * 4 + 8;}
        //       
        if ((*esena) <= 10 && (*esena) > 0)
        {Sprite.x = xtrozo * 0 + 0;}
        if ((*esena) <= 20 && (*esena) > 10)
        {Sprite.x = xtrozo * 1 + 2;}
        if ((*esena) <= 30 && (*esena) > 20)
        {Sprite.x = xtrozo * 2 + 4;}
        if ((*esena) <= 40 && (*esena) > 30)
        {Sprite.x = xtrozo * 3 + 6;}
       
        if((*esena) == 40)
        (*esena) = 1;
        SDL_Rect rect = {x, y, 0, 0};
        SDL_Rect trozo = {Sprite.x, 0, xtrozo, ytrozo};
        SDL_BlitSurface(ima, &trozo, screen, &rect);
}

void imprimir(SDL_Surface *screen, SDL_Surface *ima, int x, int y, int x1, int y1, int x2, int y2)
// Funcion tomada prestada de otro code xD, que me hace mas simple todo
{
        SDL_Rect rect = {x, y, 0, 0};
        SDL_Rect trozo = {x2,y2, x1, y1};
        SDL_BlitSurface(ima, &trozo, screen, &rect);
}

void limpiar (SDL_Surface *screen, SDL_Surface *Background)
{
        imprimir(screen,Background,0,0,640,220,0,0);
}

void subir_escalera(SDL_Surface *screen, SDL_Surface *ima, int *x, int *y, int xtrozo, int ytrozo, int *esena, int i)
{
        Uint8 *key = SDL_GetKeyState(NULL);
        int xx, yy;
        struct sprite {int x, y;}Sprite;
        if ((*esena) >= 41 && (*esena) < 56)
        {Sprite.x = xtrozo * 9 + 18;}
        if ((*esena) >= 56 && (*esena) < 71)
        {Sprite.x = xtrozo * 10 + 20;}
        if ((*esena) == 70)
        (*esena) = 41;
       
        int a=44, e= -150;
        if(i == 2)
        { a = 220; e= 46; }
        if((*esena) < 41)
        (*esena) = 41;
       
        if (key[SDLK_DOWN] && *y <= a)
        {
        (*y)+=2;
        }
        if (key[SDLK_UP] && *y >= e)
        {
        (*y)-=2;
        }
        (*esena)++;
        xx = (*x);
        yy = (*y);
        SDL_Rect rect = {xx, yy, 0, 0};
        SDL_Rect trozo = {Sprite.x, 0, xtrozo, ytrozo};
        SDL_BlitSurface(ima, &trozo, screen, &rect);
}
void lanzar_item(SDL_Surface *screen, SDL_Surface *ima, int x, int y, int xtrozo, int ytrozo, int side, int *escena)
{int Y_TOTAL = ima->h;
     struct sprite {int x, y;}Sprite;
        if (side == 1)
        {
        y-=14;
        x-=48;
        if ((*escena) >= 0 && (*escena) < 3)
        {Sprite.x = xtrozo * 0 + 0;
        Sprite.y = Y_TOTAL - (ytrozo * 4 + 3 );  }   
        else if ((*escena) >= 3 && (*escena) < 6)
        {Sprite.x = xtrozo * 1 + 2;
        Sprite.y = Y_TOTAL - (ytrozo * 4 + 3); }
        else if ((*escena) >= 6 && (*escena) < 9)
        {Sprite.x = xtrozo * 2 + 4;
        Sprite.y = Y_TOTAL - (ytrozo * 4 + 3);  }
        else if ((*escena) >= 9 && (*escena) < 12)
        {Sprite.x = xtrozo * 3 + 6;
        Sprite.y = Y_TOTAL - (ytrozo * 4 + 3);  }
/* -- */else if ((*escena) >= 12 && (*escena) < 15)
        {Sprite.x = xtrozo * 0 + 0;
        Sprite.y = Y_TOTAL - (ytrozo * 3 + 2);  }   
        else if ((*escena) >= 15 && (*escena) < 18)
        {Sprite.x = xtrozo * 1 + 2;
        Sprite.y = Y_TOTAL - (ytrozo * 3 + 2);  }
        else if ((*escena) >= 18 && (*escena) < 21)
        {Sprite.x = xtrozo * 2 + 4;
        Sprite.y = Y_TOTAL - (ytrozo * 3 + 2);  }
        else if ((*escena) >= 21 && (*escena) < 40)
        {Sprite.x = xtrozo * 3 + 6;
        Sprite.y = Y_TOTAL - (ytrozo * 3 + 2);  }
        else
        {y+=14;
            x+=48; 
        Sprite.y = 0;    Sprite.x = 0;   
        xtrozo= 42; ytrozo = 145;
        }
        }       
        else
        {x-=26;
        y-=14;
        if ((*escena) >= 0 && (*escena) < 3)
        {Sprite.x = xtrozo * 0 + 0;
        Sprite.y = Y_TOTAL - (ytrozo * 2 + 1);  }   
        else if ((*escena) >= 3 && (*escena) < 6)
        {Sprite.x = xtrozo * 1 + 2;
        Sprite.y = Y_TOTAL - (ytrozo * 2 + 1); }
        else if ((*escena) >= 6 && (*escena) < 9)
        {Sprite.x = xtrozo * 2 + 4;
        Sprite.y = Y_TOTAL - (ytrozo * 2 + 1);  }
        else if ((*escena) >= 9 && (*escena) < 12)
        {Sprite.x = xtrozo * 3 + 6;
        Sprite.y = Y_TOTAL - (ytrozo * 2 + 1);  }
/* -- */else if ((*escena) >= 12 && (*escena) < 15)
        {Sprite.x = xtrozo * 0 + 0;
        Sprite.y = Y_TOTAL - (ytrozo * 1 + 0);  }   
        else if ((*escena) >= 15 && (*escena) < 18)
        {Sprite.x = xtrozo * 1 + 2;
        Sprite.y = Y_TOTAL - (ytrozo * 1 + 0);  }
        else if ((*escena) >= 18 && (*escena) < 21)
        {Sprite.x = xtrozo * 2 + 4;
        Sprite.y = Y_TOTAL - (ytrozo * 1 + 0);  }
        else if ((*escena) >= 21 && (*escena) < 40)
        {Sprite.x = xtrozo * 3 + 6;
        Sprite.y = Y_TOTAL - (ytrozo * 1 + 0);  }
        else
        {  x+=26;
        y+=14;
             xtrozo= 42; ytrozo = 145;
             Sprite.y = 0;    Sprite.x = xtrozo * 5 + 10;   
       
        }
        }             
       
       
       
        (*escena)++;
       
        SDL_Rect rect = {x, y, 0, 0};
        SDL_Rect trozo = {Sprite.x, Sprite.y, xtrozo, ytrozo};
        SDL_BlitSurface(ima, &trozo, screen, &rect);
}
void recoger_item(SDL_Surface *screen, SDL_Surface *ima, int x, int y, int xtrozo, int ytrozo, int side, int *escena)
{   
       
        struct sprite {int x, y;}Sprite;
        int i, aux = 147;
        if (side == 1)
        {
        i= 42;
        if ((*escena) >= 0 && (*escena) < 10)
        Sprite.x = xtrozo * 0 + 0;       
        else if ((*escena) >= 10 && (*escena) < 30)
        Sprite.x = xtrozo * 1 + 2;
        else if ((*escena) >= 30 && (*escena) < 40)
        Sprite.x = xtrozo * 0 + 0;
        else
        {
        xtrozo= 42;
        aux = 0;
        Sprite.x = xtrozo * 0 + 0;
        i=0;
        }       
        }
        else
        {
        if ((*escena) >= 0 && (*escena) < 10)
        Sprite.x = xtrozo * 2 + 4;       
        else if ((*escena) >= 10 && (*escena) < 30)
        Sprite.x = xtrozo * 3 + 6;   
        else if ((*escena) >= 30 && (*escena) < 40)
        Sprite.x = xtrozo * 2 + 4;
        else
        {
        xtrozo= 42;
        aux = 0;
        Sprite.x = xtrozo * 5 + 10;
        }
        i=0;
        }
       
        (*escena)++;
       
        SDL_Rect rect = {x -= i, y, 0, 0};
        SDL_Rect trozo = {Sprite.x, aux, xtrozo, ytrozo};
        SDL_BlitSurface(ima, &trozo, screen, &rect);
}
                                         
void mover_objeto(int *x, int *y, int ancho, int alto, int *esena, int xmin, int xmax)
{
        Uint8 *key = SDL_GetKeyState(NULL);
        int min,max;
        min = xmin;
        max = xmax;
       
        if (key[SDLK_LEFT] && *x > min)
        {
        if ((*esena) < 0 || (*esena) > 41) (*esena) = 1;       
        (*x) -= 2;
        }       
        if (key[SDLK_RIGHT] && (*x + ancho) < max)
        {
        if ((*esena) > 0) (*esena) = -40; 
        (*x) += 2;
        }         
               
        (*esena)++;
}               

int main (int argc, char *argv[])
{
   
    SDL_Surface *screen, *Muerte_Enemigo, *Background[3], *Stick[2], *Lampara, *Objeto, *Pokebola, *Wall, *Texto, *Enemigo;
    Stick[0] = SDL_LoadBMP("Animaciones/Personaje Principal.bmp");
    Stick[1] = SDL_LoadBMP("Animaciones/Personaje Principal 2.bmp");
    Enemigo = SDL_LoadBMP("Animaciones/Enemigo.bmp");
    Background[0] = SDL_LoadBMP("Backgrounds/Background.bmp");
    Background[1] = SDL_LoadBMP("Backgrounds/Background 2.bmp");
    Background[2] = SDL_LoadBMP("Backgrounds/Background 3.bmp");
    Objeto = SDL_LoadBMP("Objetos/Objeto.bmp");
    Pokebola = SDL_LoadBMP("Objetos/Item.bmp");
    Wall = SDL_LoadBMP("Objetos/Objeto 2.bmp");
    Texto = SDL_LoadBMP("Textos/Texto 1.bmp");
    Lampara = SDL_LoadBMP("Objetos/Lampara.bmp");
    Muerte_Enemigo = SDL_LoadBMP("Animaciones/Ene Muerte.bmp");
   
    char TXT[10]="NULO";   
    SDL_Event evento;
    int color_key;
    int v_tajeo = 1, ene_tajeo= 0,Y = 10,rendimiento[2]={1,1}, x=260, y=45, ene_hp=100, contador= 1,xmin = 0, xmax = 0, vari=0,xd=0, ene_x=10, ene_y=44, i= 0,enemy = 0, crap = -40, BGlimit=640, doing=0, side=1, stop = 0, pokebola = 1, a=0, mov_pokebolas = 0, carne= 0, variable = 0, lol[3] = {0,0,0};
    // SUPUESTAS "CONSTANTES"
    int ASDASD=0,caminar = 0, izquierda = 1, derecha = -40, cero = 0, comprobar = 0, arriva = 41, escalera = 41;
   
    color_key = SDL_MapRGB(Pokebola->format, 255, 0, 255);
   
    SDL_SetColorKey(Stick[0], SDL_SRCCOLORKEY|SDL_RLEACCEL,color_key);
    SDL_SetColorKey(Stick[1], SDL_SRCCOLORKEY|SDL_RLEACCEL,color_key);
    SDL_SetColorKey(Objeto,SDL_SRCCOLORKEY|SDL_RLEACCEL,color_key);
    SDL_SetColorKey(Pokebola,SDL_SRCCOLORKEY|SDL_RLEACCEL,color_key);
    SDL_SetColorKey(Wall,SDL_SRCCOLORKEY|SDL_RLEACCEL,color_key);
    SDL_SetColorKey(Texto,SDL_SRCCOLORKEY|SDL_RLEACCEL,color_key);
    SDL_SetColorKey(Enemigo,SDL_SRCCOLORKEY|SDL_RLEACCEL,color_key);
    SDL_SetColorKey(Lampara,SDL_SRCCOLORKEY|SDL_RLEACCEL,color_key);
    SDL_SetColorKey(Muerte_Enemigo,SDL_SRCCOLORKEY|SDL_RLEACCEL,color_key);
   
    SDL_SetAlpha(Lampara, SDL_SRCALPHA|SDL_RLEACCEL, 100);
   
    if (SDL_Init(SDL_INIT_VIDEO) > 0)
    {
    MessageBox (NULL, "Error al iniciar video en SDL", "ERROR", MB_OK);
    return 1;
    }
   
    screen = SDL_SetVideoMode(640,220, 16, SDL_HWSURFACE|SDL_DOUBLEBUF);
    SDL_WM_SetCaption("Stick en Movimiento",NULL);
   
    imprimir(screen,Background[0],0,0,640,220,0,0);
   
    imprimir_sprite(screen, Stick[a], x, y,42,145, &cero);
    SDL_Flip(screen);
//////////////////////////////////////////////////////////////////////////////////
    while(evento.type != SDL_QUIT)
    {
    SDL_PollEvent(&evento);
   

   
if(i==0)
{
    xmin = 1;
    xmax = 685;
    if (x > 640)
    { i++; x = -20; }
}
else if(i==1)
{
    if(pokebola==0&&ene_hp!=0)
    enemy= 1;
    if(enemy==1)
    xmin = (ene_x + 15);
    else
    {
    xmin = -45;
    xmax = 605;
    }
    if (x < -40)
    { i--; x = 640; }
    if (y < -140)
    { i++; x = 20; y = 85; }
   
}
else if(i==2)
{
    xmin = 5;
    xmax = 605;
    if (y > 100)
    { i--; x = 400; y = -100; }
}
    if(evento.type == SDL_KEYDOWN&&(((y==45&&(evento.key.keysym.sym == SDLK_LEFT ||evento.key.keysym.sym == SDLK_RIGHT))||evento.key.keysym.sym == SDLK_SPACE) || (ASDASD==1&&(evento.key.keysym.sym == SDLK_UP ||evento.key.keysym.sym == SDLK_DOWN))||(pokebola==0 && evento.key.keysym.sym == SDLK_a)))
    {
    limpiar(screen,Background[i]);
    if(ASDASD==1)ASDASD=0;
    if((x>380 && x < 430 && i == 1) || (x > 19 && x < 69 && i==2))
    {
    ASDASD=1;
    if (stop == 0 && (evento.key.keysym.sym == SDLK_UP ||evento.key.keysym.sym == SDLK_DOWN))
    {
    subir_escalera(screen, Stick[a],&x,&y,42,145,&escalera, i);
    comprobar = 1;
    }
    if(y==45|| y == 44)
    {
    comprobar = 0;
    y=45;
    }
    }
   
    if(stop == 0 && comprobar==0 && (evento.key.keysym.sym == SDLK_LEFT ||evento.key.keysym.sym == SDLK_RIGHT))
    {
    mover_objeto(&x, &y, 42, 145, &caminar, xmin, xmax);
    imprimir_sprite(screen, Stick[a], x, y,42,145, &caminar);
    }
    if(stop==1)
    stop = 0;
    if(evento.key.keysym.sym == SDLK_SPACE)
    {
    recoger_item(screen, Stick[a], x, y,85,146, side, &doing);
    if (i==2 && pokebola == 1 && x > 240 && x < 360 && doing ==30)
    {
    a++;
    pokebola = 0;
    }
    stop = 1;
    }
    else if (pokebola==0 && evento.key.keysym.sym == SDLK_a)
    {
    if(doing == 21)
    mov_pokebolas = 1;
    lanzar_item(screen, Stick[a], x, y, 114,157, side, &doing);
    }   
    }
    else
    {
    doing = 0;
    limpiar(screen,Background[i]);
    if(comprobar == 0 && caminar < 0)
    { imprimir_sprite(screen, Stick[a], x, y,42,145,&derecha); side = derecha; }
    else if (comprobar == 0 && caminar > 0)
    { imprimir_sprite(screen, Stick[a], x, y,42,145,&izquierda); side = izquierda; }
    else if (comprobar == 0)
    imprimir_sprite(screen, Stick[a], x, y,42,145,&cero);
    else
    imprimir_sprite(screen, Stick[a], x, y,42,145,&arriva);
    }
   
    ///////////////////////
    if(i==0) imprimir(screen,Lampara, 140, 0, 291, 197, 0, 0);
    if(i==2 && pokebola==0 && variable != -1) strcpy(TXT,"Texto");
    if(mov_pokebolas == 1) mov_pokebola(screen,Pokebola, x-50, y+5, &carne, side, &mov_pokebolas);
    if(i==2 && pokebola == 1) imprimir(screen, Pokebola, 300,175,15,15,0,0);
    if(i==2) imprimir(screen, Objeto, 420,110, 89, 90, 0, 0);
    if(i==1 && enemy == 0 && pokebola == 0) imprimir(screen, Muerte_Enemigo, ene_x,ene_y,41,145,294,0);
    ///// ENEMY////
    if(enemy==1 && i==1)
    {
           
         
         if (x-40 > ene_x)
         {
         if(ene_tajeo==1)ene_tajeo=0;
         if(ene_tajeo==0&&ene_hp!=0&& xd < 11) ene_x++;
         if (crap>0)
         crap=-40; 
         if(ene_tajeo==0&&xd==0)crap++;
         if (x - (carne*10) <= ene_x && mov_pokebolas == 1)
         {
         if(ene_hp!=0)ene_x -= 10;
         vari=2;
         xd=0;
         }
         }
         else
         ene_tajeo=1;
         
         if (ene_tajeo==0&&vari==0&&ene_hp!=0)  imprimir_sprite(screen,Enemigo,ene_x,ene_y, 42, 145, &crap);
         else if (ene_tajeo==0&&vari==2) imprimir(screen, Enemigo,ene_x,ene_y,44,145,396,0);
         else if (ene_tajeo==0){
         imprimir_sprite(screen,Muerte_Enemigo,ene_x,ene_y, 40, 145, &contador);
         contador+=2;
         if (contador > -15 && contador < 0) enemy = 0;
         
         if(contador >= 40) contador = -40;
         }
         else
         {
             if(v_tajeo <= 6 || (v_tajeo>=51&&v_tajeo<=57))
             imprimir(screen,Enemigo,ene_x,ene_y,42,145, 485,0);
             else if(v_tajeo <= 50)
             imprimir(screen,Enemigo,ene_x+3,ene_y,76,145, 606,0);
             else
             imprimir(screen,Enemigo,ene_x,ene_y,42,145,220,0);
             if (v_tajeo>=90) v_tajeo=0;
             v_tajeo++;
         }   
    if (vari==2)xd++;
    }
         //// END ///
     
        //// TXT ////
    if(ene_hp==10) Y=50;
    if(xd >= Y) {vari=0; if(ene_hp!=0)ene_hp+=-10; xd=0;}
    if(strcmp(TXT, "NULO"))
{
    SDL_SetAlpha(Texto, SDL_SRCALPHA|SDL_RLEACCEL, variable);
    imprimir(screen, Texto, 30, 30,247,49,0,0);
   
    if (lol[0] == 0 && lol[2]<= 30)
    lol[2]++;
                 
    else if(lol[2] > 30 && variable < 252)
    variable+=4;
   
    else if (lol[0] < 300)
    lol[0]++;
   
    else if (lol[0] >= 300)
    {
        variable-=4;
        lol[2]= 0;
        if(variable <=1 )
        {
        variable = -1;
        lol[0] = 0;
        strcpy(TXT, "NULO");
        }
    }
}
 ////// FINISH /////
 ////// RENDIMIENTO /////
if (i != 2 && pokebola == 0 && variable == -1 && rendimiento[0] == 1)
{SDL_FreeSurface(Texto); rendimiento[0] = 0;}
if (i==0 && enemy == 0 && pokebola == 0 && rendimiento[1] == 1)
{SDL_FreeSurface(Enemigo); rendimiento[1] = 0;}
   
    SDL_Flip(screen);
    SDL_Delay(5);
    }
    SDL_Quit();
    return 0;
}





Descarga del Rar:

Para ver este enlace Registrate o Inicia Sesion
http://www.megaupload.com/?d=C00YEIES


Disculpen si megaupload les da dificultades, espero les ayuda en algo
Saludos

### DISCULPENME, LA VERSION ANTERIOR NO FUNCIONABA, ESTA SI.
« Última modificación: 11 de Mayo de 2008, 09:47:50 por Grib_Jr. » En línea


TXS
Moderador Global
*****
Desconectado Desconectado

Mensajes: 1,483


Prefiero morir de pie, a vivir arrodillado


Ver Perfil WWW
« Respuesta #1 : 11 de Mayo de 2008, 03:35:08 »

Genial esta 2º version Grib_Jr, esta muy bien Grin

Ya esta incluido al FAQ!

Sigue asi Smiley
En línea

Por una red libre de información y sin censuras



"Podrán morir las personas, pero jamas sus ideales"


Para ver este enlace Registrate o Inicia Sesion
Si algún tema del foro te parece inapropiado, crees que debe moverse o cerrarse, repórtalo aquí

(No respondo dudas por MP)
Para ver este enlace Registrate o Inicia Sesion
Reglas
<->
Para ver este enlace Registrate o Inicia Sesion
Subir imagen al foro
Páginas: [1] Ir Arriba Imprimir 
« anterior próximo »
Ir a:  


Ingresar con nombre de usuario, contraseña y duración de la sesión

Powered by SMF 1.1.6 | SMF © 2006-2008, Simple Machines LLC hacker

Juegos gratis - Articulos PHP - Juegos - Trucos - Letras - Juegos - Juegos Online