コード例 #1
0
    bool Enact(Movable m, ushort agentId)
    {
        if (m.who == null)
        {
            Debug.LogError($"{agentId} is lacking its game object");
            movables.Remove(agentId);
            Debug.Log($"{movables.Count} movables remain");
            return(false);
        }
        int nextX = m.NextX;
        int nextY = m.NextY;

        ResolveConflict(nextX, nextY, m.agentType, m.who, m.actionX, m.actionY);
        if (levelDidReset)
        {
            return(false);
        }
        bool occupied = IsOccupied(nextX, nextY, m.agentType);

        if (!occupied)
        {
            levelData[nextX, nextY] = LevelFeature.CopyAgent(levelData[m.x, m.y], levelData[nextX, nextY]);
            levelData[m.x, m.y]     = LevelFeature.ClearAgent(levelData[m.x, m.y]);
            m.who.SendMessage("Move", GetPositionAt(nextX, nextY), SendMessageOptions.RequireReceiver);
            return(true);
        }
        return(false);
    }
コード例 #2
0
    private void PopulateAgents()
    {
        for (int x = 0, width = levelData.GetLength(0); x < width; x++)
        {
            for (int y = 0, height = levelData.GetLength(1); y < height; y++)
            {
                LevelFeatureValue val = levelData[x, y];
                if (LevelFeature.HasAgent(val))
                {
                    ushort agentId = LevelFeature.GetAgentId(val);
                    Debug.Log($"Agent {agentId} on {x} {y} of type {LevelFeature.GetAgentType(val)}");
                    switch (LevelFeature.GetAgentType(val))
                    {
                    case AgentType.PLAYER:
                        PlayerController player = GetPlayer(agentId, x, y);
                        player.Move(GetPositionAt(x, y));
                        break;

                    case AgentType.MONSTER:
                        Enemy enemy = Beastiary.Instance.GetABeast(currentLevel);
                        SetMovable(agentId, new Movable(x, y, AgentType.MONSTER, enemy.gameObject), true);
                        enemy.Setup(AgentType.MONSTER, agentId);
                        enemy.Move(GetPositionAt(x, y));
                        break;
                    }
                }
            }
        }

        Debug.Log($"{movables.Count} movables in level");
    }
コード例 #3
0
    void ResolveMonsterConflict(int x, int y, GameObject monster)
    {
        LevelFeatureValue targetVal = levelData[x, y];

        if (LevelFeature.GetAgentType(targetVal) == AgentType.PLAYER)
        {
            ushort agentID = LevelFeature.GetAgentId(targetVal);
            movables[agentID].who.SendMessage("Hurt", SendMessageOptions.RequireReceiver);
            monster.SendMessage("PerformedAttack", SendMessageOptions.RequireReceiver);
        }
    }
コード例 #4
0
    private void CreateSlideBlock()
    {
        saveButton.interactable = false;

        LevelObject  levelObject  = LevelObjectAtPosition(startIndex);
        LevelFeature levelFeature = GetLevelFeature(LevelFeature.features.SlideBlock);

        if (levelObject == null)
        {
            levelObject                   = new LevelObject();
            levelObject.gameObject        = Instantiate(slideBlockPrefab, new Vector2(startIndex * spacingBetweenSamples + levelFeature.offset, levelTransform.position.y), Quaternion.identity, levelTransform);
            levelObject.feature           = levelFeature;
            levelObject.songPositionIndex = startIndex;

            levelObjects.Add(levelObject);
        }
    }
コード例 #5
0
    static LevelFeatureValue[,] LevelHome()
    {
        int width  = 12;
        int height = 9;

        LevelFeatureValue[,] lvl = new LevelFeatureValue[width, height];
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                if (x == 0 || y == 0 || x == width - 1 || y == height - 1)
                {
                    lvl[x, y] = LevelFeature.Ground(false, true, 0);
                }
                else if (x == 6)
                {
                    lvl[x, y] = LevelFeature.Ground(y == 2, y != 6, 0);
                }
                else if (x > 6 && y == 4)
                {
                    lvl[x, y] = LevelFeature.Ground(false, true, 0);
                }
                else
                {
                    lvl[x, y] = LevelFeature.Ground(false, false, 0);
                }
            }
        }
        switch (Random.Range(0, 2))
        {
        case 0:
            lvl[8, 3] = LevelFeature.SetAgent(true, false, 0, lvl[8, 3]);
            lvl[8, 7] = LevelFeature.SetAgent(false, true, 1, lvl[8, 7]);
            break;

        case 1:
            lvl[8, 7] = LevelFeature.SetAgent(true, false, 0, lvl[8, 7]);
            lvl[8, 3] = LevelFeature.SetAgent(false, true, 1, lvl[8, 3]);
            break;
        }
        return(lvl);
    }
コード例 #6
0
    void ResolvePlayerConflict(int x, int y, int xDir, int yDir)
    {
        LevelFeatureValue targetVal = levelData[x, y];

        if (LevelFeature.FulfillsSemanticGroundMask(true, true, targetVal))
        {
            if (IsInsideLevel(x + xDir, y + yDir))
            {
                LevelFeatureValue nextVal = levelData[x + xDir, y + yDir];
                if (LevelFeature.DoesntBlockMovableGround(nextVal))
                {
                    levelData[x, y] = LevelFeature.SetGround(false, false, targetVal);
                    levelData[x + xDir, y + yDir] = LevelFeature.SetGround(true, true, nextVal);
                }
                else
                {
                    int xExtraDir = xDir == 0 ? 0 : xDir + Mathf.RoundToInt(Mathf.Sign(xDir));
                    int yExtraDir = yDir == 0 ? 0 : yDir + Mathf.RoundToInt(Mathf.Sign(yDir));
                    if (IsInsideLevel(x + xExtraDir, y + yExtraDir))
                    {
                        LevelFeatureValue nextNextVal = levelData[x + xExtraDir, y + yExtraDir];
                        if (!LevelFeature.WouldBlockMovableGroundWithoutAgent(nextVal))
                        {
                            if (!IsOccupied(x + xExtraDir, y + yExtraDir, LevelFeature.GetAgentType(nextNextVal)))
                            {
                                ushort agentId = LevelFeature.GetAgentId(nextVal);
                                SetMovable(agentId, movables[agentId].Evolve(xDir, yDir));
                                movables[agentId].who.SendMessage("Move", GetPositionAt(x + xDir, y + yDir), SendMessageOptions.RequireReceiver);

                                levelData[x + xExtraDir, y + yExtraDir] = LevelFeature.CopyAgent(nextNextVal, levelData[x + xExtraDir, y + yExtraDir]);
                                levelData[x + xDir, y + yDir]           = LevelFeature.ClearAgent(nextNextVal);
                                levelData[x, y] = LevelFeature.SetGround(false, false, targetVal);
                                levelData[x + xDir, y + yDir] = LevelFeature.SetGround(true, true, nextVal);
                            }
                        }
                    }
                }
            }
        }
    }
コード例 #7
0
ファイル: MapGenerator.cs プロジェクト: thesambassador/ld48
    private void GenerateLevelFeatures(Chunk chunk)
    {
        if (chunk.BiggestCavern == null)
        {
            print("no biggest cavern at " + chunk.ChunkStart);
            return;
        }

        foreach (LevelFeatureSpawnPool pool in _spawnPoolFeatures.Keys)
        {
            List <LevelFeature> featurePrefabs = GetValidLevelFeaturesForChunk(_spawnPoolFeatures[pool], chunk);
            int numFeatures = GetNumLevelFeaturesToGen(pool, chunk);

            if (featurePrefabs.Count > 0)
            {
                //print("spawning shit");
                for (int i = 0; i < numFeatures; i++)
                {
                    LevelFeature prefabToUse = featurePrefabs.GetRandomElement();
                    chunk.SpawnLevelFeatureInCavern(prefabToUse);
                }
            }
        }
    }
コード例 #8
0
    private void CreateLevelObjects(GameObject levelObjectPrefab, FrequencyBand band, ref LevelFeature feature)
    {
        int iterationsSinceLast = 0;

        feature.AdjustForJumpDistance(physicsModel.jumpDistance);
        feature.CalculateSpaceIndexes(spacingBetweenSamples);

        for (int i = 0; i < band.spectralFluxSamples.Count; i++)
        {
            SpectralFluxData sample = band.spectralFluxSamples[i];

            if (sample.isOnset && (iterationsSinceLast >= feature.preSpaceIndex || feature.placeAdjacent))
            {
                LevelObject levelObject = LevelObjectAtPosition(i);

                if (levelObject == null)
                {
                    levelObject                   = new LevelObject();
                    levelObject.gameObject        = Instantiate(levelObjectPrefab, new Vector2(i * spacingBetweenSamples + feature.offset, levelTransform.position.y), Quaternion.identity, levelTransform);
                    levelObject.feature           = feature;
                    levelObject.songPositionIndex = i;

                    levelObjects.Add(levelObject);
                }

                iterationsSinceLast = 0;
            }
            else
            {
                iterationsSinceLast++;
            }
        }
    }
コード例 #9
0
 private void Awake()
 {
     _levelFeature    = FindObjectOfType <LevelFeature>();
     _backpackFeature = FindObjectOfType <BackpackFeature>();
 }
コード例 #10
0
 bool IsOccupied(int x, int y, AgentType actor)
 {
     return(LevelFeature.BlocksAgent(levelData[x, y]));
 }
コード例 #11
0
 public LevelObjectData(LevelFeature _feature, int _index)
 {
     feature           = _feature;
     songPositionIndex = _index;
 }
コード例 #12
0
ファイル: Chunk.cs プロジェクト: thesambassador/ld48
    public bool SpawnLevelFeatureInCavern(LevelFeature feature)
    {
        List <Vector3Int> coordsToUse = BiggestCavern.AirTiles;
        Vector3Int        offset      = Vector3Int.zero;

        switch (feature.SpawnSurface)
        {
        case LevelFeatureSpawnSurface.Air:
            break;

        case LevelFeatureSpawnSurface.Wall:
            coordsToUse = BiggestCavern.WallTiles;
            break;

        case LevelFeatureSpawnSurface.Ceiling:
            coordsToUse = BiggestCavern.CeilingTiles;
            if (!feature.SpawnOnSurface)
            {
                offset.y = 1;
            }
            break;

        case LevelFeatureSpawnSurface.Floor:
            coordsToUse = BiggestCavern.FloorTiles;
            if (!feature.SpawnOnSurface)
            {
                offset.y = -1;
            }
            break;

        case LevelFeatureSpawnSurface.Outline:
            coordsToUse = BiggestCavern.CavernOutlineCoordinates;
            //can't use spawn in for this yet....?
            break;

        case LevelFeatureSpawnSurface.InTerrain:
            //not implemented yet
            break;

        default:
            break;
        }

        if (coordsToUse == null || coordsToUse.Count == 0)
        {
            print("no valid spawn for " + feature.name + " at " + this.ChunkStart);
            return(false);
        }
        Vector3Int coord = coordsToUse.GetRandomElement();

        if (!feature.SpawnOnSurface)
        {
            if (feature.SpawnSurface == LevelFeatureSpawnSurface.Wall)
            {
                offset.x = GetWallOffset(coord);
            }
            coord += offset;

            //if we're embedding into the wall, need to remove the tile there
            ChunkTilemap.SetTile(coord, null);
            ForegroundTilemap.SetTile(coord, null);
        }

        Vector3 worldPos = ChunkTilemap.GetCellCenterWorld(coord);

        LevelFeature newFeature = Instantiate(feature);

        newFeature.transform.position = worldPos;
        newFeature.SpawnAt(coord);
        SpawnedFeatures.Add(newFeature);

        return(true);
    }