I’m making a game where there are many Area2Ds of different countries, but I want to know the size of each country to calculate their surrender limit (bigger countries take longer to surrender, for example).
I don’t want to find the area of just one collision2D as some countries have multiple (see island nations, overseas colonies…), but looping that with the children could work if finding area using AREA2ds isn’t a thing.
I don’t want to simply use the outermost points of a collisionshape2D and draw a big rectangle, as it would make some countries way bigger than they really are (see especially the British and French empires)
Is it possible to find the area of an Area2D? If not, is it possible to calculate the area of CollisionShape2Ds (then I could just loop through the children).
p.s. Country size will not be the only factor for surrender limit, things like equipment stockpiles and something similar to war support in HOI4 might also affect it…
Good afternoon! While, I’ll be honest, I don’t do much video game development as I’m finishing up my Master’s program in Computer Science and my Data Science graduate certificate, the best advice I can give you for purposes regarding this problem is to look to the Riemann Sum formula regarding approximation of definite integrals on a two-dimensional plane, which is presented as follows:
∑ᵢ=₁ⁿ f(xᵢ)Δx
(P.S. - This formula was copied and pasted via generative AI, as I struggled to figure out how to write formulas in Lemmy response windows)
I suggest this as the imperfect dimensions of the sizes of countries on a global map appear to suggest necessity of calculations of area by means of integral calculus. While I was exposed to these formula during my high school AP Calculus course several years ago, I will admit I had to look it up again on Google and was reminded with an AI-generate response. Basically, the integral of an imperfect shape that cannot be defined by algebraic equations can be approximated on a curve with a series of rectangle of varying heights with equivalent widths. The more rectangles are placed to approximate the curve, the more accurate your assessment becomes. So, if you’re trying to approximate the size of the country on your global map for purposes of a country-surrendering mechanic in your game via Godot Engine, I would highly suggest defining a method that takes in the standard width of all rectangles present in your graph (each represented as a distinct CollisionShape2D component/element) with heights extending just beyond the outline of the country’s graph, and returns the approximate summation of the country’s area as a whole in a two-dimensional context for purposes of applying your country’s surrender limitation game mechanic.