We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
collision (Read 346 times)
collision
Jan 26th, 2009, 6:47pm
 
Hello everyone!!!
I'm developing a platform game. Similar to super mario.
I have a character that needs to climb platforms to reach the top of the screen.
I already have a "character" moving left, right, and jumping.
What I haven't managed to do yet is making my character standing on the platforms.
Another problem I have is when my character is on a platform and I jump he goes back to the initial "y" position (which is under the platform) "that's not right lol".


Anyways I just need a little orientation with this part of my game:

1 - I need to make my platforms standable for my character;
2 - I need for when my character does evedently stand on a platform for him to keep on jumping higher to reach the top of the stage and not the bottom.

If anyone can give me some orientation with this I would very much apreciate it!!!!

Thank you so much!

This is what I have so far... and I'm using images not objects (my background image is a random image and I haven't drawn or created platforms yet; I'm using classes so I'll show my character code:


class Hero
{
 //initial position

 float hcX = 60;
 float hcY = 145;  


 String dirState = "right";
 String stillState = "right";
 String jumpState =  "none";  


 // Declares all the images for the right and left sequences

 int maxImagesR = 9; // Total number of  images
 int imageIndexR = 0; // Initial image to be displayed

 int maxImagesL = 9;
 int imageIndexL = 0;
 //



 PImage[] imagesR = new PImage[maxImagesR];
 PImage[] imagesL = new PImage[maxImagesL];

 // Loads all the images for the right and left sequences
 /*

  0 - standing
  1-3 - Running
  4 - jumping  
   
  */
 void loadImages()
 {
   // Load all images running right
   for (int i = 0; i < imagesR.length; i++) {
     imagesR[i] = loadImage("hcR" + i + ".png");
   }  
   // Load all images running left
   for (int j = 0; j < imagesR.length; j++) {
     imagesL[j] = loadImage("hcL" + j + ".png");
   }  

 }

 void runRight()
 {
   dirState = "right";
   if (imageIndexR <= 4){
     imageIndexR += 1;
     hcX+=4;
   }

   if (Char.imageIndexR > 4) {
     imageIndexR = 2;  
   }
 }

 void runLeft()
 {
   dirState = "left";
   if (imageIndexL <= 4){
     imageIndexL += 1;
     hcX-=4;
   }

   if (imageIndexL > 4) {
     imageIndexL = 2;  
   }
 }

 void still()
 {
   dirState = "still";

   if (stillState == "right"){
     imageIndexR = 0;

   }

   if (stillState == "left"){
     imageIndexL = 0;
   }

   hcX -=0;

 }

 void update()
 {  
   //println(dirState);


 }

 void jumping(){

   if (jumpState == "jump")
   {
     hcY -= 6;
     if(hcY <= 100) {
       jumpState = "falling";
     }
   }    
 }
   

 void falling(){
   if(jumpState == "falling")
   {
     hcY +=5;
     if(hcY >= 145){
       jumpState = "none";
       hcY = 145;

     }
   }  
 }

 
 void checkState()
 {
   if (dirState == "right"){
     runRight();
     stillState = "right";
   }  
   else if (dirState == "left"){
     runLeft();
     stillState = "left";
   }  
   else if (dirState == "still"){
     still();
   }  

   if (jumpState == "jump"){
     jumping();
   }  
   else if (jumpState == "falling"){
     falling();
   }  

 }

}






Page Index Toggle Pages: 1