Search Results

Search found 3 results on 1 pages for 'happybirthday'.

Page 1/1 | 1 

  • Pixel Perfect Collision Detection in Cocos2dx

    - by Happybirthday
    I am trying to port the pixel perfect collision detection in Cocos2d-x the original version was made for Cocos2D and can be found here: http://www.cocos2d-iphone.org/forums/topic/pixel-perfect-collision-detection-using-color-blending/ Here is my code for the Cocos2d-x version bool CollisionDetection::areTheSpritesColliding(cocos2d::CCSprite *spr1, cocos2d::CCSprite *spr2, bool pp, CCRenderTexture* _rt) { bool isColliding = false; CCRect intersection; CCRect r1 = spr1-boundingBox(); CCRect r2 = spr2-boundingBox(); intersection = CCRectMake(fmax(r1.getMinX(),r2.getMinX()), fmax( r1.getMinY(), r2.getMinY()) ,0,0); intersection.size.width = fmin(r1.getMaxX(), r2.getMaxX() - intersection.getMinX()); intersection.size.height = fmin(r1.getMaxY(), r2.getMaxY() - intersection.getMinY()); // Look for simple bounding box collision if ( (intersection.size.width0) && (intersection.size.height0) ) { // If we're not checking for pixel perfect collisions, return true if (!pp) { return true; } unsigned int x = intersection.origin.x; unsigned int y = intersection.origin.y; unsigned int w = intersection.size.width; unsigned int h = intersection.size.height; unsigned int numPixels = w * h; //CCLog("Intersection X and Y %d, %d", x, y); //CCLog("Number of pixels %d", numPixels); // Draw into the RenderTexture _rt-beginWithClear( 0, 0, 0, 0); // Render both sprites: first one in RED and second one in GREEN glColorMask(1, 0, 0, 1); spr1-visit(); glColorMask(0, 1, 0, 1); spr2-visit(); glColorMask(1, 1, 1, 1); // Get color values of intersection area ccColor4B *buffer = (ccColor4B *)malloc( sizeof(ccColor4B) * numPixels ); glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, buffer); _rt-end(); // Read buffer unsigned int step = 1; for(unsigned int i=0; i 0 && color.g 0) { isColliding = true; break; } } // Free buffer memory free(buffer); } return isColliding; } My code is working perfectly if I send the "pp" parameter as false. That is if I do only a bounding box collision but I am not able to get it working correctly for the case when I need Pixel Perfect collision. I think the opengl masking code is not working as I intended. Here is the code for "_rt" _rt = CCRenderTexture::create(visibleSize.width, visibleSize.height); _rt-setPosition(ccp(origin.x + visibleSize.width * 0.5f, origin.y + visibleSize.height * 0.5f)); this-addChild(_rt, 1000000); _rt-setVisible(true); //For testing I think I am making a mistake with the implementation of this CCRenderTexture Can anyone guide me with what I am doing wrong ? Thank you for your time :)

    Read the article

  • Path Finding for an Arena based map in 3D using NavMesh

    - by Happybirthday
    I have a 3D arena map (consider a small island surrounded by water on all sides) for a multiplayer Tank fight game. The moveable areas are marked using a Navigation Mesh made by the Arena designer. My question is what would be the best way for navigation in such an environment ? Specially considering the case when there is a Bridge at the center of the arena and you could walk under it or even above it ? If suppose the enemy is standing at the top of the Bridge and my AI is at one of the edges of the map ? How can it know whether the enemy is above or below the bridge and how can it navigate till it ?

    Read the article

  • using switch in strings

    - by xtemer
    guys me trying to use switch in strings by first coverting string into char and then apply switch but still didnt done it....here is my code..help me out.. import javax.swing.*; import java.io.*; class HappyBirthday { public static void main(String[] args) throws IOException { String Month; char[] Months = Month.toCharArray(); BufferedReader dataIn= new BufferedReader(new InputStreamReader(System.in)); System.out.println("Please enter your month."); Month = JOptionPane.showInputDialog("enter month"); String month1={"January","feb"}; char[] month2 = month1.toCharArray(); // String s=month1.equals(Month); //System.out.print(month2Array[0]); switch (month2) { case 0: System.out.println("kool"); break; case 1: System.out.println("not kool"); break; default: }}} /** if (month1[1].equals(Month)) System.out.println("kool"); else if(month1[0].equals(Month)) System.out.println("kooooooooooooool"); else System.out.println("Big kooooool"); **/

    Read the article

1