invertika_game.Game.MapComposite.update C# (CSharp) Method

update() public method

public update ( ) : void
return void
        public void update()
        {
            for(int i=0; i<mContent.mapHeight*mContent.mapWidth; ++i)
            {
                mContent.zones[i].destinations.Clear();
            }

            // Cannot use a WholeMap iterator as objects will change zones under its feet.
            foreach(Thing i in mContent.things)
            {
                if(!(i).canMove())
                {
                    continue;
                }

                Being obj=(Being)(i);

                Point pos1=obj.getOldPosition();
                Point pos2=obj.getPosition();

                MapZone src=mContent.getZone(pos1),
                        dst=mContent.getZone(pos2);

                if(src!=dst) //TODO Überladener Operator nötig?
                {
                    //TODO implementieren
                    //addZone(src.destinations, dst-mContent.zones);
                    src.remove(obj);
                    dst.insert(obj);
                }
            }
        }

Usage Example

Example #1
0
        /**
         * Updates object states on the map.
         */
        static void updateMap(MapComposite map)
        {
            // 1. update object status.
            List< Thing  > things = map.getEverything(); //TODO das könnte man auch weiter unten benutzen?

            foreach(Thing thing in things)
            {
                thing.update();
            }

            // 2. run scripts.
            Script s = map.getScript();
            if(s != null)
            {
                s.update();
            }

            // 3. perform actions.
            if(map.mContent!=null)
            {
            foreach(Thing thing in map.mContent.things)
            {
                if(thing is Being)
                {
                    Being being = (Being)thing;
                    being.perform();
                }
            }
            }

            //Alter Code
            // for (BeingIterator i(map.getWholeMapIterator()); i; ++i)
            // {
            //     (*i).perform();
            // }

            // 4. move objects around and update zones.
            foreach(Thing thing in map.mContent.things)
            {
                if(thing is Being)
                {
                    Being being = (Being)thing;
                    being.move();
                }
            }

            // Alter Code
            //for (BeingIterator i(map.getWholeMapIterator()); i; ++i)
            //{
            //    (*i).move();
            //}

            map.update();
        }