• Content count

  • Joined

  • Last visited

Community Reputation

100 Neutral

About NuLogic

  • Rank

Personal Information

  1. Making action delay on keyPressed

    Hmm, there is main thread, which controls animator function, but to create another thread to do such thing, I think is not ergonomic. And yes, it is a turn based game, player hits, enemy counter-attacks. And please, tell me more about flags, because currently character object reacts on key presses and immediately executes some functions like attack, jump and change image. I tried to delay enemies attack action in such way: [code] if(ENTER pressed) { executionTime = currentSystemTime + 1000; // delay for 1 sec } if(ENTER pressed && currentSystemTime >= executionTime) { attack } [/code] but it simply doesn't works, it is only performed once (execution time is equal to current time) and later execution time is always greater than current system time. So could you tell me more about game states? I understand, that after certain action it should change, but how it is performed? I mean technically, game sleeps during state change or what?
  2. Hello, I am making fighting java game, and I have one problem, when I press attack key, enemy must respond and also attack player, I know how to do it, but I need to make a short delay between actions, player attack action must be performed immediately, and enemy must attack only after one second, how to make such thing? Sample code on playerEnemy: [code]public void keyPressed(KeyEvent e) { int key = e.getKeyCode(); if (key == KeyEvent.VK_ENTER) { attack(); } }[/code]
  3. At least, how to reach that weapon object?
  4. Hello, I am creating Java game, it is my first game, so I am still a noob in that case. I got stuck in one thing: I have created main menu, after selecting start new game, user must select weapon (ex. dagger with JButton), this is how it looks: [code]public class GUI { public GUI() { initGUI(); } public void initGUI { (..................some methods.........................) final JButton newGame = new JButton(new ImageIcon(..)); newGame.setLocation(250, 420); content.add(newGame); final JButton buttonDagger = new JButton(new ImageIcon(..)); buttonDagger.setLocation(250, 420); content.add(buttonDagger); class NewGameAction implements ActionListener { @Override public void actionPerformed(ActionEvent e){ newGame.setVisible(false); daggerButton.setVisible(true); frame.add(new Barracks()); } } class DaggerAction implements ActionListener { @Override public void actionPerformed(ActionEvent e){ daggerButton.setVisible(false); Weapon w = new Weapon("Dagger", 3, 8, 5); frame.add(new Arena()); } } buttonDagger.addActionListener(new DaggerAction()); newGame.addActionListener(new NewGameAction()); } } [/code] Class DaggerAction is inside initGUI function, is an initialization of daggerButton, after clicking on that, dagger must be created. So my problem is, how I can reach that Weapon w object? Or maybe there is an option to create it's copy somewhere during DaggerAction initialization? Or maybe there is an other way to initialize such select thigs? I will really appreciate your help, thanks. GUI is the main class which handle all the graphics. And I want to appear weapon object in Barracks class, which is initialized after starting new game.
  5. Creating inGame menu

    yes, I am just exactly reading about it, I will repaint that stuff
  6. Creating inGame menu

    Can you give advice, how to put objects other objects like buttons on the background? Because my game background is hiding that objects, they are under background, how to take them out?
  7. Creating inGame menu

    ok, I will try thanks for yout continuous support
  8. Creating inGame menu

    I already know, how to make that stuff, i need normal menu, which will let to select any stuff, like New Game, Load Game etc. [img][/img] but I am a bit confused, for which functions and libraries I should search to make such like upper one? Using Java SE.
  9. Hello, I just started to work with my graphical game, it is simple, but I need some information, how the game menu is created? I have been searching everywhere, but there is only explained how to create menu bars, but I need simple menu like New Game, Options for example in the middle of the screen. This is my GUI class, it contains only background and menu bar on the top, maybe someone can say, how I can implement normal one? : [code]import java.awt.Color; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import; import; import javax.imageio.ImageIO; import javax.swing.*; public final class GUI { JFrame frame; public GUI() { frame(); } // Adding background image and JMenuBar on the top public void frame() { frame = new JFrame("My Game"); try { frame.setContentPane(new JLabel(new ImageIcon( File("D:/bg.png"))))); } catch(IOException e) { System.out.println("No image"); } frame.setResizable(false); frame.setSize(800, 449); JMenuBar menubar = new JMenuBar(); frame.setJMenuBar(menubar); JMenu file = new JMenu("Meniu"); menubar.add(file); JMenuItem exit = new JMenuItem("Exit"); file.add(exit); JMenu help = new JMenu("Help"); menubar.add(help); JMenuItem about = new JMenuItem("About"); help.add(about); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); class ExitAction implements ActionListener { @Override public void actionPerformed(ActionEvent e){ System.exit(0); } } class AboutAction implements ActionListener { @Override public void actionPerformed(ActionEvent e){ JLabel label; frame = new JFrame("About"); frame.setResizable(false); frame.setSize(200, 200); label = new JLabel("Author: ED"); Font font = new Font("Arial", Font.ITALIC, 12); label.setFont(font); frame.add(label); frame.setBackground(Color.BLUE); frame.setVisible(true); } } exit.addActionListener (new ExitAction()); about.addActionListener(new AboutAction()); } }[/code] How I you would add menu? Also I tried to put a text box, but it hides under the background, how to take it from the back?
  10. Thank you [b]bollu[/b] for fix, [b]mickd, [/b]thisis my other question, I noticed, that most of people store data in xml files, but my game will be really small, it will only containt 3 weapons and 3 armors also 2 players (human and computer), so maybe there is a way just to implement them all dinamically while game starting just with Weapon longSword = new Weapon("Long Sword", 10); without storing data somewhere[b]? 6510, [/b]abilities of the swords are the same, different only stats, same with armors, maybe you can give any example? I have been searching for it, but I did not find any simple ones. Because it is just my first java game at all and it will be simple for the first time. After finishing I will bring it here as object to learn
  11. Hello, I have class Weapon: [code]class Weapon { private String name; private int min_damage; private int max_damage; private int weight; public Weapon(String name, int weight) { = name; this.weight = weight; } public int getMinDamage() { return min_damage; } public int getMaxDamage() { return max_damage; } public void setMinDamage(int x) { min_damage = x; } public void setMaxDamage(int x) { max_damage = x; } }[/code] and I want at beginning of the program to create three weapons like longSword, shortSword, saber, each of it would have parameters min_damage, max_damage, name and weight, so how I need to create them? I am thinking about two ways, first: [code]Weapon longSword = new Weapon("Long Sword", 10); longSword.setMinDamage(5); longSword.setMaxDamage(10);[/code] second: [code]class longSword extends Weapon{ // same actions like upper }[/code] but I realise, that both methods are wrong, maybe you have any advice for java programming newbie? Thank you in advance