Monday, May 30, 2011

The Ships are Coming! The Ships, the Ships!

I'm very happy to report that I made huge progress today and now have both ships moving correctly for the guest and host. Both are displaying correctly on each player's screen. To be honest, I had avoided working on this for several days because I was getting a little overwhelmed with my own thoughts about how to continue. I had been doing really well with getting the lobby set up and networking the initial data for the ships and asteroids but I had not idea where to send over data that was updated every frame. Just thinking about order made my head spin. I spent those days working on my Independent Study and Engine. 

Then today, I decided to get back to this. My husband urged me to tackle what I was afraid of. Initially, I was really confused about how to tie each actual player with their respective ship physically. Putting in matching indices wasn't enough as that only made it so that both the guest and host controlled the same ship. The guest was also getting a read error on the rotation vector for the host's ship when I tried to read the incoming packet. I tinkered with this for about an hour and a half and then went for a walk on the beach to let it absorb and think about it. 

While out, I realized that I had the wrong call order on the ship move update, regardless of indices. Excited, I went to change this as soon as I came home. Then I noticed something else: I had forgotten to write the rotation vector in the event. Of course I was getting errors trying to read it! I was trying to read something that wasn't there. I quickly put this in and things began to look a lot better. With my two changes, I was now able to see the movement of ship 1 as controlled by the host on both machines, but the guest could also control the same ship. After debugging a little, I realized that I needed to only process certain ships movement from the controller based on the playerType (ie host or guest). I wrote respective conditionals for each and sent and read packets on both ends. 

The events for updating the ship movement are created and added to the player's respective data queue in a function that I wrote in the EvolvedScreen class. This function is called after the currentScreen.update() call in SpacewarGame.update(). The game ran fine on both machines with my new code but ship 2 still wasn't moving with input from either player. I was perplexed at first but after looking into the ship's update code again, I saw that I was passing PlayerIndex.Two to the guest's controller for ship2 when in actuality, both player's controllers needed to be tied to PlayerIndex.One. Changing this yielded wonderful results and here we are now. 

Overall, today I got ship updates and timer changes networked which is great. Tomorrow, I will finish off ship data (hyperspace button if we even need to have that implemented-- need to check first, whatever else there is) and get to work on bullets. I do feel that the more I work on this, the more I understand it. That seems like an obvious statement but sometimes with programming, I get so overwhelmed that I get more confused the longer I look at it. I think that my more optimistic attitude is really helping me to go with the flow and see the code more clearly though. Let's continue this state.

No comments:

Post a Comment