Boxing Sim Game made in Excel
Hi everyone, I previously posted about my personal project to create a boxing sim game in Excel. Admittedly, my original post was a bit of a brain dump without providing much insight so I appreciate the reason for its removal.
I now have a file to share and play test:
https://drive.google.com/file/d/11fgPyhOUB4mfyxqAp7dfbhkqHc6_nKuV/view
Gameplay video:
https://www.youtube.com/watch?v=kXnUE70LbrQ
Mods - I hope this is OK now. Would it be possible to change the flair to 'Show and tell' please?
I would appreciate feedback on the speed it runs on your machines. I'm hoping that the text commentary does not generate too quickly or too slowly.
It took me around 2 months to create this project, working on it in the evenings. As a bit of a show and tell, to begin with, I would like to do a deep dive into one feature that I had difficulty problem solving early on. However, as the game progressed, the solution became more obvious. If there is interest, I'm happy to explain other elements.
Commentary system
I wanted to create some Football Manager style commentary that sort of felt natural and not too repetitive. Without this being implemented, I would have abandoned the project.
The first step was finding a way to make it obvious on screen, which boxer a line of commentary was referring to. I went about this by adding a shape for each boxer and applying corresponding colour fills and text colours. The colours would also need to be updated automatically each time a new set of boxers was selected in the Quick Fight mode. So my solution was to store the hexadecimal codes for each selected boxer in a table. VBA was then used to apply the colors.
There was something I didn't realise at first - VBA only understands RGB, not HEX, so this was converted in the code:
fillHex = ws_fight_calc.Range("F3").Value
If Left(fillHex, 1) = "#" Then
fillHex = Mid(fillHex, 2)
End If
r = CLng("&H" & Mid(fillHex, 1, 2))
g = CLng("&H" & Mid(fillHex, 3, 2))
b = CLng("&H" & Mid(fillHex, 5, 2))
shpCommentary.Fill.ForeColor.RGB = RGB(r, g, b)
In the extract above, the HEX code for one boxer is stored in cell F3 and it is simply coverted into RGB and applied to the shape.
The second step in the process was deciding when to surface the shapes on screen by changing each shape's .Visible property in VBA. This involved identifying which boxer is performing an action. To keep things simple, I generally set the 'active boxer' to be the one launching an attack. This is based on the results of a separate attack/defend series of interactions, which I won't go into the detail here, since the mechanism is quite lengthy.
The final step was to assign a line of text commentary to each action, which are the outcomes of each attack. For example: "Boxer 1 lands a jab", "Boxer 1 swings wildly and misses", "Boxer 1 throws a hook, but it's blocked", etc.
I've counted that in my game, there are 95 interaction outcomes in total. So at the very least, I needed 95 commentary lines. However, I tried to add variety by setting different lines depending on: (i) whether a punch was a counter attack by the defending boxer, (ii) thrown as part of a combination, (iii) thrown during the clinch mechanism, or (iv) thrown to deliver a knockout blow. In total, I ended up with 183 lines.
To add more variety, I also hardcoded some 'colour commentary' lines where the description being surfaced on screen as a follow up to the main action. Some examples are lines such as:
"Boxer 1 nails a six punch combination"
"Boxer 2 is in trouble"
"Boxer 2 is able to beat the count"
"The referee breaks up the clinch"
With these lines, I wish I had a scalable way of adding more variety. A few things I thought about but quickly dismissed included:
- Could I get Microsoft Copilot to help generate commentary lines? I'm not sure.
- Can I set more than one commentary line per action, and then randomly select a line using RANDBETWEEN? I think this is actually possible to do but I fear it would slow the game down massively.
- Is it possible to use text to speech to produce sports style audio commentary? From my research, I don't think this is possible at all because text to speech relies on the Windows voices and there is no way to alter the velocity of speech, making it sound exciting.
Finally, I implemented a couple of things to help make some actions more impactful or add tension. For example, using the Pause() function to set the time gap between commentary lines.
Also, you'll see that at certain points like a knockdown, a flashing text box is used. This was easy to implement - it was just a case of switching round the colour fill and text colour codes applied to the shape. The VBA code is just quickly alternating between the two sets of colour applications.
I hope that provided some good insight. Again, I'm happy to deep dive into other elements if there is interest.
In the Excel file, if you are interested in the game logic, I would recommend reviewing the following worksheets:
- 'Fight Engine' (this explains each interaction and provides most of the cell ranges that VBA reads and writes from).
- 'Fight Calcs' (this basically helps to drive the action seen on screen).
If you made it this far down, thank you for reading. This has really been a passion project. I'm not sure why I've spent so much time on this, maybe it's consolidating all of the things I've learned in Excel over the years. It feels like closure. I would say that in my day job, I'm starting to use VBA less and less. I find that there are easier ways to achieve things now, especially with Power Query.
[link] [comments]
Want to read more?
Check out the full article on the original site