Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (540)
Games in Android Showcase (133)
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   
Pages: [1]
  ignore  |  Print  
  My First Game  (Read 1340 times)
0 Members and 1 Guest are viewing this topic.
Offline Maged

Senior Newbie





« Posted 2014-04-27 20:15:40 »

Hi Guys,

First of all, this website have one of the weirdest account activation methods!!!!

This is my first post here so if I make a mistake forgive me .
I am in the beginning of the path of Java development. I am very interested in building games with it. I have seen a tutorial about building Java game using libGDX2D and I was able to successfully follow it and come up with the attached project (not something useful though).

I use libGDX for Android games development and getting a desktop copy of the game as well. Now I am stuck trying to do some parts that I don't really have an idea how to build it in Java with graphics and all these things, the parts I am stuck with are:

1. The map in my code is 512x512, how to build, say, a map of 10000x10000 and just show 512x512 for the player then when he go to the edges I open the next 512x512 and so on (like scrolling map in RPG games).
2. The part responsible about detecting intersection in my code have a problem that when I intersect with the object House it will just never get out of the Stop loop and will forever stay there and I can't move the Player anymore, how can I fix such a thing!
3. How to associate user actions with other game characters/objects.
4. If you take a look at the code and would like to suggest a better structure for the code and what is called after what that will be very welcome. I am trying to build an RPG game that have structure close to the game called Eschalon.

How to run the code:
1. Unrar all into one folder.
2. Import project in Parallelism.
3. Open Parallelism-desktop > src > com.me.Parallelism > Main.java and RUN.
4. Code modifications are done in Parallelism.

NOTE: When running the code, the Console will show which class is entered first.

Attachments: http://www.mediafire.com/download/2ir3s81azg4wthd/Parallelism.rar
Offline AirTime

Senior Newbie


Exp: 4-6 months


Not a glitch, just a misplaced curly brace.


« Reply #1 - Posted 2014-04-27 20:18:33 »

It's in .java format? Bad idea. I'd recommend distributing in either .class files or .jar files.

Nothing's gonna change my world.. well, at least until the next syntax error appears Tongue
Offline ctomni231

JGO Wizard


Medals: 99
Projects: 1
Exp: 7 years


Not a glitch. Just have a lil' pixelexia...


« Reply #2 - Posted 2014-04-27 21:44:22 »

A little typing in the search bar brought this up...

It seems to me like a good tutorial is needed to solve all the problems you've mentioned. There is problems with your game-loop, map scrolling, collision detection, and NPC handling. Such a broad amount of issues needs to be handled one at a time. LibGDX is great, but you still need to understand the basics in order to create good game code. This is a side-scroller, but it covers a lot of the concepts of building an RPG.

http://pastebin.java-gaming.org/43823368d83

If you could understand this code, you'll be well on your way to creating this.


Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Maged

Senior Newbie





« Reply #3 - Posted 2014-04-29 09:14:56 »

Well, thanks for the reply.

I think I asked for too much at once and I wasn't specific about the problems I am having. So, let us take it step by step.

The image below shows the classes interactions with each other:



What each class does is:
Asset Loader: Loads all the texture files.
Game Screen: Mainly control the width and height of the screen.
Map Loader: Loads the map from .txt file.
Game Renderer: Will print everything on the screen.
Input Handler: Controls the input from user.

The first thing I want to ask about is map creation, in future I plan to make the map load from an online server or so.
Currently I write a .txt file that contain the map like below:
8 400 50
8 100 100
5 120 300

Where first column describe the building type, the next 2 columns will be the X and Y coordinates of it.

The map loading process consist of a class that will open the file, read it as INTEGERS and put it in a matrix. From GameWorld class then I create the world like so:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
public void createWorld() {
      int j = 0;
      int k = 0;
      for (int i = 0; i < Global.MAP_SIZE; i++) {
         switch (map.getType(i)) {
         case 8:
            house[j] = new House(map.getX(i), map.getY(i), 67, 70);
            j++;
            break;
         case 5:
            hut[k] = new Hut(map.getX(i), map.getY(i), 63, 71);
            k++;
            break;
         }
      }


Note that I created an array of type House and Hut first with the size I initially know (I created the map so I know how many houses and huts are there).
1. Let us say that I don't know initially the sizes, is it possible to create an array of House or Hut with dynamic size where I can expand it? If so how as I tried but couldn't do that?
2. For collision detection I use the update method below, is there a way to update and detect collision for the whole array at once instead of using for loops?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
   public void update(float delta) {
      player.update(delta);
      for (int i = 0; i < house.length; i++) {
         house[i].update(delta);
         if (house[i].collides(player)){
            player.stop();
         }
      }
      for (int i = 0; i < hut.length; i++) {
         hut[i].update(delta);
         if (hut[i].collides(player)){
            player.stop();
         }
      }
   }


Thanks for help in advance Smiley
Offline sirkarpfen

Junior Devvie


Medals: 2
Exp: 2 years



« Reply #4 - Posted 2014-04-30 09:54:47 »

1. Why don't you use an ArrayList? This way it would be expandable and you can add as many Houses/Huts as you want.
2. No. When using Lists/Arrays there is no way to update every element in the List/Array without looping through^^.
Offline Maged

Senior Newbie





« Reply #5 - Posted 2014-05-01 18:05:36 »

That is great help. I finally managed to load the map using the method you mentioned Cheesy

Now I want to ask about two things:

1. My future plan is to make the game online multi-player so I will need to initiate the maps and everything from a server and the players will be able to modify by adding or removing assets from the map. From your experience, should I keep the way I use for maps or should I start making tiled maps? If I should use tiled maps, can the .tmx file be modified and saved from the code?

2. Is there some tutorial I can use to implement an interaction between player and houses for example?

Thanks in advance.
Offline Drenius
« Reply #6 - Posted 2014-05-01 18:11:07 »

Your enthusiasm is good, but trying to use networking in "my first game" is a bad idea.
Theres a lot of [***] related to working with it and you will probably get demotivated very soon.
Would suggest you to get the best out of this game (and maybe some others) in singleplayer before even cosidering to work with multiplayer.
Offline sirkarpfen

Junior Devvie


Medals: 2
Exp: 2 years



« Reply #7 - Posted 2014-05-01 21:00:34 »

That is great help. I finally managed to load the map using the method you mentioned Cheesy

Now I want to ask about two things:

1. My future plan is to make the game online multi-player so I will need to initiate the maps and everything from a server and the players will be able to modify by adding or removing assets from the map. From your experience, should I keep the way I use for maps or should I start making tiled maps? If I should use tiled maps, can the .tmx file be modified and saved from the code?

2. Is there some tutorial I can use to implement an interaction between player and houses for example?

Thanks in advance.

1. As Drenius suggested, i would too recommend to stay singleplayer for a while, because the task to create a multiplayer game is not an easy one. Start small and create a great singleplayer game, maybe more than one, before considering going multiplayer.

2. What kind of interactions would you like to implement? Opening chests? Doors?
Offline Maged

Senior Newbie





« Reply #8 - Posted 2014-05-02 06:33:44 »

That is awesome, now I know the path I should follow Wink

2. What kind of interactions would you like to implement? Opening chests? Doors?

Yep, something like that. I define the interactions I want as opening a new screen when an action by player is done to allow for invoking methods within the object being interacted with.


I decided last night to understand and attempt on working with tiled maps. Following a some tutorials I ended up building (a random non-sense) map below using Tiled software:



And the code for rendering this map was:

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  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
package com.me.ParallelismHelpers;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TiledMapRenderer;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.maps.tiled.renderers.IsometricTiledMapRenderer;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;

public class TiledMapLoader {
   private TiledMap map;
   private TiledMapRenderer renderer;
   private OrthographicCamera camera;
   private AssetManager assetManager;
   private BitmapFont font;
   private SpriteBatch batch;

   public TiledMapLoader() {
      create();
      render();
   }

   public void create() {
      float w = Gdx.graphics.getWidth();
      float h = Gdx.graphics.getHeight();

      camera = new OrthographicCamera();
      camera.setToOrtho(false, (w / h) * 10, 10);
      camera.zoom = 2;
      camera.update();

      font = new BitmapFont();
      batch = new SpriteBatch();
     
      assetManager = new AssetManager();
      assetManager.setLoader(TiledMap.class, new TmxMapLoader(
            new InternalFileHandleResolver()));
      assetManager.load("data/maps/level.tmx", TiledMap.class);
      assetManager.finishLoading();
      map = assetManager.get("data/maps/level.tmx");

      renderer = new OrthogonalTiledMapRenderer(map, 1f / 32f);
   }

   public void render() {

      Gdx.gl.glClearColor(255, 255, 255, 1);
      Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

      camera.update();
      renderer.setView(camera);
      renderer.render();

      batch.begin();

      font.draw(batch, "FPS: " + Gdx.graphics.getFramesPerSecond(), 10, 20);
      batch.end();
   }
}


Some parts of this code are not implemented by me though, I used tutorials.
That game me the below pic.:



So, am I on the right path of using tiled maps? If you know more tutorials on this topic worth reading let me know Cheesy
Offline sirkarpfen

Junior Devvie


Medals: 2
Exp: 2 years



« Reply #9 - Posted 2014-05-02 07:19:45 »

This repository has helped me greatly when i was learning about tilemaps:
http://code.google.com/p/libgdx-users/wiki/TiledMaps

Maybe this here will help you too:
https://github.com/libgdx/libgdx/wiki/Tile-maps

Well i cannot tell you if you're on the "right" path. It is the right path if it fits for the purpose and helps you solving problems^^. Allways stick to stuff and mechanics you like, if you like to make tilemaps, make some^^. Afterwards you will know if it was the right way.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Maged

Senior Newbie





« Reply #10 - Posted 2014-05-03 18:15:21 »

I was able to load the map successfully, did some changes to the overall way of how the code is executing Smiley

The map I used is shown below:



Now I made the walls of the house have bounding rectangle so I can check for collision between player and wall.
The code below is used to detect collision:

1  
2  
3  
4  
5  
6  
7  
8  
9  
   public void update(float delta) {
      player.update(delta);
      for (int i = 0; i < wall.size(); i++) {
         wall.get(i).update(delta);
         if (wall.get(i).collides(player)) {
            player.stop();
         }
      }
   }


And the stop method within the player is:
1  
2  
3  
4  
5  
   public void stop() {
      velocity.x = 0;
      velocity.y = 0;
      System.out.println("x");
   }


The problem now is that once the player touches the wall, it go to the stop method and remain there forever even when I touch down other areas on the map to try to move away from the wall!
Any ideas?
Offline sirkarpfen

Junior Devvie


Medals: 2
Exp: 2 years



« Reply #11 - Posted 2014-05-04 10:24:09 »


1  
2  
3  
4  
5  
6  
7  
8  
9  
   public void update(float delta) {
      player.update(delta);
      for (int i = 0; i < wall.size(); i++) {
         wall.get(i).update(delta);
         if (wall.get(i).collides(player)) {
            player.stop();
         }
      }
   }


And the stop method within the player is:
1  
2  
3  
4  
5  
   public void stop() {
      velocity.x = 0;
      velocity.y = 0;
      System.out.println("x");
   }


The problem now is that once the player touches the wall, it go to the stop method and remain there forever even when I touch down other areas on the map to try to move away from the wall!
Any ideas?

Am i right that you call this Methode recursivly over and over again: wall.get(i).update(delta)?

Maybe you could post what wall.get(i).collides(player) does too, because i think the Error comes from there^^.
Offline Maged

Senior Newbie





« Reply #12 - Posted 2014-05-04 11:47:33 »

Yea, I mean it enters recursively and never get out of it. The collides method is:


1  
2  
3  
4  
5  
   public boolean collides(Player player) {
      if (position.x < player.getX() + player.getWidth()){
         return (Intersector.overlaps(player.getBoundingRect(), wallBound));
      }
      else return false;
Offline Kelathor

Innocent Bystander





« Reply #13 - Posted 2014-05-06 01:47:25 »

When you move the player do a collision check. If the movement would cause a collision then don't move, else move.
so something like

Player Tries to move right.
       Check the tile to the right of the player.
                 Is it passable?
                          Yes
                                 move player to the right
                          No
                                 Do nothing

You are checking to see if they have already collided and then stopping them. and since they have player.stop() is constantly being called.


Here is a good tutorial video about it https://www.youtube.com/watch?v=DOpqkaX9844
or this one https://www.youtube.com/watch?v=TLZbC9brH1c which is an update to the other video.
Offline Maged

Senior Newbie





« Reply #14 - Posted 2014-05-07 13:16:49 »

I really appreciate your help, that was a very useful tutorial indeed.

That I finally got the player blocked by some tiles on the map without problems, now I got a new thing to implement that I have been attempting without any luck Sad

I am implementing a system of interactions between player and doors, chests, etc...
When the player press some specific button while near, say the door, I want the door tile to be changes to another tile that shows the door open. The implementation I did is as follow:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
   public void openDoor() {
      layer = (TiledMapTileLayer) map.getLayers().get(2);
      Cell cellx = layer.getCell(23, 15);
      TiledMapTile tilex = map.getTileSets().getTileSet("Door1").getTile(11);
      if (!open) {

         cell = (TiledMapTile) map.getTileSets().getTileSet("Door1")
               .getTile(11);
         cellx.setTile(cell);

         open = true;

      } else {
         System.out.println("already open");

         open = false;
      }
   }


Running the game like that just removes the door tile from the map when I press the key responsible for opening door. Any suggestions?
Offline Maged

Senior Newbie





« Reply #15 - Posted 2014-05-08 09:21:14 »

No worries guys, managed to fix it Cheesy
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.

Mr.CodeIt (24 views)
2014-12-23 03:34:11

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

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

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

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

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

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

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

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

toopeicgaming1999 (152 views)
2014-11-26 15:20:36
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!