interiorslooki.blogg.se

Stack the states game on computer
Stack the states game on computer









stack the states game on computer

Am I approaching this the wrong way? Should I instead have each control be a case instead and branch from there? Any help is appreciated! I haven't even incorporated using different attacks yet (I'm going to have a variety of these). You should not have if-statements nor case-statements at least not nearly so many.

stack the states game on computer

The immediate problem is that you're hard-coding a bunch of logic where a data-driven approach would work better. What you have here on first glance is a state graph (or a finite state machine). Rebuilding this as a state graph with inputs triggering transitions would be a first pass "cleanup". State moving_left = machine.createState() State moving_right = machine.createState() e.g., once you have a state graph runtime, even your hardcoded logic becomes much simpler: state idle = machine.createState() The second pass then is to move all the specifics into separate logic or data. You can also support hierarchical graphs so e.g. your attacks can be their own state graphs independent of moving. With scripting or some other binding system, this can also easily become a data file. Data files are nice because you don't have to recompile to test changes. If you have hot reload support you can even tweak your data while playing the game, which really speeds up the development process. The data then can map to your animation system, giving you controls on animation loops for states or for animations to play on transitions.











Stack the states game on computer