64 - Cleaning up ship on ship combat
Alright so let's talk about movement. It's really annoying and hard to get right. I fiddled with it yesterday and ironed out some issues, but I still had some problems. The bulk of what I did today on stream was fixing the issues with movement, but I'm pretty sure I got everything worked out. I also did some other cleaning up, added numbers to weapon UI, hover over for crew to show skill levels, use function keys to select crew, and added a way to restart the game after it was over. I changed a good chunk of the movement stuff, so let's just jump right in. public void Move(Queue queue) { if (CheckQueue(queue)) { if (CurrentlyMoving) { CurrentlyMoving = false; Movement = new Queue(); } if (queue != null && queue.Count > 1) { Vector2 currentRoom; Vector2 newRoom; if (Movement.Count == 0) { var shipX = Mathf.RoundToInt(transform.localPosition.x); var shipY = Mathf.RoundToInt(transform.localPosition.y); currentRoom = new Vector2(shipX, shipY); newRoom = queue.Last(); Movement = queue; if (Ship.Segments[ShipX, ShipY].Secondary == this) Ship.Segments[ShipX, ShipY].Secondary = null; if (Ship.Segments[ShipX, ShipY].Primary == this) Ship.Segments[ShipX, ShipY].RemovePrimary(this); if (currentRoom != newRoom) UpdateCapcity(currentRoom, newRoom); Movement.Dequeue(); } } } } Alright so you might notice some differences if you compare it to my other movement blog post, you can read that over here. I added this CheckQueue method, really all that does is check if the last place in the queue is the same room as the last place in the current movement queue. I also added a Secondary variable to segments so I can keep track of who else is in the ship. I'm not sure why I didn't do that sooner. There arn't many changes to this method so let's move on. private void UpdateCapcity(Vector2 currentRoom, Vector2 newRoom) { Ship.Segments[(int)LastRoomCapacity.x, (int)LastRoomCapacity.y].Capacity--; var temp = Ship.Segments[(int)currentRoom.x, (int)currentRoom.y]; var newSegment = Ship.Segments[(int)newRoom.x, (int)newRoom.y]; if(newSegment.Capacity < 2) { newSegment.Capacity++; LastRoomCapacity = new Vector2(newSegment.X, newSegment.Y); } else { List tempQ = Movement.ToList(); while (tempQ.Count > 0) { tempQ.RemoveAt(tempQ.Count-1); var tempSeg = Ship.Segments[(int)tempQ.Last().x, (int)tempQ.Last().y]; if(tempSeg.Capacity < 2) { tempSeg.Capacity++; LastRoomCapacity = new Vector2(tempSeg.X, tempSeg.Y); Movement = ListToQueue(tempQ); break; } } } } So I was having issues with capacity, so I changed things, instead when I add or remove from capacity I am using a variable, a Vector2, to keep track of that. That way I will always be removing from the same room as I added to. Also if you notice, I have removed keeping track of primary here, I removed the Primary variable from dudes. After getting things working I didn't really need it, let's go into that. private void Move() { if (CurrentlyMoving) { var shipX = Mathf.RoundToInt(pos.x); var shipY = Mathf.RoundToInt(pos.y); if (shipX == CurrentMove.x && shipY == CurrentMove.y && LastRoom) { var temp = Ship.Segments[(int)CurrentMove.x, (int)CurrentMove.y]; if(temp.Primary == null) { CurrentMove.x -= .25f; temp.SetPrimary(this); } else { CurrentMove.x += .25f; temp.Secondary = this; } LastRoom = false; } } } This is the move method in Dudes, I have cut some things out, because some of it I just didn't change at all. Let's go over what I had to change. So we get a new shipX and shipY based on the position of the unit, we use this to check if the unit has made it into the last room or not. The LastRoom variable is there to make sure it's the final movement in the queue. If a unit just made it into the final room we want to check if that segment has a primary or not. I changed things to check here so no matter who reaches the room first they will be primary. We then just set Primary and Secondary and change the CurrentMove.x depending on what is needed. Really it wasn't that hard to figure out. What was a pain was I didn't want to completely throw away the code and rebuild it. While some of the code I kept and didn't touch at all, there was a good chunk that needed to be changed. I should've just went through, line by line and figure out what made sense and what didn't. Oh well I got there in the end right! Let's also show the code for how I select a crew by function keys. void Update() { if (!Ship.Paused) { Repair(); Move(); if (Ship.IsPlayer) { if(Input.GetKeyDown("f" + (Ship.DudeList.FindIndex(x => x == this)+1))) { Select(); } } } } private void Select() { Selected = !Selected; Ship.Selected = Selected; Outline.SetActive(Selected); Display.SetSelected(Selected); } So as you can tell it's pretty simple. I just check if the key that was pressed matches the crew member. I can just use FindIndex on DudeList to get its index, then I just add 1 because it's 0 based. For selecting I just swap Selected based on what it was, then sent some other bools with that Selected variable. Pretty simple all in all. Alright I guess that's it. I think starting next I'm going to work on On Ship combat, as in fighting another crew directly. Should be interesting. Once I finish that, I can add a way to instead of killing a ship you can board it. That way I can work on getting senses to interact together. Should be fun!
2/1/2017 6:28:07 PM





Add Comment Auther

Comment