Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (580)
games submitted by our members
Games in WIP (500)
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 / Newbie & Debugging Questions / Re: Sprint Stamina on: 2013-01-18 20:06:25
Thanks for the help guys!! I got it working to my liking and added some of your suggestions into it. I appreciate all of your time!
2  Game Development / Newbie & Debugging Questions / Re: Sprint Stamina on: 2013-01-15 22:03:54
This may not be entirely correct in the way someone with more experience than I would do it, but I got it to work.

Here's what I did in my Player class:
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  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
public void update() {
   int xa = 0, ya = 0;
   if (anim < 7500) {
      anim++;
   } else {
      anim = 0;
   }
   if (input.up) ya--;
   if (input.down) ya++;
   if (input.left) xa--;
   if (input.right) xa++;
   if (input.run && input.right) {
      if (hasStamina()) {
         xa = xa + 1;
         changeStamina(1);
      }
   }
   if (input.run && input.left) {
      if (hasStamina()) {
         xa = xa - 1;
         changeStamina(1);
      }
   }
   if (input.run && input.up) {
      if (hasStamina()) {
         ya = ya - 1;
         changeStamina(1);
      }
   }
   if (input.run && input.down) {
      if (hasStamina()) {
         ya = ya + 1;
         changeStamina(1);
      }
   }
   if (xa != 0 || ya != 0) {
      move(xa, ya);
      walking = true;
   } else {
      walking = false;
   }
}
   
public int getStamina() {
   return stamina;
}

private boolean hasStamina() {
   if (stamina > 0) {
      return true;
   } else {
      return false;
   }
}

public void changeStamina(int changeAmt) {
   stamina -= changeAmt;
   System.out.println(stamina);
}


and in my main Game class I added a few lines to my run() method: To get it to update once every frame was rendered I figured it would need to be called from here so I initialized a new regenTimer and had it add to the stamina every half second in increments of 2. I bolded the lines that got the program working correctly for me.
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  
public void run() {
   long lastTime = System.nanoTime();
   long timer = System.currentTimeMillis();
   long regenTimer = System.currentTimeMillis(); //The new regenTimer I initialized
  final double ns = 1000000000.0 / 60.0;
   double delta = 0;
   int frames = 0;
   int updates = 0;
   requestFocus();
   while (running) {
      long now = System.nanoTime();
      delta += (now - lastTime) / ns;
      lastTime = now;
      while (delta >= 1) {
         update();
         updates++;
         delta--;
      }
      render();
      frames++;

      if (System.currentTimeMillis() - timer > 1000) {
         timer += 1000;
         frame.setTitle(title + " | " + updates + " ups, " + frames + " fps");
         frames = 0;
         updates = 0;
      }

                //Added this part for the regeneration of Stamina
     if (System.currentTimeMillis() - regenTimer > 500) {
         regenTimer += 500;
         if (player.getStamina() < 100) {
            player.changeStamina(-2);
         }
      }
   }
   stop();
}


This might not be the best way for this, but I got it working, so I'm glad for that. What would be a better method to do this?
3  Game Development / Newbie & Debugging Questions / Sprint Stamina on: 2013-01-15 16:14:14
Hello, I'm new here, but I've been trying to get a sprint stamina system to work for a while now. I don't think I'm going about it the correct way.

What I've been trying is to create a boolean method that returns true while the meter isn't 0. What I'm having issues coming up w/ is how to design the method to count down and where to call it. I am currently trying to call the boolean method (sprintStamina()) in an if statement inside of my update method where my movement code is, like this:
1  
2  
3  
4  
5  
if (input.run && input.right) {
   if (sprintStamina()) {
      xa = xa + 1;
   }
}


and my sprintStamina() method is where I'm having trouble coming up w/ the correct code to accomplish this. My sprintStamina() method is in shambles and very broken. I'm having trouble figuring this problem out. If anyone can help me, I'd appreciate it. If you need more detail as to what I'm trying to do, please ask.
4  Game Development / Newbie & Debugging Questions / Re: createImage issue on: 2012-05-12 13:16:04
Thanks for the help! I'll be back with more stupid errors I'm sure, haha.
5  Game Development / Newbie & Debugging Questions / Re: createImage issue on: 2012-05-12 08:58:41
yeah, I am using Eclipse, but the flag it put up didn't make sense to me. But it all makes sense now.
6  Game Development / Newbie & Debugging Questions / Re: createImage issue on: 2012-05-12 08:29:22
createImage is method, not a class that can be instanced. It's owned by Toolkit class.

I'm an idiot lol! thanks!
7  Game Development / Newbie & Debugging Questions / createImage issue on: 2012-05-12 05:14:40
I'm new here (this is my first post) and a pretty big noob, just started programming and working with tutorials along with reading on Java, but I'm having an issue getting an image onto a button. I'm making a puzzle game that creates 12 cropped squares of an image that you can shuffle around to form the original picture.

Here's the part I'm having problems with.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
for (int i = 0; i < 4; i++) {
         for (int j = 0; j < 3; j++) {
            if (j == 2 && i == 3) {
               label = new JLabel();
               centerPanel.add(label);
            } else {
               button = new JButton();
               button.addActionListener(this);
               centerPanel.add(button);
               image = new createImage(new FilteredImageSource(source.getSource(),
                          new CropImageFilter(j * width / 3, i * height / 4, (width / 3) + 1, height / 4)));
               button.setIcon(new ImageIcon(image));
            }
         }
      }


the image = new createImage() part is telling me createImage() doesn't exist. Am I forgetting to import anything or am I calling and/or passing the wrong stuff?

any help would be much appreciated.

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

xsi3rr4x (52 views)
2014-04-15 18:08:23

BurntPizza (49 views)
2014-04-15 03:46:01

UprightPath (64 views)
2014-04-14 17:39:50

UprightPath (46 views)
2014-04-14 17:35:47

Porlus (63 views)
2014-04-14 15:48:38

tom_mai78101 (88 views)
2014-04-10 04:04:31

BurntPizza (147 views)
2014-04-08 23:06:04

tom_mai78101 (244 views)
2014-04-05 13:34:39

trollwarrior1 (203 views)
2014-04-04 12:06:45

CJLetsGame (210 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!