Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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
Quote
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.
Quote
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?
ie.
StarMapBlock block = new StarMapBlock();
block = new StarMapBlock();
block = new StarMapBlock();
block = new StarMapBlock();

The old ones get cleaned up ok?

Quote
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:
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  
    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.

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

<a href="http://www.youtube.com/v/WLm_PD201Lk?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/WLm_PD201Lk?version=3&amp;hl=en_US&amp;start=</a>
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (37 views)
2014-12-15 09:26:44

Mr.CodeIt (30 views)
2014-12-14 19:50:38

BurntPizza (62 views)
2014-12-09 22:41:13

BurntPizza (99 views)
2014-12-08 04:46:31

JscottyBieshaar (59 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (77 views)
2014-11-29 21:32:03

toopeicgaming1999 (138 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (38 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

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