private void NewMethod(SceneGraph2D Graph) { foreach (var hl in HL) { int mx = hl.X * TileWidth; int my = hl.Y * TileHeight; var hs = new GraphSprite(new Tex2D("content/edit/highlight1.png", true), null, 64, 64); hs.SetPos(mx, my); // tileSpr.SetPos(mx, my); Graph.Add(hs);; } }
private void SceneTree_DragDrop(object sender, DragEventArgs e) { UpdateTick.Enabled = false; foreach (var f in dragFiles) { var sn = new GraphSprite(f); sn.W = DefW; sn.H = DefH; sn.Name = new System.IO.FileInfo(f).Name; if (SceneTree.SelectedNode != null) { var gn = NodeMap[SceneTree.SelectedNode]; gn.Nodes.Add((GraphNode)sn); sn.Root = gn; } else { EditGraph.Add(sn); } } SyncUI(); UpdateTick.Enabled = true; }
public MapViewForm(Map.Map map, bool Shadows = true) { shadows = Shadows; Map = map; // ContextMenu = new ContextMenuForm(); //var add_menu = ContextMenu.AddItem("Add"); // add_menu.Menu.AddItem("Point Light"); LightSprite = new GraphSprite(new Tex2D("content/edit/light.png", true), null, 64, 64); ActiveNodeSprite = new GraphSprite(new Tex2D("content/edit/activenode.png", true), null, 64, 64); ActiveNodePivot = new GraphSprite(new Tex2D("content/edit/nodepivot.png", true), null, 16, 16); nodeLeft = new GraphSprite(new Tex2D("content/edit/left.png", true), null, 32, 32); nodeUp = new GraphSprite(new Tex2D("content/edit/up.png", true), null, 32, 32); nodeRight = new GraphSprite(new Tex2D("content/edit/right.png", true), null, 32, 32); nodeDown = new GraphSprite(new Tex2D("content/edit/down.png", true), null, 32, 32); if (MapFrame == null) { //MapFrame = new Vivid.FrameBuffer.FrameBufferColor() } AfterSet = () => { MapFrame = new Vivid.FrameBuffer.FrameBufferColor(W, H); Changed = true; }; PreDraw = () => { if (Graph != null && Changed) { if (shadows) { foreach (var l in Graph.Lights) { l.CheckShadowSize(MapFrame.IW, MapFrame.IH); l.RenderShadowBuffer(Graph); } } // Graph.GenShadow(); //shadows = false; //return; MapFrame.Bind(); Changed = false; //Console.WriteLine("Rendering map"); // AppInfo.RW = AppInfo.RW; //AppInfo.RH = AppInfo.RH; Graph.Draw(shadows); foreach (var l in Graph.Lights) { LightSprite.X = l.X; LightSprite.Y = l.Y; LightSprite.W = 64; LightSprite.H = 64; LightSprite.Graph = Graph; Graph.DrawSingleNode(LightSprite); } if (ActiveNode != null) { SetActiveSprite(); Graph.DrawSingleNode(ActiveNodeSprite); ActiveNodePivot.X = ActiveNode.X + 32; ActiveNodePivot.Y = ActiveNode.Y - 32; ActiveNodePivot.W = 16; ActiveNodePivot.H = 16; ActiveNodePivot.Graph = Graph; Graph.DrawSingleNode(ActiveNodePivot); } //Graph.X += 1; //Graph.Y += 1; //Graph.; //Graph.Z = 0.2f; //Graph.Rot += 1.0f; MapFrame.Release(); } }; float r = 1.0f; Draw = () => { DrawFormSolid(new Vector4(1, 0.8f, 0.8f, 1.0f)); Col = new Vector4(1, 1, 1, 1); if (shadows) { int bv = 2; } DrawForm(MapFrame.BB, 0, 0, -1, -1, true); if (Graph != null) { //if (SceneGraph2D.ShadowBuffer2 != null) //{ if (Graph.Lights.Count > 0 && Graph.Lights[0].SB1 != null) { // DrawForm(Graph.Lights[0].SB1.BB, 0,0, 256, 256); // DrawForm(Graph.Lights[0].SB2.BB, 0, 256, 256, 256); //Graph.Rot = r; // } } r = r + 1; //Changed = true; } }; }
public Vivid.Scene.SceneGraph2D UpdateGraph(int tw, int th) { if (sceneChanged == false) { return(oGraph); } Vivid.Scene.SceneGraph2D Graph = oGraph; if (oGraph == null) { Graph = new Vivid.Scene.SceneGraph2D(); } oGraph = Graph; sceneChanged = false; float sp = 0; int li = 0; Graph.Root = new GraphNode(); foreach (var layer in Layers) { li++; for (int y = 0; y < layer.Height; y++) { for (int x = 0; x < layer.Width; x++) { var tile = layer.GetTile(x, y); if (tile == null) { if (li == 1) { var notile = new GraphSprite(new Tex2D("content/edit/notile.png", false), null, TileWidth, TileHeight); notile.SetPos(x * TileWidth, y * TileHeight); notile.TileX = x; notile.TileY = y; Graph.Add(notile); } continue; } var tileSpr = new GraphSprite(tile.ColorImage, tile.NormalImage, TileWidth, TileHeight); tileSpr.TileX = x; tileSpr.TileY = y; int mx = x * TileWidth; int my = y * TileHeight; tileSpr.SetPos(mx, my); tileSpr.Obj[0] = tile; if (Lights.Count > 0) { tileSpr.ShadowPlane = sp; } Graph.Add(tileSpr); if (li > 1) { tileSpr.CastShadow = true; tileSpr.RecvShadow = false; } } } sp = sp + 0.1f; } NewMethod(Graph); if (Graph.Lights.Count != Lights.Count) { Graph.Lights.Clear(); Graph.Add(Lights.ToArray()); } // Graph.Add(Lights.ToArray()); foreach (var l in Lights) { var lg = new GraphSprite(new Tex2D("content/edit/light.png", true), null, 64, 64); lg.X = l.X; lg.Y = l.Y; lg.Z = l.Z; // Graph.Add(lg); } return(Graph); }
public override void Update() { if (AimSprite == null) { AimSprite = new GraphSprite(PulseAimImg, null); AimSprite.X = X; AimSprite.Y = Y; Graph.Add(AimSprite); aimLight = new GraphLight(); aimLight.Diffuse = new OpenTK.Vector3(0, 0.2f, 0.2f); aimLight.Range = 150; Graph.Add(aimLight); } else { if (usePad) { float xi = XIn.rightX(); float yi = XIn.rightY(); float dis = (float)Math.Sqrt((xi * xi) + (yi * yi)); if (dis > 0.5) { float ang = (float)Math.Atan2(-yi, xi); aimAngle = OpenTK.MathHelper.RadiansToDegrees(ang); //aimAngle = ang; AimSprite.Rot = aimAngle; float xo = (float)Math.Cos(ang); float yo = (float)Math.Sin(ang); xo = xo * 64; yo = yo * 64; AimSprite.X = X + xo; AimSprite.Y = Y + yo; aimLight.X = AimSprite.X; aimLight.Y = AimSprite.Y; } } else { float rx = RealX; float ry = RealY; float mx = Vivid.Input.Input.MX; float my = Vivid.Input.Input.MY; float ang = (float)Math.Atan2(my - ry, mx - rx); aimAngle = ang; AimSprite.Rot = OpenTK.MathHelper.RadiansToDegrees(aimAngle); //Console.WriteLine("Rot:" + AimSprite.Rot); float xo = (float)Math.Cos(aimAngle); float yo = (float)Math.Sin(aimAngle); xo = xo * 64; yo = yo * 64; AimSprite.X = X + xo; AimSprite.Y = Y + yo; aimLight.X = AimSprite.X; aimLight.Y = AimSprite.Y; } } if (!changedSlot) { if (XIn.DLeft() || Vivid.Input.Input.KeyIn(OpenTK.Input.Key.Q)) { CurSlot--; if (CurSlot < 0) { if (Slots[2] == null) { CurSlot = 1; } else { CurSlot = 2; } } changedSlot = true; RebuildWeaponHud(); Songs.PlaySource(ChangeSrc, false); } if (XIn.DRight() || Vivid.Input.Input.KeyIn(OpenTK.Input.Key.E)) { CurSlot++; if (CurSlot == 3) { CurSlot = 0; } if (Slots[CurSlot] == null) { CurSlot = 0; } changedSlot = true; RebuildWeaponHud(); Songs.PlaySource(ChangeSrc, false); } } else { if (XIn.DLeft() == false && XIn.DRight() == false && Input.KeyIn(OpenTK.Input.Key.Q) == false && Input.KeyIn(OpenTK.Input.Key.E) == false) { changedSlot = false; } } switch (State) { case ScopeState.Idle: if (CurAnim != Anims["Idle1"]) { SetAnim("Idle1"); } break; case ScopeState.Walking: if (CurAnim != Anims["Walk1"]) { SetAnim("Walk1"); } break; case ScopeState.Running: if (CurAnim != Anims["Run1"]) { SetAnim("Run1"); } break; } base.Update(); ImgFrame = GetAnimFrame(); float xm = XIn.LeftX(); if (Vivid.Input.Input.MB[0] && !ShotAlready && Environment.TickCount > (lastShot + 800)) { var shotSpr = Slots[CurSlot].GetNew(); shotSpr.X = AimSprite.X; shotSpr.Y = AimSprite.Y; Graph.Add(shotSpr); Graph.Add(shotSpr.Light1); shotSpr.XM = (float)Math.Cos(aimAngle); shotSpr.YM = (float)Math.Sin(aimAngle); ShotAlready = true; lastShot = Environment.TickCount; } if (Vivid.Input.Input.MB[0] == false) { ShotAlready = false; } if (Vivid.Input.Input.KeyIn(OpenTK.Input.Key.A)) { xm = -1; } if (Vivid.Input.Input.KeyIn(OpenTK.Input.Key.D)) { xm = 1; } xm = xm * 0.4f; if (XIn.bX() || Input.KeyIn(OpenTK.Input.Key.Space)) { if (onGround && Environment.TickCount > (lastJump + 500)) { Move2D(0, -10); onGround = false; //State = ScopeState.Jumping; Y = Y - 10; lastJump = Environment.TickCount; } } if (XIn.leftB() || Input.KeyIn(OpenTK.Input.Key.ShiftLeft)) { xm = xm * 2; if (Math.Abs(xm) > 0) { State = ScopeState.Running; } } else { if (Math.Abs(xm) > 0) { State = ScopeState.Walking; } else { State = ScopeState.Idle; } } if (Math.Abs(xm) < 0.2) { State = ScopeState.Idle; } else { //State = ScopeState.Walking; } Move2D(xm * 0.35f, 0); if (xm > 0) { FlipDrawX = false; } else if (xm < 0) { FlipDrawX = true; } //X = X + xm; var cm = Graph.CreateCollisionMap(0.05f); Graph.StoreCam(); Graph.X = 0; Graph.Y = 0; Graph.Z = 1; Graph.Rot = 0; float cx = this.RealX; float cy = this.RealY; Graph.RestoreCam(); if (Environment.TickCount > (lastJump + 500)) { var hit = cm.RayCast(cx, cy, cx, cy + 32); if (hit == null) { //X = hit.HitX; Move2D(0, 0.3f); onGround = false; } else { //Y = //Y = hit.HitY - 40; Yi = 0; onGround = true; /* * Environment.Exit(1); * float dis = hit.HitY - 32; * * dis = Math.Abs((dis - Y)); * * * if (dis < 32) * { * * Yi = 0; * Y = cy; // hit.HitY - 32 * Graph.Z; * onGround = true; * } */ } } //Rot += 0.1f; //vironment.Exit(1); //base.Update(); }
public override void InitApp() { Img1 = new Tex2D("Data/ship1.png", true); fx = new FXLitImage(); G1 = new SceneGraph(); S1 = new GraphSprite("Data/ship1.png", 128, 128); var t1 = new Tex2D("Data/tile1.jpg"); for (int y = 0; y < 32; y++) { for (int x = 0; x < 32; x++) { var ns = new GraphSprite(t1, 128, 128); G1.Add(ns); ns.X = -(128 * 16) + x * 128; ns.Y = -(128 * 16) + y * 128; ns.Z = 1.0f; } } G1.Add(S1); S1.X = 0; S1.Y = 0; // G1.X = -16 * 32; // G1.Y = 16 * 32; S1.X = 0; S1.Y = 0; S1.Z = 1.3f; // G1.Add(S1); var rnd = new Random(); for (int i = 0; i < 25; i++) { var ns = new GraphSprite(S1.ImgFrame, 128, 128); ns.X = rnd.Next(-500, 500); ns.Y = rnd.Next(-500, 500); ns.Z = 0.1f + (float)rnd.NextDouble() * 3; // G1.Add(ns); } l1 = new GraphLight() { Range = 650, X = -100, Y = -100, Diffuse = new Vector3(0.4f, 1, 0.5f) }; l2 = new GraphLight() { Range = 640, X = 0, Y = 0, Diffuse = new Vector3(1.8f, 1.2f, 1.2f) }; G1.X = 0; G1.Y = 0; G1.Add(l1); l2.X = 300; VisualFX.Init(); PS1 = new VFXParticleSystem(); VisualFX.Add(PS1); VisualFX.Graph = G1; Part1 = new Tex2D("Data/part1.png", true); // var b1 = new var b1 = new SoftParticle(Part1); b1.XDrag = 0.95f; b1.YDrag = 0.95f; b1.ZDrag = 0.95f; b1.RDrag = 0.95f; PS1.XIJit = 5; PS1.YIJit = 2; PS1.PowerSmall = 1; PS1.PowerBig = 5; PS1.AddBase(b1); }