Note that there are some explanatory texts on larger screens.

plurals
  1. POBest way to implement units in a small-scale RTS?
    text
    copied!<p>I am currently working on developing a small-scale 2D RTS in Java that will be unreliant on any non-standard libraries.</p> <p>A crucial problem I can't answer properly is how to implement the units so each one of them functions independently, as is normal in an RTS.</p> <p>I've thought of two ways:</p> <p><strong>1) Implement them as threads.</strong> Since threads, much like units, have a lifespan and operate independently, they should be a good fit.</p> <p><strong>Problem:</strong> How do I maintain other important aspects of a unit's AI, such as targeting and attacking enemies or rotating turrets for the idle animation while still moving? </p> <p>I am considering giving each unit subthreads to handle this (again, since they should be independent yet concurrent), but I am worried that this is an inefficient approach. I am not constrained by computational limits in the program, but I want to know the best way of handling things for future development. </p> <p><strong>2) "Turns".</strong> Each units has a set of actions it should consider performing during every turn, and the turns are triggered by very fast TimerTasks that iterate through all existing units.</p> <p><strong>Problem:</strong> Might result in clunky code?</p> <p>I am leaning towards the first approach, but before I dive into it, I'd like to know if I'm heading the right way, or if I'm more likely to shoot myself in the foot.</p> <p><strong>To sum up my issue:</strong> Should I use threads, timers or some other method to implement the units in a small RTS coded in Java? Any input would be appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload