Results 1 to 20 of 36
Thread: Can you help me?
- 12-27-2009, 05:48 AM #1
Member
- Join Date
- Dec 2009
- Location
- Indonesia
- Posts
- 21
- Rep Power
- 0
- 12-28-2009, 07:36 AM #2
Member
- Join Date
- Jul 2009
- Location
- batticaloa, Sri Lanka
- Posts
- 30
- Rep Power
- 0
do you want make kinda 3d FPS or old console like 2d shooter games, i dont think so it is such a small process to be explained in a tutorial. anyway i found this site on google search The Java 2D games tutorial
hope it will help to get started
- 12-28-2009, 11:47 AM #3
Member
- Join Date
- Dec 2009
- Location
- Indonesia
- Posts
- 21
- Rep Power
- 0
- 12-28-2009, 02:24 PM #4
Member
- Join Date
- Jul 2009
- Location
- batticaloa, Sri Lanka
- Posts
- 30
- Rep Power
- 0
did u check the link i gave. it is very good starting point.
Collision detection
check out this link, i think this is what you want
- 12-29-2009, 04:54 AM #5
Member
- Join Date
- Dec 2009
- Location
- Indonesia
- Posts
- 21
- Rep Power
- 0
Yes, you're right, but i want ask more similar games shooter..
the link you provided was excellent. thanks.
whether the games were games desktop or mobile games, maybe you know?
Sorry if my English bad..
Hehe..
- 12-29-2009, 05:14 AM #6
Member
- Join Date
- Jul 2009
- Location
- batticaloa, Sri Lanka
- Posts
- 30
- Rep Power
- 0
those are for desktop. i really dont know that much about game development, im also new to java. if you google you will get what you want perhaps...:)
- 12-29-2009, 05:29 AM #7
Member
- Join Date
- Dec 2009
- Location
- Indonesia
- Posts
- 21
- Rep Power
- 0
Haha, you're right srisar..
I searching on google but nothing i've found..
Its hard to find a free code, but you can found it.. LOL..
Hahaha.
Thanks Srisar
- 12-29-2009, 05:33 AM #8
Member
- Join Date
- Jul 2009
- Location
- batticaloa, Sri Lanka
- Posts
- 30
- Rep Power
- 0
believe me man, i just searched the keyword as "java games tutorial" and got the result. you have to try like that.. perhaps search it on sourceforge, you may get
- 12-29-2009, 05:52 AM #9
Member
- Join Date
- Dec 2009
- Location
- Indonesia
- Posts
- 21
- Rep Power
- 0
Hahha..
maybe only i cannot find it.
Ok then, i will seach it..
Thanks. :)
- 12-30-2009, 08:08 AM #10
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Or search the forum. You can find lots of details related to you question.
And if you can create your own for the assignment it's much better. Good luck :)
- 12-30-2009, 12:44 PM #11
Member
- Join Date
- Dec 2009
- Location
- Indonesia
- Posts
- 21
- Rep Power
- 0
Ok i will search again.
Ehm, Maybe you know how to put Jpanel on the Jframe?
Thanks Eranga. :)Last edited by Kenshei; 12-30-2009 at 01:41 PM.
- 12-30-2009, 03:24 PM #12
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I'll give a simple example code segment here. But you must study more about those things before digging into your assignment.
Java Code:JFrame myFrame = new JFrame("Title Bar Text"); JPanel panel = new JPanel(); myFrame.setSize(256,256); myFrame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE); // Rest of the properties myFrame.getContentPane().add(panel); myFrame.pack(); myFrame.setVisible(true);
- 12-31-2009, 03:03 PM #13
Member
- Join Date
- Dec 2009
- Location
- Indonesia
- Posts
- 21
- Rep Power
- 0
Thanks yow Eranga.. =)
- 01-01-2010, 02:28 AM #14
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You are welcome. If you've solved the problem please mark thread solved.
- 01-05-2010, 05:24 AM #15
Member
- Join Date
- Dec 2009
- Location
- Indonesia
- Posts
- 21
- Rep Power
- 0
How can i put image in background using Netbeans? Maybe somebody can help me? ^^
- 01-06-2010, 12:42 AM #16
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Nothing to do with NetBeans. You have to use a container. Are you using JFrame? Then how you added/place components?
Did you try anything on this, can you show your effort here? Using JPanel you can do that easily.
Hint: User drawImage() from the Graphics class with a BufferedImage object. Go through the Java doc for more details.
- 01-08-2010, 11:56 AM #17
Member
- Join Date
- Dec 2009
- Location
- Indonesia
- Posts
- 21
- Rep Power
- 0
Hmm, i mean where i can found a way to input my image to use as background? Because i search and i can't found it.
Eranga, could you help me, with this coding..
Sorry if i was wrong room to ask it.
package spaceinvaders;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Toolkit;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Random;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
public class Board extends JPanel implements Runnable, Commons {
private Dimension d;
private ArrayList aliens;
private Player player;
private Shot shot;
private int alienX = 150;
private int alienY = 5;
private int direction = -1;
private int deaths = 0;
private boolean ingame = true;
private final String expl = "../spacepix/explosion.png";
private final String alienpix = "../spacepix/alien.png";
private String message = "Game Over";
private Thread animator;
public Board()
{
addKeyListener(new TAdapter());
setFocusable(true);
d = new Dimension(BOARD_WIDTH, BOARD_HEIGTH);
setBackground(Color.black);
gameInit();
setDoubleBuffered(true);
}
public void addNotify() {
super.addNotify();
gameInit();
}
public void gameInit() {
aliens = new ArrayList();
ImageIcon ii = new ImageIcon(this.getClass().getResource(alienpix));
for (int i=0; i < 4; i++) {
for (int j=0; j < 6; j++) {
Alien alien = new Alien(alienX + 18*j, alienY + 18*i);
alien.setImage(ii.getImage());
aliens.add(alien);
}
}
player = new Player();
shot = new Shot();
if (animator == null || !ingame) {
animator = new Thread(this);
animator.start();
}
}
public void drawAliens(Graphics g)
{
Iterator it = aliens.iterator();
while (it.hasNext()) {
Alien alien = (Alien) it.next();
if (alien.isVisible()) {
g.drawImage(alien.getImage(), alien.getX(), alien.getY(), this);
}
if (alien.isDying()) {
alien.die();
}
}
}
public void drawPlayer(Graphics g) {
if (player.isVisible()) {
g.drawImage(player.getImage(), player.getX(), player.getY(), this);
}
if (player.isDying()) {
player.die();
ingame = false;
}
}
public void drawShot(Graphics g) {
if (shot.isVisible())
g.drawImage(shot.getImage(), shot.getX(), shot.getY(), this);
}
public void drawBombing(Graphics g) {
Iterator i3 = aliens.iterator();
while (i3.hasNext()) {
Alien a = (Alien) i3.next();
Alien.Bomb b = a.getBomb();
if (!b.isDestroyed()) {
g.drawImage(b.getImage(), b.getX(), b.getY(), this);
}
}
}
public void paint(Graphics g)
{
super.paint(g);
g.setColor(Color.black);
g.fillRect(0, 0, d.width, d.height);
g.setColor(Color.green);
if (ingame) {
g.drawLine(0, GROUND, BOARD_WIDTH, GROUND);
drawAliens(g);
drawPlayer(g);
drawShot(g);
drawBombing(g);
}
Toolkit.getDefaultToolkit().sync();
g.dispose();
}
public void gameOver()
{
Graphics g = this.getGraphics();
g.setColor(Color.black);
g.fillRect(0, 0, BOARD_WIDTH, BOARD_HEIGTH);
g.setColor(new Color(0, 32, 48));
g.fillRect(50, BOARD_WIDTH/2 - 30, BOARD_WIDTH-100, 50);
g.setColor(Color.white);
g.drawRect(50, BOARD_WIDTH/2 - 30, BOARD_WIDTH-100, 50);
Font small = new Font("Helvetica", Font.BOLD, 14);
FontMetrics metr = this.getFontMetrics(small);
g.setColor(Color.white);
g.setFont(small);
g.drawString(message, (BOARD_WIDTH - metr.stringWidth(message))/2,
BOARD_WIDTH/2);
}
public void animationCycle() {
if (deaths == NUMBER_OF_ALIENS_TO_DESTROY) {
ingame = false;
message = "Game won!";
}
// player
player.act();
// shot
if (shot.isVisible()) {
Iterator it = aliens.iterator();
int shotX = shot.getX();
int shotY = shot.getY();
while (it.hasNext()) {
Alien alien = (Alien) it.next();
int alienX = alien.getX();
int alienY = alien.getY();
if (alien.isVisible() && shot.isVisible()) {
if (shotX >= (alienX) &&
shotX <= (alienX + ALIEN_WIDTH) &&
shotY >= (alienY) &&
shotY <= (alienY+ALIEN_HEIGHT) ) {
ImageIcon ii =
new ImageIcon(getClass().getResource(expl));
alien.setImage(ii.getImage());
alien.setDying(true);
deaths++;
shot.die();
}
}
}
int y = shot.getY();
y -= 4;
if (y < 0)
shot.die();
else shot.setY(y);
}
// aliens
Iterator it1 = aliens.iterator();
while (it1.hasNext()) {
Alien a1 = (Alien) it1.next();
int x = a1.getX();
if (x >= BOARD_WIDTH - BORDER_RIGHT && direction != -1) {
direction = -1;
Iterator i1 = aliens.iterator();
while (i1.hasNext()) {
Alien a2 = (Alien) i1.next();
a2.setY(a2.getY() + GO_DOWN);
}
}
if (x <= BORDER_LEFT && direction != 1) {
direction = 1;
Iterator i2 = aliens.iterator();
while (i2.hasNext()) {
Alien a = (Alien)i2.next();
a.setY(a.getY() + GO_DOWN);
}
}
}
Iterator it = aliens.iterator();
while (it.hasNext()) {
Alien alien = (Alien) it.next();
if (alien.isVisible()) {
int y = alien.getY();
if (y > GROUND - ALIEN_HEIGHT) {
ingame = false;
message = "Invasion!";
}
alien.act(direction);
}
}
// bombs
Iterator i3 = aliens.iterator();
Random generator = new Random();
while (i3.hasNext()) {
int shot = generator.nextInt(15);
Alien a = (Alien) i3.next();
Alien.Bomb b = a.getBomb();
if (shot == CHANCE && a.isVisible() && b.isDestroyed()) {
b.setDestroyed(false);
b.setX(a.getX());
b.setY(a.getY());
}
int bombX = b.getX();
int bombY = b.getY();
int playerX = player.getX();
int playerY = player.getY();
if (player.isVisible() && !b.isDestroyed()) {
if ( bombX >= (playerX) &&
bombX <= (playerX+PLAYER_WIDTH) &&
bombY >= (playerY) &&
bombY <= (playerY+PLAYER_HEIGHT) ) {
ImageIcon ii =
new ImageIcon(this.getClass().getResource(expl));
player.setImage(ii.getImage());
player.setDying(true);
b.setDestroyed(true);;
}
}
if (!b.isDestroyed()) {
b.setY(b.getY() + 1);
if (b.getY() >= GROUND - BOMB_HEIGHT) {
b.setDestroyed(true);
}
}
}
}
public void run() {
long beforeTime, timeDiff, sleep;
beforeTime = System.currentTimeMillis();
while (ingame) {
repaint();
animationCycle();
timeDiff = System.currentTimeMillis() - beforeTime;
sleep = DELAY - timeDiff;
if (sleep < 0)
sleep = 2;
try {
Thread.sleep(sleep);
} catch (InterruptedException e) {
System.out.println("interrupted");
}
beforeTime = System.currentTimeMillis();
}
gameOver();
}
private class TAdapter extends KeyAdapter {
public void keyReleased(KeyEvent e) {
player.keyReleased(e);
}
public void keyPressed(KeyEvent e) {
player.keyPressed(e);
int x = player.getX();
int y = player.getY();
if (ingame)
{
if (e.isAltDown()) {
if (!shot.isVisible())
shot = new Shot(x, y);
}
}
}
}
}
Can you help me, which of the above coding which is a class, attribute, method?
And can you help me explain the coding above?
Sorry if I bother, because I was still new in java.
Thanks for your help. It really helps me. :)
- 01-11-2010, 05:04 PM #18
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 01-12-2010, 05:13 AM #19
Member
- Join Date
- Dec 2009
- Location
- Indonesia
- Posts
- 21
- Rep Power
- 0
This is not my own coding. I picked it up from one of the web games that have been mentioned above, but I do not understand when my teacher asked to make a Class diagram.
Please help me Eranga if you do not mind. Thanks. :)
- 01-12-2010, 10:40 AM #20
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yes I can help you. But if you don't know what the class is and so on, it's bit of difficult.
Anyway, did you run the code at least once?


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks