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

 

 


Tema destacado: Rompecabezas de Bitcoin, Medio millón USD en premios


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  [DUDA] clases es bueno esto?
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [DUDA] clases es bueno esto?  (Leído 2,330 veces)
anonimo12121


Desconectado Desconectado

Mensajes: 1.813


Ver Perfil WWW
[DUDA] clases es bueno esto?
« en: 11 Mayo 2010, 16:37 pm »

hola quisiera saber si este metodo de empleo para clases es bueno o malo

Código
  1. class a{
  2. }
  3. a a1[100];

esque necesito hacer 1 clase por ejemplo enemigos y mediante 1 bucle comprobar variables de la clase.

SALUDOS


En línea

Página para ganar Bitcoins y Dinero: http://earnbit.hol.es/
Video de YouTube con Hack para el LoL: http://adf.ly/5033746/youtube-lolemuhack
Si quieres ganar dinero con adfly entra y registrate aquí -> http://adf.ly/?id=5033746
Horricreu
Wiki

Desconectado Desconectado

Mensajes: 290

¡La verdad os hará libres!


Ver Perfil WWW
Re: [DUDA] clases es bueno esto?
« Respuesta #1 en: 11 Mayo 2010, 18:09 pm »

Te falta leer sobre clases en general: herencia, polimorfismo... si conoces todo esto al 100%, no harán falta estas preguntas :¬¬

Saludos :P


« Última modificación: 18 Septiembre 2010, 02:41 am por Horricreu » En línea

.:BlackCoder:.


Desconectado Desconectado

Mensajes: 388


Cada dia C++!!


Ver Perfil
Re: [DUDA] clases es bueno esto?
« Respuesta #2 en: 11 Mayo 2010, 18:11 pm »

Lo que entendi fue... Que si puedes hacer vectores de clases... claro que si... Sigue leyendo y viendo codes... lee sobre polimorfimo...

Saludos...
En línea

"No te esfuerzes por saber mas, esfuerzate por ser el mejor en lo que sabes... Y asi sabras mas" .:BlackCoder:. jajaja



anonimo12121


Desconectado Desconectado

Mensajes: 1.813


Ver Perfil WWW
Re: [DUDA] clases es bueno esto?
« Respuesta #3 en: 11 Mayo 2010, 18:22 pm »

no si ahcerlo lo hecho pero queria saber si no era cosa rara y podia pasar cosas raras.

saludos.
En línea

Página para ganar Bitcoins y Dinero: http://earnbit.hol.es/
Video de YouTube con Hack para el LoL: http://adf.ly/5033746/youtube-lolemuhack
Si quieres ganar dinero con adfly entra y registrate aquí -> http://adf.ly/?id=5033746
Horricreu
Wiki

Desconectado Desconectado

Mensajes: 290

¡La verdad os hará libres!


Ver Perfil WWW
Re: [DUDA] clases es bueno esto?
« Respuesta #4 en: 11 Mayo 2010, 18:28 pm »

¿Quieres hacer esto?

Código
  1. class bueno
  2. {
  3.     private:
  4.          int personabuena1[100];
  5. }
  6.  
  7. class malo
  8. {
  9.     private:
  10.          int personamala1[100];
  11. }

Saludos :P
« Última modificación: 18 Julio 2010, 17:34 pm por Horricreu » En línea

anonimo12121


Desconectado Desconectado

Mensajes: 1.813


Ver Perfil WWW
Re: [DUDA] clases es bueno esto?
« Respuesta #5 en: 11 Mayo 2010, 18:56 pm »

no , era para esto.
main.cpp
Código
  1. #include <iostream>
  2. #include <SDL/SDL.h>
  3. #include <SDL/SDL_image.h>
  4. #include "entidad.h"
  5. using namespace std;
  6. SDL_Surface *screen;
  7. SDL_Event evento;
  8. Uint8 *tecla;
  9. float tiempo;
  10. int framerate;
  11.  
  12. Centidad Epj;
  13. Centidad Enpc[100];
  14. Centidad Esuelo[100];
  15. int main(int argc,char *argv[]){
  16.    SDL_Init(SDL_INIT_VIDEO);
  17.    screen=SDL_SetVideoMode(640,480,32,SDL_SWSURFACE);
  18.    SDL_WM_SetCaption("App1",0);
  19.    //dando valores
  20.    Enpc[1].crear_entidad(TPJ);
  21.    Esuelo[0].setx(0);Esuelo[0].setw(640);Esuelo[0].sety(430);Esuelo[0].seth(20);
  22.    //suelo.crear_entidad(TCOLISION);
  23.    Epj.setx(320);
  24.    Epj.sety(50);
  25.    Epj.aloadimagen("ryu-01.png",6);
  26.    Epj.cani(0,0,0);
  27.    Epj.cani(1,1,4);
  28.    Enpc[1].setx(300);
  29.    Enpc[1].sety(360);
  30.    Enpc[1].loadimagen("ken-01.png",0);
  31.    while(1){
  32.        //iniciamos el reloj
  33.        tiempo=SDL_GetTicks();
  34.        framerate++;
  35.        //**************************************
  36.        SDL_FillRect(screen,0,SDL_MapRGB(screen->format,0,0,0));
  37.        tecla=SDL_GetKeyState(0);
  38.        SDL_PollEvent(&evento);
  39.        if(tecla[SDLK_ESCAPE])exit(1);
  40.        if(tecla[SDLK_a])pul=1;
  41.        if(framerate%6==0)Enpc[0].ani(pul);
  42.  
  43.        Epj.gravedad(&Esuelo[0]);
  44.        Epj.gravedad(&Enpc[0]);
  45.        Epj.caida();
  46.  
  47.        //actualizaciones visuales
  48.        Epj.drawimagen(screen,pul);
  49.        Enpc[1].drawimagen(screen,0);
  50.        SDL_Flip(screen);
  51.        //comprovamos el tiempo
  52.        tiempo =SDL_GetTicks()-tiempo;
  53.        if(tiempo < 33.33){            //si aun sobra tiempo hasta llegar a los 33.33 ms
  54.            SDL_Delay( 33.33-tiempo ); //vete a dormir durante 33.33-x milisegundos 33.33 ms es = 30 fps en 1 s
  55.        }
  56.        if(framerate==30)framerate=0;
  57.    }
  58.  
  59.  
  60. }
  61.  
remlet.h
Código
  1. int remlet(char buscar,char* entrada, char* salida,int num){
  2.    char conv[2];
  3.    for(int i=0;i<strlen(entrada);i++){
  4.        if(entrada[i]==buscar){
  5.            strcpy(salida,entrada);
  6.            itoa(num,conv,10);
  7.            if(num<10){
  8.                salida[i+1]='0';
  9.                salida[i+2]=conv[0];
  10.            }
  11.            else {
  12.                salida[i+1]= conv[0];
  13.                salida[i+2]= conv[1];
  14.            }
  15.            return 1;
  16.        }
  17.    }
  18.    return 0;
  19. }
  20.  
entidad.h
Código
  1. #include "remlet.h"
  2. //TIPOS
  3. #define TPJ 1
  4. #define TMOB 2
  5. #define TOBJETO 3
  6. #define TCOLISION 4
  7. //ESTADO
  8. #define _EQUIETO 1
  9. #define _EAIRE 2
  10. #define _ESALTO 3
  11. #define _ECAER 4
  12. /**********************************************
  13. clase para cargar 1 imagen y posicionarla en 1 posicion
  14. */
  15. int pul=0;
  16. class Centidad{
  17.    public:
  18.        Centidad();
  19.        struct STani{
  20.            int fmax;
  21.            int fn;
  22.            int tmp;
  23.        } stani[100];
  24.        SDL_Surface *plantilla[100];
  25.        SDL_Surface *imagen;
  26.        SDL_Rect pos;
  27.        int tipo;
  28.        int estado;
  29.        int posx;
  30.        int posy;
  31.        int posw;
  32.        int posh;
  33.        int tmp1;
  34.        int sani1;
  35.        int sani2;
  36.        int crear_entidad(int t);
  37.        int loadimagen(char* file,int f);
  38.        int aloadimagen(char* file,int fmax);
  39.        int drawimagen(SDL_Surface *scr, int v);
  40.        int getx();
  41.        int gety();
  42.        int getw();
  43.        int geth();
  44.        void setx(int x);
  45.        void sety(int y);
  46.        void setw(int w);
  47.        void seth(int h);
  48.        void ani(int v);
  49.        void cani(int v,int fn,int fmax);
  50.        int choca(Centidad *ent);
  51.        int gravedad(Centidad *ent);
  52.        int saltar();
  53.        void Centidad::caida();
  54.  
  55. };
  56. Centidad::Centidad(){
  57.    estado=1;
  58.    tmp1=0;
  59. }
  60. int Centidad::crear_entidad(int e){
  61.    tipo=e;
  62. }
  63. int Centidad::loadimagen(char *file, int f){
  64.    plantilla[f]=IMG_Load(file);
  65.    if(plantilla[f]!=0)return 1;
  66.    else return 0;
  67. }
  68. int Centidad::aloadimagen(char *file, int fmax){
  69.    char salida[strlen(file)];
  70.    for(int i=0;i<fmax;i++){
  71.        remlet('-',file,salida,i+1);
  72.        plantilla[i]=IMG_Load(salida);
  73.    }
  74. }
  75. int Centidad::drawimagen(SDL_Surface *scr,int v){
  76.    imagen=plantilla[stani[v].tmp];
  77.    SDL_BlitSurface(imagen,0,scr,&pos);
  78. }
  79. int Centidad::getx(){
  80.    return posx;
  81. }
  82. int Centidad::gety(){
  83.    return posy;
  84. }
  85. int Centidad::getw(){
  86.    if(imagen!=0)return imagen->w;
  87.    else return posw;
  88. }
  89. int Centidad::geth(){
  90.    if(imagen!=0)return imagen->h;
  91.    else posh;
  92. }
  93. void Centidad::setx(int x){
  94.    pos.x=posx=x;
  95. }
  96. void Centidad::sety(int y){
  97.    pos.y=posy=y;
  98. }
  99. void Centidad::setw(int w){
  100.    pos.w=posw=w;
  101. }
  102. void Centidad::seth(int h){
  103.    pos.h=posh=h;
  104. }
  105. void Centidad::ani(int v){
  106.    sani1=v;
  107.    if(sani1!=sani2){
  108.        stani[v].tmp=stani[v].fn;
  109.        sani2=sani1;
  110.    }
  111.    if(stani[v].tmp <stani[v].fn+stani[v].fmax){
  112.        stani[v].tmp++;
  113.    }
  114.    else { stani[v].tmp=stani[v].fn;pul=0;}
  115. }
  116. void Centidad::cani(int v,int fn,int fmax){
  117.    stani[v].fn=fn;
  118.    stani[v].fmax=fmax;
  119. }
  120. int Centidad::choca(Centidad *ent){
  121.    int x1=getx();
  122.    int y1=gety();
  123.    int w1=getw();
  124.    int h1=geth();
  125.    int x2=ent[0].getx();
  126.    int y2=ent[0].gety();
  127.    int w2=ent[0].getw();
  128.    int h2=ent[0].geth();
  129.    for(int i=0;i<100;i++){
  130.        x2=ent[i].getx();
  131.        y2=ent[i].gety();
  132.        w2=ent[i].getw();
  133.        h2=ent[i].geth();
  134.        if(  (((x1+w1) > x2) && (x1<(x2+w2))) &&  (((y1+h1) > y2) && (y1 < (y2+h2))) ){
  135.            //hay colision
  136.            return 1;
  137.        }
  138.    }
  139.    return 0;
  140. }
  141. int Centidad::gravedad(Centidad *ent){
  142.    int ctmp=choca(ent);
  143.    if(ctmp==1){
  144.        estado=_EQUIETO;
  145.        return 1;
  146.    }
  147.    else {
  148.        estado=_ECAER;
  149.        return 0;
  150.    }
  151. }
  152.  
  153. void Centidad::caida(){
  154.  
  155.    int y=gety();
  156.    if(estado==4)sety(y+6);
  157. }
  158. int Centidad::saltar(){
  159.    if(estado == _EQUIETO){
  160.  
  161.    }
  162. }
  163.  
En línea

Página para ganar Bitcoins y Dinero: http://earnbit.hol.es/
Video de YouTube con Hack para el LoL: http://adf.ly/5033746/youtube-lolemuhack
Si quieres ganar dinero con adfly entra y registrate aquí -> http://adf.ly/?id=5033746
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Duda con implementación de clases de UML a C++
Programación C/C++
novalida 2 2,937 Último mensaje 23 Septiembre 2011, 22:16 pm
por novalida
Duda sobre clases
Java
Zedmix 1 1,918 Último mensaje 30 Noviembre 2011, 08:58 am
por Slava_TZD
Duda con Clases
.NET (C#, VB.NET, ASP)
Senior++ 6 3,059 Último mensaje 24 Febrero 2012, 10:48 am
por Senior++
Duda clases internas vb.net
.NET (C#, VB.NET, ASP)
Senior++ 4 3,253 Último mensaje 28 Febrero 2012, 21:34 pm
por Senior++
Duda con las clases [c++] « 1 2 »
Programación C/C++
Lotux5 11 5,281 Último mensaje 20 Abril 2013, 02:29 am
por rir3760
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines