Exemplo n.º 1
0
        //Handles individual tiles at individual layers
        //Some things shouldn't be done by the loop such as exiting the game - so use the calledByLoop to differentiate between the two
        //if this gets messy could split this function into two for each use
        void tileHandler(CCPoint world, CCTileMapLayer layer, character oldUser, Boolean calledByLoop=false)
        {
            CCTileMapCoordinates tileAtXy = layer.ClosestTileCoordAtNodePosition(world); // get tile coordinates corresponding to our touch location
            CCTileGidAndFlags info = layer.TileGIDAndFlags(tileAtXy.Column, tileAtXy.Row);
            //Tilemaps made in the "tiled" program can hold properties - get the properties of the tile
            Dictionary<string, string> properties = TilePropertiesForGID(info.Gid); 

            //Clicking a walkable tile
            if (!calledByLoop && properties != null && properties.ContainsKey("walkable") && properties["walkable"] == "true")
            {
                //if tile has an enemy and user is near it
                if(isTileOccupied(tileAtXy) && isUserNear(tileAtXy))
                {
                    character attackedEnemy = getEnemyAt(tileAtXy);
                    if (attackedEnemy.attacked(user.weapon.attack))
                        enemyDeath(attackedEnemy);

                    foreach (character enemy in enemiesList)
                    {
                        CCTileMapCoordinates positionAsTile = LayerNamed("Map").ClosestTileCoordAtNodePosition(enemy.Position);
                        if (!isUserNear(positionAsTile))
                            enemy.moveOneRandom();
                        else
                        {
                                if (user.attacked(enemy.weapon.attack) && !ifdied)
                                {
                                    userDeath();
                                    break;
                                }
                            
                        }
                    }
                }
                //TODO - if tile has an item, pick it up
                if(!isTileOccupied(tileAtXy))
                    userMoves = user.move(world); //get new pathfind
            }
            //Spawning in the user - only happens once - not called by user
            if (user == null && calledByLoop && properties != null && properties.ContainsKey("name") && properties["name"] == "exit")
            {
                if(oldUser==null)
                {
                    user = new character("userChar", 20, world, availableWeapons[0]);
                    layer.AddChild(user);
                }
                else
                {
                    user = new character(oldUser, world);
                    layer.AddChild(user);                }
            }
        }
Exemplo n.º 2
0
        private bool[,] extractHitboxTiles(CCTileMapLayer physicsLayer, CCTileMap physicsMap)
        {
            bool[,] Tile = new bool[(int)physicsLayer.LayerSize.Size.Width, (int)physicsLayer.LayerSize.Size.Height];

            //erstellt ein bool Abbild der Map
            Dictionary<string,string> tileProperties;
            for (int x = 1; x < physicsLayer.LayerSize.Size.Width - 1; x++) {
                for (int y = 1; y < physicsLayer.LayerSize.Size.Height - 1; y++) {
                    //wenn das tile allein steht, dann ist es ein Element der Hitbox
                    tileProperties = physicsMap.TilePropertiesForGID (physicsLayer.TileGIDAndFlags (new CCTileMapCoordinates (x, y)).Gid);
                    if (tileProperties != null) {
                        tileProperties = physicsMap.TilePropertiesForGID (physicsLayer.TileGIDAndFlags (new CCTileMapCoordinates (x - 1, y)).Gid);
                        if (tileProperties == null) {
                            Tile [x, y] = true;
                        }
                        tileProperties = null;
                        tileProperties = physicsMap.TilePropertiesForGID (physicsLayer.TileGIDAndFlags (new CCTileMapCoordinates (x + 1, y)).Gid);
                        if (tileProperties == null) {
                            Tile [x, y] = true;
                        }
                        tileProperties = null;
                        tileProperties = physicsMap.TilePropertiesForGID (physicsLayer.TileGIDAndFlags (new CCTileMapCoordinates (x, y - 1)).Gid);
                        if (tileProperties == null) {
                            Tile [x, y] = true;
                        }
                        tileProperties = null;
                        tileProperties = physicsMap.TilePropertiesForGID (physicsLayer.TileGIDAndFlags (new CCTileMapCoordinates (x, y + 1)).Gid);
                        if (tileProperties == null) {
                            Tile [x, y] = true;
                        }
                        tileProperties = null;
                    }
                }
            }

            return Tile;
        }