Seite 278 von 340 ErsteErste ... 178 228 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 328 ... LetzteLetzte
Zeige Ergebnis 8.311 bis 8.340 von 10174

C/C++ Programming Help Thread

This is a discussion on C/C++ Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; ...

  
  1. #8311
    QJ Gamer Blue
    Points: 4.296, Level: 41
    Level completed: 73%, Points required for next Level: 54
    Overall activity: 0%

    Registriert seit
    Jul 2006
    Beiträge
    132
    Points
    4.296
    Level
    41
    Downloads
    0
    Uploads
    0

    Standard

    Code:
    /*****************************************************\
     Auteur : Foury Jean-francois
     Auteur de : Super Mario toy
     Jour 10 collision entre 1 sprite et une map
    \*****************************************************/
    //La librairie principale OSLib
    #include <oslib/oslib.h>
    #include "collisions.h"
    #include "sprite.h"
    
    //les callbacks
    PSP_MODULE_INFO("OSLib Sample", 0, 1, 1);
    PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
    
    
    //definition des pointeurs vers notre map
    OSL_MAP *Map01, *Map_collision;
    OSL_IMAGE *Map01_tileset, *collision_tileset;
    
    #define  TILE_NOSOLID  0
    #define  TILE_SOLID  1
    
    OSL_IMAGE *Joueur ;
    
    
    //fonctions
    void Touches();
    void AnimMarche();
    void Gestion_Map();
    short GetTile(OSL_MAP *m,int col, int row);
    int oslCollisionMap(OSL_MAP *m,OSL_IMAGE *sprite,int haut,int bas, int gauche, int droit);
    
    /*
    ====================
    colision
    
    Verifie si il y a une colision entre 2 sprites
    ====================
    */
    int main()
    {
    	//Initialisation de la librairie
    	oslInit(0);
    
    	//Initialisation du mode graphique
    	oslInitGfx(OSL_PF_8888, 1);
    
    	//chargement de nos images (oui, le "loading" :p)
    	Map01_tileset = oslLoadImageFile("sprite_s.png", OSL_IN_RAM, OSL_PF_5551);
    	collision_tileset = oslLoadImageFile("collisions_s.png", OSL_IN_RAM, OSL_PF_5551);
    
    	Joueur= oslLoadImageFile("player.png", OSL_IN_RAM, OSL_PF_5551);
    	//place Le joueur vers le centre de l'écran et dans sa position de départ
    	Joueur->x = 240;
    	Joueur->y = 130;
    
    	Gestion_Map(); //Initialisation des map
    
    
    	//boucle principale
    	while (!osl_quit)
    	{
    		//Permet de dessiner
    		oslStartDrawing();		
    		
    		//check des touches
    		Touches();
    
    		//Affiche la map concerner, mais n'affiche pas la map des collision
    		oslDrawMapSimple(Map01);
    
    		//dessine nos sprite
    		oslDrawImage(Joueur);
    
    		//Fin du dessin
    		oslEndDrawing();
    
    		//Synchronise l'écran
    		oslSyncFrame();		
    	}
    	
    	//on quitte l'application
    	oslEndGfx();
    	oslQuit();
    	return 0;
    }
    
    
    /*
    ====================
    Touches
    
    Gestion des touches pour le jeux :)
    ====================
    */
    void Touches()
    {
    //Lit les touches
    oslReadKeys();
    		
    if (osl_keys->held.down)
    {
    	if (!oslCollisionMap(Map_collision,Joueur,0,1,0,0))
    	{
    
            //ok on bouge
            Joueur->y += 2;
    	}
    
    }
    
    if (osl_keys->held.up)
    {
      	if (!oslCollisionMap(Map_collision,Joueur,1,0,0,0))
    	{
    		Joueur->y -= 2;
    	}
    
    }
    
    if (osl_keys->held.left)
    {
    	if (!oslCollisionMap(Map_collision,Joueur,0,0,1,0))
     	{
    		Joueur->x -= 2;
    	}
    
    }
    
    if (osl_keys->held.right)
    {
    	if (!oslCollisionMap(Map_collision,Joueur,0,0,0,1))
    	{
    		Joueur->x += 2;
    	}
    }
    
    
    }
    
    
    
    
    /*
    ====================
    Gestion_Map()
    
    Initialilsation des map
    ====================
    */
    
    void Gestion_Map()
    {
    
        //configuration de la map
        Map01= oslCreateMap(
            Map01_tileset,                        //Tileset
            (void *)sprite_map,                            //Map
            16,16,                                //Taille des tiles
            30,17,                                //Taille de la Map
            OSL_MF_U16);                        //Format de la Map
    
        //configuration de la map
        Map_collision= oslCreateMap(
            collision_tileset,                        //Tileset
            (void *)collisions_map,                            //Map
            16,16,                                //Taille des tiles 
            30,17,                                //Taille de la Map
            OSL_MF_U16);                        //Format de la Map
    
    }
    
    
    
    
    /*
    ====================
    GetTile
    
    Retourne sur quel sprite le player et possitionner
    ====================
    */
    
    short GetTile(OSL_MAP *m,int col, int row)
    {
     u16 *map = (u16*)m->map;
     return map[row*m->mapSizeX + col];
    }
    
    
    
    /*
    ====================
    oslCollisionMap
    
    Gestion des collisions avec les map et les perso pour le RPG
    ====================
    */
    
    int oslCollisionMap(OSL_MAP *m,OSL_IMAGE *Collision,int haut,int bas, int gauche, int droit)  
    {
     int tile;
    
    
    //Test de collition pour la partie Demander suivant la touche appuyer haut, bas, gauche, droit.
    
    if (haut)
     {
      tile = GetTile(m,((m->scrollX + Collision->x +Collision->stretchX ))/ m->tileX, (m->scrollY + Collision->y - 2)/ m->tileY);
      if (!tile)
      {
      tile = GetTile(m,((m->scrollX + Collision->x))/ m->tileX, (m->scrollY + Collision->y - 2)/ m->tileY);  //essaye avec la moitier du personnage pour que la tete passe quoi qu'il arrive                   
      }
     }
    
    if (bas)
     {
      tile = GetTile(m,((m->scrollX + Collision->x +Collision->stretchX ))/ m->tileX, (m->scrollY + Collision->y + Collision->stretchY + 2)/ m->tileY);
      if (!tile)
      {
      tile = GetTile(m,((m->scrollX + Collision->x))/ m->tileX, (m->scrollY + Collision->y + Collision->stretchY + 2)/ m->tileY);
      }
     }
    if (gauche)
     {
      tile = GetTile(m,((m->scrollX + Collision->x - 2))/ m->tileX, (m->scrollY + Collision->y + Collision->stretchY)/ m->tileY);
      if (!tile)
      {
      tile = GetTile(m,((m->scrollX + Collision->x - 2))/ m->tileX, (m->scrollY + Collision->y)/ m->tileY);
      }
     }
    
    if (droit)
     {
       tile = GetTile(m,((m->scrollX + Collision->x +Collision->stretchX + 2))/ m->tileX, (m->scrollY + Collision->y + Collision->stretchY)/ m->tileY);
       if (!tile)
      {
      tile = GetTile(m,((m->scrollX + Collision->x +Collision->stretchX + 2))/ m->tileX, (m->scrollY + Collision->y)/ m->tileY);
      }
     }
    
    
      switch(tile)
      {
       case TILE_NOSOLID:
        // pas de collision sur le sprite retourne donc 0
        return 0;
        break;
       case TILE_SOLID:
        // impassable retourne simplement 1 car impossable
        return 1;
        break;
    
       //On peut rajouter autant de case que besoin celon ce que on recherche.
      }
    
    
    return 0;
    }





    [IMG]http://pjeffadsl.free.fr/docs2/output/tut2_screen3.png[****]

    what i am haveing trouble figuring out is how he used this image to make the whole map? i dont get it, how you can use 1 image and make duplicates.



    [IMG]http:/****206.imageshack.us**** 206/5092/spritesyl1.png[****]

    also what do this image have anything to do with collision? like how does this work.

    [IMG]http:/****518.imageshack.us**** 518/2122/collisionsskf7.png[****]

    ya so im just wondering how he creates the whole map with those 2 sprites(like what part of the code and how) and what the second images has anything to do with collision.


    Geändert von cruisx (03-29-2008 um 09:02 AM Uhr)

  2. #8312
    QJ Gamer Bronze
    Points: 8.045, Level: 60
    Level completed: 48%, Points required for next Level: 105
    Overall activity: 0%

    Registriert seit
    Aug 2007
    Ort
    Australia
    Beiträge
    659
    Points
    8.045
    Level
    60
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Xsjado7
    Hey,
    Just a quick question, iv written a small function to remove a given colour from an image using graphics.h. Problem is that putPixelImage() doesnt support alpha colours so how else could i go about changing the pixel colour to transparent or how would i go about adding transparency to the function?
    Any ideas?

  3. #8313
    Points: 2.590, Level: 30
    Level completed: 94%, Points required for next Level: 10
    Overall activity: 0%

    Registriert seit
    Mar 2008
    Beiträge
    2
    Points
    2.590
    Level
    30
    Downloads
    0
    Uploads
    0

    Standard

    how difficult would it be to execute the official sony music player within a homebrew using an execute function?

  4. #8314
    I'm back!
    Points: 8.236, Level: 61
    Level completed: 29%, Points required for next Level: 214
    Overall activity: 99,0%

    Registriert seit
    Feb 2007
    Ort
    England
    Beiträge
    902
    Points
    8.236
    Level
    61
    Downloads
    0
    Uploads
    0

    Standard

    Well, you'd have to find what modules were required, then which partitions to load them in, then how to load them (I.E. what arguments were needed).

    All in all, pretty hard, because I'm guessing you'd have to do it yourself as I don't think anyone else has done it. Still, be an interesting thing to work on.

    -Aura
    Last.fm | Deviant Art | First working OS picture

    Zitat Zitat von nickxab Beitrag anzeigen
    I will beat myself. :p

  5. #8315
    QJ Gamer Blue
    Points: 4.296, Level: 41
    Level completed: 73%, Points required for next Level: 54
    Overall activity: 0%

    Registriert seit
    Jul 2006
    Beiträge
    132
    Points
    4.296
    Level
    41
    Downloads
    0
    Uploads
    0

    Standard

    ok i need some help guys. I am trying to lean how to do collision detection with 2 objects on the screen but i am kinda stuck, im sure the problem is an easy one, but for a beginner i am having some trouble.

    Code:
    //Oslib header file
    #include <oslib/oslib.h>
    
    //This is needed for eboot
    PSP_MODULE_INFO("OSLib Sample", 0, 1, 1);
    PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
    
    //this creates pointers for our images.
    OSL_IMAGE *sprite, *sprite2, *sprite3;
    
    //definations
    #define DOWN 0
    #define UP 35
    #define RIGHT 70
    #define LEFT 105
    
    //variables
    int sprite_position;
    int sprite_march;
    
    //declare the function like buttons and spriteAnimation
    void Buttons();
    void SpriteAnimate();
    int collision(OSL_IMAGE *img1,float img1posX, float img1posY, OSL_IMAGE *img2, float img2posX, float img2posY,OSL_IMAGE *img3, float img3posX, float img3posY );
    
    int main()
    {
    
    //start the Oslib library
    	oslInit(0);
    //start the graphixs mode
    	oslInitGfx(OSL_PF_8888, 1);
    
    //sets the transparency color
    	oslSetTransparentColor(RGB(255,0,255));
    
    //loads the images into memory
    	sprite = oslLoadImageFile("sprite.png", OSL_IN_RAM, OSL_PF_5551);
    	sprite2 = oslLoadImageFile("sprite2.png", OSL_IN_RAM, OSL_PF_5551);
    	sprite3 = oslLoadImageFile("sprite3.png", OSL_IN_RAM, OSL_PF_5551);
    
    //Disables the transparent color so it cannot be used again
    	oslDisableTransparentColor();
    
    //sees if all files are avaiable
    	if (!sprite || !sprite2||!sprite3)
    		oslDebug("! one or more of the files were missing, the program cannot run");
    		
    		
    //Sets the sprites original position, lets see if i can get 2 sprites on da bloody screen
    	sprite->x = 155;
    	sprite->y = 95;
    	sprite_position = DOWN;
    
    //sets second sprite position
    	sprite2->x = 230;
    	sprite2->y = 130;
    	
    //sets thrid sprite pos
    	sprite3->x = 270;
    	sprite3->y = 130;
    
    
    //main while loop
    	while (!osl_quit)
    	{
    		//to be able ot draw on the screen
    			oslStartDrawing();
    			
    		//Buttons 
    			Buttons();
    			
    		//draws a green background
    			oslDrawGradientRect(0,0,480,272,RGB(0,128,0),RGB(0,128,0), RGB(128,255,128), RGB(128,255,128)); 
    			
    		//this draws the images to the screen
    			oslDrawImage(sprite);
    			oslDrawImage(sprite2);
    			oslDrawImage(sprite3);
    			
    		//stops the drawing mode
    			oslEndDrawing();
    			
    		//sync the screen 
    			oslSyncFrame();
    		}
    		
    		//terminate the program
    		oslEndGfx();
    		oslQuit();
    		return 0;
    	}
    	
    		void Buttons()
    		{
    		//starts up the psp buttons
    			oslReadKeys();
    			
    		if (osl_keys->held.down)
    		{
    			if(!collision(sprite, sprite->x, sprite->y + 2, sprite2, sprite2->x, sprite2->y, sprite3, sprite3->x, sprite3->y ))
    			{
    			//sprite movement
    			sprite->y +=2;
    			
    			//sets sprite position on sprite sheet
    				sprite_position = DOWN;
    			
    			//calls sprie animate
    				SpriteAnimate();
    		}
    		}
    				
    			if (osl_keys->held.up)
    		{
    			if(!collision(sprite, sprite->x, sprite->y - 2, sprite2, sprite2->x, sprite2->y,sprite3, sprite3->x, sprite3->y ))
    			{
    				sprite->y-= 2;
    				sprite_position = UP;
    				SpriteAnimate();
    			
    		}
    		}
    		
    	   if (osl_keys->held.right)
        {
    			if(!collision(sprite, sprite->x + 2, sprite->y, sprite2, sprite2->x, sprite2->y,sprite3, sprite3->x, sprite3->y  ))
    			{
            sprite->x += 2;
            sprite_position = RIGHT;
            SpriteAnimate();
        }
    	}
    			
    		        if (osl_keys->held.left)
        {
    		if(!collision(sprite, sprite->x - 2, sprite->y, sprite2, sprite2->x, sprite2->y,sprite3, sprite3->x, sprite3->y  ))
    		{
            sprite->x -= 2;
            sprite_position = LEFT;
            SpriteAnimate();
        }
    	}
    			
    			   //If a button is not pressed
        if (!osl_keys->held.value) 
        {
        //Start the variable over for when a button is pressed again
            sprite_march = 0; 
    
            //Sets the sprite's direction
            oslSetImageTileSize(sprite,0,sprite_position,22,35);
        }
    }
    
    
    void SpriteAnimate()
       {    
            //Moves the sprite in the row that it is in
            sprite_march++;
    
            //Moves the sprite constantly
            oslSetImageTileSize(sprite,(sprite_march * 22),sprite_position,22,35);
    
            //resets the sprite movement in that row
            if (sprite_march == 6) sprite_march = 0;
        
    }
    			
    		
    		int collision(OSL_IMAGE *img1,float img1posX, float img1posY, OSL_IMAGE *img2, float img2posX, float img2posY, OSL_IMAGE *img3, float img3posX, float img3posY ) 
    {
       int collision;
       collision = 0;
       float img1width  = img1->stretchX;
       float img1height = img1->stretchY;
       float img2width  = img2->stretchX;
       float img2height = img2->stretchY;
       float img3width = img3->stretchX;
       float img3height = img3->stretchY;
      
       
       if ((img1posX + img1width > img2posX) &&
           (img1posX < img2posX + img2width) &&
    	   (img1posX + img1width > img3posX) &&
           (img1posX < img2posX + img3width) &&
           (img1posY + img1height > img2posY) &&
           (img1posY < img2posY + img2height) ) 
    {
             collision = 1;               
       }     
       return collision;
    }
    I know where the problem is but i dont know what im doing wrong


    Code:
    if ((img1posX + img1width > img2posX) &&
           (img1posX < img2posX + img2width) &&
    	   (img1posX + img1width > img3posX) &&
           (img1posX < img2posX + img3width) &&
           (img1posY + img1height > img2posY) &&
           (img1posY < img2posY + img2height) ) 
    {

    if i put that in, none of the sprites have collision but if i take out the Bolded parts the first sprite has collision but the second one dose not.(second sprite as in the second object, not the character that is moving). How do i modify this correctly for every new object on the screen? help will be greatly appreciated.
    Geändert von cruisx (03-30-2008 um 08:21 AM Uhr)

  6. #8316
    QJ Gamer Bronze
    Points: 8.045, Level: 60
    Level completed: 48%, Points required for next Level: 105
    Overall activity: 0%

    Registriert seit
    Aug 2007
    Ort
    Australia
    Beiträge
    659
    Points
    8.045
    Level
    60
    Downloads
    0
    Uploads
    0

    Standard

    Could someone please tell me what the hell is going on?
    Spoiler for Compiler Errors:

    source/main.c: In function 'mainGame':
    source/main.c(178) : error: incompatible types in assignment
    source/main.c(181) : error: incompatible types in assignment
    source/main.c(185) : error: incompatible types in assignment
    source/main.c(189) : error: incompatible types in assignment
    source/main.c(193) : error: incompatible types in assignment
    source/main.c: In function 'main':
    source/main.c(270) : error: incompatible types in assignment
    source/main.c(271) : error: incompatible types in assignment
    source/main.c(272) : error: incompatible types in assignment
    source/main.c(273) : error: incompatible types in assignment
    source/main.c(274) : error: incompatible types in assignment

    Lines *supposedly* containing errors:
    Spoiler for Lines:

    score.hs1name = player.name;
    score.hs2name = player.name;
    score.hs3name = player.name;
    score.hs4name = player.name;
    score.hs5name = player.name;
    score.hs1name = "Unknown";
    score.hs2name = "Unknown";
    score.hs3name = "Unknown";
    score.hs4name = "Unknown";
    score.hs5name = "Unknown";

    Score struct:
    Spoiler for Score struct:

    ...
    ...
    char hs1name[128];
    char hs2name[128];
    char hs3name[128];
    char hs4name[128];
    char hs5name[128];
    ...
    ...

    Player struct:
    Spoiler for Player struct:

    ...
    ...
    char name[128];
    ...
    ...

  7. #8317
    Developer
    Points: 7.577, Level: 58
    Level completed: 14%, Points required for next Level: 173
    Overall activity: 0%

    Registriert seit
    Mar 2006
    Beiträge
    1.026
    Points
    7.577
    Level
    58
    Downloads
    0
    Uploads
    0

    Standard

    You can't assign them like you are.

    Use strcpy(), sprintf() or similar.

    Check out my homebrew & C tutorials at http://insomniac.0x89.org/
    Coder formerly known as Insomniac197

    tshirtz: what is irshell ??
    Atarian_: it's where people who work for the IRS go when they die

  8. #8318
    QJ Gamer Bronze
    Points: 8.045, Level: 60
    Level completed: 48%, Points required for next Level: 105
    Overall activity: 0%

    Registriert seit
    Aug 2007
    Ort
    Australia
    Beiträge
    659
    Points
    8.045
    Level
    60
    Downloads
    0
    Uploads
    0

    Standard

    sprintf...could i get any dumber...

    I thought coders are usually at their peak at 2 in the morning

    Thanks IWN :)

  9. #8319
    QJ Gamer Bronze
    Points: 5.354, Level: 47
    Level completed: 2%, Points required for next Level: 196
    Overall activity: 0%

    Registriert seit
    Jan 2007
    Ort
    Right here
    Beiträge
    179
    Points
    5.354
    Level
    47
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von midnight_rush
    how difficult would it be to execute the official sony music player within a homebrew using an execute function?
    it's not as easy as you think. the hardware ME decoder can be initialized by
    Code:
    sceUtilityLoadAvModule(PSP_AV_MODULE_AVCODEC);
    but this is only for the initialization of the decoder. you still have to manually read the mp3 data from the file.
    sudo rm -rf /

    PSN ID: FigMan13

  10. #8320
    QJ Gamer Silver
    Points: 11.326, Level: 70
    Level completed: 19%, Points required for next Level: 324
    Overall activity: 0%

    Registriert seit
    Jan 2006
    Beiträge
    871
    Points
    11.326
    Level
    70
    Downloads
    0
    Uploads
    0

    Standard

    Hi. I started using OSLib today, and I wanted to know a way of having collision with something that is a more of an odd shape or Diagonal Boxes and not a Squarish look shape(Flat Box,Flat Platform)?
    Free Prizes at Prizerebel Join us!
    I already got 11 Gifts. Ask me for details or proof.

  11. #8321
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von ZereoX
    Hi. I started using OSLib today, and I wanted to know a way of having collision with something that is a more of an odd shape or Diagonal Boxes and not a Squarish look shape(Flat Box,Flat Platform)?
    Use Object Orientated Bounding Box (OOBB) Collision or Line Box collision tests.

  12. #8322
    QJ Gamer Bronze
    Points: 6.359, Level: 52
    Level completed: 5%, Points required for next Level: 191
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    france
    Beiträge
    170
    Points
    6.359
    Level
    52
    Downloads
    0
    Uploads
    0

    Standard

    edit: see what yaustar said.
    Try my latest game (iOS):


  13. #8323
    QJ Gamer Silver
    Points: 11.326, Level: 70
    Level completed: 19%, Points required for next Level: 324
    Overall activity: 0%

    Registriert seit
    Jan 2006
    Beiträge
    871
    Points
    11.326
    Level
    70
    Downloads
    0
    Uploads
    0

    Standard

    Like a said I'm still a newbie. So could you show me an example?
    Free Prizes at Prizerebel Join us!
    I already got 11 Gifts. Ask me for details or proof.

  14. #8324
    QJ Gamer Bronze
    Points: 8.045, Level: 60
    Level completed: 48%, Points required for next Level: 105
    Overall activity: 0%

    Registriert seit
    Aug 2007
    Ort
    Australia
    Beiträge
    659
    Points
    8.045
    Level
    60
    Downloads
    0
    Uploads
    0

    Standard

    Say i had something like:
    Code:
    char str[32];
    sprintf(str, "score 1 = 10, score 2 = 13");
    how would i go about copying "score 2" into another string? strcpy doesnt let you set the params for where to copy to and from

  15. #8325
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von ZereoX
    Like a said I'm still a newbie. So could you show me an example?
    http://www.gamasutra.com/features/19991018/Gomez_5.htm

  16. #8326
    QJ Gamer Blue
    Points: 4.296, Level: 41
    Level completed: 73%, Points required for next Level: 54
    Overall activity: 0%

    Registriert seit
    Jul 2006
    Beiträge
    132
    Points
    4.296
    Level
    41
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von cruisx
    ok i need some help guys. I am trying to lean how to do collision detection with 2 objects on the screen but i am kinda stuck, im sure the problem is an easy one, but for a beginner i am having some trouble.

    Code:
    //Oslib header file
    #include <oslib/oslib.h>
    
    //This is needed for eboot
    PSP_MODULE_INFO("OSLib Sample", 0, 1, 1);
    PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
    
    //this creates pointers for our images.
    OSL_IMAGE *sprite, *sprite2, *sprite3;
    
    //definations
    #define DOWN 0
    #define UP 35
    #define RIGHT 70
    #define LEFT 105
    
    //variables
    int sprite_position;
    int sprite_march;
    
    //declare the function like buttons and spriteAnimation
    void Buttons();
    void SpriteAnimate();
    int collision(OSL_IMAGE *img1,float img1posX, float img1posY, OSL_IMAGE *img2, float img2posX, float img2posY,OSL_IMAGE *img3, float img3posX, float img3posY );
    
    int main()
    {
    
    //start the Oslib library
    	oslInit(0);
    //start the graphixs mode
    	oslInitGfx(OSL_PF_8888, 1);
    
    //sets the transparency color
    	oslSetTransparentColor(RGB(255,0,255));
    
    //loads the images into memory
    	sprite = oslLoadImageFile("sprite.png", OSL_IN_RAM, OSL_PF_5551);
    	sprite2 = oslLoadImageFile("sprite2.png", OSL_IN_RAM, OSL_PF_5551);
    	sprite3 = oslLoadImageFile("sprite3.png", OSL_IN_RAM, OSL_PF_5551);
    
    //Disables the transparent color so it cannot be used again
    	oslDisableTransparentColor();
    
    //sees if all files are avaiable
    	if (!sprite || !sprite2||!sprite3)
    		oslDebug("! one or more of the files were missing, the program cannot run");
    		
    		
    //Sets the sprites original position, lets see if i can get 2 sprites on da bloody screen
    	sprite->x = 155;
    	sprite->y = 95;
    	sprite_position = DOWN;
    
    //sets second sprite position
    	sprite2->x = 230;
    	sprite2->y = 130;
    	
    //sets thrid sprite pos
    	sprite3->x = 270;
    	sprite3->y = 130;
    
    
    //main while loop
    	while (!osl_quit)
    	{
    		//to be able ot draw on the screen
    			oslStartDrawing();
    			
    		//Buttons 
    			Buttons();
    			
    		//draws a green background
    			oslDrawGradientRect(0,0,480,272,RGB(0,128,0),RGB(0,128,0), RGB(128,255,128), RGB(128,255,128)); 
    			
    		//this draws the images to the screen
    			oslDrawImage(sprite);
    			oslDrawImage(sprite2);
    			oslDrawImage(sprite3);
    			
    		//stops the drawing mode
    			oslEndDrawing();
    			
    		//sync the screen 
    			oslSyncFrame();
    		}
    		
    		//terminate the program
    		oslEndGfx();
    		oslQuit();
    		return 0;
    	}
    	
    		void Buttons()
    		{
    		//starts up the psp buttons
    			oslReadKeys();
    			
    		if (osl_keys->held.down)
    		{
    			if(!collision(sprite, sprite->x, sprite->y + 2, sprite2, sprite2->x, sprite2->y, sprite3, sprite3->x, sprite3->y ))
    			{
    			//sprite movement
    			sprite->y +=2;
    			
    			//sets sprite position on sprite sheet
    				sprite_position = DOWN;
    			
    			//calls sprie animate
    				SpriteAnimate();
    		}
    		}
    				
    			if (osl_keys->held.up)
    		{
    			if(!collision(sprite, sprite->x, sprite->y - 2, sprite2, sprite2->x, sprite2->y,sprite3, sprite3->x, sprite3->y ))
    			{
    				sprite->y-= 2;
    				sprite_position = UP;
    				SpriteAnimate();
    			
    		}
    		}
    		
    	   if (osl_keys->held.right)
        {
    			if(!collision(sprite, sprite->x + 2, sprite->y, sprite2, sprite2->x, sprite2->y,sprite3, sprite3->x, sprite3->y  ))
    			{
            sprite->x += 2;
            sprite_position = RIGHT;
            SpriteAnimate();
        }
    	}
    			
    		        if (osl_keys->held.left)
        {
    		if(!collision(sprite, sprite->x - 2, sprite->y, sprite2, sprite2->x, sprite2->y,sprite3, sprite3->x, sprite3->y  ))
    		{
            sprite->x -= 2;
            sprite_position = LEFT;
            SpriteAnimate();
        }
    	}
    			
    			   //If a button is not pressed
        if (!osl_keys->held.value) 
        {
        //Start the variable over for when a button is pressed again
            sprite_march = 0; 
    
            //Sets the sprite's direction
            oslSetImageTileSize(sprite,0,sprite_position,22,35);
        }
    }
    
    
    void SpriteAnimate()
       {    
            //Moves the sprite in the row that it is in
            sprite_march++;
    
            //Moves the sprite constantly
            oslSetImageTileSize(sprite,(sprite_march * 22),sprite_position,22,35);
    
            //resets the sprite movement in that row
            if (sprite_march == 6) sprite_march = 0;
        
    }
    			
    		
    		int collision(OSL_IMAGE *img1,float img1posX, float img1posY, OSL_IMAGE *img2, float img2posX, float img2posY, OSL_IMAGE *img3, float img3posX, float img3posY ) 
    {
       int collision;
       collision = 0;
       float img1width  = img1->stretchX;
       float img1height = img1->stretchY;
       float img2width  = img2->stretchX;
       float img2height = img2->stretchY;
       float img3width = img3->stretchX;
       float img3height = img3->stretchY;
      
       
       if ((img1posX + img1width > img2posX) &&
           (img1posX < img2posX + img2width) &&
    	   (img1posX + img1width > img3posX) &&
           (img1posX < img2posX + img3width) &&
           (img1posY + img1height > img2posY) &&
           (img1posY < img2posY + img2height) ) 
    {
             collision = 1;               
       }     
       return collision;
    }
    I know where the problem is but i dont know what im doing wrong


    Code:
    if ((img1posX + img1width > img2posX) &&
           (img1posX < img2posX + img2width) &&
    	   (img1posX + img1width > img3posX) &&
           (img1posX < img2posX + img3width) &&
           (img1posY + img1height > img2posY) &&
           (img1posY < img2posY + img2height) ) 
    {

    if i put that in, none of the sprites have collision but if i take out the Bolded parts the first sprite has collision but the second one dose not.(second sprite as in the second object, not the character that is moving). How do i modify this correctly for every new object on the screen? help will be greatly appreciated.
    can someone please help? =)

  17. #8327
    OMFG
    Points: 19.453, Level: 88
    Level completed: 21%, Points required for next Level: 397
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Toronto
    Beiträge
    2.814
    Points
    19.453
    Level
    88
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Xsjado7
    Say i had something like:
    Code:
    char str[32];
    sprintf(str, "score 1 = 10, score 2 = 13");
    how would i go about copying "score 2" into another string? strcpy doesnt let you set the params for where to copy to and from
    ugh
    Code:
    char str[64]; // I would go a little higher just incase of bigger variables
    int score1 = 10, score2 = 13;
    sprintf(str, "Score 1 = %i, Score 2 = %i", score1, score2);
    Look it over, it's pretty self explanatory. Store the scores in variables, then get them from there.

  18. #8328
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Slasher
    ugh
    Code:
    char str[64]; // I would go a little higher just incase of bigger variables
    int score1 = 10, score2 = 13;
    sprintf(str, "Score 1 = %i, Score 2 = %i", score1, score2);
    Look it over, it's pretty self explanatory. Store the scores in variables, then get them from there.
    I think he was asking about splitting an existing string.

  19. #8329
    QJ Gamer Bronze
    Points: 8.045, Level: 60
    Level completed: 48%, Points required for next Level: 105
    Overall activity: 0%

    Registriert seit
    Aug 2007
    Ort
    Australia
    Beiträge
    659
    Points
    8.045
    Level
    60
    Downloads
    0
    Uploads
    0

    Standard

    lol, yeah. For eample; i wanna cut "score = 2" and chuck it another string or something to that extent

  20. #8330
    QJ Gamer Bronze
    Points: 6.359, Level: 52
    Level completed: 5%, Points required for next Level: 191
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    france
    Beiträge
    170
    Points
    6.359
    Level
    52
    Downloads
    0
    Uploads
    0

    Standard std::string

    Zitat Zitat von Xsjado7
    lol, yeah. For eample; i wanna cut "score = 2" and chuck it another string or something to that extent
    Why not use std::string instead of messing around with char[] sprintf and the likes? it's so easier.
    http://www.cplusplus.com/reference/string/string/
    Try my latest game (iOS):


  21. #8331
    QJ Gamer Bronze
    Points: 8.045, Level: 60
    Level completed: 48%, Points required for next Level: 105
    Overall activity: 0%

    Registriert seit
    Aug 2007
    Ort
    Australia
    Beiträge
    659
    Points
    8.045
    Level
    60
    Downloads
    0
    Uploads
    0

    Standard

    my apps in C, not C++

  22. #8332
    QJ Gamer Bronze
    Points: 6.359, Level: 52
    Level completed: 5%, Points required for next Level: 191
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    france
    Beiträge
    170
    Points
    6.359
    Level
    52
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Xsjado7
    my apps in C, not C++
    you can still use std::strings I think, you'll just have to modify some things (.cpp instead of .c for your files, -lstdc++ added in your makefile). this won't stop you writing everything in C if you like, but you'll be able to use std::strings at the same time (you'll also benefit from iostreams & lists/vectors/maps, this will make your life a lot easier).
    Try my latest game (iOS):


  23. #8333
    QJ Gamer Bronze
    Points: 8.045, Level: 60
    Level completed: 48%, Points required for next Level: 105
    Overall activity: 0%

    Registriert seit
    Aug 2007
    Ort
    Australia
    Beiträge
    659
    Points
    8.045
    Level
    60
    Downloads
    0
    Uploads
    0

    Standard

    Oh, ok. Thanks for the help
    -= Double Post =-
    Just renamed my stuff and added the etra lib but i get errors thrown at me. Im going to try something else. Im gonna write the string to a temporary file on the memory stick. from there i can use sceIo functions like sceIoRead which allows me to tell it how far to read and such. Thanks again for the help though
    Geändert von Xsjado7 (04-01-2008 um 12:23 AM Uhr) Grund: Automerged Doublepost

  24. #8334
    QJ Gamer Bronze
    Points: 6.359, Level: 52
    Level completed: 5%, Points required for next Level: 191
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    france
    Beiträge
    170
    Points
    6.359
    Level
    52
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Xsjado7
    Just renamed my stuff and added the etra lib but i get errors thrown at me. Im going to try something else. Im gonna write the string to a temporary file on the memory stick. from there i can use sceIo functions like sceIoRead which allows me to tell it how far to read and such.
    really really bad solution. you better show us the errors and your code so we can help, or continue investigate proper C code with memcopy and all that crap.
    Try my latest game (iOS):


  25. #8335
    QJ Gamer Bronze
    Points: 8.045, Level: 60
    Level completed: 48%, Points required for next Level: 105
    Overall activity: 0%

    Registriert seit
    Aug 2007
    Ort
    Australia
    Beiträge
    659
    Points
    8.045
    Level
    60
    Downloads
    0
    Uploads
    0

    Standard

    Code:
    source/../settings/stats.h(26) : error: expected unqualified-id before 'throw'
    source/main.cpp: In function 'void newGame()':
    source/main.cpp(33) : error: 'mainGame' was not declared in this scope
    source/main.cpp: In function 'void mainGame()':
    source/main.cpp(89) : warning: passing 'double' for argument 4 to 'void fillScre
    enRect(Color, int, int, int, int)'
    source/main.cpp(90) : warning: passing 'double' for argument 4 to 'void fillScre
    enRect(Color, int, int, int, int)'
    source/main.cpp(115) : error: expected unqualified-id before 'throw'
    source/main.cpp(115) : error: expected `)' before 'throw'
    source/main.cpp(117) : error: expected unqualified-id before 'throw'
    source/main.cpp(117) : error: expected `;' before 'throw'
    source/main.cpp(118) : error: expected unqualified-id before 'throw'
    source/main.cpp(118) : error: expected `;' before 'throw'
    source/main.cpp: In function 'int main()':
    source/main.cpp(277) : error: cannot convert 'const char*' to 'short unsigned in
    t*' for argument '2' to 'int OSK(char*, short unsigned int*, short unsigned int*
    )'
    source/main.cpp(364) : error: cannot convert 'const char*' to 'short unsigned in
    t*' for argument '2' to 'int OSK(char*, short unsigned int*, short unsigned int*
    )'
    source/main.cpp(373) : error: 'dispCredits' was not declared in this scope
    My errors, and thats just from my main.cpp. I have more than 8 more source files

  26. #8336
    QJ Gamer Bronze
    Points: 6.359, Level: 52
    Level completed: 5%, Points required for next Level: 191
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    france
    Beiträge
    170
    Points
    6.359
    Level
    52
    Downloads
    0
    Uploads
    0

    Standard

    I'll need your main.cpp to see what's wrong.
    Try my latest game (iOS):


  27. #8337
    QJ Gamer Bronze
    Points: 8.045, Level: 60
    Level completed: 48%, Points required for next Level: 105
    Overall activity: 0%

    Registriert seit
    Aug 2007
    Ort
    Australia
    Beiträge
    659
    Points
    8.045
    Level
    60
    Downloads
    0
    Uploads
    0

    Standard

    Oh, forgot to mention, "throw" is actually a variable in my "player" struct. I take it its a command in C++ due to it being highlighted in Notepad++ when i type it

  28. #8338
    QJ Gamer Bronze
    Points: 6.359, Level: 52
    Level completed: 5%, Points required for next Level: 191
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    france
    Beiträge
    170
    Points
    6.359
    Level
    52
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Xsjado7
    Oh, forgot to mention, "throw" is actually a variable in my "player" struct. I take it its a command in C++ due to it being highlighted in Notepad++ when i type it
    yup, it's a reserved key word of the c++ language. hope this solves everything, if not post here.
    Try my latest game (iOS):


  29. #8339
    QJ Gamer Bronze
    Points: 8.045, Level: 60
    Level completed: 48%, Points required for next Level: 105
    Overall activity: 0%

    Registriert seit
    Aug 2007
    Ort
    Australia
    Beiträge
    659
    Points
    8.045
    Level
    60
    Downloads
    0
    Uploads
    0

    Standard

    Ok, i think iv got it sorted out. Do i have to code any different to use those new functions?

  30. #8340
    QJ Gamer Bronze
    Points: 6.359, Level: 52
    Level completed: 5%, Points required for next Level: 191
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    france
    Beiträge
    170
    Points
    6.359
    Level
    52
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Xsjado7
    Ok, i think iv got it sorted out. Do i have to code any different to use those new functions?
    only when using strings, remember that it's a c++ class, so to allocate memory for it (if you want to use pointers, which in most cases is not needed) istead of malloc use new, and instead of free use delete. apart from that, you can continue working completely in C.

    small example to get you started:
    PHP-Code:
    #include <string>
    using namespace std;

    string str ("this is a string");

    //now use the power of the string class: str.substr(), str.find()..
    //nothing else to do! 
    Try my latest game (iOS):



 

Tags for this Thread

Forumregeln

  • Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
  • Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
  • Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
  • Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.
  •  





Alle Zeitangaben in WEZ -8. Es ist jetzt 09:28 PM Uhr.

Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © , Caputo Media, LLC. All Rights Reserved. Cluster .