XNA Creators Club Online
Page 1 of 1 (6 items)
Sort Posts: Previous Next

Destroy 2D scenario like Worms

Last post 2/20/2009 6:10 PM by Keshi. 5 replies.
  • 2/19/2009 4:54 PM

    Destroy 2D scenario like Worms

    Hi, I am writting a 2D game, i want that the scenario can be destroyed when the player launch a bomb, whit a worms similar effect. I don't know as can get this effect.
    Thank's
  • 2/19/2009 5:02 PM In reply to

    Re: Destroy 2D scenario like Worms

    If you want to do it the same way Worms do then you simply take the impact point and specify a diameter to the size of the impact crater then remove all pixels within the diameter from your level graphic. It's not really a very complex concept. You're just removing the pixels from the level.
    Retroburn Game Studios
    XBoxArt.com - Now includes box art from Community games, Arcade games and Retail 360 games!
  • 2/19/2009 7:05 PM In reply to

    Re: Destroy 2D scenario like Worms

    Ok, thank's. I'm loocking for who can i remove pixels and i will try to do it!
  • 2/19/2009 7:26 PM In reply to

    Re: Destroy 2D scenario like Worms

    http://blog.xna3.com/2007/12/2d-deformable-level.html

    I'm trying to do something similar, the above is a good starting point.

    I've got it to a point where my projectile is deforming the level once but I have hit a glitch.  It only deforms the first time, if I get the projectile to hit the same spot again it seems like it recognizes the fact the terrain was there (even though there is a crater alpha'd out).  This means I can never fire into a crater to make it deeper.  My first attmept I had the opposite, Once I fired it tunnel through the entire landscape in one hit.

    Any ideas?

    Mat
  • 2/20/2009 10:03 AM In reply to

    Re: Destroy 2D scenario like Worms

    How are you doing you're collision detection?
    It sounds like you are doing a getdata on your screen graphic to get an array of pixel values, and not updating it after deforming the landscape. You'll need to redo the getdata everytime you deform the level.
  • 2/20/2009 6:10 PM In reply to

    Re: Destroy 2D scenario like Worms

    Hi

    The code below is run when I detect the collision has occured

            protected void DeformLevel() 
            { 
                //// Declare an array to hold the pixel data 
                //uint[] pixelLevelData = new uint[textureLevel.Width * textureLevel.Height]; 
                //// Populate the array 
                //textureLevel.GetData(pixelLevelData, 0, textureLevel.Width * textureLevel.Height); 
     
            for (int x = 0; x < textureDeform.Width; x++) 
            { 
                for (int y = 0; y < textureDeform.Height; y++) 
                { 
                    // Do some error checking so we dont draw out of bounds of the array etc.. 
                    if (((cannonBall.position.X + x) < (textureLevel.Width))&&((cannonBall.position.Y + y) < (textureLevel.Height))) 
                        { 
                            if ((cannonBall.position.X + x) >= 0 && (cannonBall.position.Y + y) >= 0) 
                        { 
                        // Here we check that the current co-ordinate of the deform texture is not an alpha value 
                        // And that the current level texture co-ordinate is not an alpha value 
                            if (pixelDeformData[x + y * textureDeform.Width] != 16777215  
                            && pixelLevelData[((int)cannonBall.position.X + x) + 
                            ((int)cannonBall.position.Y + y) * textureLevel.Width] != 16777215) 
                            { 
                            // We then check to see if the deform texture's current pixel is white (4294967295) 
                                if (pixelDeformData[x + y * textureDeform.Width] == 4294967295) 
                                { 
                                // It's white so we replace it with an Alpha pixel 
                                    pixelLevelData[((int)cannonBall.position.X + x) + ((int)cannonBall.position.Y + y) 
                                * textureLevel.Width] = 16777215; 
                                 
                                } 
                                else 
                                { 
                                    // Its not white so just set the level texture pixel to the deform texture pixel 
                                    pixelLevelData[((int)cannonBall.position.X + x) + ((int)cannonBall.position.Y + y) 
                                * textureLevel.Width] = pixelDeformData[x + y * textureDeform.Width]; 
                                 
                                } 
     
                                 
                                 
                            } 
                        } 
                    } 
                } 
            } 
     
     
            // Update the texture with the changes made above 
            textureLevel.SetData(pixelLevelData); 
            } 

Page 1 of 1 (6 items) Previous Next