dioioib
YaBB Newbies
Offline
Posts: 12
Re: Gamesprite Draw Order
Reply #2 - Aug 12th , 2007, 2:30am
I have these variables: Monk m_a = new Monk(); // player 1 Monk m_b = new Monk(); // player 2 Monk enemy = new Monk(); // new enemy Monk enemy2 = new Monk(); // new enemy Monk enemy3 = new Monk(); // new enemy Monk enemy4 = new Monk(); // new enemy from class: public class Monk { int x = 130; // position of monk 'b' x-axis NOTE* constrain to play area int y = 64; // position of monk 'b' y-axis int z = 0; // position of monk 'b' z-axis - accounts for increased or decreased character scale int old_x = 0; // old positions int old_y = 0; int old_z = 0; int facing = 0; // facing 0 is to screen left, facing 1 is to screen right. int onGround = 1; // 1 = yes , 0 = no int playerNum = 1; // 0 = player 1, 1 = player 2. //stats int health = 100; int strength = 10; int vitality = 10; int holy = 50; float regen = 1; //Special stats / attacks boolean holyCow = false ; boolean holyMackerel = false; boolean holyMolie = false; boolean handOfGod = false; boolean sacraficialLamb = false; boolean theTenCommandments = false; boolean brewersYeast = false; boolean scribsScribbles = false; boolean blindFaith = false; boolean firstTestimate = false; boolean kingJames = false; boolean mosesWave = false; //animation sequence data = to the number of cells in the animation int sequence_walk = 2; int sequence_punch = 2; int sequence_stand = 4; PImage[] walkingL = new PImage[sequence_walk]; PImage[] walkingR = new PImage[sequence_walk]; PImage[] punchingL = new PImage[sequence_punch]; PImage[] punchingR = new PImage[sequence_punch]; PImage[] standingL = new PImage[sequence_stand]; PImage[] standingR = new PImage[sequence_stand]; void Monk(){ //nothing int sequence_walk = 2; // double the number to account for right and left movements. int sequence_punch = 2; // double the number to account for right and left movements. int sequence_stand = 4; // double the number to account for right and left movements. PImage[] walkingL = new PImage[sequence_walk]; PImage[] walkingR = new PImage[sequence_walk]; PImage[] punchingL = new PImage[sequence_punch]; PImage[] punchingR = new PImage[sequence_punch]; PImage[] standingL = new PImage[sequence_stand]; PImage[] standingR = new PImage[sequence_stand]; } void printVariables(){ print(x+y+z+old_x+old_y+old_z+facing+ onGround + playerNum+health+ strength+vitality+holy); } void update(){ if( x > old_x){ old_x = x; facing = 1; //character should face right } else if(x < old_x) { old_x = x; facing = 0; //character should face left } } boolean collision(int colliderA, int colliderB, int spriteWidth, int spriteHight){ // run the collision detection // very basic collision detection just tells if the two sprites have any portions touching. if ( colliderA <= x && colliderA >= (x + spriteHight)){ if (colliderB <= y && colliderB >= (y + spriteWidth)){ return true; } } else{ return false; } return false; } void drawWalking(int frameNumber){ if(facing == 0){ image(walkingL[frameNumber], x , y); } else if(facing == 1){ image(walkingR[frameNumber], x , y); } } void drawStanding(int frameNumber){ if(facing == 0){ image(standingL[frameNumber], x , y); } else if(facing == 1){ image(standingR[frameNumber], x , y); } } void drawPunching(int frameNumber){ if(facing == 0){ image(punchingL[frameNumber], x , y); } else if(facing == 1){ image(punchingR[frameNumber], x , y); } } } What is the best way to display these game sprites to answer the problem: If monk.y is larger than all other monk.y's draw PImage first ... Is there an easy way to implement this with out bloating my code with a huge number of "if" statements?