Initial commit
This commit is contained in:
16
shared/build.gradle
Normal file
16
shared/build.gradle
Normal file
@@ -0,0 +1,16 @@
|
||||
plugins {
|
||||
id 'java-library'
|
||||
}
|
||||
|
||||
group = 'io.github.eldek0'
|
||||
version = "$projectVersion"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
maven { url = 'https://jitpack.io' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api "com.github.crykn:kryonet:$kryoNetVersion"
|
||||
}
|
||||
17
shared/src/main/java/io/github/eldek0/Main.java
Normal file
17
shared/src/main/java/io/github/eldek0/Main.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package io.github.eldek0;
|
||||
|
||||
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
|
||||
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
|
||||
// to see how IntelliJ IDEA suggests fixing it.
|
||||
System.out.printf("Hello and welcome!");
|
||||
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
|
||||
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
|
||||
System.out.println("i = " + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
23
shared/src/main/java/io/github/eldek0/network/Network.java
Normal file
23
shared/src/main/java/io/github/eldek0/network/Network.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package io.github.eldek0.network;
|
||||
|
||||
import com.esotericsoftware.kryo.Kryo;
|
||||
import com.esotericsoftware.kryonet.EndPoint;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Network {
|
||||
public static final int TCP_PORT = 54555;
|
||||
public static final int UDP_PORT = 54777;
|
||||
|
||||
public static void register(EndPoint endPoint) {
|
||||
Kryo kryo = endPoint.getKryo();
|
||||
|
||||
kryo.register(NetworkPackets.Login.class);
|
||||
kryo.register(NetworkPackets.PlayerConnected.class);
|
||||
kryo.register(NetworkPackets.PlayerDisconnected.class);
|
||||
kryo.register(NetworkPackets.PlayerMove.class);
|
||||
kryo.register(NetworkPackets.WorldState.class);
|
||||
kryo.register(NetworkPackets.PlayerState.class);
|
||||
|
||||
kryo.register(ArrayList.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package io.github.eldek0.network;
|
||||
|
||||
public class NetworkPackets {
|
||||
|
||||
public static class Login {
|
||||
public String name;
|
||||
}
|
||||
|
||||
public static class PlayerConnected {
|
||||
public int id;
|
||||
public String name;
|
||||
public float x;
|
||||
public float y;
|
||||
}
|
||||
|
||||
public static class PlayerDisconnected {
|
||||
public int id;
|
||||
}
|
||||
|
||||
public static class PlayerMove {
|
||||
public int id;
|
||||
public float x;
|
||||
public float y;
|
||||
}
|
||||
|
||||
public static class WorldState {
|
||||
public java.util.ArrayList<PlayerState> players = new java.util.ArrayList<>();
|
||||
}
|
||||
|
||||
public static class PlayerState {
|
||||
public int id;
|
||||
public String name;
|
||||
public float x;
|
||||
public float y;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user