Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (553)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  Electron Golf 4k  (Read 4266 times)
0 Members and 1 Guest are viewing this topic.
Offline LonghornDude08

Senior Newbie





« Posted 2012-01-10 06:26:40 »

Everyone seemed to have a page about their game, so here's one for mine. There's one tiny issue that I'd appreciate advice on: my game is a CPU hog. It doesn't need to be, but it seems to max out or almost max out one of my cores.

http://java4k.com/index.php?action=games&method=view&gid=378
Offline ReBirth
« Reply #1 - Posted 2012-01-10 13:20:54 »

I kicked the ball off screen (empty screen where no circles), then I can't kicked it out.

Offline LonghornDude08

Senior Newbie





« Reply #2 - Posted 2012-01-10 15:35:43 »

Not sure what you mean, but the ball should reset whenever it gets too far away from the course. You can also reset it by pressing space
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ReBirth
« Reply #3 - Posted 2012-01-10 15:39:16 »

that's the problem, space won't reset Grin

Offline LonghornDude08

Senior Newbie





« Reply #4 - Posted 2012-01-10 15:44:15 »

That's a really odd bug. What OS, browser are you running? Also, was this a one time thing or does it do this every time? Also, reset is not supposed to do anything when the ball has already stopped if that's what you are trying to do.
Offline ReBirth
« Reply #5 - Posted 2012-01-10 15:51:17 »

Quote
Also, reset is not supposed to do anything when the ball has already stopped if that's what you are trying to do.
so that the problem. I thought it's used to restart level so when the ball done its move, I tried to press space and nothing happened. So I need to reload browser to start new game?

Offline LonghornDude08

Senior Newbie





« Reply #6 - Posted 2012-01-10 16:20:31 »

Yes and no. There's no way to restart a level. Once you finish all holes, you can restart again. Otherwise, that would be cheating  Grin
Offline ra4king

JGO Kernel


Medals: 345
Projects: 2
Exp: 5 years


I'm the King!


« Reply #7 - Posted 2012-01-11 00:14:53 »

None of the keys work for me. Neither W,A,S,D or space :S Google Chrome on Windows 7 Smiley

Really fun game though I did terrible T___T

Offline LonghornDude08

Senior Newbie





« Reply #8 - Posted 2012-01-11 05:15:00 »

None of the keys work for me.

That's very odd. Do me a favor and try it out at https://webspace.utexas.edu/dah2744/www/ and see if it works for you there. I'll try looking into it, but it'll be difficult unless I can replicate it Undecided
Offline ra4king

JGO Kernel


Medals: 345
Projects: 2
Exp: 5 years


I'm the King!


« Reply #9 - Posted 2012-01-11 12:29:04 »

Nope second link is the same.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline LonghornDude08

Senior Newbie





« Reply #10 - Posted 2012-01-11 18:53:21 »

I've never seen java do that before. Maybe it has something to do with your keyboard or drivers? I'll try and look into it, but no guarantees
Offline LonghornDude08

Senior Newbie





« Reply #11 - Posted 2012-01-11 19:38:52 »

I found a resource online where they had the same problem as you caused by SCIM. If you have this program running, disable it and try again. Also, the problem might arise if you have any other software that handles keyboard events. Let me know if this is not the case, and also let me ask if this happens with any other applets that require keyboard input?
Offline ra4king

JGO Kernel


Medals: 345
Projects: 2
Exp: 5 years


I'm the King!


« Reply #12 - Posted 2012-01-11 22:05:28 »

I'm not using any other input-tampering software. However, this sounds like a normal Swing/AWT problem of putting listeners on the wrong component where it works for some but not for others. How do you setup your listeners?

Offline LonghornDude08

Senior Newbie





« Reply #13 - Posted 2012-01-11 22:48:32 »

In the recommended processEvent function of course  Smiley
Offline LonghornDude08

Senior Newbie





« Reply #14 - Posted 2012-01-27 16:54:38 »

I took your advice and re-did my I/O, so everything is handled through KeyListener, etc. It took up more space, but not too much, so hopefully it works for everyone now  Grin
Offline ra4king

JGO Kernel


Medals: 345
Projects: 2
Exp: 5 years


I'm the King!


« Reply #15 - Posted 2012-01-28 18:33:12 »

Yeah spacebar and WASD still don't work :/

Offline Shazer2

Junior Member


Medals: 3


Aspiring developer.


« Reply #16 - Posted 2012-01-29 01:39:00 »

Spacebar and WASD aren't working for me either.

~Shazer2 Smiley

"When you want to be successful as bad as you want to breathe, then you will be successful." - Eric Thomas
Offline LonghornDude08

Senior Newbie





« Reply #17 - Posted 2012-01-29 01:44:22 »

NOOOOOOOOOOO!

I'm starting to think that it might be the compression?
Offline StephR

Senior Member


Medals: 9



« Reply #18 - Posted 2012-01-29 19:53:36 »

LonghornDude08, your great and original game runs fine on both my Internet Explorer 9 and Google Chrome under Windows 7, including the WASD and spacebar keys. And I have no idea why it doesn't work on ra4king and Shazer 2's computers. You may give us the source of your program frame, including the part on key handling.

I just regret I can't use the arrow keys on my azerty keyboard.
Offline LonghornDude08

Senior Newbie





« Reply #19 - Posted 2012-01-29 20:25:11 »

up/down/left/right weren't supposed to do anything; they do now. I tweaked it a little bit again and changed from a boolean array to a few boolean values. Hopefully this will work, and if not, I'll post the source and let ya'll test the uncompressed version.
Offline StephR

Senior Member


Medals: 9



« Reply #20 - Posted 2012-01-29 20:51:07 »

Thanks for adding the arrow keys. And it was not necessary to ask you twice to get them !

Still runs fine on my Internet Explorer 9 and Google Chrome under Windows 7, WASD as arrow keys and spacebar.

Concerning your source, if the key problem lasts for ra4king and Shazer 2, I was asking for the frame with only the handling key part detailed.
Offline LonghornDude08

Senior Newbie





« Reply #21 - Posted 2012-01-29 20:56:53 »

This is what the Keyboard handlers look like now:

@Override
public void keyPressed(KeyEvent e) {
   switch(e.getKeyCode()){
      case KeyEvent.VK_UP:
      case KeyEvent.VK_W:
         up = true;
         break;
      case KeyEvent.VK_DOWN:
      case KeyEvent.VK_S:
         down = true;
         break;
      case KeyEvent.VK_LEFT:
      case KeyEvent.VK_A:
         left = true;
         break;
      case KeyEvent.VK_RIGHT:
      case KeyEvent.VK_D:
         right = true;
         break;
      case KeyEvent.VK_SPACE:
         space = true;
         break;
   }
}
@Override
public void keyReleased(KeyEvent e) {
   switch(e.getKeyCode()){
      case KeyEvent.VK_UP:
      case KeyEvent.VK_W:
         up = false;
         break;
      case KeyEvent.VK_DOWN:
      case KeyEvent.VK_S:
         down = false;
         break;
      case KeyEvent.VK_LEFT:
      case KeyEvent.VK_A:
         left = false;
         break;
      case KeyEvent.VK_RIGHT:
      case KeyEvent.VK_D:
         right = false;
         break;
      case KeyEvent.VK_SPACE:
         space = false;
         break;
   }
}
Offline ra4king

JGO Kernel


Medals: 345
Projects: 2
Exp: 5 years


I'm the King!


« Reply #22 - Posted 2012-01-29 21:00:53 »

What component do you add the listener to? The applet itself? Do you add any other components on the applet? Try adding a call to "requestFocus()" right before your loop starts.

Offline Damocles
« Reply #23 - Posted 2012-01-29 21:04:50 »

This is my event function...
(There are some good sources here to look for ideas to make it short)

1  
2  
3  
4  
5  
6  
public boolean handleEvent(Event ev)
   {
      boolean pressed = (ev.id==403 || ev.id==401) ?true:false;
      if(ev.id>=401 && ev.id<=404) keys[ev.key] = pressed;
      return true;
   }




in the gameloop used like this: (Ok, a bit unclean, you can read out the keycode in ev.key)
1  
2  
3  
4  
if (keys[keyFire] || keys[119] || keys[keyUp]) comJump = true;
if (keys[keyRight] || keys[100]) comRight = true;
if (keys[keyLeft] || keys[97]) comLeft = true;
if(keys[keyDown] || keys[115]) comDown=true;


-> and DONT! use switch case constructs, they make a much larger bytecode than a simple if chain.

Offline LonghornDude08

Senior Newbie





« Reply #24 - Posted 2012-01-29 21:32:30 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public class A extends JApplet implements ActionListener, KeyListener, MouseListener, MouseMotionListener{
   ...
   public A() throws HeadlessException {
      ...
      space = up = down = left = right = false;
      addKeyListener(this);
      addMouseListener(this);
      addMouseMotionListener(this);
      ...
   }


That's what it looks like right now. The listeners are added to the Applet itself and no other components are added. I just added a call to requestFocus() in my constructor, so give it a try.

I'm at like 3.29 kB so I've got space to BS around with (hence the switch/case).
Offline Damocles
« Reply #25 - Posted 2012-01-29 21:37:27 »

if you use the event function directly, you dont need any listeners.

Offline LonghornDude08

Senior Newbie





« Reply #26 - Posted 2012-01-29 21:41:52 »

That's how I had it before, but it wasn't working for some people  Sad
Offline Damocles
« Reply #27 - Posted 2012-01-29 21:43:02 »

Try out this skeleton

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  
60  
61  
62  
63  
64  
65  
66  
67  
68  
import java.applet.Applet;
import java.awt.Event;

public class S extends Applet implements Runnable
{


   final private boolean[] keys = new boolean[32767];
   private static final int keyUp = 1004;
   private static final int keyDown = 1005;
   private static final int keyLeft = 1006;
   private static final int keyRight = 1007;
   private static final int keyFire = 32;
   
   
   public void init()
   {
      new Thread(this).start();
   }

   public void start()
   {
      setSize(800, 600);
   }


   
   
   public void run()
   {

      //wait for activation
     while (!isActive())
      {
         Thread.yield();
      }
     
      try
      {
     
         while(true)
            {

               if (keys[keyFire] || keys[119] || keys[keyUp]) System.out.println("UP");
               if (keys[keyRight] || keys[100]) System.out.println("RIGHT");
               if (keys[keyLeft] || keys[97]) System.out.println("LEFT");
               if(keys[keyDown] || keys[115]) System.out.println("DOWN");
               Thread.yield();
            }
         
   

      }
   catch (Exception e)
      {
            e.printStackTrace();
      }
   }


public boolean handleEvent(Event ev)
   {
      boolean pressed = (ev.id==403 || ev.id==401) ?true:false;
      if(ev.id>=401 && ev.id<=404) keys[ev.key] = pressed;
         return true;
   }

}

Offline LonghornDude08

Senior Newbie





« Reply #28 - Posted 2012-01-29 21:53:40 »

That looks identical to what I had before only instead of a Thread, updates are dictated by Timers. (I also used a more complicated handleEvent function seeing as I need to process Mouse events)

Also,

1  
boolean pressed = (ev.id==403 || ev.id==401) ?true:false;


could be

1  
boolean pressed = ev.id==403 || ev.id==401;


?: is unnecessary
Offline Damocles
« Reply #29 - Posted 2012-01-29 21:59:00 »

well, same bytecode in the end

looks nicer though

Pages: [1] 2
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

CopyableCougar4 (23 views)
2014-08-22 19:31:30

atombrot (34 views)
2014-08-19 09:29:53

Tekkerue (30 views)
2014-08-16 06:45:27

Tekkerue (28 views)
2014-08-16 06:22:17

Tekkerue (18 views)
2014-08-16 06:20:21

Tekkerue (27 views)
2014-08-16 06:12:11

Rayexar (65 views)
2014-08-11 02:49:23

BurntPizza (41 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (42 views)
2014-08-06 19:49:38
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!