Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 11 Nov 2009
Offline Last Active May 20 2012 03:19 PM

Posts I've Made

In Topic: Spaceship movement parameters update

20 May 2012 - 03:22 PM

Okay, I think I figured it out correctly:

	private void updateParameters() {
		long currentTime = System.currentTimeMillis();
		double timeDelta = (currentTime - lastUpdate) / 1000.0;
		lastUpdate = currentTime;
		if(timeDelta == 0.0)
		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);

Tested and seems to work pretty nicely.
Problem solved!

In Topic: Spaceship movement parameters update

20 May 2012 - 11:05 AM

Let me fix my last post:
I calculated the velocity of the thrust:

	    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;

In Topic: Spaceship movement parameters update

20 May 2012 - 11:01 AM

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:

	    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;

And now I should be able to calculate the x and y position using the derivative of acceleration?

In Topic: Client-Server Game Logic Distribution

09 April 2012 - 04:15 PM

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.

In Topic: Worth beginning with dx9?

26 June 2011 - 04:28 AM

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.

Most people use windows 7. Check this out.
So I would go with directX 11