Page 1 of 2 12 LastLast
Results 1 to 20 of 36
  1. #1
    Kenshei is offline Member
    Join Date
    Dec 2009
    Location
    Indonesia
    Posts
    21
    Rep Power
    0

    Lightbulb Can you help me?

    Hai all, can you help me?

    Now I'm working on my final assignment. I want to make a game using netbeans. maybe any of you who have a tutorial how to make a shooting game or maybe the source code for game shooting?


    Thanks.. :)

  2. #2
    srisar is offline Member
    Join Date
    Jul 2009
    Location
    batticaloa, Sri Lanka
    Posts
    30
    Rep Power
    0

    Default

    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

  3. #3
    Kenshei is offline Member
    Join Date
    Dec 2009
    Location
    Indonesia
    Posts
    21
    Rep Power
    0

    Smile

    Quote Originally Posted by srisar View Post
    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

    hope it will help to get started
    Oh yes, you right, i means old console 2D Shooter games..
    maybe you have the others?
    Thanks.

  4. #4
    srisar is offline Member
    Join Date
    Jul 2009
    Location
    batticaloa, Sri Lanka
    Posts
    30
    Rep Power
    0

    Default

    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

  5. #5
    Kenshei is offline Member
    Join Date
    Dec 2009
    Location
    Indonesia
    Posts
    21
    Rep Power
    0

    Default

    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..

  6. #6
    srisar is offline Member
    Join Date
    Jul 2009
    Location
    batticaloa, Sri Lanka
    Posts
    30
    Rep Power
    0

    Default

    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...:)

  7. #7
    Kenshei is offline Member
    Join Date
    Dec 2009
    Location
    Indonesia
    Posts
    21
    Rep Power
    0

    Default

    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

  8. #8
    srisar is offline Member
    Join Date
    Jul 2009
    Location
    batticaloa, Sri Lanka
    Posts
    30
    Rep Power
    0

    Default

    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

  9. #9
    Kenshei is offline Member
    Join Date
    Dec 2009
    Location
    Indonesia
    Posts
    21
    Rep Power
    0

    Default

    Hahha..
    maybe only i cannot find it.
    Ok then, i will seach it..
    Thanks. :)

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    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 :)

  11. #11
    Kenshei is offline Member
    Join Date
    Dec 2009
    Location
    Indonesia
    Posts
    21
    Rep Power
    0

    Default

    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 02:41 PM.

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    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);

  13. #13
    Kenshei is offline Member
    Join Date
    Dec 2009
    Location
    Indonesia
    Posts
    21
    Rep Power
    0

    Default

    Thanks yow Eranga.. =)

  14. #14
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  15. #15
    Kenshei is offline Member
    Join Date
    Dec 2009
    Location
    Indonesia
    Posts
    21
    Rep Power
    0

    Default

    How can i put image in background using Netbeans? Maybe somebody can help me? ^^

  16. #16
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    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.

  17. #17
    Kenshei is offline Member
    Join Date
    Dec 2009
    Location
    Indonesia
    Posts
    21
    Rep Power
    0

    Smile

    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. :)

  18. #18
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  19. #19
    Kenshei is offline Member
    Join Date
    Dec 2009
    Location
    Indonesia
    Posts
    21
    Rep Power
    0

    Default

    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. :)

  20. #20
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •