princec
« League of Dukes » JGO Kernel      Posts: 8086 Medals: 95
Eh? Who? What? ... Me?
|
 |
«
on:
2006-12-07 18:43:42 » |
|
2,255 bytes. That's how big my 4K entry is so far and all it does is open a double buffered window and listen for mouse and keyboard input. How the hell do you guys get so much into 4K??? Cas  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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
| import java.awt.Color; import java.awt.Dimension; import java.awt.Frame; import java.awt.Graphics; import java.awt.Point; import java.awt.Toolkit; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.awt.image.BufferStrategy; import java.awt.image.BufferedImage;
public class G implements MouseMotionListener, MouseListener, KeyListener, WindowListener{
static Frame w; static G g; static BufferStrategy s;
public static void main(String[] a) {
g = new G(); w = new Frame("4k"); w.addWindowListener(g); w.addKeyListener(g); w.addMouseListener(g); w.addMouseMotionListener(g);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); w.setBounds((d.width - 320) / 2, (d.height - 320) / 2, 320, 320); w.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB), new Point(0, 0), ""));
w.setVisible(true);
w.createBufferStrategy(2); s = w.getBufferStrategy();
for (;;) { long t = System.nanoTime();
do { do { Graphics g = s.getDrawGraphics();
g.setColor(Color.black); g.fillRect(0, 0, 320, 320);
g.dispose();
} while (s.contentsRestored());
s.show();
} while (s.contentsLost());
long n = t + 1; while (n > t && (n - t) < 2000000) { try { Thread.sleep(1); } catch (InterruptedException e) { } n = System.nanoTime(); } } }
public void mouseDragged(MouseEvent e) { }
public void mouseMoved(MouseEvent e) { mouseDragged(e); }
public void mouseClicked(MouseEvent e) { }
public void mousePressed(MouseEvent e) { }
public void mouseReleased(MouseEvent e) { }
public void mouseEntered(MouseEvent e) { }
public void mouseExited(MouseEvent e) { }
public void keyTyped(KeyEvent e) { }
public void keyPressed(KeyEvent e) { }
public void keyReleased(KeyEvent e) { }
public void windowOpened(WindowEvent e) { }
public void windowClosing(WindowEvent e) { System.exit(0); }
public void windowClosed(WindowEvent e) { }
public void windowIconified(WindowEvent e) { }
public void windowDeiconified(WindowEvent e) { }
public void windowActivated(WindowEvent e) { }
public void windowDeactivated(WindowEvent e) { }
} |
|
|
|
|
CaptainJester
JGO Neuromancer     Posts: 1138 Medals: 8
Make it work; make it better.
|
 |
«
Reply #1 on:
2006-12-07 18:55:26 » |
|
2,255 bytes. That's how big my 4K entry is so far and all it does is open a double buffered window and listen for mouse and keyboard input.
Is that in a compressed JAR? My final class sizes are around 10-11k. Then you jar it up. Then run it through Proguard. This will shrink to the final 4k size. Also, did you check out the WiKi: http://wiki.java.net/bin/view/Games/4KGamesDesignOne thing I can point out right away. Don't use WindowListener to exit. Use setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); instead. Every method you create puts a method signature in the class file. With WindowListener, that is 7 signatures. The other way has none, just a call. 1 2 3 4 5
| static Frame w; static G g; static BufferStrategy s;
public static void main(String[] a) { |
Class level variables take more space than instance variables. 1 2 3 4
| public static void main(String[] a) { Frame w; G g = new G(); BufferStrategy s; |
This should be smaller.
|
|
|
|
princec
« League of Dukes » JGO Kernel      Posts: 8086 Medals: 95
Eh? Who? What? ... Me?
|
 |
«
Reply #2 on:
2006-12-07 19:10:09 » |
|
I learn fast  1,853 bytes to achieve the same results: 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
| import java.awt.AWTEvent; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Point; import java.awt.Toolkit; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.awt.image.BufferStrategy; import java.awt.image.BufferedImage;
import javax.swing.JFrame; import javax.swing.WindowConstants;
@SuppressWarnings("serial") public class G extends JFrame {
BufferStrategy s; public static void main(String[] a) { new G(); } G() { super("4k");
Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); setBounds((d.width - 320) / 2, (d.height - 320) / 2, 320, 320); setCursor(Toolkit.getDefaultToolkit().createCustomCursor(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB), new Point(0, 0), ""));
setVisible(true);
createBufferStrategy(2); s = getBufferStrategy(); enableEvents ( AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.KEY_EVENT_MASK ); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); run(); } void run() { for (;;) { long t = System.nanoTime(); logic();
do { do { render(); } while (s.contentsRestored());
s.show();
} while (s.contentsLost());
long n = t + 1; while (n > t && (n - t) < 2000000) { try { Thread.sleep(1); } catch (InterruptedException e) { } n = System.nanoTime(); } } }
synchronized void logic() { } void render() { Graphics g = s.getDrawGraphics();
g.setColor(Color.black); g.fillRect(0, 0, 320, 320);
g.dispose(); } @Override protected synchronized void processKeyEvent(KeyEvent e) { } @Override protected synchronized void processMouseEvent(MouseEvent e) { } @Override protected synchronized void processMouseMotionEvent(MouseEvent e) { } } |
Cas 
|
|
|
|
Games published by our own members! Go get 'em!
|
|
princec
« League of Dukes » JGO Kernel      Posts: 8086 Medals: 95
Eh? Who? What? ... Me?
|
 |
«
Reply #3 on:
2006-12-07 19:12:34 » |
|
Think that's a decent enough framework for a whole smorgasbord of silly little games. I wonder what I'll come up with with those lovely 2,200 remaining bytes. Has anybody any knowledge about sound effects? I'd quite like to do some sounds - notably missing from 4K entries by and large - you know, just simple saws and pulse waves through waveout. Cas 
|
|
|
|
oNyx
JGO Kernel      Posts: 2943 Medals: 5
pixels! :x
|
 |
«
Reply #4 on:
2006-12-07 19:31:13 » |
|
You can do all 3 types of events with processEvents... just check the type of the event and do the matching actions.
You can also do everything in the c'tor. That leaves you with: c'tor, main (which calls the c'tor) and processEvents.
You also might want to try different obfuscators (jarg, proguard, joga etc), zippers (7zip, kzip, bjwflate) and if you have more than one file you also should try zipmix (can be also found at the pngout page).
For fuzetsu I used: jarg->joga... once wtih kzip... once with bjwflate -> zipmix.
|
|
|
|
Riven
« League of Dukes » JGO Kernel      Posts: 5870 Medals: 255
Hand over your head.
|
 |
«
Reply #5 on:
2006-12-07 20:34:20 » |
|
What oNyx said, and compile with -g:none.
Further, you might change your mind about spending so many bytes only to remove the mouse-pointer!
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings
|
|
|
oNyx
JGO Kernel      Posts: 2943 Medals: 5
pixels! :x
|
 |
«
Reply #6 on:
2006-12-07 20:53:08 » |
|
>compile with -g:none
Don't obfuscators strip all that already?
>Further, you might change your mind about spending so many bytes only to remove the mouse-pointer!
Thanks to Java2D's PLATFORM SPECIFIC way to create images... it needs to be cleared. Otherwise its either filled with opaque gray (Mac) or random bullcrap (Linux).
Also... on Mac you may lose your custom cursor. Whenever you regain focus you have to reset the cursor to the desired one. Gah! (Hadn't enough room for that rather massive fix.)
I still think that it was really bad that they decided against having a pre defined empty cursor.
So, my (obvious) advice: If your game is fine with the cursor, keep it.
|
|
|
|
woogley
JGO Neuromancer     Posts: 1098 Medals: 5
|
 |
«
Reply #7 on:
2006-12-07 21:42:50 » |
|
you can also save bytes by just calling setLocation(10,10) rather than centering the window..
also calling show() instead of setVisible(true) will save a few bytes as well.
|
|
|
|
|
EnderGT
Jr. Member   Posts: 98
|
 |
«
Reply #8 on:
2006-12-07 22:42:18 » |
|
you can also save bytes by just calling setLocation(10,10) rather than centering the window..
what about calling setLocationRelativeTo(null)? not sure how it compares to your way, but it's still smaller than the way he's doing it and it does what he wants.
|
|
|
|
|
princec
« League of Dukes » JGO Kernel      Posts: 8086 Medals: 95
Eh? Who? What? ... Me?
|
 |
«
Reply #9 on:
2006-12-08 05:55:40 » |
|
Keep 'em coming, you're only helping me to win  Cas 
|
|
|
|
Games published by our own members! Go get 'em!
|
|
EnderGT
Jr. Member   Posts: 98
|
 |
«
Reply #10 on:
2006-12-08 09:26:10 » |
|
Keep 'em coming, you're only helping me to win  Based on the code you've shown us, I'm not too worried about that happening  Besides, you've still got to come up with a good game idea. Good luck.
|
|
|
|
|
g666
Sr. Member   Posts: 388
|
 |
«
Reply #11 on:
2006-12-08 13:56:39 » |
|
Based on the code you've shown us, I'm not too worried about that happening  Besides, you've still got to come up with a good game idea. Good luck. titan attacks 4k would be nice 
|
desperately seeking sanity
|
|
|
f.l.x
Sr. Member   Posts: 305
there is no place like 127.0.0.1
|
 |
«
Reply #12 on:
2006-12-11 14:16:27 » |
|
i have found that sometimes if/else sentences are smaller than '?' inline comparations, specially comparing ints, don't ask me why  On sounds, i'm working a litle one procedural, if i manage to get some more time to play with it (just got my first job as junior java programmer and i have to catch up  ) i'll post something soon.
|
|
|
|
nonnus29
JGO Ninja    Posts: 687
Giving Java a second chance after ludumdare fiasco
|
 |
«
Reply #13 on:
2006-12-15 03:21:42 » |
|
2,255 bytes. That's how big my 4K entry is so far and all it does is open a double buffered window and listen for mouse and keyboard input.
How the hell do you guys get so much into 4K???
LOL! NooB! YOU SUCK!!!!11 Check out the previous years threads, some people post source after the contest (miners4k hint hint).
|
|
|
|
|
|