• Create Account

# PsionicTransvection

Member Since 07 Feb 2012
Offline Last Active Jun 29 2013 01:02 PM

### Projectile Motion (Parabola)

17 August 2012 - 06:58 AM

So here is the thing I`m working on a small game which it looks like this

there are 2 tanks shooting at each other in turns and you are supposed to change the angle (moving arrow up or arrow down) and the power with which the projectile is flying (holding down the space the longer you hold the more power the projectile gets).

So far managed to make a small figure moving around the screen and shooting but until this point I made it shoot only in a straight line
searched a lot of links and videos about this problem I found the formulas needed for calculating the curve but still have problems applying it in my code :/ I`m open to any suggestions or criticisms I`m sure I`m doing something wrong all advices and code examples will be gladly appreciated looking forward for your posts I really need help with the parabola problem .

Here is the shoot method which makes the projectile move it`s a rectangle :

(sorry for not putting the code in tags for some reason when I do it does not print the whole code)

public void shoot()
{
if (shot)
{
bullet.x -= 5;
bullet.y--;

System.out.println(bullet.y);
if (bullet.x <= 0)
{
System.out.println("Boom");
boom = true;
//power = 0;
}

}
}

I also attached a rar with the whole code so far it`s only 2 classes it`s not much

### Moving an image

08 June 2012 - 12:09 PM

```import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.*;

public class View extends JFrame implements KeyListener
{
JPanel jp = new JPanel();
JLabel jl1 = new JLabel();

ImageIcon img = new ImageIcon(getClass()
.getResource("/images/Standing.png"));

static int Xposition = 0;
static int Yposition = 300;

public View()
{
setTitle("GG");
setSize(800, 600);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
jp.setLayout(null);
setLocationRelativeTo(null);
jl1.setIcon(img);
jl1.setBounds(Xposition, Yposition, jl1.getIcon().getIconWidth(), jl1
.getIcon().getIconHeight());
validate();
}

public static void main(String[] args)
{
View view = new View();

}

@Override
public void keyPressed(KeyEvent e)
{

int keyCode = e.getKeyCode();

}

@Override
public void keyReleased(KeyEvent e)
{

}

@Override
public void keyTyped(KeyEvent e)
{

}
}```

once I have loaded an image into the JFrame how can I make it move with the arrow keys I saw some tutorials how to do it if you draw a figure yourself but how to do with an actual image you have loaded ?

### Problem with JAVA ImageIcon

08 June 2012 - 02:34 AM

```import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class View extends JFrame
{

JPanel jp = new JPanel();
JLabel jl1 = new JLabel();
ImageIcon figure = new ImageIcon(getClass().getResource("/blank.png")); // I get the exception here

public View(){
setTitle("test");
setSize(800, 600);
setResizable(false);
setVisible(true);
setLocationRelativeTo(null);
jl1.setIcon(figure);
jl1.setBounds(0, 0, jl1.getIcon().getIconWidth(), jl1.getIcon()
.getIconHeight());
validate();
}
public static void main(String[] args){
new View();
}
}```

for some reason I can`t fetch the image and the path and name is correct checked it several times
and the funny thing is I`m doing it by checking some old code of mine and there is working perfectly ...
This is the exception I get any Ideas ?

Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:167)
at View.<init>(View.java:14)
at View.main(View.java:30)

### OpenGL vs DirectX ?

29 May 2012 - 01:30 PM

Could you tell me which one is better to use ?

### Modeling and coding

29 March 2012 - 01:44 AM

So my question is when you make some 3D model or some 3D animation on let`s say 3D studio max and after that when you export it or something how do you actually connect it the source code of the game ?

PARTNERS