Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (546)
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  Discussions / Miscellaneous Topics / Re: Throw me with programming ideas! on: 2014-01-05 21:16:12
A Donkey Kong clone, but instead of jumping the barrels the player controlled character has a giant belly which he flops up and down to crush the barrels??
That sounds like fun  Cheesy I guess I could try something like that, thanks mate!

Towerfall clone?
This is a great idea too, it offers challenge but seems like something I could manage.
2  Discussions / Miscellaneous Topics / Re: Throw me with programming ideas! on: 2014-01-02 19:21:42
This is more just a challenge for the hell of it: Build a new programming language with an emulator in java. so it compiles back down to a .jar but is higher level, would be a cool exercise to do.

Yeah another unrelated challenge:
Use regex in Java (or Python or Ruby I don't care)to get the latest posts from the index page of JGO. Yes, regex, to parse HTML. *Laughs maniacally*
More to learn regex than anything because it's a cool little thing.

Both ideas sound like fun! I tried to create simple scripting language a long time ago, but it was not very successful  Grin
I guess I should learn some regex too...

Thanks for anyone answering so far, but I still feel like we haven't found THE idea.. Keep tossing everyone!
3  Discussions / Miscellaneous Topics / Throw me with programming ideas! on: 2014-01-02 16:31:31
I need some help everyone! I'm yearning to program a new game, but I'm all out of ideas  Cry
I feel like I need something new and exciting to work on and I'm asking YOU to throw any ideas you have (No matter how crazy, everything goes).

All I have planned out currently is that I want to make a 2d game and I'd like to implement some server/client action, where the server would run on my Raspberry pi.

So feel free to throw in any cool game mechanics and ideas and anything you think that could be used in a game.
4  Game Development / Networking & Multiplayer / Re: [KryoNet] Networking only works on LAN? on: 2013-10-23 18:58:14
Have you port forwarded your program? I've never used Hamachi so I don't know whats wrong with that.
Well I quess I should try port forwarding, but Hamachi should work just the same so I'm not sure if that is causing my problem. I'll probably try forwarding tomorrow just to be sure, thanks for answering!  Smiley
5  Game Development / Networking & Multiplayer / [KryoNet] Networking only works on LAN? on: 2013-10-23 14:51:38
Hi everyone.

I'm making a rpg game with plain Java2D and I'm using KryoNet library to do the networking. Now when I test the game on the same computer, everything works fine, clients send data to server and server sends that to other clients. But when I try to test it with my friend who is on other computer the connection fails every time. We have tried Hamachi but it's the same. Do you guys have any similar experiences, fixes or ideas on what is wrong?

Here are my GameClient and GameServer classes (Sorry for messy code, I'm gonna clean it later I promise  Tongue) if they are any help at all.

GameClient
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  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
package net;

import Game.gameManager;
import Gui.Ginterface;
import Gui.UI;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryonet.Client;
import com.esotericsoftware.kryonet.Connection;
import com.esotericsoftware.kryonet.Listener;
import java.awt.Point;
import java.io.IOException;

public class GameClient {
   
    private Client client = new Client();
    private GamePackage pack;
    private Ginterface inface;
    private gameManager mgm;
    private String username, hostAddress;
    private UI ui;
   
    public void voidSetHostAdd(String a) {
        hostAddress = a;
    }
   
    public void setUi(UI ui) {
        this.ui = ui;
    }
   
    public void setInface(Ginterface inface) {
        this.inface = inface;
    }
   
    public void setMgm(gameManager mgm) {
        this.mgm = mgm;
    }
   
    public void setUsername(String username) {
        this.username = username;
        sendJoinMSG();
    }
   
    public GameClient(String a) {
        hostAddress = a;
        new Thread(client).start();
        Kryo kryo = client.getKryo();
        kryo.register(byte[].class);
        kryo.register(GamePackage.class);
        try {
            client.connect(30000, hostAddress, 54555, 54777);
        } catch (IOException e) {
        }
        client.addListener(new Listener() {
            @Override
            public void received(Connection connection, Object object) {
                if (object instanceof GamePackage) {
                    GamePackage pack = (GamePackage) object;
                    String[] dataArray = readData(pack.getData()).split(",");
                   
                    //Process the incoming packages


                    if ("-1".equals(dataArray[0])) {
                        ui.newNick();
                    }
                    if ("-2".equals(dataArray[0])) {
                        sendJoinMSG();
                    }
                    if ("00".equals(dataArray[0]) && dataArray.length > 1) {
                        inface.addMsg(pack.getSenderName() + ": " + dataArray[1]);
                    }
                    if ("01".equals(dataArray[0])) {
                        if (!pack.getSenderName().equals(username) && !mgm.hasMPP(pack.getSenderName())) {
                            inface.addMsg("> " + pack.getSenderName() + " connected.");
                            mgm.addMPPlayer(pack.getSenderName(), new Point(300, 300));
                            String data = "05";
                            pack = new GamePackage(data.getBytes(), username);
                            client.sendTCP(pack);
                        }
                    }
                    if ("05".equals(dataArray[0])) {
                        if (!pack.getSenderName().equals(username) && !mgm.hasMPP(pack.getSenderName())) {
                            System.out.println("05");
                            inface.addMsg("> " + pack.getSenderName() + " connected.");
                            mgm.addMPPlayer(pack.getSenderName(), new Point(300, 300));
                        }
                    }
                    if ("02".equals(dataArray[0])) {
                        inface.addMsg("> " + pack.getSenderName() + " disconnected.");
                        mgm.removeMPPlayer(pack.getSenderName());
                    }
                    if ("03".equals(dataArray[0]) && dataArray.length >= 2) {
                        if (mgm.hasMPP(pack.getSenderName())) {
                            mgm.getMPP(pack.getSenderName()).setPosition(new Point(Integer.parseInt(dataArray[1]), Integer.parseInt(dataArray[2])));
                        }
                    }
                    if ("07".equals(dataArray[0])) {
                        inface.setIsAdmin(true);
                    }
                    if ("08".equals(dataArray[0])) {
                        inface.setIsAdmin(false);
                    }
                    if ("09".equals(dataArray[0])) {
                        inface.addMsg("You have been kicked from the game.");
                        mgm.cleanAll();
                        sendDisconnect();
                    }
                    if ("26".equals(dataArray[0]) && dataArray.length >= 2) {
                        if (mgm.hasMPP(pack.getSenderName())) {
                            mgm.getMPP(pack.getSenderName()).setPosition(new Point(Integer.parseInt(dataArray[1]), Integer.parseInt(dataArray[2])));
                            mgm.getMPP(pack.getSenderName()).setFrame(Integer.parseInt(dataArray[3]));
                        }
                    }
                }
            }
        });
       
       
       
    }

     //Sending packages
   
    public String readData(byte[] data) {
        String message = new String(data).trim();
        return message;
    }
   
    public void sendMSG(String msg) {
        String data = "00" + "," + msg;
        pack = new GamePackage(data.getBytes(), username);
        client.sendTCP(pack);
    }
   
    public void sendJoinMSG() {
        String data = "01";
        pack = new GamePackage(data.getBytes(), username);
        client.sendTCP(pack);
    }
   
    public void sendDisconnect() {
        String data = "02";
        pack = new GamePackage(data.getBytes(), username);
        client.sendTCP(pack);
        client.close();
    }
   
    public void sendPosT() {
        String data = "03" + "," + ((int) mgm.getPlayer().getPosition().getX()) + "," + ((int) mgm.getPlayer().getPosition().getY());
        pack = new GamePackage(data.getBytes(), username);
        client.sendTCP(pack);
    }
   
    public void subNick(String n) {
        username = n;
        String data = "04";
        pack = new GamePackage(data.getBytes(), username);
        client.sendTCP(pack);
    }
   
    public void sendPrivateMSG(String msg, String to) {
        String data = "06" + "," + to + "," + msg;
        pack = new GamePackage(data.getBytes(), username);
        client.sendTCP(pack);
    }
   
    public void sendAdminTo(String who) {
        String data = "07," + who;
        pack = new GamePackage(data.getBytes(), username);
        client.sendTCP(pack);
    }
   
    public void removeAdminFrom(String who) {
        String data = "08," + who;
        pack = new GamePackage(data.getBytes(), username);
        client.sendTCP(pack);
    }
   
    public void kickPlayer(String who) {
        String data = "09," + who;
        pack = new GamePackage(data.getBytes(), username);
        client.sendTCP(pack);
    }
   
    public void sendPosU() {
        String data = "26" + "," + ((int) mgm.getPlayer().getPosition().getX()) + "," + ((int) mgm.getPlayer().getPosition().getY() + "," + mgm.getPlayer().getPg().getFrames());
        pack = new GamePackage(data.getBytes(), username);
        client.sendUDP(pack);
    }
}


GameServer

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  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
package net;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryonet.Connection;
import com.esotericsoftware.kryonet.Listener;
import com.esotericsoftware.kryonet.Server;
import java.io.IOException;
import java.util.HashMap;
import java.util.Random;
import java.util.Scanner;

public class GameServer {

    private Server server;
    private static Scanner scan = new Scanner(System.in);
    private HashMap<Connection, String> users = new HashMap<>();
    private HashMap<String, Connection> rev = new HashMap<>();

    public GameServer() {
 

        server = new Server();
        Random rand = new Random();
        new Thread(server).start();
        Kryo kryo = server.getKryo();
        kryo.register(byte[].class);
        kryo.register(GamePackage.class);
        try {
            server.bind(54555, 54777);
        } catch (IOException e) {
        }
        final byte[] someData = new byte[10];
        for (int i = 0; i < 10; i++) {
            someData[i] = (byte) rand.nextInt(5);
        }
        server.addListener(new Listener() {
            @Override
            public void received(Connection connection, Object object) {

                if (object instanceof GamePackage) {

                    GamePackage pack = (GamePackage) object;

                    String[] dataArray = readData(pack.getData()).split(",");

                    if (Integer.parseInt(dataArray[0]) <= 5 && Integer.parseInt(dataArray[0]) > 0) {
                        server.sendToAllExceptTCP(connection.getID(), object);
                    } else if (Integer.parseInt(dataArray[0]) == 0) {
                        server.sendToAllTCP(object);
                    }
                    if (Integer.parseInt(dataArray[0]) == 6 && dataArray.length >= 3) {
                        if (rev.containsKey(dataArray[1])) {
                            GamePackage packN = new GamePackage(("00," + dataArray[2]).getBytes(), pack.getSenderName());
                            server.sendToTCP(rev.get(dataArray[1]).getID(), packN);
                        }
                    }
                    if (Integer.parseInt(dataArray[0]) == 7) {
                        if (rev.containsKey(dataArray[1])) {
                            GamePackage packN = new GamePackage(("07,").getBytes(), pack.getSenderName());
                            server.sendToTCP(rev.get(dataArray[1]).getID(), packN);
                        }
                    }
                    if (Integer.parseInt(dataArray[0]) == 8) {
                        if (rev.containsKey(dataArray[1])) {
                            GamePackage packN = new GamePackage(("08,").getBytes(), pack.getSenderName());
                            server.sendToTCP(rev.get(dataArray[1]).getID(), packN);
                        }
                    }
                    if (Integer.parseInt(dataArray[0]) == 9) {
                        if (rev.containsKey(dataArray[1])) {
                            GamePackage packN = new GamePackage(("09,").getBytes(), pack.getSenderName());
                            server.sendToTCP(rev.get(dataArray[1]).getID(), packN);
                        }
                    }
                    if (Integer.parseInt(dataArray[0]) == 1) {
                        if (users.containsValue(pack.getSenderName())) {
                            pack = new GamePackage("-1".getBytes(), "SERVER");
                            server.sendToTCP(connection.getID(), pack);
                        } else {
                            users.put(connection, pack.getSenderName());
                            rev.put(pack.getSenderName(), connection);
                        }
                    }
                    if (Integer.parseInt(dataArray[0]) == 4) {
                        if (users.containsValue(pack.getSenderName())) {
                            pack = new GamePackage("-2".getBytes(), "SERVER");
                            server.sendToTCP(connection.getID(), pack);
                        } else {
                            users.put(connection, pack.getSenderName());
                            rev.put(pack.getSenderName(), connection);
                            String data = "01";
                            pack = new GamePackage(data.getBytes(), pack.getSenderName());
                            server.sendToAllExceptTCP(connection.getID(), pack);
                        }
                    }
                    if (Integer.parseInt(dataArray[0]) >= 26) {
                        server.sendToAllUDP(object);
                    }
                }
            }
        });
    }

    public String readData(byte[] data) {
        String message = new String(data).trim();
        return message;
    }

    public void sendMSG(String msg) {
    }
}


And the GamePackage class

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
package net;

public class GamePackage {

   private byte[] data;
   private String senderName;
   
   public GamePackage() {
     
   }

   public GamePackage(byte[] data, String name) {
      this.data = data;
      senderName = name;
   }

   public byte[] getData() {
      return data;
   }

   public String getSenderName() {
      return senderName;
   }
}


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.

atombrot (23 views)
2014-08-19 09:29:53

Tekkerue (22 views)
2014-08-16 06:45:27

Tekkerue (21 views)
2014-08-16 06:22:17

Tekkerue (12 views)
2014-08-16 06:20:21

Tekkerue (19 views)
2014-08-16 06:12:11

Rayexar (57 views)
2014-08-11 02:49:23

BurntPizza (37 views)
2014-08-09 21:09:32

BurntPizza (29 views)
2014-08-08 02:01:56

Norakomi (36 views)
2014-08-06 19:49:38

BurntPizza (66 views)
2014-08-03 02:57:17
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!