help me to rotae an arrow 360 degree?

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

help me to rotae an arrow 360 degree?

Postby itskrishnaraj » Fri Sep 05, 2008 7:18 am

Hi all
im developing a game (j2me)....
in this i want to impliment a throwing effect....
ie .the player1 want to throw an obstacle (image) to player2....
The player1 've the option to choose force and direction.
according to this force and direction i want to make the throw. The throw should move like a parabola ....

i ve a sample midlet(given bellow) which is for 90 degree(ie the throw is possible only to right side)...
i want to make it 360 degree..

plz help me to make it in 360 degree........


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); //suppose 2+ force
ySpeed = - (10 + rand.nextInt(10));

xPosition = 20;
yPosition = 200;

}

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()
{
/* this equation is for one direction , i want to make it 4 all direction */
ySpeed += gravity;
xPosition += xSpeed;
yPosition += ySpeed;

if(xPosition > stageWidth || yPosition > stageHeight)
{
newStone();// next throw starting
}
}

public void run()
{
while(true)
{
try
{
repaint();

moveStone();

synchronized(this)
{
wait(100L);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

}


in this sample Midlet assume force and direction are taking as random numbers.........

is there any other logic to impliment this ?


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

Re: help me to rotae an arrow 360 degree?

Postby DevelopmentTeam » Fri Sep 05, 2008 7:25 am

we already have posted a code for throwing an object in parabola, which is similar to jumping. please check that code. And if you mean rotating an image in 360 degrees, In J2ME we don't have any such function that can rotate an image in each angle and that is CPU consuming even if you try yourself. Better use and array of sprites.
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Re: help me to rotae an arrow 360 degree?

Postby hannaaran » Sat Sep 13, 2008 6:48 am

How can I accomblish an arrow, which is pointing into directions between 0° - 360°. The easy way would be to just rotate an image by a certain degree. But I couldn't find any information on how to rotate images. Is this possible at all?
---------------------------------------

hannaaran
hannaaran
 

Re: help me to rotae an arrow 360 degree?

Postby DevelopmentTeam » Sat Sep 13, 2008 7:07 am

You have to render it with lines and fill polygons. Otherwise Image rotation would be difficult in J2ME
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: Majestic-12 [Bot] and 1 guest

cron