Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (121)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Problem with code  (Read 1785 times)
0 Members and 1 Guest are viewing this topic.
Offline masteryoom

JGO Coder


Medals: 5
Projects: 2


If you look closely, you might see it turning...


« 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  Clueless. The source code is here.
Thanks

EDIT: The new source code is in the link and on pastebin!!

Smiley
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 136
Projects: 4
Exp: 3 years



« Reply #1 - Posted 2012-12-22 05:11:27 »

I have to download the code?
Just pastebin it...
Offline HeroesGraveDev

JGO Kernel


Medals: 269
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« 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!
Legends of Yore - The Casual Retro Roguelike
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 136
Projects: 4
Exp: 3 years



« Reply #3 - Posted 2012-12-22 05:24:54 »

I can't see that image too well but s1by, s2by, s3by are pretty obscure...
Offline HeroesGraveDev

JGO Kernel


Medals: 269
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« 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.

Offline HeroesGraveDev

JGO Kernel


Medals: 269
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« 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.

Offline namrog84

JGO Ninja


Medals: 46
Projects: 4


Keep programming!


« 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"
Offline 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);


 Smiley

Subscribe to me on YouTube: http://youtube.com/javaprogrammerguy
Offline masteryoom

JGO Coder


Medals: 5
Projects: 2


If you look closely, you might see it turning...


« 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.  Huh

Smiley
Offline HeroesGraveDev

JGO Kernel


Medals: 269
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« 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!
Legends of Yore - The Casual Retro Roguelike
Offline 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  
//render each entity
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();
}

Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 136
Projects: 4
Exp: 3 years



« Reply #11 - Posted 2012-12-23 04:48:41 »


Holy mother of the gods of atheism that code burns my eyes  Shocked
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.
Offline 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.
Offline HeroesGraveDev

JGO Kernel


Medals: 269
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #13 - Posted 2012-12-23 05:14:35 »

See this

Offline 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

Pages: [1]
  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.

theagentd (16 views)
2014-10-25 15:46:29

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (45 views)
2014-10-16 15:22:06

Norakomi (34 views)
2014-10-16 15:20:20

lcass (39 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (68 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (74 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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