public override void Update() { timeLived_ += Core.lastDT; if (timeLived_ > lifeTime_) { entity.Destroy(); return; } entity.Position += entity.Direction * velocity_; Vector2 curPos = entity.Position; List <Fixture> cols = Physics.World.RayCast(lastPos, curPos); if (cols.Count > 0) { entity.Destroy(); foreach (Fixture col in cols) { // FSCollisionShape s = (FSCollisionShape) col.userData; // foreach (Component component in s.entity.getComponents<Component>()) // { // (component as FI_Damageable)?.InformHit(damage); // } } } Dbg.AddDebugLine(lastPos, curPos, Color.Red); lastPos = curPos; }
public override void Update() { int m = Keys.LeftShift.IsDown() ? 50 : 1; entity.Position += new Vector2( Keys.A.IsDown() ? -1 : Keys.D.IsDown() ? 1 : 0, Keys.W.IsDown() ? 1 : Keys.S.IsDown() ? -1 : 0 ) * Core.lastDT * 50f * m; entity.Rotation += Keys.Q.IsDown() ? 0.025f : Keys.E.IsDown() ? -0.025f : 0; if (Input.LMB.WasPressed()) { for (int i = 0; i < 1; i++) { // var newEnt = new Entity(entity.Position);// + new Vector2(r.Next(-10,10)/10f, r.Next(-10,10)/10f)); // newEnt.Direction = entity.Position-Core.mainCam.WorldMousePosition; // newEnt.AddComponent(new Projectile()); //newEnt.AddComponent(new Sprite(new SpriteData(Color.PaleVioletRed))); // newEnt.AddComponent(new Quad(new QuadData(Sheet.Get(Sheet.ID.Obj_crate12), new Vector2(1,1), true))); } } if (Keys.Z.WasPressed()) { entity.Position += Vector2.UnitX * 40; } if (Keys.Z.WasReleased()) { entity.Position += Vector2.UnitX * -40; } //Entity.KeepOriginForPosition(entity.Position); Dbg.AddDebugLine(entity.Position, Core.mainCam.WorldMousePosition, Color.Red); Dbg.AddDebugLine(entity.Position, entity.Position + entity.Direction, Color.White); Dbg.AddDebugText("PLAYER", entity.Position, Color.Green); }
public override void Update() { Vector2 lastPos = entity.Position; entity.Position += entity.Direction * speed_ * Core.lastDT; lifeTime_ += Core.lastDT; Dbg.AddDebugLine(lastPos, entity.Position, Color.Yellow); var hit = Physics.World.RayCastSingle(lastPos, entity.Position); if (hit.Key != null) { hit.Key.GetPhysicalBody().entity.Destroy(); SoundSystem.PlayOneShotAt(TestGame.ExplosionSound, entity.Position); entity.Destroy(); } else if (lifeTime_ > 5) { entity.Destroy(); } }
public override void Update() { float movement = Keys.W.IsDown() ? SPEED : Keys.S.IsDown() ? -SPEED : 0; float dbgmovement = Keys.D.IsDown() ? SPEED : Keys.A.IsDown() ? -SPEED : 0; float multiplier = Keys.LeftShift.IsDown() ? 2 : 0.5f; entity.Position += new Vector2(dbgmovement * Core.lastDT * multiplier, movement * multiplier * Core.lastDT); entity.Rotation += Keys.Q.IsDown() ? 0.03f : Keys.E.IsDown() ? -0.03f : 0; //TODO this is dbg if (Input.LMB.IsDown()) { entity.GetComponent <SoundPlayer>()?.Play(); //you'll want to cache this for (int i = 0; i < 32; i++) { var bullet = new Entity(entity.Position + Randy.UnitCircle(), Core.mainCam.WorldMousePosition - (entity.Position + Randy.UnitCircle())); new QuadComponent(bullet, new QuadData(Atlas.small_projectile)); //add quad to render bullet new Projectile(bullet, 60); // add projectile script to bullet } } Dbg.AddDebugLine(entity.Position, Core.mainCam.WorldMousePosition, Color.Green); }
public Tuple <int, IndexBuffer, DynamicVertexBuffer> GetOccludersBuffers(RectF rect) { if (!isDirty_ && rect.Equals(lastRectF_)) //TODO rectf ==, TODO mark dirty when occluders change/ctor { Dbg.Log("returning cached occluders data"); goto ReturnData; //TODO } isDirty_ = false; allOccludersSegments.Clear(); //TODO use array - low/med prior //collect all occluders segments in range foreach (LightOccluder occluder in GetComponentsInRect(rect)) { allOccludersSegments.AddRange(occluder.GlobalSegments); //TODO slooooow, pass list? } int verticesNeeded = allOccludersSegments.Count * 4 + 4; //each segment is a quad in vbo, PLUS the projector (first 4) // each miss we double our buffers ;) while (verticesNeeded > vb.VertexCount) { int newVtxQty = vb.VertexCount * 2; int newIdxQty = ib.IndexCount * 2; vb = new DynamicVertexBuffer(Graphics.Device, OccluderVertexFormat.VertexDeclaration, newVtxQty, BufferUsage.WriteOnly); ib = new IndexBuffer(Graphics.Device, IndexElementSize.ThirtyTwoBits, newIdxQty, BufferUsage.WriteOnly); int[] indices = new int[newIdxQty]; for (int i = 0, v = 0; i < newIdxQty; i += 6, v += 4) { indices[i + 0] = v + 0; indices[i + 1] = v + 1; indices[i + 2] = v + 2; indices[i + 3] = v + 0; indices[i + 4] = v + 2; indices[i + 5] = v + 3; } ib.SetData(indices); // copy to gfx, create actual IBO, once per resize } List <OccluderVertexFormat> verts = new List <OccluderVertexFormat>(verticesNeeded); //add projector (first 4 verts) verts.Add(new OccluderVertexFormat(new Vector3(0, 0, 0), 0, OccluderVertexFormat.Corner0)); //TODO use vert idx for id? verts.Add(new OccluderVertexFormat(new Vector3(1, 0, 0), 0, OccluderVertexFormat.Corner1)); verts.Add(new OccluderVertexFormat(new Vector3(1, 1, 0), 0, OccluderVertexFormat.Corner2)); verts.Add(new OccluderVertexFormat(new Vector3(0, 1, 0), 0, OccluderVertexFormat.Corner3)); //add shadow casters foreach (OccluderSegment segment in allOccludersSegments) { verts.Add(new OccluderVertexFormat(segment.A.ToVector3(), shadowBias)); verts.Add(new OccluderVertexFormat(segment.B.ToVector3(), shadowBias)); verts.Add(new OccluderVertexFormat(segment.B.ToVector3(), 1)); verts.Add(new OccluderVertexFormat(segment.A.ToVector3(), 1)); Dbg.AddDebugLine(segment.A, segment.B, Color.Cyan); } vb.SetData(verts.ToArray()); // copy to gfx, once per draw call ReturnData: return(new Tuple <int, IndexBuffer, DynamicVertexBuffer>(allOccludersSegments.Count, ib, vb)); //TODO descriptive object }