• Content count

  • Joined

  • Last visited

Community Reputation

101 Neutral

About pythedev

  • Rank
  1. Spaceship movement parameters update

    Okay, I think I figured it out correctly: [CODE] private void updateParameters() { long currentTime = System.currentTimeMillis(); double timeDelta = (currentTime - lastUpdate) / 1000.0; lastUpdate = currentTime; if(timeDelta == 0.0) return; double posX = params.get(ShipPhysicalParam.POS_X); double posY = params.get(ShipPhysicalParam.POS_Y); double velX = params.get(ShipPhysicalParam.SPEED_X_PIX_SEC); double velY = params.get(ShipPhysicalParam.SPEED_Y_PIX_SEC); double dir = params.get(ShipPhysicalParam.DIRECTION_RAD); double dirSpeed = params.get(ShipPhysicalParam.DIRECTION_SPEED_RAD_SEC); double thrust = params.get(ShipPhysicalParam.THRUST_PIX_SEC); double dirAtEnd = dir + dirSpeed * timeDelta; double thrustX = thrust * Math.sin(dir); double thrustY = thrust * Math.cos(dir); double thrustAtEndX = thrust * Math.sin(dirAtEnd); double thrustAtEndY = thrust * Math.cos(dirAtEnd); double thrustVelX = (thrustAtEndX - thrustX) / timeDelta; double thrustVelY = (thrustAtEndY - thrustY) / timeDelta; posX += velX * timeDelta + thrustX * timeDelta * timeDelta / 2.0 + thrustVelX * timeDelta * timeDelta * timeDelta / 6.0; posY += velY * timeDelta + thrustY * timeDelta * timeDelta / 2.0 + thrustVelY * timeDelta * timeDelta * timeDelta / 6.0; velX += thrustX * timeDelta + thrustVelX * timeDelta * timeDelta / 2.0; velY += thrustY * timeDelta + thrustVelY * timeDelta * timeDelta / 2.0; params.put(ShipPhysicalParam.POS_X, posX); params.put(ShipPhysicalParam.POS_Y, posY); params.put(ShipPhysicalParam.SPEED_X_PIX_SEC, velX); params.put(ShipPhysicalParam.SPEED_Y_PIX_SEC, velY); params.put(ShipPhysicalParam.DIRECTION_RAD, dirAtEnd); } [/CODE] Tested and seems to work pretty nicely. Problem solved!
  2. Spaceship movement parameters update

    Let me fix my last post: I calculated the velocity of the thrust: [CODE] double dirAtEnd = dir + dirSpeed * timeDelta; double thrustVelX = thrust * (Math.sin(dirAtEnd) - Math.sin(dir)) / timeDelta; double thrustVelY = thrust * (Math.cos(dirAtEnd) - Math.cos(dir)) / timeDelta; [/CODE]
  3. Spaceship movement parameters update

    Yes, sorry about this, I meant velocity under "acceleration" and thrust is the same as acceleration. I thought that I would calculate the acceleration of the thrust first(accelerating acceleration) in both axes: [CODE] double dirAtEnd = dir + dirSpeed * timeDelta; double thrustAccX = thrust * (Math.sin(dirAtEnd) - Math.sin(dir)) / timeDelta; double thrustAccY = thrust * (Math.cos(dirAtEnd) - Math.cos(dir)) / timeDelta; [/CODE] And now I should be able to calculate the x and y position using the derivative of acceleration?
  4. Hello! I'm making a pretty basic spaceship game. Every time I update or change a main parameter, that affects others(acceleration, acceleration change speed, direction change speed) then I want to recalculate all parameters. I have the following parameters at the beginning of the movement: [CODE] long currentTime = System.currentTimeMillis(); double timeDelta = (currentTime - lastUpdate) / 1000.0; lastUpdate = currentTime; double posX = params.get(Param.POS_X); double posY = params.get(Param.POS_Y); double accX = params.get(Param.SPEED_X_PIX_SEC); // ship acceleration x axis. double accY = params.get(Param.SPEED_Y_PIX_SEC); // ship acceleration y axis. double dir = params.get(Param.DIRECTION_RAD); double dirSpeed = params.get(Param.DIRECTION_SPEED_RAD_SEC); double thrust = params.get(Param.THRUST_PIX_SEC); // acceleration change speed. Depends on direction change. [/CODE] And now I want to set the parameter values to what they should be after a certain amount of time has passed(timeDelta). Two parameters don't need updating since they are there only to affect other parameters - thrust and dirSpeed. It would be a piece of cake to figure it out when there would not be any direction change...
  5. Hello! I have a posgresql database where information about rivers are stored. [CODE] CREATE TABLE river_data ( id_river integer, id_destination integer, river_name character varying(15), ... many other fields ) WITH ( OIDS=FALSE ); ALTER TABLE river_data OWNER TO xyz; [/CODE] Getting information about one single river without its subrivers works well: [CODE] @Entity @Table(name = "river_data") public class RiverData { @Id @Column (name = "id_river") private int riverId; @Column (name = "river_name") private String riverName; @Column (name = "id_destination") private int destinationRiverId; public int getRiverId() { return riverId; } public String getRiverName() { return riverName; } public int getDestinationRiverId() { return destinationRiverId; } } [/CODE] Now I want to retrieve information about a river with a list(collection) of its subrivers, but I don't know how. All subrivers should have their destination_id equal to the main river_id. The current code looks like this(it crashes the sql server): [CODE] @Entity @Table(name = "river_data") public class RiverDataWithSubRivers { @Id @Column (name = "id_river") private int riverId; @Column (name = "river_name") private String riverName; @Column (name = "id_destination") private int destinationRiverId; @OneToMany @JoinColumn(name="id_destination") // TODO: problem is here. private Collection<RiverData> subRivers= new ArrayList<RiverData>(10); public Collection<RiverData> getSubRivers() { return subRivers; } public int getRiverId() { return riverId; } public void setRiverId(int riverId) { this.riverId = riverId; } public String getRiverName() { return riverName; } public void setRiverName(String riverName) { this.riverName = riverName; } public int getDestinationRiverId() { return destinationRiverId; } public void setDestinationRiverId(int destinationRiverId) { this.destinationRiverId = destinationRiverId; } } [/CODE] The question is, what annotations and how should I use them in this part of code: [CODE] @OneToMany @JoinColumn(name="id_destination") // TODO: problem is here. private Collection<RiverData> subRivers= new ArrayList<RiverData>(10); [/CODE] My idea was that the @JoinColumn would help me to select all rivers, which have the same id_destination, that equal to the id_river of this class.
  6. That's a pretty interesting thread here. I have a school project, where we need to create a basic server-client game. My project is a bit more complex than it should be - I'm making a multi-player space shooter. In this case it is easier to solve the problem of hacking because the space ships do not collide with almost nothing, expect maybe against other ships but I will try to solve this later. Current logic consists of a simple movement formula, that will calculate the new position every time the getPosXY method is called or when the thrust or speed of the ship will change. This logic applies to both - the client and the server. Only the server is the god, the player(slave) cannot change any parameters without the permission of the server. When the player clicks any movement buttons, it will request the server to update his player parameter values and send a message back with the new parameters. The player will send a message only if the key has just been pressed and when it will be released. It will take time to react to these events because of the connection speed between the client and the server. Currently I got 3 different login frames and 8 different game frames. The average bandwidth used by this game(client) is less than 1 K bit/s even when I click the movement buttons like a madman. Maybe I will release my source code after 3-5 weeks and post on these forums as an example about how to handle networking. I will add a lot of candy to it. I forgot to say what I am using - Java with lwjgl, slick-utils and netty libraries. I love that asynchronous netty nio library . Yes, it will run on all popular OS-s. About the problem that the client has all the data and you end up having 2 copies - on the server and the clients. Yes that's a big problem that I try to avoid in my project - I will make my client software as much slave as possible. I don't care what data the client has, I just send the data, that the server has and the client must have the same data. So there is only 1 copy - only one original and others(that the clients have) are aged piles of corrupted data. The client only has the right to ask what it wants the server to do and the server decides. I remember that WoW had some issues with players speed hacking. So you can make a conclusion about that - the high skilled WoW programmers even didn't figure out a proper way to solve this problem. Some other games had these problems also, including Counter Strike. One more thing about Counter Strike: when you shoot, you cannot see your bullet, it will just calculate the end spot of the bullet. So they avoided the concurrency and real-time logic problems of simulating bullets.
  7. Worth beginning with dx9?

    [quote name='Varine' timestamp='1309056651' post='4827761'] A lot of people still use XP, which only goes up to 9. If you don't care about inclusion, then no. If you want to make it run on XP, then yes. [/quote] Most people use windows 7. [url=""]Check this out.[/url] So I would go with directX 11
  8. How many UDP ports should I use?

    [quote name='VildNinja' timestamp='1295697976' post='4762926'] [...]Right now it uses one UDP port for everything.[...] [/quote] I don't think that it's a good idea to use only UDP ports. It's better to send critical data using TCP because UDP might lose data. I suggest you to use one UDP and one TCP port.
  9. You need Java MicroEdition and javaFX for that I found this about sending messages using J2ME on the java website: [url=""][/url] Check it out. Hope it helps a little bit.
  10. You should check out the jMonkeyEngine forums. There are lots of people doing 3D games using OpenGL in Java(for example minecraft). I've been using Java as my "main" programming language since the beginning of 2009. I have finished doing only 1-2 games in Java. In the past I used to code without documentation/structure descriptions and because of this, I haven't finished any bigger projects. It just gets very uncomfortable to code tons of classes and many lines of code without a clear structure of your project... I don't have always time to code games because I'm in the Uni(bachelor studies) and I'm also working.
  11. Create your own button class that extends the Button class and use some sort of index in it. Now, in the ActionListener, just get the source button(like describled in the above post, but without labels) and you're done because you know its index. Hope it helps(haven't tried, but should work theoretically)
  12. I would do it like that: Load the image [code]File file = new File("location"); BufferedImage =;[/code] Create a new panel class [code]public class DrawingPanel extends JPanel { public DrawingPanel() { } //.... //.... stuff //.... public void paint(Graphics gfx) { Graphics2D g = (Graphics2D)gfx; g.drawImage(yourimg, x, y, null) } } [/code] And now just attach it to your frame easely: frame.add(drawingpanel); The panel drawing area should be the same size as your frame is if you don't use some additional GUI objects. For example if you created a 800x800 px frame then your drawing area will be also 800x800. I would also make the DrawingPanel class runnable so it would refresh itself after every xx ms. Just use[b] repaint()[/b] like in java applets if you want to refresh your drawing. The area that you leave uncovered with images/graphics objects is going to leave the old pixels. Graphics2D is a subclass of the Graphics class. It has more functions and you can do more things with it. For example you can use anti-alias. In the current situation, the JPanel actually gives the Graphics2D class in the paint method(it is casted to Graphics, I don't know why so I just cast it back)...