Regarding Parabola points

Forum for J2ME mobile games related topics including programming doubts, books and other resources for J2ME game development

Regarding Parabola points

Postby uvrpavan » Tue Aug 28, 2007 4:09 pm

hi,
i am doing a game in wich i need to use a ball.to make a effect of ball bouncing in the 2D i want to darw the ball in a parabolic path.so
can u give me the source code wich will return the points in a parabolic shape...
uvrpavan
 
Posts: 19
Joined: Sun Feb 11, 2007 8:52 am

Postby DevelopmentTeam » Wed Aug 29, 2007 1:02 pm

1) we calculate the parabolic path with simple algorithm... with 2 variables, say xspeed and yspeed.
2) Reduce yspeed untill the object reaches the surface...
3) Reduce xspeed according to time and yspeed.
4) yspeed can go negative but xspeed is always positive.
5) add the xspeed to x co-ordinate of object and yspeed to y co-ordinate of the object.
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Postby DevelopmentTeam » Wed Aug 29, 2007 1:15 pm

I'll try to post the code in couple of days...
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Re: Regarding Parabola points

Postby DevelopmentTeam » Thu Aug 07, 2008 3:04 pm

Request from @itskrishnaraj

Code: Select all
        if(jumping) {
            y -= speed;
            jumpCounter++;
            if(jumpCounter * speed > maxJump) {
                jumpCounter = 0;
                jumping = false;
                falling = true;
            }
        } else if(falling) {
            y += speed;
            if(y <= groundx) {
                  falling = false;
            }
        }
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Re: Regarding Parabola points

Postby itskrishnaraj » Fri Aug 08, 2008 5:39 am

DevelopmentTeam wrote:Request from @itskrishnaraj

Code: Select all
        if(jumping) {
            y -= speed;
            jumpCounter++;
            if(jumpCounter * speed > maxJump) {
                jumpCounter = 0;
                jumping = false;
                falling = true;
            }
        } else if(falling) {
            y += speed;
            if(y <= groundx) {
                  falling = false;
            }
        }







thanks man.....
itskrishnaraj
 
Posts: 39
Joined: Thu Aug 07, 2008 1:28 pm

Re: Regarding Parabola points

Postby DevelopmentTeam » Fri Aug 08, 2008 6:33 am

no probs. Happy coding... ;)
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Re: Regarding Parabola points

Postby itskrishnaraj » Tue Aug 19, 2008 11:18 am

hi friends

i m doing a game in that a character willl throw a stone from a side to other side...consider from left to right.

when the character throws it it should reach other side with a realistic feeling...i m trying to use some ophysics concepts in my code...each and every time he /she throw the stone it should go randomly...

can anybody help me to sort this out....
itskrishnaraj
 
Posts: 39
Joined: Thu Aug 07, 2008 1:28 pm

Re: Regarding Parabola points

Postby DevelopmentTeam » Tue Aug 19, 2008 1:05 pm

I thing you have already answered your question. Make the path random. That should solve it.
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Re: Regarding Parabola points

Postby itskrishnaraj » Wed Aug 20, 2008 1:09 pm

DevelopmentTeam wrote:I thing you have already answered your question. Make the path random. That should solve it.


thanks for the comment yaar....when i throw the stone upward i m increasing the x position and decreasing the y position ..when it reaches a fixed position the stone comes down using the reverse order...but its not giving a realistic throwing feeling...it just creating a diagonal path only...

i m trying to throw the stone in a parabolic path...or a projectile motion ...pls help me if you hav any sample or any suggestion


thanks in advance
kris
itskrishnaraj
 
Posts: 39
Joined: Thu Aug 07, 2008 1:28 pm

Re: Regarding Parabola points

Postby DevelopmentTeam » Wed Aug 20, 2008 5:56 pm

If you want to make the parabola random, then vary the xspeed and yspeed for every throw. This will give the difference. Some times the stone will fall near and sometimes far. Other you can try randomizing the xspeed alone.
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Re: Regarding Parabola points

Postby itskrishnaraj » Thu Aug 21, 2008 6:22 am

DevelopmentTeam wrote:If you want to make the parabola random, then vary the xspeed and yspeed for every throw. This will give the difference. Some times the stone will fall near and sometimes far. Other you can try randomizing the xspeed alone.



ya got it man....thanks for the suggestion


here is teh code ..if any body want ..jus use it

Code: Select all
import java.util.Random;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;

public class RandomStoneCanvas extends Canvas implements Runnable
{
   int xPosition = 0;
   int yPosition = 0;
   int xSpeed = 0;
   int ySpeed = 0;
   int gravity = 1;
   Random rand = null;
   
   int stageWidth = 0;
   int stageHeight = 0;
   customfont midlet;
   
   public RandomStoneCanvas(customfont m_Midlet)
   {
      midlet = m_Midlet;
      rand = new Random();
      
      stageWidth = getWidth();
      stageHeight = getHeight();
      
      newStone();
      
      new Thread(this).start();
   }
   public void newStone()
   {
      xSpeed =   2 + rand.nextInt(20);
      System.out.println("XSPEED- "+xSpeed);
   ySpeed = - (10 + rand.nextInt(10));
   System.out.println("YSPEED- "+ySpeed);
   System.out.println("------------------------------------------");
      
   xPosition = 50;
   yPosition = 240;

   /*   xSpeed = 5 + rand.nextInt(20);
      ySpeed = 0;
      
      xPosition = 0;
      yPosition = 100;   */
   }

   public void paint(Graphics g)
   {
      g.setColor(0xffffff);
      g.fillRect(0, 0, getWidth(), getHeight());
      
      g.setColor(0x000000);
      g.fillRect(xPosition - 2,yPosition - 2, 4, 4);
   }
   void moveStone()
   {
      ySpeed += gravity;
      
      xPosition += xSpeed;
      yPosition += ySpeed;
      
      if(xPosition > stageWidth || yPosition > stageHeight)
      {
         newStone();
      }
   }
   public void run()
   {
      while(true)
      {
         try
         {
            repaint();
            
            moveStone();
            
            synchronized(this)
            {
               wait(100L);
            }
         }
         catch(Exception e)
         {
            e.printStackTrace();
         }
      }
   }

}



happy coding
itskrishnaraj
 
Posts: 39
Joined: Thu Aug 07, 2008 1:28 pm

Re: Regarding Parabola points

Postby DevelopmentTeam » Thu Aug 21, 2008 6:57 am

Thanks for the post @itskrishnaraj
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India


Return to J2ME Games

Who is online

Users browsing this forum: No registered users and 2 guests

cron