Forum: PS3 Technical Development - Topics relating to Playstation 3 Technical development ONLY! Read and discuss the latest Cobra USB updates, tutorials and explanations or find out about bluray drive bypass firmwares plus much more.


The above video goes away if you are a member and logged in, so log in now!




 
Would you like to get all the new info from
PSX-Scene in your email each day?




Want to learn more about the team keeping you up to date with the latest scene news?

Read about them now!

Check out our Developer bios, too!

 


User Tag List

Thread: Sanke port
  

Results 1 to 2 of 2
  1. #1 Sanke port 
    RootedSys is offline Member
    Join Date
    Aug 2010
    Posts
    33
    Downloads
    0
    Uploads
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Likes Given
    0
    Likes Received
    0
    I'v been wanting to port snake over to the ps3, I'm not good at programming for the most part and just started learning some stuff on the psgl. So I'm porting an open source sanke game here , the buttons and everything I know the only thing I don't know how to do is draw the boundaries and objects to the screen

    You can see most of the code is just logic which makes it an ideal game to port as not a lot needs to be known about the ps3.

    Heres the incomplete code below, feel free to help on it.

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    
    #include <cell/pad.h>
    
    #include <sys/process.h>
    #include <sys/spu_initialize.h>
    #include <sys/paths.h>
    
    #include <PSGL/psgl.h>
    #include <PSGL/psglu.h>
    #include <Cg/cg.h>
    
    #include <cell/dbgfont.h>
    #include "../../Common/gfxCommon.h"
    #include "../../Common/gfxPad.h"
    
    // Macros
    #define LEFT 1
    #define RIGHT 2
    #define UP 3
    #define DOWN 4
    
    //Game settings
    int score; //Keeps the count of game score
    int gamedelay;//Lower the game delay faster is the game speed.
    
    struct Snake_Data {
    int length;
    int head_x; // Stores Head X Coordinate
    int head_y; // Stores Head Y Coordinate
    int head_dir; // Stores Head Direction
    int tail_x; // Stores Tail X Coordinat
    int tail_y; // Stores Tail Y Coordinat
    int tail_dir; // Stores Tail Direction
    int bend_x [1000]; //Stores X Bend Coordinate Declare it big enough to accomodate maximum bends
    int bend_y [1000]; //Stores Y Bend Coordinate Declare it big enough to accomodate maximum bends
    int bend_dir [1000]; // Stores Bend direction when tail reaches that X Coordinate
    } Snake; // Declares a variable of the structure
    
    void userinput()
    {
    		
          //Read ps3 pad 
    	gfxPadRead();
    
      static int i = 0;
      if ( i > 1000) i = 0; // Makes the bend array a circular queue
      static int j = 0;
      if ( j > 1000) j = 0;
      char input;
      if (kbhit ())
       {
         
        //Change Respective Return value to our MACRO Direction Code Value 
                   
         if (gfxDpadDown(0)) input = DOWN;
                   
         if (gfxDpadUp(0)) input = UP;
                   
         if (gfxDpadLeft(0)) input = LEFT;
                   
         if (gfxDpadRight(0)) input = RIGHT;
    
       //Change head direction based on logic
                   
         if (input == LEFT && Snake.head_dir != RIGHT && Snake.head_dir != LEFT)
            {
              Snake.head_dir = LEFT; 
              Snake.bend_x [i] = Snake.head_x;
              Snake.bend_y [i] = Snake.head_y;
              Snake.bend_dir [i] = LEFT;
              i++;
            } 
         if (input == RIGHT && Snake.head_dir != LEFT && Snake.head_dir != RIGHT)
            {
              Snake.head_dir = RIGHT;
              Snake.bend_x [i] = Snake.head_x;
              Snake.bend_y [i] = Snake.head_y;
              Snake.bend_dir [i] = RIGHT;
              i++; 
             }
         if (input == UP && Snake.head_dir != DOWN && Snake.head_dir != UP)
            {
              Snake.head_dir = UP;
              Snake.bend_x [i] = Snake.head_x;
              Snake.bend_y [i] = Snake.head_y;
              Snake.bend_dir [i] = UP;
              i++; 
            }
        if (input == DOWN && Snake.head_dir != UP && Snake.head_dir != DOWN)
            {
              Snake.head_dir = DOWN; 
              Snake.bend_x [i] = Snake.head_x;
              Snake.bend_y [i] = Snake.head_y;
              Snake.bend_dir [i] = DOWN;
              i++; 
             } 
    
    }
    
    void movesnake ()
     {
      //Move the Head
      if (Snake.head_dir == LEFT)
         {
            Snake.head_x --; 
         }
      if (Snake.head_dir == RIGHT) 
         {
            Snake.head_x ++; 
         }
      if (Snake.head_dir == UP) 
         {
           Snake.head_y --;
         }
      if (Snake.head_dir == DOWN) 
         {
           Snake.head_y ++;
         } 
      putpixel (Snake.head_x, Snake.head_y,15); //Conver to ps3
      
      //Move the Tail
      putpixel (Snake.tail_x, Snake.tail_y,0); //Convert to ps3
    
      if (Snake.tail_dir == LEFT)
          {
            Snake.tail_x --; 
          }
      if (Snake.tail_dir == RIGHT) 
          {
            Snake.tail_x ++; 
          }
      if (Snake.tail_dir == UP) 
          {
            Snake.tail_y --;
          }
      if (Snake.tail_dir == DOWN) 
          {
            Snake.tail_y ++;
          }
    }
    
    void gameengine ()
     {
       while (1) 
         {
           movesnake ();
           userinput ();
           delay (5);
         }
      }
    
    void snakeRender() 
    {
    	 int i;
          char scorestring [100];
          //Print title and score
          dbgFontPrintf(40,70,1.0f,"Snake For Ps3");
          printf(scorestring, "Score: %.2f\n", score);
        
          dbgFontDraw();
    }
    
    void initgamedata ( ) //Snakes starting coordinate if you modify any one make sure also modify dependent values
     {
       int i;
       Snake.length = 100;
       Snake.head_x = 200;
       Snake.head_y = 200;
       Snake.head_dir = RIGHT;
       Snake.tail_x = Snake.head_x- Snake.length;
       Snake.tail_y = Snake.head_y;
       Snake.tail_dir = Snake.head_dir;
       for (int i = 0; i <1000;i++) // There is no bend initally
         {
           Snake.bend_x[i] = 0;
           Snake.bend_y[i] = 0;
           Snake.bend_dir[i] = 0; 
         }
        score = 0;
        gamedelay = 1000; // Should be change according to game speed need. 
    }
    
    
    SYS_PROCESS_PARAM(1001, 0x10000)
    
    int main() {
       sys_spu_initialize(6, 1);   
       gfxInitGraphics();   
       gfxInitPad(); 
       dbgFontInit();  
     
       while (1) {
          
    		//Clear screen on start up
    		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    
    		initgamedata ();
               snakeRender();
               gameengine ();
    
           // swap PSGL buffers 
              psglSwap();
       }
    
       return 0;
       
    }
    Reply With Quote  

  2. #2  
    psx1 is offline Registered User
    Join Date
    Sep 2010
    Posts
    22
    Downloads
    0
    Uploads
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Likes Given
    0
    Likes Received
    0
    Solid Snake....
    Reply With Quote  

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •