Show Posts
|
|
Pages: [1]
|
|
2
|
Game Development / Networking & Multiplayer / Problem with object modifications not sending over network
|
on: 2013-01-20 01:11:04
|
The variables are not the same for some reason. Here is where I receive the object: 1 2 3 4 5 6 7 8 9 10 11 12 13 14
| if(omsg instanceof ServerPlayerStateMessage){ ServerPlayerStateMessage msg = (ServerPlayerStateMessage) omsg; for(int i=0; i<msg.players.length; i++){ PlayerModel newModel = msg.players[i];
PlayerModel oldModel = playerManager.getByID(newModel.clientID); if(oldModel != null){ oldModel.setTilePos(newModel.tileX,newModel.tileY); }
} } |
Here is where I send: 1 2 3 4 5 6 7
| if(msg instanceof ClientMoveMessage){ System.out.println("Client move msg"); ClientMoveMessage msg2 = (ClientMoveMessage) msg; cThread1.getPlayerModel().setTilePos(msg2.tileX, msg2.tileY); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| public void sendPlayerStates(){ ArrayList<PlayerModel> playerModels = new ArrayList<PlayerModel>(); for(int i=0; i<cThreads.size(); i++){ ClientThread t = cThreads.get(i); playerModels.add(t.getPlayerModel()); } ServerPlayerStateMessage msg = new ServerPlayerStateMessage(); msg.players = new PlayerModel[playerModels.size()]; msg.players = playerModels.toArray(msg.players); broadcast(msg); } |
Here is the actual objectoutputstream writing: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| public void sendAll() { if(socket.isConnected()){ Object msg = null; while((msg = outQueue.poll()) != null){ try { out.writeUnshared(msg); out.flush(); out.reset(); } catch (IOException e) { e.printStackTrace(); } } } } |
1 2 3 4
| public class ServerPlayerStateMessage implements Serializable { public PlayerModel[] players; } |
1 2 3 4 5 6 7 8 9 10 11 12 13
| public class PlayerModel implements Serializable { public int clientID; public int tileX; public int tileY; public void setTilePos(int tileX, int tileY){ this.tileX = tileX; this.tileY = tileY; } } |
|
|
|
|
|
3
|
Game Development / Newbie & Debugging Questions / [solved]LuaJava
|
on: 2008-05-16 11:20:42
|
I want to use LuaJava to script things like events and triggers etc. Im confused on how integration works. Here is what I tried: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| import org.keplerproject.luajava.LuaState; import org.keplerproject.luajava.LuaStateFactory;
public class Main { public static void main(String[] args) { LuaState l = LuaStateFactory.newLuaState(); l.openLibs(); NPCManager npcMan = new NPCManager(); l.LdoFile("hello.lua"); l.pushJavaObject(npcMan); System.out.println("Hello World from Java!"); } } |
1 2 3 4 5
| public class NPCManager { public void createNPC(String name){ System.out.println(name); } } |
1 2 3 4 5
| print("Hello world from LUA") local npcMan
npcMan:createNPC("Brad") |
|
|
|
|
|
4
|
Game Development / Performance Tuning / Seamless Terrain
|
on: 2007-03-01 00:04:42
|
|
Anyone want to comment on seamless terrain. Different then infinite terrain, but the way I was planning on doing it was to have a 3x3 grid around the player of terrains, and whenever he passes over one it'll unload the farthest ones and load in the height map and initilize everything for the new terrain... are there better ways?
|
|
|
|
|
8
|
Game Development / Newbie & Debugging Questions / Re: Wondering effeciency of my code.
|
on: 2005-07-18 21:52:29
|
Oh the Client I am still working on. Thanks for the comments guys! Im thinking about removing the Game class, as it serves no real purpose and instead using the vanMain class as the main class, would look something like: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| public class vanMain, extends Frame { public static void main(String args[]) { vanMain vm = new vanMain(); } vanMain() { while(gameOn) { this.repaint(); }
} } |
|
|
|
|
|
9
|
Game Development / Newbie & Debugging Questions / Wondering effeciency of my code.
|
on: 2005-07-18 12:27:06
|
Okay so I'm new to alot of techniques in Java, such as OOP. My code is messy, execution of things are a bit wierd. Im wondering what way I could better organize my code so that it is easier to read and runs more effecient! Please any tips are welcome! (Paste is of my 2D tile engine) Sorry if there is a bit much. Just want to make sure I am on the right track, and not doing any bad habits.. 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
| import java.net.*; import java.io.*; import java.util.*; import java.lang.*; import java.awt.*; import java.awt.event.*; import javax.swing.*;
public class vanMain { public static Game myGame; public static void main(String args[]) { myGame = new Game(); myGame.setSize(640,480); myGame.setVisible(true); myGame.setResizable(false); myGame.setTitle("Vandrel Online"); myGame.mainGame(); } } class Game extends Frame implements KeyListener { public Image dbImage = null; public Graphics dbg = null; ArrayList clientList = new ArrayList(); Image[] tiles = new Image[80]; TileManager tileMan = new TileManager(); Layer map01; Layer map02; Layer map03; Layer map04; Player myPlayer = new Player(); boolean gameOn=true; long startTime = 0; float currentTime=0; float speedFactor=0; float deltaTime=0; float lastTime=0; public void mainGame() { startTime=System.currentTimeMillis(); this.addKeyListener(this); myPlayer.loadPlayerData();
loadMap("nicehouse.MAP"); while(gameOn) { myPlayer.movePlayer(); this.repaint(); } } public void addMapOffset(int x, int y) { map01.offsetX+=x; map02.offsetX+=x; map03.offsetX+=x; map04.offsetX+=x; map01.offsetY+=y; map02.offsetY+=y; map03.offsetY+=y; map04.offsetY+=y; } public void subMapOffset(int x, int y) { map01.offsetX-=x; map02.offsetX-=x; map03.offsetX-=x; map04.offsetX-=x; map01.offsetY-=y; map02.offsetY-=y; map03.offsetY-=y; map04.offsetY-=y; } public void addNewPlayer(String name,int x,int y) { Client singleClient = new Client(name,x,y); clientList.add(singleClient); } public void update (Graphics Screen) { if (dbImage == null) { dbImage = createImage (this.getSize().width, this.getSize().height); dbg = dbImage.getGraphics (); } dbg.setColor (getBackground ()); dbg.fillRect (0, 0, this.getSize().width, this.getSize().height); dbg.setColor (getForeground()); paint (dbg); Screen.drawImage (dbImage, 0, 0, this); } public void paint(Graphics g) { g.setClip(0,0,640,480); g.setColor(Color.black); g.fillRect(0,0,640,480); map01.drawLayer(g); map02.drawLayer(g); myPlayer.drawPlayer(g); map03.drawLayer(g); if(map04.grid[myPlayer.corX][myPlayer.corY]==0) map04.drawLayer(g); } public void loadMap(String mapName) { try { BufferedReader Input = new BufferedReader(new FileReader(mapName)); int newSize = Integer.parseInt(Input.readLine()); map01 = new Layer(newSize,newSize,0); map02 = new Layer(newSize,newSize,0); map03 = new Layer(newSize,newSize,0); map04 = new Layer(newSize,newSize,0); for(int x = 0;x<=newSize-1;x++) for(int y = 0;y<=newSize-1;y++) { map01.grid[x][y]=Integer.parseInt(Input.readLine()); map02.grid[x][y]=Integer.parseInt(Input.readLine()); map03.grid[x][y]=Integer.parseInt(Input.readLine()); map04.grid[x][y]=Integer.parseInt(Input.readLine()); map01.isWall[x][y]=Integer.parseInt(Input.readLine()); } Input.close(); }catch(IOException e){} } public void keyTyped(KeyEvent e){} public void keyReleased(KeyEvent e) { } public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_LEFT) { if(myPlayer.playerDir==0) myPlayer.playerDir=1; } if (e.getKeyCode() == KeyEvent.VK_RIGHT) { if(myPlayer.playerDir==0) myPlayer.playerDir=2; } if (e.getKeyCode() == KeyEvent.VK_DOWN) { if(myPlayer.playerDir==0) myPlayer.playerDir=3; } if (e.getKeyCode() == KeyEvent.VK_UP) { if(myPlayer.playerDir==0) myPlayer.playerDir=4; } } } |
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
| import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; class Layer { int[][] grid; int[][] isWall; int x,y,n; int offsetX; int offsetY; public Layer(int x, int y, int n) { this.n = n; Toolkit toolkit = Toolkit.getDefaultToolkit(); this.x=x-1; this.y=y-1; grid = new int[x][y]; isWall = new int[x][y]; } public void drawLayer(Graphics g) { for(int x = 0;x<=this.x;x++) { for(int y = 0;y<=this.y;y++) { int tileNum=grid[x][y]; if(tileNum!=0) g.drawImage(vanMain.myGame.tileMan.tileImg[tileNum],offsetX+(x*20),offsetY+(y*20),null); } } } } class TileManager { BufferedReader Input=null;
Image[] tileImg = new Image[200]; String[] tileList = new String[100]; int numTiles; public TileManager() { Toolkit toolkit = Toolkit.getDefaultToolkit(); String inVal=""; int lcv=1; try { Input = new BufferedReader(new FileReader("tiles.lis")); while((inVal=Input.readLine()) != null) { tileList[lcv]=inVal; tileImg[lcv]= toolkit.getImage(inVal); System.out.println(inVal); lcv++; } numTiles=lcv; }catch(IOException e){} } } |
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
| import java.util.*; import javax.swing.*; import java.io.*; import java.lang.*; import java.awt.*; class Player { int speedX=0; int speedY=0; int x=0; int y=0; int corX=0; int corY=0; int playerDir=0; float moveAmnt=0; Image[] playerImg = new Image[4]; public Player() { } public void movePlayer() { if(System.currentTimeMillis()-vanMain.myGame.startTime>=0) { int moveSpeed=2; if(playerDir==0 || moveAmnt==0) { corX=-1*(vanMain.myGame.map01.offsetX-320)/20; corY=(-1*(vanMain.myGame.map01.offsetY-240)/20)+1; } if(playerDir==1 && (vanMain.myGame.map01.isWall[corX-1][corY]==0)) { if(moveAmnt<=10) { vanMain.myGame.addMapOffset(moveSpeed, 0); moveAmnt++; } if(moveAmnt>=10) moveAmnt=0; } if(playerDir==2 && (vanMain.myGame.map01.isWall[corX+1][corY]==0)) { if(moveAmnt<=10) { vanMain.myGame.subMapOffset(moveSpeed, 0); moveAmnt++; } if(moveAmnt>=10) moveAmnt=0; } if(playerDir==3 && (vanMain.myGame.map01.isWall[corX][corY+1]==0)) { if(moveAmnt<=10) { vanMain.myGame.subMapOffset(0,moveSpeed); moveAmnt++; } if(moveAmnt>=10) moveAmnt=0; } if(playerDir==4 && (vanMain.myGame.map01.isWall[corX][corY-1]==0)) { if(moveAmnt<=10) { vanMain.myGame.addMapOffset(0,moveSpeed); moveAmnt++; } if(moveAmnt>=10) moveAmnt=0; } if(moveAmnt==0) playerDir=0; vanMain.myGame.startTime=System.currentTimeMillis(); }
} public int checkCollision() { int returnVar=0; int mapSize = vanMain.myGame.map01.x; Layer tempLayer = vanMain.myGame.map01; for(int x = 0;x<=mapSize;x++) { for(int y = 0;y<=mapSize;y++) { int tileLeft = x*20 - tempLayer.offsetX; System.out.println("Tiles left side: "+tileLeft+ "Players leftside: "+x); if((tempLayer.isWall[x][y]==1) && ((this.x+10+tempLayer.offsetX)>=tileLeft)) { returnVar=1; break; } } } return returnVar; } public void loadPlayerData() { Toolkit toolkit = Toolkit.getDefaultToolkit(); playerImg[0]= toolkit.getImage("player1.png"); } public void drawPlayer(Graphics g) { g.drawImage(this.playerImg[0],(vanMain.myGame.getWidth()/2),6+vanMain.myGame.getHeight()/2,null); } } class Client { int x,y; public Client(String name, int x, int y) { this.x=x; this.y=y; } } |
|
|
|
|
|
13
|
Java Game APIs & Engines / JOGL Development / Common Problem installing JOGL
|
on: 2005-06-06 02:31:48
|
Hello Fellow Java Users. I am trying to get into JOGL so I can create demos and basically play around with it. I am having a issue installing JOGL and running it. My Setup: Windows XP, JCreator LE 2.5.0 , Java SDK 1.5 I can't seem to get the HelloWorld example to run. In Jcreator it will compile fine, but when I try to run it from the IDE it doesn't work. I put the jogl.jar in: D:\Program Files\Java\jdk1.5.0_03\jre\lib\ext I also put the dll in:D:\Program Files\Java\jdk1.5.0_03\jre\bin I also added the jar file to the library tab in the project settings inside Jcreator The error message I get is: 1 2 3 4 5 6 7 8 9
| Exception in thread "main" java.lang.UnsatisfiedLinkError: D:\Program Files\Java \jdk1.5.0_03\jre\bin\jogl.dll: Can't find dependent libraries at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1668) at java.lang.Runtime.loadLibrary0(Runtime.java:822) at java.lang.System.loadLibrary(System.java:992) at HelloWorld.main(HelloWorld.java:7) Press any key to continue... |
Thanks in advance.
|
|
|
|
|
14
|
Java Game APIs & Engines / Xith3D Forums / MIRC
|
on: 2004-12-12 02:51:30
|
|
is there a xith3d mirc channel? Im just wondering because it'd be cool to meet everyone and see their projects etc. if not we could start one up.
|
|
|
|
|
17
|
Java Game APIs & Engines / Xith3D Forums / Re: alot of custom APIS broke :-(
|
on: 2004-12-10 21:57:00
|
|
to get lwjgl working on my comp i would have to put all the lwjgl files in with the class file on execution .. is a similar thing possible with xith?
UPDATE: made some progress, i put the vecmath jar in xith/third-party/vecmath
and it got rid of the tuple3f error but now a new one popped up: NoClassDefError: net/java/games/jogl/GLEventListener
|
|
|
|
|
18
|
Java Game APIs & Engines / Xith3D Forums / Re: alot of custom APIS broke :-(
|
on: 2004-12-10 02:54:03
|
|
can you give a example of what it would look like to add the files into a bat?
also for lwjgl, i could get things to compile in JCreator, with the library added to custom but they wouldn't execute unless i had all the lwjgl files in the same directory as the class and .java file. i wonder if the same will work for this?
|
|
|
|
|
21
|
Java Game APIs & Engines / Xith3D Forums / Re: alot of custom APIS broke :-(
|
on: 2004-12-09 21:43:27
|
|
is there any chance you can give me a working link to props.java ? the program that finds your paths for you
and i never ment they're broke as in bad code; just ment that for some reason they didnt work on my computer..
update: i noticed i still had JRE 1.4.2 installed and uninstalled that but still nothing :-( i went in and changed JAVA_HOME to the java5 directory but still nothing ..
|
|
|
|
|
24
|
Java Game APIs & Engines / Xith3D Forums / alot of custom APIS broke :-(
|
on: 2004-12-09 03:49:03
|
|
i had trouble with lwjgl and now Xith3D doesn't seem to work :-( i get a noClassdeferror for javax/vecmath/toulpes3f or something
any help appreciated, i followed the instructions pretty straight forward.. if you can help me, contant me on aim ( Kenshin5X ) to speed things up
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|