Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (404)
games submitted by our members
Games in WIP (289)
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  Game Development / Game Mechanics / Re: Entity knockback on: 2013-04-20 21:34:53
It's probably a bad way of doing it, but this is my code for knockback to give you an idea

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
   public void knockback(float r, float force){
      r = r - 180;
     
      force *= knockbackResistance; // how heavy the entity is (so lesser knock back)
     
      knockbackTimer = force * 8;
      knockbackTo = new Vector2((force * (float) MathUtils.sin(r * MathUtils.degreesToRadians)),
                         (-force * (float) MathUtils.cos(r * MathUtils.degreesToRadians)))
                                       .add(position);
               
   }


Then I have this on the update loop for the entity

1  
2  
3  
4  
5  
6  
   public void update(){
      if(knockbackTimer > 0){
         position = Tools.lerp(position, knockbackTo, 0.2f);
         knockbackTimer -= Gdx.graphics.getDeltaTime() * 1000;
      }
        }
2  Game Development / Networking & Multiplayer / Re: Kryonet packet sending on connection issue! on: 2013-01-29 19:48:50
You call a method in the connected event that sends something no?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
            for (int i = 0; i < 200; i++) {
               if (!(cuboids[i][0] == 0 && cuboids[i][1] == 0
                     && cuboids[i][2] == 0 && cuboids[i][3] == 0
                     && cuboids[i][4] == 0 && cuboids[i][5] == 0)) {
                 
                  // this guy
                 sendCuboid(connection, cuboids[i][0], cuboids[i][1],
                        cuboids[i][2], cuboids[i][3], cuboids[i][4],
                        cuboids[i][5]);

               }
            }


Do you know for sure that this sendCuboid is actually being called?
3  Game Development / Networking & Multiplayer / Re: Kryonet packet sending on connection issue! on: 2013-01-29 03:12:46
Are you certain that you are actually sending anything on your connected event?

1  
System.out.println("Sent all cuboids present");
is outside your if statement.


Also, you shouldn't send each "cuboid" individually; batch them up into one server.sendToTCP call.
4  Game Development / Networking & Multiplayer / Re: Starting point for multiplayer development needed! on: 2012-02-29 17:51:51
If you have never touched sockets before, I suggest you try implementing a chat server, before you undertake a multiplayer game.

http://pirate.shu.edu/~wachsmut/Teaching/CSAS2214/Virtual/Lectures/chat-client-server.html

Also +1 for the KryoNet library

5  Game Development / Networking & Multiplayer / Re: [Kryonet] SerializationException on: 2011-10-01 21:48:39
Make sure you are registering your network classes in the same order, on both client and server side.
6  Game Development / Newbie & Debugging Questions / Re: NPC Collision on: 2011-08-11 14:50:31
Are you literally checking each NPC one by one?

Sorry if I completly miss it, but I think what you are looking for is a loop.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
for(int i = 0; i < NPCRect.length; i++){

   // ignore null NPCs in the list
  if(NPCRect[i] == null) continue;

   // make sure there is no collisions on any of the NPCs
  if(PlayerRect.intersect(NPCRect[i]) == false){
      // your logic??
  }
}


7  Game Development / Newbie & Debugging Questions / Re: Boomerang logic? on: 2011-08-10 19:07:56
The x and y are the boomerang coordinates and the targetX and targetY would be your character's coordinates.

Try to get this working, it's simpler:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
// when the boomerang is ahead of the character, move it backwards and move it
// forwards when it is behind the character.
if(boomerangX > characterX){
   boomerangX-=boomerangSpeed;
}
else{
   boomerangX+=boomerangSpeed;
}

// when the boomerang is below of the character, move it upwards and move it
// downwards when it is above the character.
if(boomerangY > characterY){
   boomerangY-=boomerangSpeed;
}
else{
   boomerangY+=boomerangSpeed;
}


8  Game Development / Newbie & Debugging Questions / Re: Boomerang logic? on: 2011-08-10 17:25:53
so to track back it would have remembered the route it took and just backtrack that after it's max time out?


No, pathfinding is too expensive an operation for projectiles (especially if you have lots).

To backtrack to the source, you simply get position of source and the projectile and then move projectile closer towards source (at desired speed). You repeat this every frame until projectile reaches the source. To get a more smoother curvey move back just slowly subtract new direction from projectiles current direction.

Kappa is correct. You can google examples of follow missiles or homing missiles as they are the exact same logic you want.

Formula I found from google to go towards a target:
1  
2  
3  
4  
5  
6  
        int dy = targetY - y;
        int dx = targetX - x;
        double speed, sep;

        sep = Math.sqrt(dx * dx + dy * dy);
        speed = scale/sep;


There is a cheaper way than doing square roots but at this point, you shouldn't be worrying about optimization as small as that.
9  Game Development / Newbie & Debugging Questions / Re: Boomerang logic? on: 2011-08-10 15:10:41
I think it would be even easier to just forget about pathing the boomerang. Just shoot it out like a bullet and have a timer that will expire (or when it collides with a wall/enemy) and tell the boomerang to a "go back to player" state. In this state, it will stop moving forward and instead, track back towards the player (just like a follow missile).
10  Game Development / Networking & Multiplayer / Re: KryoNet - Suppress multiple connections from same user? on: 2011-08-03 19:37:07
if they play the game from work, school, open wifi, etc.
every house / apartment with more than one human living in it, have a lan and use a router, wifi or not makes no difference.

I agree. I was just giving some simple examples; open wifi being like a cafe or a downtown hot spot.

But I also want to prevent the same person playing with more than one account on the same server (at least on the same machine).

It's possible to grab the MAC (unique to the machine) of the network card being used by the client and have that client send that MAC to the server to store and compare to other clients.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
import java.net.InetAddress;
import java.net.NetworkInterface;

public class Main {
  public static void main(String[] args) throws Exception {
    InetAddress addr = InetAddress.getLocalHost();

    NetworkInterface ni = NetworkInterface.getByInetAddress(addr);
    byte[] maca = ni.getHardwareAddress();

    for (int k = 0; k < maca.length; k++) {
      System.out.format("%02X%s", maca[k], (k < maca.length - 1) ? "-" : "");
    }
  }
}


Source: http://forums.techarena.in/software-development/1295054.htm
11  Game Development / Networking & Multiplayer / Re: KryoNet - Suppress multiple connections from same user? on: 2011-08-03 18:57:37
If they come from the same LAN, they will have the same IP address. Unfortunately, this can not be helped and will cause problems, if they play the game from work, school, open wifi, etc.

Here's what you can have in your server listener:

1  
2  
3  
4  
5  
6  
7  
8  
         public void connected(Connection c){
            Connection[] connections = server.getConnections();

            for(int i = 0; i < connections.length; i++)
               if(c.getRemoteAddressTCP().equals(connections[i].getRemoteAddressTCP()))
                  c.close();
           
         }


I haven't tested it, but you can see the general idea here. Also, now that I think of it, it should be in the received method so that you may send back a error message to why the player was disconnected from the server.
12  Game Development / Networking & Multiplayer / Re: KryoNet - Suppress multiple connections from same user? on: 2011-08-03 18:37:02
I don't have access to my code on this computer but...

You should be able to grab the host information from the connection and do a match to the other connections to make sure there are no equals.
Pages: [1]
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (43 views)
2013-05-17 21:29:12

alaslipknot (52 views)
2013-05-16 21:24:48

gouessej (81 views)
2013-05-16 00:53:38

gouessej (80 views)
2013-05-16 00:17:58

theagentd (89 views)
2013-05-15 15:01:13

theagentd (82 views)
2013-05-15 15:00:54

StreetDoggy (126 views)
2013-05-14 15:56:26

kutucuk (148 views)
2013-05-12 17:10:36

kutucuk (148 views)
2013-05-12 15:36:09

UnluckyDevil (158 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.266 seconds with 21 queries.