|
|
ReBirth
|
 |
«
Reply #1 - Posted
2012-01-10 14:20:54 » |
|
I kicked the ball off screen (empty screen where no circles), then I can't kicked it out.
|
|
|
|
LonghornDude08
Senior Newbie 
|
 |
«
Reply #2 - Posted
2012-01-10 16: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!
|
|
ReBirth
|
 |
«
Reply #3 - Posted
2012-01-10 16:39:16 » |
|
that's the problem, space won't reset 
|
|
|
|
LonghornDude08
Senior Newbie 
|
 |
«
Reply #4 - Posted
2012-01-10 16: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.
|
|
|
|
|
ReBirth
|
 |
«
Reply #5 - Posted
2012-01-10 16:51:17 » |
|
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?
|
|
|
|
LonghornDude08
Senior Newbie 
|
 |
«
Reply #6 - Posted
2012-01-10 17: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 
|
|
|
|
|
ra4king
|
 |
«
Reply #7 - Posted
2012-01-11 01:14:53 » |
|
None of the keys work for me. Neither W,A,S,D or space :S Google Chrome on Windows 7  Really fun game though I did terrible T___T
|
|
|
|
LonghornDude08
Senior Newbie 
|
 |
«
Reply #8 - Posted
2012-01-11 06: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 
|
|
|
|
|
ra4king
|
 |
«
Reply #9 - Posted
2012-01-11 13:29:04 » |
|
Nope second link is the same.
|
|
|
|
Games published by our own members! Check 'em out!
|
|
LonghornDude08
Senior Newbie 
|
 |
«
Reply #10 - Posted
2012-01-11 19: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
|
|
|
|
|
LonghornDude08
Senior Newbie 
|
 |
«
Reply #11 - Posted
2012-01-11 20: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?
|
|
|
|
|
ra4king
|
 |
«
Reply #12 - Posted
2012-01-11 23: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?
|
|
|
|
LonghornDude08
Senior Newbie 
|
 |
«
Reply #13 - Posted
2012-01-11 23:48:32 » |
|
In the recommended processEvent function of course 
|
|
|
|
|
LonghornDude08
Senior Newbie 
|
 |
«
Reply #14 - Posted
2012-01-27 17: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 
|
|
|
|
|
ra4king
|
 |
«
Reply #15 - Posted
2012-01-28 19:33:12 » |
|
Yeah spacebar and WASD still don't work :/
|
|
|
|
Shazer2
Junior Member   Medals: 3
Aspiring developer.
|
 |
«
Reply #16 - Posted
2012-01-29 02:39:00 » |
|
Spacebar and WASD aren't working for me either. ~Shazer2 
|
"When you want to be successful as bad as you want to breathe, then you will be successful." - Eric Thomas
|
|
|
LonghornDude08
Senior Newbie 
|
 |
«
Reply #17 - Posted
2012-01-29 02:44:22 » |
|
NOOOOOOOOOOO!
I'm starting to think that it might be the compression?
|
|
|
|
|
StephR
|
 |
«
Reply #18 - Posted
2012-01-29 20: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.
|
|
|
|
|
LonghornDude08
Senior Newbie 
|
 |
«
Reply #19 - Posted
2012-01-29 21: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.
|
|
|
|
|
StephR
|
 |
«
Reply #20 - Posted
2012-01-29 21: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.
|
|
|
|
|
LonghornDude08
Senior Newbie 
|
 |
«
Reply #21 - Posted
2012-01-29 21: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; } }
|
|
|
|
|
ra4king
|
 |
«
Reply #22 - Posted
2012-01-29 22: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.
|
|
|
|
Damocles
|
 |
«
Reply #23 - Posted
2012-01-29 22: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.
|
|
|
|
LonghornDude08
Senior Newbie 
|
 |
«
Reply #24 - Posted
2012-01-29 22: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).
|
|
|
|
|
Damocles
|
 |
«
Reply #25 - Posted
2012-01-29 22:37:27 » |
|
if you use the event function directly, you dont need any listeners.
|
|
|
|
LonghornDude08
Senior Newbie 
|
 |
«
Reply #26 - Posted
2012-01-29 22:41:52 » |
|
That's how I had it before, but it wasn't working for some people 
|
|
|
|
|
Damocles
|
 |
«
Reply #27 - Posted
2012-01-29 22: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() {
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; }
} |
|
|
|
|
LonghornDude08
Senior Newbie 
|
 |
«
Reply #28 - Posted
2012-01-29 22: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
|
|
|
|
|
Damocles
|
 |
«
Reply #29 - Posted
2012-01-29 22:59:00 » |
|
well, same bytecode in the end
looks nicer though
|
|
|
|
|