Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (575)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Game Mechanics / How to make a graphical text box? on: 2013-04-15 16:55:08
Hello, I really this is the right section.

In my game, I need to have a text box where you'd enter information. A character name and description for example.

I am stumped about an easy way for me to create a JTextBox analogue. I obviously don't want to use a real one since it would horribly clash with the graphics of the game.

Does anyone have any good way of doing this or where to start?
2  Game Development / Game Play & Game Design / Re: Proper positioning of Listeners. on: 2012-12-28 00:25:11
and wow that was a pathetically protracted time period for my response. Apologies.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
public class DMToolGame extends JPanel implements ActionListener{
   
   /**
    *
    */

   private static final long serialVersionUID = 3711700171154644204L;  
   private Screen mCurrentScreen;
   private MouseListener mListener;
   private KeyListener mKeyListener;
   private double mCurrentFrame, mLastFrame;
   private Timer mTimer;

   public DMToolGame(int width, int height){
      //Screen setup
      setFocusable(true);
      setDoubleBuffered(true);
     
      init();
   }
   
   public void init(){
      mCurrentScreen = new TitleScreen();
      mListener = new MouseListener(this);
     
      mLastFrame = 0;
      mCurrentFrame = 0;
     
      mTimer = new Timer(5, this);
      mTimer.start();
     
      addMouseListener(mListener);
     
      addKeyListener(mKeyListener);
   }


This class does the painting to the canvas and is itself the window. However, all of the objects that you can interact with are stored on various Screens, a character select screen, a battle Screen etc. This class just represents the window, stores which Screen we are currently on and tells it to draw itself.

Currently I have one single MouseListener called mListener as explained

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
public class MouseListener extends MouseAdapter{
   private DMToolGame mTool;
   private Screen mCurrentScreen;
   
   public MouseListener(DMToolGame tool){
      mTool = tool;
      mCurrentScreen = mTool.getCurrentScreen();
   }
     
   public void mousePressed(MouseEvent e){
      Point p = e.getPoint();
         
      ScreenItem intersectObject = mCurrentScreen.objectIntersects(p);
      if(intersectObject != null){
         if(intersectObject.getClass() == Button.class){
            if(intersectObject.getName().equals("Battle")){
               mTool.setCurrentScreen(new BattleScreen());
               mCurrentScreen = mTool.getCurrentScreen();
            }
            else if(intersectObject.getName().equals("Load Campaign")){
               mTool.setCurrentScreen(new CampaignScreen());
               mCurrentScreen = mTool.getCurrentScreen();
            }
            else if(intersectObject.getName().equals("Next Turn")){
               ((BattleScreen)mCurrentScreen).NextTurn();
            }
            else if(intersectObject.getName().equals("Add Character")){
               ((BattleScreen)mCurrentScreen).AddCharacterDialog();
            }
         }
      }
   }
}


Since I'm making this listener generic and do all the work for the various screens, I'm requiring it to do various abstract hurdles to figure out what to do.

I've been trying to make Screen extend JPanel, and then add custom MouseListeners to each of the subScreens *BattleScreen, CampaignScreen etc, but they don't seem to trigger...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
public class TitleScreen extends Screen{
   /**
    *
    */

   private static final long serialVersionUID = 4838620713526543945L;
   private Image mBackground;
   private Button mLoadButton;

   public TitleScreen(){
      mBackground = managers.ImageManager.getInstance().getImage("TitleScreen.png");
      mLoadButton = new Button("Load Campaign", 100, 100);
     
      addMouseListener(new MouseListener());
   }
   
   public void draw(Graphics2D g2d, DMToolGame window) {
      g2d.drawImage(mBackground, 0, 0, window);
      mLoadButton.draw(g2d,  window);
   }
   
   public ScreenItem objectIntersects(Point p) {
      if(mLoadButton.contains(p)){
         return mLoadButton;
      }
      return null;
   }
   
   public class MouseListener extends MouseAdapter{
      public MouseListener(){
         System.out.println("Mcreated!");
      }
      @Override
      public void mouseClicked(MouseEvent e){
            System.out.println("Mouse was clicked");
        }
      @Override
        public void mouseEntered(MouseEvent arg0) {}
      @Override
        public void mouseExited(MouseEvent arg0) {}
      @Override
        public void mousePressed(MouseEvent arg0) {}
      @Override
        public void mouseReleased(MouseEvent arg0) {}
   }
}


It should be noted that I'm not using JButtons or any other Java Objects except for the Canvas so I cant just add listeners to the buttons in question.
3  Game Development / Game Play & Game Design / Proper positioning of Listeners. on: 2012-12-18 03:48:56
Hey everyone, I'm sorry to bother you but this is a subject that's been bothering me a lot. I learned in University about Model View Control architecture, and we always had listener classes as separate classes. Every time I see listeners anywhere else though, they are part of the class that they are attached to.

In my game, I have several separate screens all with different buttons, features and controls. Currently I have it so that each Screen is it's own object and there is one listener to deal with everything. I was thinking though that maybe I should have one listener in each Screen class that is specifically programmed to handle that one screen's reactions.

Thoughts?
4  Game Development / Newbie & Debugging Questions / Re: Help understanding the significance of using Java on: 2012-01-25 21:29:23
I graduated with a degree in Game Design, although my school was in hindsight a bit derp and I really don't have much experience actually making games. I want to build a portfolio of "I'm not an idiot please hire me" projects. They're both learning experiences and portfolio fodder.

I think I'll work with Java for now and switch the languages up after.
5  Game Development / Newbie & Debugging Questions / Re: Help understanding the significance of using Java on: 2012-01-25 20:50:02
Well as it stands I know both C++ and Java. I'm looking to start work on some projects *primarily PC based since I don't have a smart phone* and I enjoy Java programming more, but am concerned about whether or not I should program in C++.
6  Game Development / Newbie & Debugging Questions / Help understanding the significance of using Java on: 2012-01-25 20:04:09
I understand that Java is useful for portable gaming because it can be run on multiple platforms. However, if I'm building a video game with the intention of only having it be on the PC, is there any reason for me to use Java over, say, C++?

From what I understand Java is slower and not as efficient as C++, even if it is easier to use.
7  Game Development / Game Mechanics / Lighting and generating random objects. on: 2011-10-03 17:32:12
Hello all. I'm hoping you can all give me a hand with my game project again.

My game uses a grid of nodes to determine where everything is and for pathfinding. Each node is 20 by 20 pixels. I'm having an issue with lighting. As you can see in my screenshot, the wall in the upper left is visible to the player, even though it really shouldn't be.



I've been trying to figure out an efficient way to have the system check to see if the nodes are out of blocked but nothing has come up that works. I am currently using the following:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
public void update(){
      for(int i = 0; i<width; i++){
         for(int j=0; j<height; j++){
            Node n = nodeMap[i][j];
            for(int k=0; k<player.getParty().size(); k++){
               if(n.getDistance(player.getParty().get(k).getNode()) > 160){
                     n.setSight(false);
               }
               else{
                  ArrayList<Node> temp = n.getNeighbours();
                  int wallCheck = 0;
                  for(int l=0; l<temp.size(); l++){
                     if(!temp.get(l).getTraversible()){
                        wallCheck++;
                     }
                  }
                  if(wallCheck != temp.size()){
                     n.setSight(true);
                     break;
                  }
                  else{
                     n.setSight(false);
                  }
               }
            }
         }
      }
   }


This code is called during every update cycle, which I accept may be too many times since it only really needs to be called whenever the player moves. If a node has it's inSight value set to false, then it is not drawn. Any ideas for how I can check if there are walls between the player characters and the nodes? Note WallCheck checks to see if any node is completely surrounded by walls, because if it is then there's no point to drawing it.

Additionally, I want to be able to create random objects. For example, lets say I have a treasure chest and I want it to be filled with a random assortment of weapons. How can I do this? Currently, I have Items like Longsword and Quarterstaff extending Weapon which extends Item, but I need to use new in order to create these objects. How can I do this?

Many thanks Smiley
8  Game Development / Newbie & Debugging Questions / Issues with animated GIFs on: 2011-09-09 03:01:53
Hello, I am trying to add some animation to my game to make it a little bit more interesting to look at. I've made an animated gif using GIMP, but when I load the image in Eclipse it runs through the animation far faster than it is supposed to. What am I doing wrong?

Here are the relevant bits of code for assigning the image value and drawing the gif.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
...

ImageIcon ii = new ImageIcon(this.getClass().getResource(src));
      image = ii.getImage();

...

public void draw(Graphics2D g2d, game.Window window){
      if(currentHP > 0)
         g2d.drawImage(getImage(), x-width/2, y-height/2, window);
   }
9  Game Development / Newbie & Debugging Questions / Re: Help using extends on: 2011-08-26 15:51:26
I am so absolutely appalled with myself.

Completely and totally disgusted.

Thank you so much!
10  Game Development / Newbie & Debugging Questions / Help using extends on: 2011-08-26 02:58:15
Hello, I'm hoping I can get some help with this...

I have several different objects who all share the same code. I am originally coding each object separately but find the fact that I am writing out the exact same methods in each object to be frustrating. I tried compiling all the methods in a superclass Actor which the other classes extends but I am getting a null pointer exception error when I attempt to access a field of the subclass.

Here is the subclass code Fighter which extends Actor. Actor contains all the getters and setters. The default constructor for the Actor method does nothing currently. Can you tell me what I'm doing wrong?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
public class Fighter extends Actor{
   private Node node, target;
   private int x, y, width, height;
   private Image image;
   private String src;
   private double speed;
   private ArrayList<Node> path;
   private ArrayList<Node> open;
   private ArrayList<Node> closed;

   public Fighter(Node node){
      System.out.println("MAR");
      src = "/resources/fighter.gif";
      path = new ArrayList<Node>();
      open = new ArrayList<Node>();
      closed = new ArrayList<Node>();
      this.node = node;
      this.node.setActor(this);
      target = null;
      speed = 2;
      x = node.getCentreX();
      y = node.getCentreY();
     
      ImageIcon ii = new ImageIcon(this.getClass().getResource(src));
      image = ii.getImage();
     
      width = image.getWidth(null);
      height = image.getHeight(null);
   }
}

public class Actor{
   private Node node, target;
   private int x, y, width, height;
   private Image image;
   private String src;
   private double speed;
   private ArrayList<Node> path;
   private ArrayList<Node> open;
   private ArrayList<Node> closed;

   public Actor(){
   }

        ... insert methods here ...
}
11  Game Development / Game Mechanics / Help implementing path finding. on: 2011-06-29 00:36:30
Hello all, I've looked at the sample pages listed in the pathfinding for beginners thread, and yet I'm still having problems implementing my pathfinding. The following code returns a path, and I'm sure the total value is the shortest path.

Unfortunately, what it does is it uses all the horizontal distance first, and then travels diagonally. This creates a very unnatural form of movement. I was hoping someone could help me?

I am using the Chebyshev distance equation listed at http://theory.stanford.edu/~amitp/GameProgramming/Heuristics.html#S7 to calculate the heuristic, I've checked to ensure that the G values are all being added properly and both forms of movement cost the same... What am I doing wrong?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
public void pathFind(Node target){
      this.target = target;
      open.add(node);
      target.setG(0);
      Node current = node;
      Node min = null;

      while(!open.isEmpty()){
         for(int i=0; i<current.getNeighbours().size(); i++){
            Node temp = current.getNeighbours().get(i);
            if(!open.contains(temp) && !closed.contains(temp)){
               open.add(temp);
               temp.setParent(current);
               temp.setG(current.getG() + current.getMovement());
               calculateF(temp);
            }
            else if(open.contains(temp) && !closed.contains(temp)){
               if(temp.getG() < current.getG()+current.getMovement()){
                  temp.setParent(current);
                  temp.setG(current.getG() + current.getMovement());
                  calculateF(temp);
               }
            }
         }
         open.remove(current);
         closed.add(current);
         min = open.get(0);
         for(int i=0; i<open.size(); i++){
            if(open.get(i).getF() < min.getF())
               min = open.get(i);
         }
         current = min;
         
         if(closed.contains(target)){
            deconstruct();
            break;
         }
      }
      System.out.println("FINISHED");
   }
   
   
   public void calculateF(Node aNode){
      int move = aNode.getStraight();
     
      aNode.setH(move * Math.max(Math.abs(aNode.getCentreX()-target.getCentreX()), Math.abs(aNode.getCentreY()-target.getCentreY())));
      aNode.setF(aNode.getG() + aNode.getH());
   }
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (35 views)
2014-10-17 03:59:02

Norakomi (25 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (26 views)
2014-10-15 16:18:58

TehJavaDev (50 views)
2014-10-14 00:39:48

TehJavaDev (50 views)
2014-10-14 00:35:47

TehJavaDev (40 views)
2014-10-14 00:32:37

BurntPizza (63 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (75 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!