Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Java Game Help
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Luca3490




PostPosted: Wed Jul 03, 2013 3:23 pm   Post subject: Java Game Help

kso, been working on a Java game for a bit now, and I want to make it so the person controlling the character doesn't see the whole map so when the player moves up a tile, he can see the pre-rendered tile that he could not see before.

I have a total of 6 classes:

- The main class (holds the dimension's and all of the boring stuff)
- The GameFrame class (holds all of the FPS, Screen to look at the rendered tiles)
- Entity class (going to hold all of the stuff about the player ie: health)

- Player class (Holds all of the player movement and the ImageIcon for the player)
- KeyAdapt class (basically returns the key presses and returns them to the player)
- Home class (the map itself)

Now I don't have any idea on how to make it so you only view a part of the map.
And as well my map isn't working at all.
I'll upload the 2 files (Home.java and GameFrame.java) so you guys can look at the code.
Even if you guys just know the sudo code for a solution to this problem that would be wonderful, in fact any input would be
amazing Smile



Home.java
 Description:

Download
 Filename:  Home.java
 Filesize:  1.7 KB
 Downloaded:  209 Time(s)


GameFrame.java
 Description:

Download
 Filename:  GameFrame.java
 Filesize:  1.22 KB
 Downloaded:  233 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Wed Jul 03, 2013 8:36 pm   Post subject: RE:Java Game Help

Is your map physically separated into tiles? What I did was I created different pictures for each kind of tile. Then I told my program if the tile is within the screens bounds, then draw it.

It takes more work but that way its easier to work with and its more customizable.
Luca3490




PostPosted: Thu Jul 04, 2013 12:10 pm   Post subject: Re: Java Game Help

yeah i tried doing that, but I have never done 2 Dimensional arrays and then assigned it so each number represented a picture.
do you happen to have any source code i can look at? Smile

I've tried googleing both questions I had but nothing really helped :/
Raknarg




PostPosted: Thu Jul 04, 2013 5:46 pm   Post subject: RE:Java Game Help

hmm... I've never worked in java, so I can try whipping up some pseudocode for you. If you knew turing, I could make a real example.
Raknarg




PostPosted: Thu Jul 04, 2013 6:09 pm   Post subject: Re: Java Game Help

code:


Picture [][] map; //I just made up a random class for it
int playerx, playery; // players coordinates

// Now what you do is set the array to the map size. For instance, in the language I'm working in, if you had a 10 x 10 grid:
map = new Picture [10][10];

set_pictures {
        // usually, you'll save you map in a text file. In this case you might have a 10 x 10 grid of letters, and each letter means a certain kind of picture
        for (int i = 0; i < 10; i ++) {
                for (int j = 0; j < 10; j ++) {
                        // What we're doing here is getting the string at i, j in the text file. The easiest way to to have this directly relate to a picture.
                        // Just note you'll also have to understand text file reading. Alternatively, you could just hard code the map types into the program
                        map [i][j] = NewPic (textfile (i, j) + ".jpg");
                }
        }
}

loop {
        // In this example, we'll set the screen width and height to five pictures max. Also in this example, we'll say we want the character to always be center screen. Makes sense for rpgs.

        if (UpKeyPressed) {
                playery += 1;
        }
        else if (DownKeyPressed) {
                playery -= 1;
        }

        if (RightKeyPressed) {
                playerx += 1;
        }
        else if (LeftKeyPressed) {
                playerx -= 1;
        }

        for (int i = 0; i < 10; i ++) {
                for (int j = 0; j < 10; j ++) {
                        // Note here, that we're working in a 5 x 5 grid on the screen. Therefore for the map to be within range, it has to be the same, 1 or 2 away. Any more and it's out of screen.
                        if (abs (i - playerx) < 3 && abs (j - playery) < 3) {
                                // This is a procedure I made, up, takes in a picture, and an x and y coordinate.
                                DrawPic (map [i][j], i - playerx, j - playery);
                        }
                }
        }
}


This is a pretty rough idea. You initialize the array, the read through a text file and set each element to the same point in the file. After that, you just check to see if it's in range of your character when you draw it. If you want, I can explain 2d arrays better.

againm if you knew turing (or Processing, by chance) I could make you a real example.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: