masteryoom
|
 |
«
Posted
2012-12-22 05:07:13 » |
|
I have a game I am working on. But when I go from the "menu", it draws 1 frame and then freezes (the game logic stil works though  . The source code is here. Thanks EDIT: The new source code is in the link and on pastebin!!
|
|
|
|
Jimmt
|
 |
«
Reply #1 - Posted
2012-12-22 05:11:27 » |
|
I have to download the code? Just pastebin it...
|
|
|
|
HeroesGraveDev
|
 |
«
Reply #2 - Posted
2012-12-22 05:21:36 » |
|
 AAAAAAAAAAAAAAAAAAARGH! *goes and hides in box and tries to recover sanity* ...bad... ...variable names... ...bad... ...formatting...* (Yes, there is bad formatting in parts, I just wanted to emphasize the unreadability of the code)
|
|
|
|
Games published by our own members! Check 'em out!
|
|
Jimmt
|
 |
«
Reply #3 - Posted
2012-12-22 05:24:54 » |
|
I can't see that image too well but s1by, s2by, s3by are pretty obscure...
|
|
|
|
HeroesGraveDev
|
 |
«
Reply #4 - Posted
2012-12-22 05:26:21 » |
|
I can't see that image too well but s1by, s2by, s3by are pretty obscure...
Copy the image URL and paste it in the title bar. At least he won't have to use an obfuscator.
|
|
|
|
HeroesGraveDev
|
 |
«
Reply #5 - Posted
2012-12-22 05:28:36 » |
|
@OP
You are using deprecated GL functions (Like immediate mode, GL_QUADS etc.) Use your IDE to format your code properly. AND PLEASE: Make the variable names more understandable.
Also, I recommend having an ArrayList of objects instead of having s1by, s2by, s3by etc.
|
|
|
|
namrog84
|
 |
«
Reply #6 - Posted
2012-12-22 05:29:27 » |
|
Also, although I am not 100% sure, I think the reason its getting jammed up is because of your
public void start()
more specifically your
if/else statement revolving around the boolean started
|
"Experience is what you get when you did not get what you wanted"
|
|
|
PeterNicholson
|
 |
«
Reply #7 - Posted
2012-12-22 08:13:34 » |
|
You have imported import static org.lwjgl.opengl.GL11.*; statically, and then, in the initGL() method, you have done: 1 2 3 4 5
| GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); GL11.glLoadIdentity(); GL11.glOrtho(0, 800, 0, 600, 1, -1); GL11.glMatrixMode(GL11.GL_MODELVIEW); |
which should be: 1 2 3 4 5
| glMatrixMode(GL_PROJECTION); glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glLoadIdentity(); glOrtho(0, 800, 0, 600, 1, -1); glMatrixMode(GL_MODELVIEW); |

|
|
|
|
masteryoom
|
 |
«
Reply #8 - Posted
2012-12-22 23:02:19 » |
|
I've done both of those, and it still won't work! But the animation works fine for the square that you can move. 
|
|
|
|
HeroesGraveDev
|
 |
«
Reply #9 - Posted
2012-12-22 23:15:43 » |
|
Rename your variables and format your code before you ask anyone to try and fix it.
|
|
|
|
Games published by our own members! Check 'em out!
|
|
davedes
|
 |
«
Reply #10 - Posted
2012-12-23 00:53:46 » |
|
Holy shiza. Learn what an object is and start writing your own classes. Seriously, you should delete everything you have written so far and start from ground zero. Try learning programming techniques with simple text based programs before moving into graphics. Here's a tip: never try to duplicate code. So if you have this: 1 2 3 4 5 6 7 8 9 10 11
| if (a) { glBegin(..) glVertex(..) glVertex(..) glEnd(..); } else { glBegin(..); <- DUPLICATE CODE!!! glVertex(..); <- glVertex(..); <- glEnd(..); <- } |
You can use a method "drawQuad" instead of duplicating code: 1 2 3 4 5
| if (a) { drawQuad(...); } else { drawQuad(...); } |
You can further minimize code duplication by using classes and collections: 1 2 3 4 5 6 7 8 9 10 11 12 13 14
| for (Sprite entity : enemies) { entity.render(): }
...... now ... inside the entity class
class Entity { ...
public void render() { GLUtils.drawQuad(this.x, this.y, this.width, this.height); } }
|
Your entire app structure might look more like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| List<Sprite> enemies = new ArrayList<Sprite>(); PlayerSprite player;
public void init() { ... add sprites to "enemies" list ... player = new PlayerSprite(); }
public void render() { for (Sprite s : enemies) { s.render(); }
player.render(); } |
|
|
|
|
Jimmt
|
 |
«
Reply #11 - Posted
2012-12-23 04:48:41 » |
|
 Holy mother of the gods of atheism that code burns my eyes  Never have I facepalmed so hard Completely agree with davedes, go back to the basics with normal java (not lwjgl) and learn to write with object oriented design paradigm. Use loops instead of copying+pasting, follow naming conventions, be more descriptive with class/variable/method names, and don't use so many if statements.
|
|
|
|
theagentd
|
 |
«
Reply #12 - Posted
2012-12-23 05:11:31 » |
|
I'm sure I can write a program that does the same as those 700 lines of code in less than 200 lines. To give you a check list:
1. Create a class that contains the position, size and state of a square. 2. Give all variables and classes sensible names. Someone else (= your future self) should be able to instantly understand what everything is used for. 3. Create an ArrayList and just add instances to it to create new objects. You won't be limited to only 12 squares this way. 4. Use loops for manipulating. If you want to draw all squares, just loop over the objects in your list and draw each of them.
|
Myomyomyo.
|
|
|
|
Cero
|
 |
«
Reply #14 - Posted
2012-12-23 14:54:08 » |
|
And dont be discouraged, we all started with no idea
the lack of loops and arrays and bad names and such does suggest that you have not read a book or went through tutorials for the basics and it is pretty fundamental - so do it.
Its like trying to drift when you cant even drive
|
|
|
|
|