private void AddMesh() { Vector3[] vertices = new Vector3[] { new Vector3(-5f, 0f, -5f), new Vector3(5f, 0f, -5f), new Vector3(5f, 0f, 5f), new Vector3(-5f, 0f, 5f) }; Vector3[] normals = new Vector3[] { Vector3.Up, Vector3.Up, Vector3.Up, Vector3.Up }; int[] indices = new int[] { 0, 1, 2, 0, 2, 3 }; Godot.Collections.Array meshData = new Godot.Collections.Array(); meshData.Resize((int)Mesh.ArrayType.Max); meshData[(int)Mesh.ArrayType.Vertex] = vertices; meshData[(int)Mesh.ArrayType.Normal] = normals; meshData[(int)Mesh.ArrayType.Index] = indices; _mesh = VisualServer.MeshCreate(); VisualServer.MeshAddSurfaceFromArrays(_mesh, VisualServer.PrimitiveType.Triangles, meshData); _instance = VisualServer.InstanceCreate(); VisualServer.InstanceSetBase(_instance, _mesh); RID scenario = GetWorld().Scenario; VisualServer.InstanceSetScenario(_instance, scenario); }
/// <summary> /// Uses the VisualServer to draw each of an entity's split sprites, by: /// 1. Obtaining the Node2D that is designated to play host to a given split sprite /// 2. Changing the Node2D's (TileMap) parent if required /// 3. Creating an RID for the canvas item (the sprite drawing) and storing it so it can be freed later /// </summary> /// <param name="tileMaps"></param> /// <param name="tileMapZIndex"></param> /// <param name="entityPos"></param> /// <param name="entityDrawPos">Offsets the sprite upwards. Used for drawing entities falling/jumping.</param> public void DrawSplitSprites(TileMapList tileMaps, int tileMapZIndex, Vector2 entityPos, float entityDrawPos /*State goes here*/) { List <SplitSpriteSheetValue> splitSprites = this._splitSpriteSheet.GetSplitSpriteInfoForAnim("idle", 0); //TODO match to entity anim state foreach (SplitSpriteSheetValue splitSprite in splitSprites) { Node2D splitNode2D = this._idToSplitNodes[splitSprite.splitIndex]; TileMap tileMap = tileMaps[tileMapZIndex + splitSprite.zIndex]; if (splitNode2D.GetParent() != tileMap) { if (splitNode2D.GetParent() != null) { splitNode2D.GetParent().RemoveChild(splitNode2D); } tileMap.AddChild(splitNode2D); } RID splitSpriteRID = VisualServer.CanvasItemCreate(); this._drawnSprites.Add(splitSpriteRID); VisualServer.CanvasItemSetParent(splitSpriteRID, splitNode2D.GetCanvasItem()); VisualServer.CanvasItemAddTextureRectRegion(splitSpriteRID, new Rect2(Vector2.Zero, splitSprite.size), this._splitSpriteSheet.GetSpriteSheetRID(), new Rect2(splitSprite.sheetPos, splitSprite.size), new Color(1, 1, 1, 1), false, this._splitSpriteSheet.GetSpriteSheetRID()); VisualServer.CanvasItemSetTransform(splitSpriteRID, new Transform2D(0, this._relativePos - new Vector2(Globals.TileWidth / 2, Globals.TileHeight / 2) + new Vector2(0, entityDrawPos))); splitNode2D.Position = entityPos + splitSprite.splitPos + new Vector2(Globals.TileWidth / 2, Globals.TileHeight / 2); } }
public override void _Ready() { VisualServer.SetDefaultClearColor(Color.Color8(0, 0, 0, 255)); Camera camera = new Camera() { Current = true, }; camera.SetScript(ResourceLoader.Load("res://maujoe.camera_control/camera_control.gd") as GDScript); AddChild(camera); AddChild(new WorldEnvironment() { Environment = new Godot.Environment() { BackgroundColor = Color.Color8(85, 85, 85, 255), BackgroundMode = Godot.Environment.BGMode.Color, }, }); AddChild(DosScreen = new DosScreen() { GlobalTransform = new Transform(Basis.Identity, new Vector3(0, 0, -2)), }); }
public override void _Ready() { GD.Print(ConfigManager.BASE_CONFIG_FILE_DIRECTORY_PATH); GD.Print(ConfigManager.BASE_DIRECTORY); GD.Print(ConfigManager.BASE_CONFIG_FILE_PATH); VisualServer.SetDebugGenerateWireframes(true); gameController = (GameController)FindParent("GameController"); ray = (RayCast)gameController.FindNode("Picker"); camera = (Camera)FindNode("Camera"); fps = (Label)camera.FindNode("FPS"); position = (Label)camera.FindNode("Position"); chunks = (Label)camera.FindNode("Chunks"); vertices = (Label)camera.FindNode("Vertices"); memory = (Label)camera.FindNode("Memory"); speed = (Label)camera.FindNode("Movement Speed"); initialRotation = new Vector3(); picker = gameController.GetPicker(); Input.SetMouseMode(Input.MouseMode.Captured); TerraVector3 origin = Converter.ConvertVector(GlobalTransform.origin); TerraBasis basis = Converter.ConvertBasis(GlobalTransform.basis); marker = new LoadMarker(origin, basis); gameController.Prepare(camera, marker); }
public override void _Ready() { // Base default clear color VisualServer.SetDefaultClearColor(DefaultClearColor); background = GetNode <ColorRect>("Background"); launcherUI = GetNode <VBoxContainer>("Margin/VBox"); backButton = GetNode <Button>("Margin/BackButton"); examplesButton = GetNode <Button>("Margin/VBox/Margin/Buttons/ExamplesButton"); ecosystemButton = GetNode <Button>("Margin/VBox/Margin/Buttons/EcosystemButton"); quitButton = GetNode <Button>("Margin/VBox/Margin/Buttons/QuitButton"); links = GetNode <RichTextLabel>("Margin/VBox/Margin/Links"); drawSpace = GetNode <Control>("DrawSpace"); fpsLabel = GetNode <Label>("Margin/FPS"); versionLabel = GetNode <Label>("Margin/Version"); examplesButton.Connect("pressed", this, nameof(LoadSceneExplorer)); ecosystemButton.Connect("pressed", this, nameof(LoadEcosystem)); quitButton.Connect("pressed", this, nameof(Quit)); backButton.Connect("pressed", this, nameof(ReloadLauncher)); links.Connect("meta_clicked", this, nameof(LinkClicked)); // Set version versionLabel.Text = "Version " + VERSION; if (OS.GetName() == "HTML5") { quitButton.Hide(); } ToggleBackUI(false); }
public override void _Ready() { DownloadShareware.Main(new string[] { Folder }); Assets = new Assets(Folder); VisualServer.SetDefaultClearColor(new Color(Assets.BackgroundColor)); Level level = new Level() { Assets = Assets, Map = Assets.Maps[0], }; AddChild(level); AddChild(new Label() { Text = "Dopefish lives!", Theme = new Theme() { DefaultFont = Assets.Fonts[0], }, }); }
public static void Shutdown() { foreach (RID rid in _children) { VisualServer.FreeRid(rid); } ImGui.DestroyContext(); }
public override void _Ready() { _originalOffset = Offset; _colorRect = GetNode <ColorRect>("HitEffectLayer/ColorRect"); _tween = GetNode <Tween>("HitEffectLayer/Tween"); _camera = this; VisualServer.SetDefaultClearColor(new Color(15f / 255f, 15f / 255f, 15f / 255f, 1f)); }
public override void _Ready() { VisualServer.SetDebugGenerateWireframes(true); MaterialOverride = new SpatialMaterial { AlbedoTexture = TextureAtlas.instance.atlas, ParamsCullMode = SpatialMaterial.CullMode.Back }; UseInBakedLight = true; }
/// <summary> /// Attempts to free any split sprites drawn by the VisualServer related to this class's entity. /// </summary> public void FreeDrawnRIDs() { foreach (RID splitSpriteRID in this._drawnSprites) { VisualServer.FreeRid(splitSpriteRID); } this._drawnSprites.Clear(); }
public override void _Ready() { this.level_select_scene = ResourceLoader.Load <PackedScene>("res://knytt/ui/LevelSelection.tscn"); this.settings_scene = ResourceLoader.Load <PackedScene>("res://knytt/ui/SettingsScreen.tscn"); fade = GetNode <FadeLayer>("MenuLayer/Fade"); GetNode <HBoxContainer>("MenuLayer/ButtonRow").GrabFocus(); VisualServer.SetDefaultClearColor(new Color(0, 0, 0)); }
public override void _Ready() { VisualServer.SetDefaultClearColor(Color.Color8(0, 0, 0, 255)); AddChild(ARVROrigin = new ARVROrigin()); ARVROrigin.AddChild(ARVRCamera = new ARVRCamera() { Current = true, }); ARVROrigin.AddChild(LeftController = new ARVRController() { ControllerId = 1, }); LeftController.AddChild(GD.Load <PackedScene>("res://OQ_Toolkit/OQ_ARVRController/models3d/OculusQuestTouchController_Left.gltf").Instance()); ARVROrigin.AddChild(RightController = new ARVRController() { ControllerId = 2, }); RightController.AddChild(GD.Load <PackedScene>("res://OQ_Toolkit/OQ_ARVRController/models3d/OculusQuestTouchController_Right.gltf").Instance()); AddChild(new WorldEnvironment() { Environment = new Godot.Environment() { BackgroundColor = Color.Color8(0, 0, 0, 255), BackgroundMode = Godot.Environment.BGMode.Color, }, }); AddChild(DosScreen = new DosScreen() { GlobalTransform = new Transform(Basis.Identity, new Vector3(0, 0, -2)), }); DosScreen.Screen.WriteLine("Platform detected: " + OS.GetName()); switch (OS.GetName()) { case "Android": Path = "/storage/emulated/0/"; ARVRInterface = ARVRServer.FindInterface("OVRMobile"); State = PermissionsGranted ? LoadingState.DOWNLOAD_SHAREWARE : LoadingState.ASK_PERMISSION; break; default: ARVRInterface = ARVRServer.FindInterface("OpenVR"); State = LoadingState.DOWNLOAD_SHAREWARE; break; } if (ARVRInterface != null && ARVRInterface.Initialize()) { GetViewport().Arvr = true; } LeftController.Connect("button_pressed", this, nameof(ButtonPressed)); RightController.Connect("button_pressed", this, nameof(ButtonPressed)); }
public override void _Ready() { viewUtils = new ViewportUtils(GetViewport()); viewUtils.OnViewportResize += new ViewportUtils.OnViewportResizeDelegate(OnViewportResize); table = new Table(viewUtils, Piles); deck = new Deck(viewUtils, Cards); cardPositions = new CardPositions(viewUtils); VisualServer.SetDefaultClearColor(BackgroundColor); }
public override void _Ready() { fadeAnimationPlayer = GetNode <AnimationPlayer>("FadeAnimationPlayer"); Instance = this; Viewport root = GetTree().Root; CurrentScene = root.GetChild(root.GetChildCount() - 1); FadeIn(); VisualServer.SetDefaultClearColor(Color.Color8(0, 0, 0, 255)); }
public override void _Process(float delta) { Transform t = Transform.Identity; Vector3 o = t.origin; o.z = cameraZoom; t.origin = o; t = GlobalTransform * t; VisualServer.CameraSetTransform(GetCameraRid(), t); }
public override void _Ready() { _noise = new OpenSimplexNoise(); _noise.Seed = (int)Main.RNG.Randi(); _noise.Octaves = 4; _noise.Period = .2f; VisualServer.SetDefaultClearColor(_clearColor); GameEventDispatcher.Instance.Connect(nameof(GameEventDispatcher.WeaponFired), this, nameof(OnWeaponFired)); GameEventDispatcher.Instance.Connect(nameof(GameEventDispatcher.EnemyStruck), this, nameof(OnEnemyStruck)); GameEventDispatcher.Instance.Connect(nameof(GameEventDispatcher.CameraShaken), this, nameof(OnCameraShaken)); }
public void LoadTheme(Resource themeSet) { VisualServer.SetDefaultClearColor((Color)themeSet.Get("background_color")); Array themeables = GetTree().GetNodesInGroup(Groups.Themeable); foreach (Node node in themeables) { if (node is IThemeable themeable) { themeable.UpdateTheme(themeSet); } } EmitSignal(nameof(ThemeSetChanged), themeSet); }
public void MeshChunk(Chunk chunk, ArrayPool <Position> pool) { RawChunk rawChunk = new RawChunk(); rawChunk.arrays = new Godot.Collections.Array[chunk.Materials - 1]; rawChunk.materials = new SpatialMaterial[chunk.Materials - 1]; rawChunk.colliderFaces = new Vector3[chunk.Materials - 1][]; if (chunk.Materials > 1) { rawChunk = Meshing(chunk, rawChunk, pool); } else { rawChunk = FastGodotCube(chunk, rawChunk); } RID meshID = VisualServer.MeshCreate(); //RID body = PhysicsServer.BodyCreate (PhysicsServer.BodyMode.Static); for (int t = 0; t < rawChunk.arrays.Count(); t++) { SpatialMaterial material = rawChunk.materials[t]; Godot.Collections.Array godotArray = rawChunk.arrays[t]; if (godotArray.Count > 0) { /* RID shape = PhysicsServer.ShapeCreate (PhysicsServer.ShapeType.ConcavePolygon); * // PhysicsServer.ShapeSetData (shape, vertice); * * PhysicsServer.BodyAddShape (body, shape, new Transform (Transform.basis, new Vector3 (chunk.x, chunk.y, chunk.z))); */ VisualServer.MeshAddSurfaceFromArrays(meshID, VisualServer.PrimitiveType.Triangles, godotArray); VisualServer.MeshSurfaceSetMaterial(meshID, VisualServer.MeshGetSurfaceCount(meshID) - 1, material.GetRid()); } } RID instance = VisualServer.InstanceCreate(); VisualServer.InstanceSetBase(instance, meshID); VisualServer.InstanceSetTransform(instance, new Transform(Transform.basis, new Vector3(chunk.x, chunk.y, chunk.z))); VisualServer.InstanceSetScenario(instance, GetWorld().Scenario); // PhysicsServer.BodySetSpace (body, GetWorld ().Space); }
public override void _Ready() { VisualServer.SetDefaultClearColor(BackgroundColor); AddChild(new WorldEnvironment() { Environment = new Godot.Environment() { BackgroundColor = BackgroundColor, BackgroundMode = Godot.Environment.BGMode.Color, }, }); AddChild(ARVROrigin = new ARVROrigin()); ARVROrigin.AddChild(ARVRCamera = new ARVRCamera() { Current = true, }); ARVROrigin.AddChild(LeftController = new ARVRController() { ControllerId = 1, }); ARVROrigin.AddChild(RightController = new ARVRController() { ControllerId = 2, }); LeftController.AddChild((Spatial)GD.Load <PackedScene>("res://OQ_Toolkit/OQ_ARVRController/models3d/OculusQuestTouchController_Left.gltf").Instance()); RightController.AddChild((Spatial)GD.Load <PackedScene>("res://OQ_Toolkit/OQ_ARVRController/models3d/OculusQuestTouchController_Right.gltf").Instance()); ARVRInterface = ARVRServer.FindInterface(OS.GetName().Equals("Android") ? "OVRMobile" : "OpenVR"); if (ARVRInterface != null && ARVRInterface.Initialize()) { GetViewport().Arvr = true; } AddChild(VirtualScreen = new VirtualScreen() { Transform = new Transform(Basis.Identity, new Vector3(0f, VirtualScreen.Height / 2f, -1f)), }); AddChild(Line3D = new Line3D() { Color = Color.Color8(255, 0, 0, 255), }); AddChild(Cube); }
void StepSimulation() { simulationFrame++; // TODO: find a way to retrieve all active viewports, not just the main one. var mainViewport = GetViewport().GetViewportRid(); // disable main viewport VisualServer.ViewportSetActive(mainViewport, false); try { var loadedTilesList = LoadedTiles.ToList(); foreach (var tile in loadedTilesList) { tile.RunSimulationOnNextDraw(simulationFrame); } VisualServer.ForceDraw(false); foreach (var tile in loadedTilesList) { if (!tile.SwapBuffer()) { continue; } var neighbors = GetTilesRange(tile.TileX - 1, tile.TileX + 1, tile.TileY - 1, tile.TileY + 1).Where(n => n != tile); foreach (var neighbor in neighbors) { neighbor.SetDataTexture(tile.TileX, tile.TileY, tile.DataTexture); } } } finally { // restore main viewport VisualServer.ViewportSetActive(mainViewport, true); } }
private void OnScreen_Resized() { var newWindowSize = OS.WindowSize; var scaleH = Mathf.Max((int)(newWindowSize.x / _baseSize.x), 1); var scaleW = Mathf.Max((int)(newWindowSize.y / _baseSize.y), 1); var scale = Mathf.Min(scaleH, scaleW); var diff = newWindowSize - _baseSize * scale; var diffHalf = (diff * 0.5f).Floor(); _root.SetAttachToScreenRect(new Rect2(diffHalf, _baseSize * scale)); var oddOffset = new Vector2 { x = (int)newWindowSize.x % 2, y = (int)newWindowSize.y % 2 }; VisualServer.BlackBarsSetMargins( (int)Mathf.Max(diffHalf.x, 0), (int)Mathf.Max(diffHalf.y, 0), (int)Mathf.Max(diffHalf.x, 0) + (int)oddOffset.x, (int)Mathf.Max(diffHalf.y, 0) + (int)oddOffset.y ); }
public override void _Process(float delta) { VisualServer.CameraSetTransform(GetCameraRid(), cameraTransform); }
public override void _Ready() { VisualServer.SetDefaultClearColor(new Color(color_background)); ui_controller = GetNode <ui_game_controller>("ui_game_controller"); }
void LoadLevel (int number) { currentLevel = number; //GODOT: how on earth do I load a text file? //var resource = GD.Load($"res://Levels/{number}.txt"); //this took 30mins to figure out. every operation is different than the //C# BCL version and the docs are not helpful var f = new File(); f.Open($"res://Levels/{number}.txt", (int)File.ModeFlags.Read); var lines = new System.Collections.Generic.List<string>(); while(!f.EofReached()) { lines.Add(f.GetLine()); } //var lines = System.IO.File.ReadAllLines(System.IO.Path.Combine("Levels", $"{number}.txt")); var boardDef = lines[0].Split('|'); int boardSize = int.Parse(boardDef[0]); if (boardDef.Length == 6) { TileColor = new Color(boardDef[1]); if (string.IsNullOrEmpty(boardDef[2])) { StaticTileColor = TileColor.Darkened(0.2f); } else { StaticTileColor = new Color(boardDef[2]); } BoardColor = new Color(boardDef[3]); if (string.IsNullOrEmpty(boardDef[4])) { BackgroundColor = Colors.Black; } else { BackgroundColor = new Color(boardDef[4]); } LineHighlightColor = new Color(boardDef[5]); } else { TileColor = new Color("e017c2"); StaticTileColor = TileColor.Darkened(0.2f); BoardColor = new Color("bdf0ec"); BackgroundColor = Colors.Black; LineHighlightColor = Colors.Yellow; } VisualServer.SetDefaultClearColor(BackgroundColor); CreateLevel(boardSize); for (int i = 1; i < lines.Count; i++) { var line = lines[i]; if (string.IsNullOrWhiteSpace(line)) { continue; } int commaIdx = line.IndexOf(','); int q = int.Parse(line.Substring(0,commaIdx)); var pipeIdx = line.IndexOf('|'); int r = int.Parse(line.Substring(commaIdx + 1, pipeIdx - commaIdx - 1)); int[] desc = new int[6]; for (int j = 0; j < 6; j++) { desc[j] = line[pipeIdx+ 1+j] - '0'; } //offset due to the map we're using to figure out positions int offset = Math.Max(0, 4 - boardSize); var coord = new HexCoord(q, r - offset); var tile = new PuzzleTileHex { LineDescriptions = desc, Position = coord.Position() }; tile.IsStatic = true; map.SetCell(new CellInfo(coord, tile)); board.AddChild(tile); tile.CalculatePaths(this, coord); } var c = TileColor; c.a = 0.6f; hexCursor.Modulate = c; Rescale(); }
public Mesh() { _InstanceRID = VisualServer.InstanceCreate(); _MeshRID = VisualServer.MeshCreate(); }
public override void _Ready() { VisualServer.SetDefaultClearColor(new Color(background_color_name)); }
private static void RenderDrawData(ImDrawDataPtr drawData, RID parent) { // allocate and clear out our CanvasItem pool as needed int neededNodes = 0; for (int i = 0; i < drawData.CmdListsCount; i++) { neededNodes += drawData.CmdListsRange[i].CmdBuffer.Size; } while (_children.Count < neededNodes) { RID newChild = VisualServer.CanvasItemCreate(); VisualServer.CanvasItemSetParent(newChild, parent); VisualServer.CanvasItemSetDrawIndex(newChild, _children.Count); _children.Add(newChild); _meshes.Add(new ArrayMesh()); } // trim unused nodes to reduce draw calls while (_children.Count > neededNodes) { int idx = _children.Count - 1; VisualServer.FreeRid(_children[idx]); _children.RemoveAt(idx); _meshes.RemoveAt(idx); } // render drawData.ScaleClipRects(ImGui.GetIO().DisplayFramebufferScale); int nodeN = 0; for (int n = 0; n < drawData.CmdListsCount; n++) { ImDrawListPtr cmdList = drawData.CmdListsRange[n]; int idxOffset = 0; int nVert = cmdList.VtxBuffer.Size; Godot.Vector2[] vertices = new Godot.Vector2[nVert]; Godot.Color[] colors = new Godot.Color[nVert]; Godot.Vector2[] uvs = new Godot.Vector2[nVert]; for (int i = 0; i < cmdList.VtxBuffer.Size; i++) { var v = cmdList.VtxBuffer[i]; vertices[i] = new Godot.Vector2(v.pos.X, v.pos.Y); // need to reverse the color bytes byte[] col = BitConverter.GetBytes(v.col); colors[i] = Godot.Color.Color8(col[0], col[1], col[2], col[3]); uvs[i] = new Godot.Vector2(v.uv.X, v.uv.Y); } for (int cmdi = 0; cmdi < cmdList.CmdBuffer.Size; cmdi++, nodeN++) { ImDrawCmdPtr drawCmd = cmdList.CmdBuffer[cmdi]; int[] indices = new int[drawCmd.ElemCount]; for (int i = idxOffset, j = 0; i < idxOffset + drawCmd.ElemCount; i++, j++) { indices[j] = cmdList.IdxBuffer[i]; } var arrays = new Godot.Collections.Array(); arrays.Resize((int)ArrayMesh.ArrayType.Max); arrays[(int)ArrayMesh.ArrayType.Vertex] = vertices; arrays[(int)ArrayMesh.ArrayType.Color] = colors; arrays[(int)ArrayMesh.ArrayType.TexUv] = uvs; arrays[(int)ArrayMesh.ArrayType.Index] = indices; var mesh = _meshes[nodeN]; while (mesh.GetSurfaceCount() > 0) { mesh.SurfaceRemove(0); } mesh.AddSurfaceFromArrays(Mesh.PrimitiveType.Triangles, arrays); RID child = _children[nodeN]; Texture tex = GetTexture(drawCmd.TextureId); VisualServer.CanvasItemClear(child); VisualServer.CanvasItemSetClip(child, true); VisualServer.CanvasItemSetCustomRect(child, true, new Godot.Rect2( drawCmd.ClipRect.X, drawCmd.ClipRect.Y, drawCmd.ClipRect.Z - drawCmd.ClipRect.X, drawCmd.ClipRect.W - drawCmd.ClipRect.Y) ); VisualServer.CanvasItemAddMesh(child, mesh.GetRid(), null, null, tex.GetRid(), new RID(null)); // why doesn't this quite work? // VisualServer.CanvasItemAddTriangleArray(child, indices, vertices, colors, uvs, null, null, tex.GetRid(), -1, new RID(null)); idxOffset += (int)drawCmd.ElemCount; } } }
public override void _Ready() { play_area.Clear(); VisualServer.SetDefaultClearColor(Colors.Black); HashSet <int2> rocks = new HashSet <int2>(); int2 start = new int2(); play_area.Add(start); rocks.Add(start); int loop = 0; while (loop < 4)// && loop < 100) { //loop++; switch (Rand.Int(3)) { case 0: start.x += 1; break; case 1: start.x -= 1; break; default: start.y += 1; break; } if (!play_area.Contains(start)) { play_area.Add(start); rocks.Add(start); } if (start.y == 100) { loop++; start = new int2(); } } int minX = 0, maxX = 0; foreach (var position in play_area) { for (int x = position.x - 5; x < position.x + 6; ++x) { for (int y = position.y - 1; y < position.y + 2; ++y) { if (x < minX) { minX = x; } if (x > maxX) { maxX = x; } if (rocks.Contains(new int2(x, y))) { continue; } rocks.Add(new int2(x, y)); if (y > 100) { continue; } var wall = Corals.Wall_Prefabs.GetRandom()(); wall.GlobalPosition = new Vector2(x, y) * block_width; wall.ZIndex += 10; } } } List <int2> caves = new List <int2>(), sides = new List <int2>(), open_areas = new List <int2>(), grounded = new List <int2>(); foreach (var position in play_area) { int obstruction_count = 0; int cave_count = 0; int side_count = 0; bool is_grounded = false; for (int x = position.x - 1; x < position.x + 2; ++x) { for (int y = position.y - 1; y < position.y + 2; ++y) { if (y >= 100) { continue; } bool obstructed = !play_area.Contains(new int2(x, y)); if (obstructed) { obstruction_count++; if (y == position.y + 1 && x == position.x) { is_grounded = true; } if (y == position.y || x == position.x) { cave_count++; } if (y == position.x) { side_count++; } } } } if (is_grounded) { grounded.Add(position); } if (position.y < 5) { continue; } if (obstruction_count == 0) { open_areas.Add(position); } if (side_count == 0) { sides.Add(position); } if (cave_count == 3 && is_grounded) { caves.Add(position); } } spawn_puffers(grounded); spawn_spikes(grounded); spawn_sharks(open_areas, play_area); spawn_corpses(caves, play_area); spawn_edge_boundaries(minX, maxX); spawn_weeds(grounded); }
private void _UpdateBackgroundHue() { VisualServer.SetDefaultClearColor(Color.FromHsv(backgroundHue, 0.4f, 1f)); backgroundHue += 0.0001f * (float)Math.Pow(BackendInstance.Game.CurrentLevel, 3); }