Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by TommyBs

I'm trying to create a turn based strategy at the moment, where a user can select a unit, move it, then end their turn. When it is a users turn again, I reset the movement allowance of all units so they can be moved again. But what I'm struggling with, is that in theory 2 different players could be the same "faction" as such I can't figure out how to assign a unit to a particular user, so that a user can only move their units. Baring in mind both users could have the same types of entities.

Any ideas how to overcome this problem?

1 decade ago by lTyl

Create a Manager class. Specifically, what I would do is something like this:

gameunit.js class = The base entity that holds all of the methods that every unit shares, as well as properties. (Such as turn points, HP, atk, etc) Every type of unit in the game will extend this class (tankunit, infantryunit, etcetcetc).

Next I would create a Manager class that keeps track of all of the individual gameunit.js classes in the game. This class will do all the update/draw calls as well as remove gameunits from the playfield. Everytime a new unit is created, it will be added to the appropriate manager class. Each player, weather AI or human controlled, will have it's own manager class keeping track of the individual game units. When a player selects an individual unit on the playfield, the Manager class knows which unit was selected and then calls the methods needed in order to manipulate that specific unit.

1 decade ago by TommyBs

Hey,

Thanks for replying. So the manager class wouldn't extend anything within Impact but would pretty much just be responsible for keeping tabs on a players units? I'm guessing something quite simple like?
function Manager(){
    var update = (function(){
        for(var i =0; i < this.units.length; i++){
             var unit = this.units[i];
             unit.update();
        }
    });
    return{
        units:[],
        bases:[],
        update:update
    }
}
                  
var player = new Manager();
    
player.units.push(EntityInfantry); 
player.update();

1 decade ago by ckcollab

Well, you could do it with an overall "Manager" or couldn't you just create a property on your User entity like

ownedEntities: []

And maybe add a property pushOwnedEntity or removeOwnedEntity? I'm pretty new to ImpactJS so I'm not sure if this is a good way of doing it nor not.

EDIT:
Also, because you may need to check ownership of Entity before trying to move it, I'd add an owner property to your movable units.

1 decade ago by TommyBs

Thanks, I think I'm actually just struggling with the structure to really set-up my 'players' in the overall game and how it fits in with the Impact framework. Adding in the complexity of making it a turn-based game I think I'm just frying my brain. The turn stuff is reasonably simple but I think it's just all adding to my trying to work out the logic.

I've made games in Impact before,but neither tried anything like this.

1 decade ago by drhayes

I like ckcollab's second suggestion: put an owner property on your entities. That way, if a user clicks on an entity it's pretty quick to check if the entity is selectable.

How many units do you expect within a single game? If there aren't that many (like only hundreds or less) then iterating through all the entities is probably okay if you ever need to do a "every entity that belongs to such-and-such a player" operation.

It might also help to think of the Impact Entities as the "View" to a "Model" sitting outside of the Impact system. I mean, you could still extend ig.Class but the model doesn't have to be an #update#able entity like the units on the board are. That way your logic is all in these models that are really simple compared to the entities that represent them.

1 decade ago by TommyBs

Thanks, I've been thinking more about this and trying to do some research. I think I need a state machine implementation of some kind. I'm going to play around a bit with a dumb AI just to try and get the basic mechanics in place
Page 1 of 1
« first « previous next › last »