Dreamscape

Here’s the current version, all you can do is walk around and walk into the pathway tiles which I’m using as ‘walls’ to test the collision detection for now. I’m going to be fixing up the code a little bit more so that it stops you from going into the black areas and a few other tweaks today.

http://www.mediafire.com/?2qg360fqgb5z9p6

Do you plan on keeping the controlls that way? Meaning that you cannot go, for example down and left at the same time? Because if you do plan on allowing the player to do that you might run into new problems with the collision avoidance, just a heads up. (I did at least)

I was actually just thinking about allowing the player to move in that way; I’m going to attempt to get diagonal movement working in a moment. As far as I know, due to the way I’ve implemented collision detection, there shouldn’t be any problems with moving diagonally.

Edit:
I managed to add diagonal movement but it ended up being a bit too awkward and buggy so I’ve decided to scrap that idea. It looked decent but having characters speed up when walking against walls along with a few other things made me have to give up on the idea for now.
The current way that characters move, in one direction only, will be, in the long run, easier for me, in my opinion, to code with when it comes to waypoints for NPCs.

There isn’t too much to say in this update but it got me excited so I decided to post it anyway. ^.^ Over the past few days I managed to fix up the code a little bit and drastically improve the performance of the game by selectively rendering only the area within x number of tiles above, below and to the sides of the player; this gave me the idea to have infinitely sized maps or at least very-very large maps.
After a lot of trial and error trying to ‘optimize’ the code that loads the map.png image pixel-by-pixel into an int[][] array which I use to tell where to render certain tiles I finally came to the conclusion that there way no reason for it to be running as slowly as it was. After a few minutes of intense staring at the code that loads the map I decided to remove a single System.out.println(); statement; after that I tested the game and it loaded a 1,000,000 tile map within a second instead of three minutes or more.

Updates:

  • Selective Map Rendering
  • Can now handle maps of over 4,000,000 tiles. (Note: Never try loading a 1 billion tile map… Computer was frozen for awhile and then Java crashed)

Wohooow! :smiley: yeah, Java’s console write is ridiculously slow… :smiley:

I never thought that it would make a simple piece of code lag that horribly though, at least it’s fixed now. ^.^

Got a name yet?

I have a few ideas but they all depend on what I decide to use as the story. The only name that I thought of that might work is Dreamscape; it is the name of a Warcraft 3 project that I was working on a few years ago, I was never able to finish it due to the limitations of the game but the story that we had brainstormed for it might just work for this RPG. Actually, now that I think about it, I will continue Dreamscape here.

Looks like the project does have a name now. ^.^

I haven’t been working on this project too much but I’ve been thinking about how to do certain things that I plan to include. Although I haven’t worked on it too much, I do have a small update:

  • Figured out how to render enemies onto the screen along with deciding when to render them and getting them to walk along waypoints.
  • Added an FPS and RAM used display for debugging and making sure that everything is running smoothly.
  • Attempted to rewrite certain parts of the code to allow for the window to be resized; it seems as if I’ll need to do a major rewrite on the render method and on some calculation methods.
  • Rewrote many parts of the code to conform to the Java standards and to do some micro-optimization. I really need to stop micro-optimizing…

What I’ll be doing next is probably figuring out how to load a whole map worth of NPCs and their data and update their positions and that instead of just one NPC. After that I’ll probably attempt to rewrite a lot of the code to allow for a resizable window.

Here’s another small update:

  • Finally discovered the movement bug that was overriding certain keys and fixed it pretty easily.
  • Discovered and fixed another bug where the player’s walking animation would still play when it shouldn’t have.
  • Deleted the entire NPC class; it was a huge trainwreck and I just couldn’t bare to work on it. I’ll be rewriting NPC movement and that over the next little while.
  • Photoshopped up two images as an example of how to use an interface later on. They’re just two black images being rendered to the screen.

Here is the latest version of the program. There’s still nothing to do other than walk around and that but I’ll start working on some features after I get NPCs working somewhat decently.

http://www.java-gaming.org/user-generated-content/members/151044/sword-v2.jar
(Hopefully that link works…)

Here’s another small update:

  • Finally discovered the movement bug that was overriding certain keys and fixed it pretty easily.
  • Discovered and fixed another bug where the player’s walking animation would still play when it shouldn’t have.
  • Deleted the entire NPC class; it was a huge trainwreck and I just couldn’t bare to work on it. I’ll be rewriting NPC movement and that over the next little while.
  • Photoshopped up two images as an example of how to use an interface later on. They’re just two black images being rendered to the screen.

Here is the latest version of the program. There’s still nothing to do other than walk around and that but I’ll start working on some features after I get NPCs working somewhat decently.

http://www.java-gaming.org/user-generated-content/members/151044/sword-v2.jar
(Hopefully that link works…)

Its a nice start, but I noticed you are lacking the ability to move in more than one direction at the same time. For instance, when I hold D and W at the same time, I do not actually move up and to the right. Instead, the player completely stops moving. I don’t entirely understand why that would happen unless you are seriously only letting one key be pressed at a time. If you are doing that, stop now please. You need to allow for more than one key press!

The collision code doesn’t work with diagonal movement so you’re only allowed to use one key at a time for now. I’ll see about a fix later on though.

 if((KeyboardListener.isKeyPressed(KeyEvent.VK_W) && KeyboardListener.isKeyPressed(KeyEvent.VK_S) || KeyboardListener.isKeyPressed(KeyEvent.VK_UP) && KeyboardListener.isKeyPressed(KeyEvent.VK_DOWN)) || (KeyboardListener.isKeyPressed(KeyEvent.VK_W) && KeyboardListener.isKeyPressed(KeyEvent.VK_A) || KeyboardListener.isKeyPressed(KeyEvent.VK_UP) && KeyboardListener.isKeyPressed(KeyEvent.VK_LEFT)) || (KeyboardListener.isKeyPressed(KeyEvent.VK_W) && KeyboardListener.isKeyPressed(KeyEvent.VK_D) || KeyboardListener.isKeyPressed(KeyEvent.VK_UP) && KeyboardListener.isKeyPressed(KeyEvent.VK_RIGHT)) || (KeyboardListener.isKeyPressed(KeyEvent.VK_S) && KeyboardListener.isKeyPressed(KeyEvent.VK_A) || KeyboardListener.isKeyPressed(KeyEvent.VK_DOWN) && KeyboardListener.isKeyPressed(KeyEvent.VK_LEFT)) || (KeyboardListener.isKeyPressed(KeyEvent.VK_S) && KeyboardListener.isKeyPressed(KeyEvent.VK_D) || KeyboardListener.isKeyPressed(KeyEvent.VK_DOWN) && KeyboardListener.isKeyPressed(KeyEvent.VK_RIGHT)) || (KeyboardListener.isKeyPressed(KeyEvent.VK_A) && KeyboardListener.isKeyPressed(KeyEvent.VK_D) || KeyboardListener.isKeyPressed(KeyEvent.VK_LEFT) && KeyboardListener.isKeyPressed(KeyEvent.VK_RIGHT)))
        {
            isWalking = false;
        }

That’s what’s stopping you for now =P

There isn’t any reason for your collision code not to be working with diagonal movement…

public boolean checkPointCollision(final int xPosition, final int yPosition)
    {
        final int[] temp = MiscellaniousCalculations.collisionDetection_GetXYPositionsOnMap(xPosition, yPosition);

        switch(currentMap[temp[0]][temp[1]])
        {
            case -16777216: //Black Map Border
            {
                return false;
            }
            case -14503604: //Stone Path
            {
                return false;
            }
            default:
            {
                return true;
            }
        }
 //This while statement checks 4 different points around the player's sprite, if any of them return false then the player's position is changed until they all return true.
        while(collision.checkPointCollision(playerXLocation - 12, playerYLocation + 22) == false /*LowerLeftPoint*/ || collision.checkPointCollision(playerXLocation + 12, playerYLocation + 22) == false /*Lower Right Point*/ || collision.checkPointCollision(playerXLocation - 12, playerYLocation) == false /*Middle Left Point*/ || collision.checkPointCollision(playerXLocation + 12, playerYLocation) == false /*Middle Right Point*/)
        {
            switch(playerDirection)
            {
                case 0:
                {
                    player.setXLocation(1);
                    playerXLocation++;
                    break;
                }
                
                case 1:
                {
                    player.setYLocation(1);
                    playerYLocation++;
                    break;
                }
                    
                case 2:
                {
                    player.setXLocation(-1);
                    playerXLocation--;
                    break;
                }
                    
                case 3:
                {
                    player.setYLocation(-1);
                    playerYLocation--;
                    break;
                }
            }
        }

Walk into the top-middle of a block while using diagonal movement and it’ll place you on one of the sides of the block; or walk into the side of a block walking down-left, up-left, down-right or up-right and it’ll move you either downwards or upwards very quickly.

No, I mean, you really should fix that…really no rpg doesn’t allow diagonal movement, unless maybe if it’s turn based.

Its a nice start, but I noticed you are lacking the ability to move in more than one direction at the same time. For instance, when I hold D and W at the same time, I do not actually move up and to the right. Instead, the player completely stops moving. I don’t entirely understand why that would happen unless you are seriously only letting one key be pressed at a time. If you are doing that, stop now please. You need to allow for more than one key press!

The collision code doesn’t work with diagonal movement so you’re only allowed to use one key at a time for now. I’ll see about a fix later on though.

 if((KeyboardListener.isKeyPressed(KeyEvent.VK_W) && KeyboardListener.isKeyPressed(KeyEvent.VK_S) || KeyboardListener.isKeyPressed(KeyEvent.VK_UP) && KeyboardListener.isKeyPressed(KeyEvent.VK_DOWN)) || (KeyboardListener.isKeyPressed(KeyEvent.VK_W) && KeyboardListener.isKeyPressed(KeyEvent.VK_A) || KeyboardListener.isKeyPressed(KeyEvent.VK_UP) && KeyboardListener.isKeyPressed(KeyEvent.VK_LEFT)) || (KeyboardListener.isKeyPressed(KeyEvent.VK_W) && KeyboardListener.isKeyPressed(KeyEvent.VK_D) || KeyboardListener.isKeyPressed(KeyEvent.VK_UP) && KeyboardListener.isKeyPressed(KeyEvent.VK_RIGHT)) || (KeyboardListener.isKeyPressed(KeyEvent.VK_S) && KeyboardListener.isKeyPressed(KeyEvent.VK_A) || KeyboardListener.isKeyPressed(KeyEvent.VK_DOWN) && KeyboardListener.isKeyPressed(KeyEvent.VK_LEFT)) || (KeyboardListener.isKeyPressed(KeyEvent.VK_S) && KeyboardListener.isKeyPressed(KeyEvent.VK_D) || KeyboardListener.isKeyPressed(KeyEvent.VK_DOWN) && KeyboardListener.isKeyPressed(KeyEvent.VK_RIGHT)) || (KeyboardListener.isKeyPressed(KeyEvent.VK_A) && KeyboardListener.isKeyPressed(KeyEvent.VK_D) || KeyboardListener.isKeyPressed(KeyEvent.VK_LEFT) && KeyboardListener.isKeyPressed(KeyEvent.VK_RIGHT)))
        {
            isWalking = false;
        }

That’s what’s stopping you for now =P

There isn’t any reason for your collision code not to be working with diagonal movement…

public boolean checkPointCollision(final int xPosition, final int yPosition)
    {
        final int[] temp = MiscellaniousCalculations.collisionDetection_GetXYPositionsOnMap(xPosition, yPosition);

        switch(currentMap[temp[0]][temp[1]])
        {
            case -16777216: //Black Map Border
            {
                return false;
            }
            case -14503604: //Stone Path
            {
                return false;
            }
            default:
            {
                return true;
            }
        }
 //This while statement checks 4 different points around the player's sprite, if any of them return false then the player's position is changed until they all return true.
        while(collision.checkPointCollision(playerXLocation - 12, playerYLocation + 22) == false /*LowerLeftPoint*/ || collision.checkPointCollision(playerXLocation + 12, playerYLocation + 22) == false /*Lower Right Point*/ || collision.checkPointCollision(playerXLocation - 12, playerYLocation) == false /*Middle Left Point*/ || collision.checkPointCollision(playerXLocation + 12, playerYLocation) == false /*Middle Right Point*/)
        {
            switch(playerDirection)
            {
                case 0:
                {
                    player.setXLocation(1);
                    playerXLocation++;
                    break;
                }
                
                case 1:
                {
                    player.setYLocation(1);
                    playerYLocation++;
                    break;
                }
                    
                case 2:
                {
                    player.setXLocation(-1);
                    playerXLocation--;
                    break;
                }
                    
                case 3:
                {
                    player.setYLocation(-1);
                    playerYLocation--;
                    break;
                }
            }
        }

Walk into the top-middle of a block while using diagonal movement and it’ll place you on one of the sides of the block; or walk into the side of a block walking down-left, up-left, down-right or up-right and it’ll move you either downwards or upwards very quickly.