Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (753)
Games in Android Showcase (228)
games submitted by our members
Games in WIP (842)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Re: Open World Map Generation Feedback on: 2014-02-21 18:17:11
I just tried the short one = 1 code and it worked fine. I was trying all sorts of things and must have just left that in. Might as well get rid of it.

I do remember learning about anonymous classes, but will need to look them up for a refresher. Been awhile since "Introduction to Java" Wink

Thanks guys, this forum seems pretty great so far Cheesy
2  Game Development / Newbie & Debugging Questions / Re: Open World Map Generation Feedback on: 2014-02-21 17:23:13
No - "short one = 1;" would be fine.
When I do that it errors out and says it cannot convert from integer to short. I did some googling, and it seemed that java programmers had just "accepted" that.

Likewise with "center_x-one" (or center_x-1). Because the - operator only works with integers, the result of a short - short is an integer for some reason, which it could not convert back to a short. I was yelling at my compiler (IntelliJ IDEA) for a while trying to figure out why I needed those casts. Eventually I just gave up and put them in.
you can make it a static nested class (define the class inside another class and make it static) in which case it would be referenced as "StarMap.Block"
That actually sounds interesting, I didn't know one could do that Cheesy

My primary concern with this code was with re-allocating the blocks continually into the same variable. Is that OK in Java?
StarMapBlock block = new StarMapBlock();
block = new StarMapBlock();
block = new StarMapBlock();
block = new StarMapBlock();

The old ones get cleaned up ok?

The problem is that the "2" in H20 and O2 is referring to the molecular formula and so it should be done with subscript. "H2O" and "O2". Also if you are going to refer to Oxygen as O2 you should probably refer to Hydrogen and Nitrogen as H2 and N2 as they are generally diatomic molecules as well.
Haha, that's good! Thanks Cheesy
3  Game Development / Newbie & Debugging Questions / Open World Map Generation Feedback on: 2014-02-21 09:02:20
Hey guys, first post. I'm developing a game using LibGDX and it is going quite well!
I took Java in college, but my previous game dev experience is with C/C++ (and a library called Allegro).

My game is similar to the star stage of Spore, but it is just a wide open star field. Stars are generated randomly as the player moves into new space using a predictive algorithm so that the same stars are always generated.

The problem I have is with this tremendously ugly piece of code that is central to my game:
    StarMap_block[][] blocks;
    Stage stage;

    public void generateBlocks() {
        short center_x = gameData.player_x;
        short center_y = gameData.player_y;
        short one = (short)(1);
        stage.clear(); // scene2d stage, clear them out and add in the new stars

        blocks = new StarMap_block[][] {
                        new StarMap_block((short)(center_x-one),(short)(center_y+one), stage),
                        new StarMap_block(center_x,(short)(center_y+one), stage),
                        new StarMap_block((short)(center_x+one),(short)(center_y+one), stage)
                        new StarMap_block((short)(center_x-one),center_y, stage),
                        new StarMap_block(center_x,center_y, stage),
                        new StarMap_block((short)(center_x+one),center_y, stage)
                        new StarMap_block((short)(center_x-one),(short)(center_y-one), stage),
                        new StarMap_block((short)(center_x),(short)(center_y-one), stage),
                        new StarMap_block((short)(center_x+one),(short)(center_y-one), stage)

        for(int i = 0; i < 3; i++) {
            for(int j = 0; j < 3; j++) {
                blocks[i][j].adjust(j * 480, i * 480);

The 9 blocks make up a 1440x1440 pixel "active map". Each StarMap_block contains a node list of stars, which are added to the stage.
This function is called each time the camera moves out of the current active blocks.

What is a better approach to accomplish this? Is this leaking memory? Is this actually not a bad way to do what I need to? Do I honestly need to constantly cast shorts like that in Java?

I'm at a point where I need to add more into this code, but am looking for some feedback before I shoot myself in the foot. Smiley

Thanks for any help.

I posted a little demo video if anyone is interested in checking it out:

<a href=";hl=en_US&amp;start=" target="_blank">;hl=en_US&amp;start=</a>
Pages: [1]
ivj94 (583 views)
2018-03-24 14:47:39

ivj94 (48 views)
2018-03-24 14:46:31

ivj94 (374 views)
2018-03-24 14:43:53

Solater (62 views)
2018-03-17 05:04:08

nelsongames (109 views)
2018-03-05 17:56:34

Gornova (151 views)
2018-03-02 22:15:33

buddyBro (694 views)
2018-02-28 16:59:18

buddyBro (92 views)
2018-02-28 16:45:17

xxMrPHDxx (493 views)
2017-12-31 17:17:51

xxMrPHDxx (733 views)
2017-12-31 17:15:51
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!