Last post I mentioned that I was done, DONE, making random new content for GRF and instead wanted to work toward a single player mode. And, well, I did that! Or at least started to. So, there are no new sounds or powerups or random events in this post. Just some single player AI stuff! The video below shows all that I’ve accomplished since last week:
Wow! Did you see that! Amazing! The AI first:
– Choose a coin in the coin flip!
Then, after winning the coin toss (I hard coded it so the AI would win the toss for this test…) the AI then chooses:
– Kick or receive. They choose kick!
After choosing to kick, the AI then does the next logical thing and kicks the ball!
The “how” of all this is very simple. The coin flip and kick/receive decisions are just random. The kick off is also just randomly choosing a kicking angle and kick power to submit. In the future I’d like to add some more “strategy” to that instead of complete randomness. Still something simple like:
- If AI is ahead, kick the ball deep to kill time
- if AI is behind, try an “onside” kick by doing high angles and high power to get a high kick on the side lines that the kicking team can try and recover
The most time consuming thing during this was getting all my “previous” code on how players choose coins and kick and stuff to work with an automated AI. I decided to keep my weird multiplayer server/client set up where even though it is single player, moves and actions are still submitted to a local “server.” This has allowed me to keep reusing most of my code for actions.
When the game starts, a GamePlayer object is spawned that is the AI player. The local player has authority over the AI player object because they are the server, so the game can submit actions/commands/whatever on the AI object. I then just have a few “this.isLocalPlayer” checks to make sure that I only am sending commands to the AI and not the actual local game player.
I can only imagine that this will cause issues, but hey, those can be fun to work through, right? Right? Anyway, at least this seemed better than my other idea of just recording everything for a single player mode which seemed a lot less fun and a lot less efficient use of my time. Then the issues of adding/fixing something in one mode and having to redo it in the other mode, ugh.
So, anyway, I now have the beginnings of a single player mode for GRF! Yay!
Well, I will continue working on getting the single player mode working. The next “phase” in the game after the kickoff is the gameplay phase. Thanks to the 1v1 mode I already have some AI code for having goblins moving around independently. That’s only for goblins without the ball and that the player doesn’t have selected. Now, I’ll need to add stuff for the AI player to do when their goblin has the ball. Run in a straight line toward the endzone? Works for me! Can’t be much more difficult than that, right?
Smell ya later nerds.