public void DrawNormalEyes(Room currentRoom) { Vector3 center = currentRoom.center; Vector3 outDirection = Engine.player.center.position - center; Vector3 up = Engine.player.cameraUp; outDirection.Normalize(); up.Normalize(); Vector3 right = Vector3.Cross(up, outDirection); VertexPositionColorNormalTexture[] eyeVertices = new VertexPositionColorNormalTexture[12]; Color eyeColor = Color.White; if (salvoCooldown < 800) { eyeColor.G = (Byte)(255f - (800f - 1f*salvoCooldown) / 800f * 150f); eyeColor.B = (Byte)(255f - (800f - 1f*salvoCooldown) / 800f * 150f); } eyeVertices[0] = new VertexPositionColorNormalTexture(center + outDirection * 6 + 2f * right, eyeColor, outDirection, Room.plateTexCoords[2]); eyeVertices[1] = new VertexPositionColorNormalTexture(center + outDirection * 6 + 1f * right + .2f * up, eyeColor, outDirection, Room.plateTexCoords[3]); eyeVertices[2] = new VertexPositionColorNormalTexture(center + outDirection * 6 + 2f * right + up, eyeColor, outDirection, Room.plateTexCoords[1]); eyeVertices[3] = new VertexPositionColorNormalTexture(center + outDirection * 6 + 1f * right + .2f * up, eyeColor, outDirection, Room.plateTexCoords[3]); eyeVertices[4] = new VertexPositionColorNormalTexture(center + outDirection * 6 + 2f * right + up, eyeColor, outDirection, Room.plateTexCoords[1]); eyeVertices[5] = new VertexPositionColorNormalTexture(center + outDirection * 6 + 1f * right + up, eyeColor, outDirection, Room.plateTexCoords[0]); eyeVertices[6] = new VertexPositionColorNormalTexture(center + outDirection * 6 - 2 * right, eyeColor, outDirection, Room.plateTexCoords[2]); eyeVertices[7] = new VertexPositionColorNormalTexture(center + outDirection * 6 - 1 * right + .2f * up, eyeColor, outDirection, Room.plateTexCoords[3]); eyeVertices[8] = new VertexPositionColorNormalTexture(center + outDirection * 6 - 2f * right + up, eyeColor, outDirection, Room.plateTexCoords[1]); eyeVertices[9] = eyeVertices[7]; eyeVertices[10] = eyeVertices[8]; eyeVertices[11] = new VertexPositionColorNormalTexture(center + outDirection * 6 - 1f * right + up, eyeColor, outDirection, Room.plateTexCoords[0]); Engine.playerTextureEffect.Texture = Monster.monsterTextures[(int)MonsterTextureId.FaceNormalEye]; Engine.playerTextureEffect.CurrentTechnique.Passes[0].Apply(); Game1.graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, eyeVertices, 0, eyeVertices.Count() / 3, VertexPositionColorNormalTexture.VertexDeclaration); }
public static void BlockUnfold(Room r, Vector3 normal, Vector3 up) { if (Engine.player.center.normal != Engine.player.oldNormal || Engine.player.center.direction != Engine.player.oldUp) { Engine.player.oldNormal = Engine.player.center.normal; Engine.player.oldUp = Engine.player.center.direction; refresh = true; } Vector3 right = Vector3.Cross(up, normal); foreach (Doodad d in r.doodads) { d.UpdateUnfoldedDoodad(r, normal, up); d.UpdateBoundingBox(Engine.player.up, Engine.player.right, refresh); } foreach (Monster m in r.monsters) { m.UpdateUnfoldedDoodad(r, normal, up); m.UpdateBoundingBox(Engine.player.up, Engine.player.right); } foreach (Projectile p in r.projectiles) { p.UpdateUnfoldedDoodad(r, normal, up); p.UpdateBoundingBox(Engine.player.up, Engine.player.right); } foreach (Block b in r.blocks) { if (b.staticObject == false || b.unfoldedBlocks.Count == 0 || refresh == true) { b.UpdateUnfoldedBlocks(r, normal, up); b.UpdateBoundingBox(Engine.player.up, Engine.player.right); } } refresh = false; }
public Wormhole(Vector3 position, Vector3 up, Vector3 normal, Room src, Room dest) { this.srcRoom = src; this.destRoom = dest; this.position = position; this.up = up; this.normal = normal; this.right = Vector3.Cross(normal, up); }
public Vertex Unfold(Room r, Vector3 n, Vector3 u) { Vector3 anchor = r.center + Math.Abs(Vector3.Dot(r.size / 2, n)) * n; Vertex v = new Vertex(); if (normal == n) { v.normal = normal; v.position = position; v.velocity = velocity; v.direction = direction; } else if (Vector3.Dot(normal, n) == 0) { Vector3 badComponent = Vector3.Dot(n, position - anchor) * n; Vector3 badVelComponent = Vector3.Dot(n, velocity) * n; Vector3 badDirComponent = Vector3.Dot(n, direction) * n; float badVelLength = Vector3.Dot(n, velocity); float badDirLength = Vector3.Dot(n, direction); v.position = position - badComponent + badComponent.Length() * normal; v.velocity = velocity - badVelComponent - badVelLength * normal; v.direction = direction - badDirComponent - badDirLength * normal; v.normal = n; } else { Vector3 upAnchor = r.center + Math.Abs(Vector3.Dot(r.size / 2, u)) * u; Vector3 badComponent = Vector3.Dot(u, position - upAnchor) * u; Vector3 gapComponent = Vector3.Dot(r.size, n) * n; float badVelLength = Vector3.Dot(u, velocity); float badDirLength = Vector3.Dot(u, direction); v.position = position - 2 * badComponent + gapComponent.Length() * n + gapComponent.Length() * u; v.velocity = velocity - 2*badVelLength * u; v.direction = direction - 2*badDirLength * u; v.normal = n; } return v; }
public void DrawAngryEyes(Room currentRoom) { Vector3 center = currentRoom.center; Vector3 outDirection = Engine.player.center.position - center; Vector3 up = Engine.player.cameraUp; outDirection.Normalize(); up.Normalize(); Vector3 right = Vector3.Cross(up, outDirection); VertexPositionColorNormalTexture[] eyeVertices = new VertexPositionColorNormalTexture[6]; eyeVertices[0] = new VertexPositionColorNormalTexture(center + outDirection * 6 + 2f * right, Color.White, outDirection, Room.plateTexCoords[2]); eyeVertices[1] = new VertexPositionColorNormalTexture(center + outDirection * 6 + 1f * right + .2f * up, Color.White, outDirection, Room.plateTexCoords[3]); eyeVertices[2] = new VertexPositionColorNormalTexture(center + outDirection * 6 + 2f * right + up, Color.White, outDirection, Room.plateTexCoords[1]); eyeVertices[3] = new VertexPositionColorNormalTexture(center + outDirection * 6 - 2 * right, Color.White, outDirection, Room.plateTexCoords[2]); eyeVertices[4] = new VertexPositionColorNormalTexture(center + outDirection * 6 - 1 * right + .2f * up, Color.White, outDirection, Room.plateTexCoords[3]); eyeVertices[5] = new VertexPositionColorNormalTexture(center + outDirection * 6 - 2f * right + up, Color.White, outDirection, Room.plateTexCoords[1]); Engine.playerTextureEffect.Texture = Monster.monsterTextures[(int)MonsterTextureId.FaceAngryEye]; Engine.playerTextureEffect.CurrentTechnique.Passes[0].Apply(); Game1.graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, eyeVertices, 0, eyeVertices.Count() / 3, VertexPositionColorNormalTexture.VertexDeclaration); }
public void Update(Room r, int updateTime, bool enforceVelocityConstraints) { position += updateTime * velocity; Vector3 relative = position - r.center; float overFlow = 0; Vector3 oldNormal = normal; if (relative.X > r.size.X / 2) { normal = new Vector3(1, 0, 0); overFlow = relative.X - r.size.X / 2; position.X -= overFlow; } if (relative.X < -r.size.X / 2) { normal = new Vector3(-1, 0, 0); overFlow = Math.Abs(relative.X) - r.size.X / 2; position.X += overFlow; } if (relative.Y > r.size.Y / 2) { normal = new Vector3(0, 1, 0); overFlow = relative.Y - r.size.Y / 2; position.Y -= overFlow; } if (relative.Y < -r.size.Y / 2) { normal = new Vector3(0, -1, 0); overFlow = Math.Abs(relative.Y) - r.size.Y / 2; position.Y += overFlow; } if (relative.Z > r.size.Z / 2) { normal = new Vector3(0, 0, 1); overFlow = relative.Z - r.size.Z / 2; position.Z -= overFlow; } if (relative.Z < -r.size.Z / 2) { normal = new Vector3(0, 0, -1); overFlow = Math.Abs(relative.Z) - r.size.Z / 2; position.Z += overFlow; } if (overFlow > 0) { position -= overFlow * oldNormal; Vector3 oldVelocity = Vector3.Dot(normal, velocity) * normal; Vector3 newVelocity = -oldVelocity.Length() * oldNormal; velocity = velocity - oldVelocity + newVelocity; float oldDirectionSign = Vector3.Dot(normal, direction); Vector3 oldDirection = oldDirectionSign * normal; Vector3 newDirection = -oldDirection.Length() * oldDirectionSign * oldNormal; direction = direction - oldDirection + newDirection; } if(enforceVelocityConstraints) velocity = velocity - Vector3.Dot(velocity, normal) * normal; }
public void Draw(Room r) { if (r.refreshVertices == true || ringList ==null ) { UpdateVertexList(r); r.staticRings.AddRange(ringList); } }
public void UpdateVertexData(Room currentRoom) { if (baseTriangleList == null || staticObject == false) { Engine.debug_blocksGenerated++; baseTriangleList = new List<VertexPositionColorNormalTexture>(); sideTriangleList = new List<VertexPositionColorNormalTexture>(); List<Vertex> vList = new List<Vertex>(); vList.Add(edges[0].start); vList.Add(edges[1].start); vList.Add(edges[2].start); vList.Add(edges[3].start); Color powerUpColor = GetCurrentColor(currentRoom); if (scales) { if (staticObject == false) { currentRoom.AddBlockToTriangleList2(vList, powerUpColor, depth, baseTriangleList); currentRoom.AddBlockSidesToTriangleList(vList, powerUpColor, depth, Room.plateTexCoords, sideTriangleList); } else { currentRoom.AddBlockToTriangleList2(vList, powerUpColor, depth, baseTriangleList); currentRoom.AddBlockSidesToTriangleList(vList, powerUpColor, depth, Room.plateTexCoords, sideTriangleList); } } else { if (staticObject == false) { currentRoom.AddBlockToTriangleList(vList, powerUpColor, depth, Room.plateTexCoords, baseTriangleList); currentRoom.BasicAddBlockSidesToTriangleList(vList, powerUpColor, depth, Room.plateTexCoords, sideTriangleList); } else { currentRoom.AddBlockToTriangleList(vList, powerUpColor, depth, Room.plateTexCoords, baseTriangleList); currentRoom.BasicAddBlockSidesToTriangleList(vList, powerUpColor, depth, Room.plateTexCoords, sideTriangleList); } } if (staticObject == false) { baseTriangleArray = baseTriangleList.ToArray(); sideTriangleArray = sideTriangleList.ToArray(); } else { if (wallType == VL.WallType.Plate || wallType == VL.WallType.Cargo || wallType == VL.WallType.Crate) { for (int i = 0; i < baseTriangleList.Count(); i++) { int index = (int)wallType; currentRoom.masterBlockArray[(int)wallType][cacheOffset[(int)wallType] + i] = baseTriangleList[i]; } for (int i = 0; i < sideTriangleList.Count(); i++) { currentRoom.masterBlockArray[(int)VL.WallType.FancyPlate][cacheOffset[(int)VL.WallType.FancyPlate] + i] = sideTriangleList[i]; } } else if (wallType == VL.WallType.Gearslot) { for (int i = 0; i < baseTriangleList.Count(); i++) { currentRoom.masterBlockArray[(int)VL.WallType.FancyPlate][cacheOffset[(int)VL.WallType.FancyPlate] + i] = baseTriangleList[i]; } for (int i = 0; i < sideTriangleList.Count(); i++) { currentRoom.masterBlockArray[(int)wallType][cacheOffset[(int)wallType] + i] = sideTriangleList[i]; } } else { for(int i = 0; i < baseTriangleList.Count(); i++) { currentRoom.masterBlockArray[(int)wallType][cacheOffset[(int)wallType] + i] = baseTriangleList[i]; } for (int i = 0; i < sideTriangleList.Count(); i++) { currentRoom.masterBlockArray[(int)wallType][cacheOffset[(int)wallType] + baseTriangleList.Count() + i] = sideTriangleList[i]; } } } } if (currentRoom.refreshVertices == true && staticObject == true) { Color powerUpColor = GetCurrentColor(currentRoom); if (wallType == VL.WallType.Plate || wallType == VL.WallType.Cargo || wallType == VL.WallType.Crate) { for (int i = 0; i < baseTriangleList.Count(); i++) { if (baseTriangleList[i].Color.A == 254) { currentRoom.masterBlockArray[(int)wallType][cacheOffset[(int)wallType] + i].Color = FakeShader.RearShade(FakeShader.Shade(powerUpColor, baseTriangleList[i].Normal)); } else { currentRoom.masterBlockArray[(int)wallType][cacheOffset[(int)wallType] + i].Color = FakeShader.Shade(powerUpColor, baseTriangleList[i].Normal); } } for (int i = 0; i < sideTriangleList.Count(); i++) { if (sideTriangleList[i].Color.A == 254) { currentRoom.masterBlockArray[(int)VL.WallType.FancyPlate][cacheOffset[(int)VL.WallType.FancyPlate] + i].Color = FakeShader.RearShade(FakeShader.Shade(powerUpColor, sideTriangleList[i].Normal)); } else { currentRoom.masterBlockArray[(int)VL.WallType.FancyPlate][cacheOffset[(int)VL.WallType.FancyPlate] + i].Color = FakeShader.Shade(powerUpColor, sideTriangleList[i].Normal); } } } else if (wallType == VL.WallType.Gearslot) { for (int i = 0; i < baseTriangleList.Count(); i++) { if (baseTriangleList[i].Color.A == 254) { currentRoom.masterBlockArray[(int)VL.WallType.FancyPlate][cacheOffset[(int)VL.WallType.FancyPlate] + i].Color = FakeShader.RearShade(FakeShader.Shade(powerUpColor, baseTriangleList[i].Normal)); } else { currentRoom.masterBlockArray[(int)VL.WallType.FancyPlate][cacheOffset[(int)VL.WallType.FancyPlate] + i].Color = FakeShader.Shade(powerUpColor, baseTriangleList[i].Normal); } } for (int i = 0; i < sideTriangleList.Count(); i++) { if (sideTriangleList[i].Color.A == 254) { currentRoom.masterBlockArray[(int)wallType][cacheOffset[(int)wallType] + i].Color = FakeShader.RearShade(FakeShader.Shade(powerUpColor, sideTriangleList[i].Normal)); } else { currentRoom.masterBlockArray[(int)wallType][cacheOffset[(int)wallType] + i].Color = FakeShader.Shade(powerUpColor, sideTriangleList[i].Normal); } } } else { for (int i = 0; i < baseTriangleList.Count(); i++) { if (baseTriangleList[i].Color.A == 254) { currentRoom.masterBlockArray[(int)wallType][cacheOffset[(int)wallType] + i].Color = FakeShader.RearShade(FakeShader.Shade(powerUpColor, baseTriangleList[i].Normal)); } else { currentRoom.masterBlockArray[(int)wallType][cacheOffset[(int)wallType] + i].Color = FakeShader.Shade(powerUpColor, baseTriangleList[i].Normal); } } for (int i = 0; i < sideTriangleList.Count(); i++) { if (sideTriangleList[i].Color.A == 254) { currentRoom.masterBlockArray[(int)wallType][cacheOffset[(int)wallType] + baseTriangleList.Count() + i].Color = FakeShader.RearShade(FakeShader.Shade(powerUpColor, sideTriangleList[i].Normal)); } else { currentRoom.masterBlockArray[(int)wallType][cacheOffset[(int)wallType] + baseTriangleList.Count() + i].Color = FakeShader.Shade(powerUpColor, sideTriangleList[i].Normal); } } } } }
public Color GetCurrentColor(Room currentRoom) { Color powerUpColor = color; if (currentRoom.maxOrbs != 0) { powerUpColor.R = (Byte)(40 + currentRoom.currentOrbs * (color.R - 40) / currentRoom.maxOrbs); powerUpColor.G = (Byte)(40 + currentRoom.currentOrbs * (color.G - 40) / currentRoom.maxOrbs); powerUpColor.B = (Byte)(40 + currentRoom.currentOrbs * (color.B - 40) / currentRoom.maxOrbs); } return powerUpColor; }
public Block(List<Vertex> vList, List<EdgeProperties> edgePropertiesList, Room r, Vector3 n, Vector3 u) { Vector3 anchor = r.center + Math.Abs(Vector3.Dot(r.size/2,n))*n; edges = new List<Edge>(); for (int i = 0; i < 4; i++) { Edge newEdge = new Edge(); newEdge.start = vList[i].Unfold(r, n, u); newEdge.end = vList[(i+1)%4].Unfold(r, n, u); newEdge.properties = edgePropertiesList[i]; edges.Add(newEdge); } }
/* Test for collision between player and blocks, and adjust player's position and velocity accordingly. * There's some tricky order of operations here that is explained inline*/ public static void CollisionCheck(Room r, Player p, int gameTime) { // Variables used for entire collision test method. Physics.BlockUnfold(r, p.center.normal, p.center.direction); List<Vector3> playerVertexList = new List<Vector3>(); List<Vector3> playerGroundBox = new List<Vector3>(); List<Vector3> playerLeftBox = new List<Vector3>(); List<Vector3> playerRightBox = new List<Vector3>(); Vector3 up = p.center.direction; Vector3 right = Vector3.Cross(up, p.center.normal); /* Stores the result of friction calculations, to be applied at the END of the function. Must be done at the end * because during the algorithm, it isn't fully determined what the player's state is, and friction is only applied * in certain cases. Specifically, it isn't known if the player has landed on the ground until the algorithm completes. */ Vector3 frictionAdjustment = Vector3.Zero; /* Perform the basic algorithm several times, each time taking only the most powerful contribution. I'm assuming for now * that it is EXTREMELY unlikely for the player to have meaningful collisions simultaneously with > 3 blocks. * The purpose of this is that sometimes two collisions will be detected, but only one needs to be resolved. For example, * if two blocks are adjacent to one another such that their edges form a single, straight edge, we only need (and want) * to use the projection from one of them*/ #region player-block collision if(p.state != State.Phase && p.state != State.PhaseFail && p.state != State.Tunnel && p.state != State.Jump && p.state != State.Death) { for (int attempt = 0; attempt < 2; attempt++) { playerVertexList = p.GetCollisionRect(); List<Vector3> projectionList = new List<Vector3>(); List<Vector3> relVelList = new List<Vector3>(); List<EdgeProperties> edgePropertiesList = new List<EdgeProperties>(); foreach (Block baseBlock in r.blocks) { foreach (Block b in baseBlock.unfoldedBlocks) { if (p.CollisionFirstPass(b)) continue; List<Vector3> blockVertexList = b.GetCollisionRect(); Vector3 projection = Collide(playerVertexList, blockVertexList, p.center.normal); // If a collision is found, save the necessary data and continue. if (projection.Length() > 0f) { projectionList.Add(projection); relVelList.Add(b.GetVelocity()); EdgeProperties eTemp = b.GetProperties(projection); edgePropertiesList.Add(b.GetProperties(projection)); } } } foreach (Doodad d in r.doodads) { if (p.CollisionFirstPass(d)) continue; if (d.type == VL.DoodadType.BridgeGate) { List<Vector3> doodadVertexList = d.GetCollisionRect(); Vector3 projection = Collide(playerVertexList, doodadVertexList, p.center.normal); d.ActivateDoodad(r, projection.Length() > 0f); } if (d.hasCollisionRect && d.type != VL.DoodadType.PowerPlug) { List<Vector3> doodadVertexList = d.GetCollisionRect(); Vector3 projection = Collide(playerVertexList, doodadVertexList, p.center.normal); if (projection.Length() > 0f) { projectionList.Add(projection); relVelList.Add(d.position.velocity); edgePropertiesList.Add(new EdgeProperties()); } } } foreach (Monster m in r.monsters) { if (p.CollisionFirstPass(m)) continue; if (m.dead == true) continue; if (m.moveType == VL.MovementType.SnakeBoss) { List<Vector3> monsterVertexList = m.GetCollisionRect(); Vector3 projection = Collide(playerVertexList, monsterVertexList, Engine.player.center.normal); if (projection.Length() > 0f) { projectionList.Add(projection); relVelList.Add(m.position.velocity); edgePropertiesList.Add(new EdgeProperties()); } } } // Compute the most powerful collision and resolve it. CollisionResult result = ResolveCollision(projectionList, relVelList, edgePropertiesList, p.center.velocity, p.HasTraction()); if (result.properties != null && result.properties.type == VL.EdgeType.Ice && Vector3.Dot(result.projection, p.center.direction) > 0) p.sliding = true; else p.sliding = false; p.center.velocity += result.velocityAdjustment; frictionAdjustment += result.frictionAdjustment; if(result.projection != Vector3.Zero) { p.center.position += result.projection; if (result.properties.type == VL.EdgeType.Spikes || (result.properties.type == VL.EdgeType.Electric && result.properties.primaryValue > 0) || (result.properties.type == VL.EdgeType.Fire && result.properties.primaryValue > 0)) { p.Damage(result.projection, false); } if (result.projection.Length() > p.playerHalfWidth) { if (p.boosting == true) p.boosting = false; else p.Damage(result.projection,true); } } else break; } List<Vector3> pVertexList = p.GetCollisionRect(); foreach (Projectile s in r.projectiles) { if (s.active == true && s.exploding == false && (s.type != ProjectileType.EyeLaser || Math.Abs(s.depth - p.depth) < .5f)) { if (s.srcMonster == null && (s.type == ProjectileType.Missile || s.type == ProjectileType.Bomb)) continue; s.UpdateBoundingBox(p.center.direction, Vector3.Cross(p.center.direction, p.center.normal)); if (p.CollisionFirstPass(s) == false) { List<Vector3> projectileVertexList = s.GetCollisionRect(); Vector3 projection = Collide(pVertexList, projectileVertexList, Engine.player.center.normal); if (projection != Vector3.Zero) { p.Damage(projection,false); s.Detonate(); s.position.velocity = Vector3.Zero; } } } } foreach (Monster m in r.monsters) { if (m.dead == true) continue; m.UpdateBoundingBox(p.center.direction, Vector3.Cross(p.center.direction, p.center.normal)); if (p.CollisionFirstPass(m) == false) { if (m.moveType == VL.MovementType.ChaseBoss) { List<Vector3> monsterVertexList = m.GetCollisionRect(); Vector3 projection = Collide(playerVertexList, monsterVertexList, Engine.player.center.normal); if (projection.Length() > 0f) { if (m.position.velocity != Vector3.Zero) p.Damage(m.position.velocity,false); else p.Damage(projection,false); } } else if (m.moveType != VL.MovementType.SnakeBoss) { Vector3 distance = (p.center.position - m.unfoldedPosition.position); if (distance.Length() < (p.playerHalfHeight + m.halfHeight)) { Vector3 projection = Vector3.Normalize(distance) * ((p.playerHalfHeight + m.halfHeight) - distance.Length()); p.Damage(projection, false); } } } } foreach (Doodad d in r.doodads) { if (d.type == VL.DoodadType.Beam) { d.UpdateBoundingBox(p.center.direction, Vector3.Cross(p.center.direction, p.center.normal)); if (p.CollisionFirstPass(d) == false) { List<Vector3> doodadVertexList = d.GetCollisionRect(); Vector3 projection = Collide(pVertexList, doodadVertexList, Engine.player.center.normal); if (projection != Vector3.Zero) { p.Damage(projection,false); } } } } // Now that player position is stabilized, use the special rects to detect if it is grounded // or prepped for a wall jump. #region special-blocks for ground and walljump detection playerGroundBox.Add(p.center.position + p.playerHalfWidth * right); playerGroundBox.Add(p.center.position - p.playerHalfWidth * right); playerGroundBox.Add(p.center.position - (p.playerHalfHeight + .1f) * up - p.playerHalfWidth * right); playerGroundBox.Add(p.center.position - (p.playerHalfHeight + .1f) * up + p.playerHalfWidth * right); playerLeftBox.Add(p.center.position); playerLeftBox.Add(p.center.position - (p.playerHalfWidth + .1f) * right); playerLeftBox.Add(p.center.position - (p.playerHalfHeight - .1f) * up - (p.playerHalfWidth + .1f) * right); playerLeftBox.Add(p.center.position - (p.playerHalfHeight - .1f) * up); playerRightBox.Add(p.center.position + (p.playerHalfWidth + .1f) * right); playerRightBox.Add(p.center.position); playerRightBox.Add(p.center.position - (p.playerHalfHeight - .1f) * up); playerRightBox.Add(p.center.position - (p.playerHalfHeight - .1f) * up + (p.playerHalfWidth + .1f) * right); p.leftWall = false; p.rightWall = false; //p.platformVelocity = Vector3.Zero; foreach (Block baseBlock in r.blocks) { foreach (Block b in baseBlock.unfoldedBlocks) { if (p.boundingBoxBottom > b.boundingBoxTop + 1 || p.boundingBoxTop < b.boundingBoxBottom - 1 || p.boundingBoxLeft > b.boundingBoxRight + 1 || p.boundingBoxRight < b.boundingBoxLeft - 1) continue; // if block intesects with rectVertexList List<Vector3> blockVertexList = b.GetCollisionRect(); Vector3 groundProjection = Collide(playerGroundBox, blockVertexList, p.center.normal); Vector3 leftProjection = Collide(playerLeftBox, blockVertexList, p.center.normal); Vector3 rightProjection = Collide(playerRightBox, blockVertexList, p.center.normal); //if (Vector3.Dot(groundProjection, up) > 0) //if (groundProjection != Vector3.Zero) if (groundProjection.Length() > .001f) { p.grounded = true; EdgeProperties properties = b.GetProperties(groundProjection); p.platformVelocity = b.GetVelocity(); if (properties.type == VL.EdgeType.ConveyorBelt) { Vector3 lateralDirection = Vector3.Cross(groundProjection, p.center.normal); lateralDirection.Normalize(); p.platformVelocity += .001f * properties.primaryValue * lateralDirection; } } if (Vector3.Dot(leftProjection, right) > 0) { p.leftWall = true; EdgeProperties properties = b.GetProperties(leftProjection); p.platformVelocity = b.GetVelocity(); if (properties.type == VL.EdgeType.Magnet) { p.Spin(leftProjection / leftProjection.Length()); } } if (Vector3.Dot(rightProjection, -right) != 0) { p.rightWall = true; EdgeProperties properties = b.GetProperties(rightProjection); p.platformVelocity = b.GetVelocity(); if (properties.type == VL.EdgeType.Magnet) { p.Spin(rightProjection / rightProjection.Length()); } } } } foreach (Doodad b in r.doodads) { if (b.hasCollisionRect && b.type != VL.DoodadType.PowerPlug) { b.UpdateBoundingBox(p.center.direction, p.right); if (p.boundingBoxBottom > b.boundingBoxTop +2f || p.boundingBoxTop < b.boundingBoxBottom-2f || p.boundingBoxLeft > b.boundingBoxRight+2f || p.boundingBoxRight < b.boundingBoxLeft-2f) continue; // if block intesects with rectVertexList List<Vector3> brickVertexList = b.GetCollisionRect(); Vector3 groundProjection = Collide(playerGroundBox, brickVertexList, p.center.normal); Vector3 leftProjection = Collide(playerLeftBox, brickVertexList, p.center.normal); Vector3 rightProjection = Collide(playerRightBox, brickVertexList, p.center.normal); if (Vector3.Dot(groundProjection, up) > 0) { p.grounded = true; p.platformVelocity = b.position.velocity; } if (Vector3.Dot(leftProjection, right) > 0) { p.leftWall = true; p.platformVelocity = b.position.velocity; } if (Vector3.Dot(rightProjection, -right) != 0) { p.rightWall = true; p.platformVelocity = b.position.velocity; } } } foreach (Monster m in r.monsters) { if (p.CollisionFirstPass(m)) continue; if (m.dead == true) continue; if (m.moveType == VL.MovementType.SnakeBoss || m.moveType == VL.MovementType.ChaseBoss) { m.UpdateBoundingBox(p.center.direction, p.right); if (p.boundingBoxBottom > m.boundingBoxTop + 2f || p.boundingBoxTop < m.boundingBoxBottom - 2f || p.boundingBoxLeft > m.boundingBoxRight + 2f || p.boundingBoxRight < m.boundingBoxLeft - 2f) continue; // if block intesects with rectVertexList List<Vector3> brickVertexList = m.GetCollisionRect(); Vector3 groundProjection = Collide(playerGroundBox, brickVertexList, p.center.normal); Vector3 leftProjection = Collide(playerLeftBox, brickVertexList, p.center.normal); Vector3 rightProjection = Collide(playerRightBox, brickVertexList, p.center.normal); if (Vector3.Dot(groundProjection, up) > 0) { p.grounded = true; p.platformVelocity = m.position.velocity; } if (Vector3.Dot(leftProjection, right) > 0) { p.leftWall = true; p.platformVelocity = m.position.velocity; } if (Vector3.Dot(rightProjection, -right) != 0) { p.rightWall = true; p.platformVelocity = m.position.velocity; } } } #endregion // Now that we know if the player is grounded or not, we can use the walking property to determine whether or // not we should apply friction. if (!p.walking && !p.boosting) p.center.velocity += frictionAdjustment; } #endregion #region doodad-activation // Test and activate doodads. foreach (Doodad d in r.doodads) { if (d.type == VL.DoodadType.DialogPoint) { if (d.active == false && d.ActivationRange(p)) { DialogBox.SetDialog(d.targetObject); d.active = true; } } if (d.type == VL.DoodadType.TriggerPoint) { if (d.active == false && d.id.Contains("Dialog") && d.ActivationRange(p)) { DialogBox.SetDialog(d.targetObject); d.active = true; } if (d.id.Contains("Rock2Trigger") && d.ActivationRange(p)) RockBoss.triggered = true; } if (d.type == VL.DoodadType.Checkpoint) { d.ActivateDoodad(r, d == p.respawnPoint); } if (d.type == VL.DoodadType.Vortex || d.type == VL.DoodadType.JumpPad || d.type == VL.DoodadType.ItemBlock || d.isStation) { if(Engine.player.state != State.Upgrade && Engine.player.state != State.Save) d.ActivateDoodad(r, d.ActivationRange(p)); } if (d.type == VL.DoodadType.Holoprojector) { d.ActivateDoodad(r, d.ActivationRange(p)); } if( (d.position.position - p.center.position).Length() < 3f*d.triggerDistance) { if (d.isOrb && d.active) { d.tracking = true; } } if ((d.position.position - p.center.position).Length() < d.triggerDistance) { if (d.type == VL.DoodadType.PowerOrb) { if(d.active == true) { d.ActivateDoodad(r, false); d.position.direction = Vector3.Zero; d.position.normal = Vector3.Zero; d.position.position = Vector3.Zero; d.refreshVertexData = true; foreach (Doodad powerup in d.currentRoom.doodads) powerup.RefreshPowerLevels(); r.currentOrbs++; r.parentSector.currentOrbs++; r.refreshVertices = true; p.orbsCollected++; SoundFX.CollectOrb(); } } if (d.type == VL.DoodadType.RedCube) { if (d.active == true) { d.ActivateDoodad(r, false); r.currentRedOrbs++; r.parentSector.currentRedOrbs++; r.refreshVertices = true; p.redOrbsCollected++; if (p.redOrbsCollected % 5 == 0) { p.naturalShield.maxAmmo = p.naturalShield.maxAmmo + 1; p.naturalShield.ammo = p.naturalShield.maxAmmo; } SoundFX.CollectOrb(); } } if (d.type == VL.DoodadType.BlueCube) { if (d.active == true) { d.ActivateDoodad(r, false); r.currentBlueOrbs++; r.parentSector.currentBlueOrbs++; r.refreshVertices = true; SoundFX.CollectOrb(); } } if (d.type == VL.DoodadType.Checkpoint) { if (p.respawnPoint != d) { LevelLoader.QuickSave(); p.respawnPoint = d; p.respawnPlayer = new Player(); p.respawnPlayer.currentRoom = p.currentRoom; p.respawnPlayer.center = new Vertex(d.position.position, p.center.normal, Vector3.Zero, p.center.direction); } } if(d.type == VL.DoodadType.WallSwitch) { d.Activate(); } } } #endregion #region doodadCollisionDetection foreach(Doodad d in r.doodads) { if (d.freeMotion == true) { frictionAdjustment = Vector3.Zero; for (int attempt = 0; attempt < 2; attempt++) { List<Vector3> projectionList = new List<Vector3>(); List<Vector3> relVelList = new List<Vector3>(); List<EdgeProperties> edgePropertiesList = new List<EdgeProperties>(); List<Vector3> doodadVertexList = d.GetCollisionRect(); d.UpdateBoundingBox(p.center.direction, Vector3.Cross(p.center.direction, p.center.normal)); foreach (Block baseBlock in r.blocks) { foreach (Block b in baseBlock.unfoldedBlocks) { if (d.CollisionFirstPass(b)) continue; List<Vector3> blockVertexList = b.GetCollisionRect(); Vector3 projection = Collide(doodadVertexList, blockVertexList, p.center.normal); if (projection.Length() > 0f) { projectionList.Add(projection); relVelList.Add(b.GetVelocity()); edgePropertiesList.Add(b.GetProperties(projection)); } } } foreach (Doodad b in r.doodads) { b.UpdateBoundingBox(p.center.direction, Vector3.Cross(p.center.direction, p.center.normal)); if (b.hasCollisionRect && b != d) { if (d.CollisionFirstPass(b)) continue; List<Vector3> brickVertexList = b.GetCollisionRect(); Vector3 projection = Collide(doodadVertexList, brickVertexList, p.center.normal); if (projection.Length() > 0f) { projectionList.Add(projection); relVelList.Add(b.position.velocity); edgePropertiesList.Add(new EdgeProperties()); } } } CollisionResult result = ResolveCollision(projectionList, relVelList, edgePropertiesList, d.unfoldedPosition.velocity, false); if(result.projection != Vector3.Zero) { d.AdjustVertex(result.projection, result.velocityAdjustment + result.frictionAdjustment, p.center.normal, p.center.direction); d.position.Update(p.currentRoom, 0); d.unfoldedPosition.position += result.projection; d.unfoldedPosition.velocity += result.velocityAdjustment; d.unfoldedPosition.velocity += result.frictionAdjustment; } else break; } } } foreach (Doodad d in r.doodads) { if (d.freeMotion) { foreach (Doodad b in r.doodads) { if ((d.position.position - b.position.position).Length() < b.triggerDistance) { if (b.type == VL.DoodadType.WallSwitch) { b.Activate(); } if (b.type == VL.DoodadType.PlugSlot && d.type == VL.DoodadType.PowerPlug) { d.position.position = b.position.position; if (d.active == false) { d.SetTargetBehavior(); } d.active = true; } } } } } #endregion #region monsters bool smashRockBarrier = false; foreach (Monster m in r.monsters) { if (m.moveType == VL.MovementType.FaceBoss) continue; if (m.dead == true) continue; frictionAdjustment = Vector3.Zero; for (int attempt = 0; attempt < 2; attempt++) { List<Vector3> projectionList = new List<Vector3>(); List<Vector3> relVelList = new List<Vector3>(); List<EdgeProperties> edgePropertiesList = new List<EdgeProperties>(); List<Vector3> monsterVertexList = m.GetCollisionRect(); m.UpdateBoundingBox(p.center.direction, Vector3.Cross(p.center.direction, p.center.normal)); foreach (Block baseBlock in r.blocks) { foreach (Block b in baseBlock.unfoldedBlocks) { if (m.CollisionFirstPass(b)) continue; List<Vector3> blockVertexList = b.GetCollisionRect(); Vector3 projection = Collide(monsterVertexList, blockVertexList, p.center.normal); if (projection.Length() > 0f) { projectionList.Add(projection); relVelList.Add(b.GetVelocity()); edgePropertiesList.Add(b.GetProperties(projection)); } } } foreach (Doodad b in r.doodads) { b.UpdateBoundingBox(p.center.direction, Vector3.Cross(p.center.direction, p.center.normal)); if (b.hasCollisionRect && b.type != VL.DoodadType.PowerPlug) { if (m.CollisionFirstPass(b)) continue; if (m.moveType == VL.MovementType.RockBoss && b.id.Contains("RockBarrier")) { smashRockBarrier = true; } if (m.moveType == VL.MovementType.ChaseBoss && b.id.Contains("ChaseBarrier")) { smashRockBarrier = true; } if (m.moveType == VL.MovementType.ChaseBoss && b.id.Contains("ChaseStop")) { ChaseBoss.studder = true; } if (m.moveType == VL.MovementType.ChaseBoss && b.type == VL.DoodadType.Brick) { b.ActivateDoodad(r, true); continue; } List<Vector3> brickVertexList = b.GetCollisionRect(); Vector3 projection = Collide(monsterVertexList, brickVertexList, p.center.normal); if (projection.Length() > 0f) { if (m.moveType == VL.MovementType.RockBoss && b.type == VL.DoodadType.Crate) { if (m.rockBoss.rockHits > 0) { m.impactVector = projection; m.lastHitType = ProjectileType.Impact; } continue; } projectionList.Add(projection); relVelList.Add(b.position.velocity); edgePropertiesList.Add(new EdgeProperties()); } } } CollisionResult result = ResolveCollision(projectionList, relVelList, edgePropertiesList, m.unfoldedPosition.velocity, false); if (result.projection != Vector3.Zero) { m.AdjustVertex(result.projection, result.velocityAdjustment, p.center.normal, p.center.direction); m.position.Update(p.currentRoom, 0); m.unfoldedPosition.position += result.projection; m.unfoldedPosition.velocity += result.velocityAdjustment; if (result.properties.type == VL.EdgeType.Spikes) { m.impactVector = Monster.AdjustVector(result.projection, m.position.normal, Engine.player.center.normal, Engine.player.center.direction, true); m.lastHitType = ProjectileType.Spikes; } if (result.projection.Length() > m.halfWidth) { m.impactVector = Monster.AdjustVector(result.projection, m.position.normal, Engine.player.center.normal, Engine.player.center.direction, true); m.lastHitType = ProjectileType.Spikes; } if (Vector3.Dot(m.position.direction, Monster.AdjustVector(result.projection, m.position.normal, p.center.normal, p.center.direction, true)) <= 0) { m.AdjustVertex(Vector3.Zero, result.frictionAdjustment, p.center.normal, p.center.direction); m.unfoldedPosition.velocity += result.frictionAdjustment; } } else break; } List<Vector3> mVertexList = m.GetCollisionRect(); m.UpdateBoundingBox(p.center.direction, Vector3.Cross(p.center.direction, p.center.normal)); foreach (Monster m2 in r.monsters) { if (m == m2 || m2.dead == true) continue; if (m.moveType == VL.MovementType.SnakeBoss && m2.moveType == VL.MovementType.SnakeBoss) continue; m2.UpdateBoundingBox(p.center.direction, Vector3.Cross(p.center.direction, p.center.normal)); if (m.CollisionFirstPass(m2)) continue; List<Vector3> brickVertexList = m2.GetCollisionRect(); Vector3 projection = Collide(mVertexList, brickVertexList, p.center.normal); if (projection.Length() > 0f) { m.AdjustVertex(.3f*projection, Vector3.Zero, p.center.normal, p.center.direction); m.position.Update(p.currentRoom, 0); m.unfoldedPosition.position += .3f * projection; m2.AdjustVertex(-.3f * projection, Vector3.Zero, p.center.normal, p.center.direction); m2.position.Update(p.currentRoom, 0); m2.unfoldedPosition.position -= .3f * projection; } } foreach (Projectile s in r.projectiles) { if (s.type == ProjectileType.EyeLaser) continue; if (s.type == ProjectileType.Missile && s.srcMonster == null && (s.position.position - m.position.position).Length() < 7f) { s.SetTarget(m.position.position); } //if (s.active == true || m != s.srcMonster) if (s.srcMonster != null && s.srcMonster.moveType == VL.MovementType.SnakeBoss && m.moveType == VL.MovementType.SnakeBoss) continue; if (m != s.srcMonster) { s.UpdateBoundingBox(p.center.direction, Vector3.Cross(p.center.direction, p.center.normal)); if (m.CollisionFirstPass(s) == false) { List<Vector3> projectileVertexList = s.GetCollisionRect(); Vector3 projection = Collide(mVertexList, projectileVertexList, Engine.player.center.normal); if (projection != Vector3.Zero) { s.Detonate(); m.impactVector = Monster.AdjustVector(s.position.velocity, m.position.normal, Engine.player.center.normal, Engine.player.center.direction, true); m.lastHitType = s.type; s.position.velocity = Vector3.Zero; } } } } List<Vector3> monsterGroundBox = m.GetGroundCollisionRect(); List<Vector3> monsterForwardGroundBox = m.GetForwardGroundCollisionRect(); List<Vector3> monsterForwardBox = m.GetForwardCollisionRect(); m.groundProjection = Vector3.Zero; m.forwardGroundProjection = Vector3.Zero; m.forwardProjection = Vector3.Zero; foreach (Block baseBlock in r.blocks) { foreach (Block b in baseBlock.unfoldedBlocks) { if (m.boundingBoxBottom > b.boundingBoxTop + 2 || m.boundingBoxTop < b.boundingBoxBottom - 2 || m.boundingBoxLeft > b.boundingBoxRight + 2 || m.boundingBoxRight < b.boundingBoxLeft - 2) continue; // if block intesects with rectVertexList List<Vector3> blockVertexList = b.GetCollisionRect(); Vector3 groundProjection = Collide(monsterGroundBox, blockVertexList, p.center.normal); Vector3 forwardGroundProjection = Collide(monsterForwardGroundBox, blockVertexList, p.center.normal); Vector3 forwardProjection = Collide(monsterForwardBox, blockVertexList, p.center.normal); if (forwardGroundProjection != Vector3.Zero) m.forwardGroundProjection = Monster.AdjustVector(forwardGroundProjection, m.position.normal, p.center.normal, p.center.direction, true); if (forwardProjection != Vector3.Zero) m.forwardProjection = Monster.AdjustVector(forwardProjection, m.position.normal, p.center.normal, p.center.direction, true); if (groundProjection != Vector3.Zero) m.groundProjection = Monster.AdjustVector(groundProjection, m.position.normal, p.center.normal, p.center.direction, true); } } foreach (Monster m2 in r.monsters) { if (m == m2 || m2.dead == true) continue; if (m.boundingBoxBottom > m2.boundingBoxTop + 2 || m.boundingBoxTop < m2.boundingBoxBottom - 2 || m.boundingBoxLeft > m2.boundingBoxRight + 2 || m.boundingBoxRight < m2.boundingBoxLeft - 2) continue; // if block intesects with rectVertexList List<Vector3> blockVertexList = m2.GetCollisionRect(); Vector3 forwardProjection = Collide(monsterForwardBox, blockVertexList, p.center.normal); if (forwardProjection != Vector3.Zero) { m.forwardProjection = Monster.AdjustVector(forwardProjection, m.position.normal, p.center.normal, p.center.direction, true); } } } if (smashRockBarrier == true) { foreach (Doodad d in r.doodads) { if (d.id.Contains("RockBarrier") || d.id.Contains("ChaseBarrier")) { d.ActivateDoodad(r, true); } } } #endregion #region projectile-collisions foreach (Projectile s in r.projectiles) { if (s.type == ProjectileType.EyeLaser) continue; frictionAdjustment = Vector3.Zero; List<Vector3> projectionList = new List<Vector3>(); List<Vector3> relVelList = new List<Vector3>(); List<EdgeProperties> edgePropertiesList = new List<EdgeProperties>(); List<Vector3> doodadVertexList = s.GetCollisionRect(); s.UpdateBoundingBox(p.center.direction, Vector3.Cross(p.center.direction, p.center.normal)); foreach (Block baseBlock in r.blocks) { foreach (Block b in baseBlock.unfoldedBlocks) { if (s.CollisionFirstPass(b)) continue; List<Vector3> blockVertexList = b.GetCollisionRect(); Vector3 projection = Collide(doodadVertexList, blockVertexList, p.center.normal); if (projection != Vector3.Zero) { s.Detonate(); s.position.velocity = Vector3.Zero; } } } foreach (Doodad b in r.doodads) { b.UpdateBoundingBox(p.center.direction, Vector3.Cross(p.center.direction, p.center.normal)); if ((b.hasCollisionRect && b.type != VL.DoodadType.PowerPlug) || (b.type == VL.DoodadType.LaserSwitch && s.type == ProjectileType.Laser && b.active == false)) { if (s.CollisionFirstPass(b)) continue; List<Vector3> brickVertexList = b.GetCollisionRect(); Vector3 projection = Collide(doodadVertexList, brickVertexList, p.center.normal); if (projection != Vector3.Zero) { s.Detonate(); s.position.velocity = Vector3.Zero; if (b.type == VL.DoodadType.LaserSwitch && s.type == ProjectileType.Laser) { b.ActivateDoodad(r, true); b.SetTargetBehavior(); } if ((s.type == ProjectileType.Bomb || s.type == ProjectileType.Missile) && s.exploding == true && b.type == VL.DoodadType.Brick) { b.ActivateDoodad(r, true); } } } } } #endregion p.center.Update(r, 0); }
public static void DebugDraw(Room r, Vector3 normal, Vector3 up) { /*List<VertexPositionColorNormalTexture> triangleList = new List<VertexPositionColorNormalTexture>(); List<Block> debugList = Physics.BlockUnfold(r, normal, up).blocks; foreach (Block b in debugList) { List<Vertex> vList = new List<Vertex>(); vList.Add(b.edges[0].start); vList.Add(b.edges[1].start); vList.Add(b.edges[2].start); vList.Add(b.edges[3].start); r.AddBlockToTriangleList(vList, Color.Yellow, 0f, Room.plateTexCoords, triangleList); //Draw projection Normals for (int i = 0; i < 4; i++) { triangleList.Add(new VertexPositionColorNormal(b.edges[i].start.position, Color.Red, normal)); //triangleList.Add(new VertexPositionColorNormal(b.edges[i].end.position, Color.Red, normal)); //Vector3 projectionNormal = -Vector3.Cross(normal, b.edges[i].end.position - b.edges[i].start.position); //projectionNormal.Normalize(); //triangleList.Add(new VertexPositionColorNormal(projectionNormal + .5f * (b.edges[i].end.position + b.edges[i].start.position), Color.Red, normal)); Vector3 velocityNormal = b.edges[i].start.velocity; velocityNormal.Normalize(); Vector3 sideNormal = Vector3.Cross(velocityNormal, normal); triangleList.Add(new VertexPositionColorNormalTexture(b.edges[i].start.position + .2f * sideNormal, Color.Red, normal, new Vector2(0,0))); triangleList.Add(new VertexPositionColorNormalTexture(b.edges[i].start.position - .2f * sideNormal, Color.Red, normal, new Vector2(0, 0))); triangleList.Add(new VertexPositionColorNormalTexture(b.edges[i].start.position + velocityNormal, Color.Red, normal, new Vector2(0, 0))); } } Game1.graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, triangleList.ToArray(), 0, triangleList.Count / 3, VertexPositionColorNormal.VertexDeclaration);*/ }
public Rm(Room r) { cbo = r.currentBlueOrbs; cro = r.currentRedOrbs; co = r.currentOrbs; bc = r.bossCleared; e = r.explored; }
public void Render(Room currentRoom) { DrawSphere(currentRoom,false); DrawSphere(currentRoom, true); if(state == FaceState.Armored) DrawNormalEyes(currentRoom); else DrawAngryEyes(currentRoom); }
public void DrawSphere(Room currentRoom, bool armor) { int numThetaSides = 10; int numPhiSides = 8; float horizontalRadius = 5f; float verticalRadius = 5f; VertexPositionColorNormalTexture[] vertices = new VertexPositionColorNormalTexture[numThetaSides * 6 * (numPhiSides + 1)]; int index = 0; for (int i = 0; i < numThetaSides; ++i) { float theta1 = ((float)i / (float)numThetaSides) * MathHelper.ToRadians(360f); float theta2 = ((float)(i + 1) / (float)numThetaSides) * MathHelper.ToRadians(360f); for (int j = -1; j < numPhiSides; ++j) { float phi_a = ((float)j / (float)numPhiSides) * MathHelper.ToRadians(180f); float x1_a = (float)(Math.Sin(phi_a) * Math.Cos(theta1)) * horizontalRadius; float z1_a = (float)(Math.Sin(phi_a) * Math.Sin(theta1)) * horizontalRadius; float x2_a = (float)(Math.Sin(phi_a) * Math.Cos(theta2)) * horizontalRadius; float z2_a = (float)(Math.Sin(phi_a) * Math.Sin(theta2)) * horizontalRadius; float y_a = (float)Math.Cos(phi_a) * verticalRadius; float phi_b = ((float)(j+1) / (float)numPhiSides) * MathHelper.ToRadians(180f); float x1_b = (float)(Math.Sin(phi_b) * Math.Cos(theta1)) * horizontalRadius; float z1_b = (float)(Math.Sin(phi_b) * Math.Sin(theta1)) * horizontalRadius; float x2_b = (float)(Math.Sin(phi_b) * Math.Cos(theta2)) * horizontalRadius; float z2_b = (float)(Math.Sin(phi_b) * Math.Sin(theta2)) * horizontalRadius; float y_b = (float)Math.Cos(phi_b) * verticalRadius; Vector3 position1 = currentRoom.center + new Vector3(x1_a, y_a, z1_a); Vector3 position2 = currentRoom.center + new Vector3(x2_a, y_a, z2_a); Vector3 position3 = currentRoom.center + new Vector3(x1_b, y_b, z1_b); Vector3 position4 = currentRoom.center + new Vector3(x2_b, y_b, z2_b); Vector3 offset = (position1 + position2 + position3 + position4)/4 - currentRoom.center; offset.Normalize(); offset *= 20f * armorExplodeTime / armorExplodeMaxTime; if (armor == true) { vertices[index] = new VertexPositionColorNormalTexture(position1 + offset, Color.White, position1 - currentRoom.center, Room.plateTexCoords[0]); vertices[index + 1] = new VertexPositionColorNormalTexture(position2 + offset, Color.White, position2 - currentRoom.center, Room.plateTexCoords[1]); vertices[index + 2] = new VertexPositionColorNormalTexture(position3 + offset, Color.White, position3 - currentRoom.center, Room.plateTexCoords[3]); vertices[index + 3] = new VertexPositionColorNormalTexture(position2 + offset, Color.White, position2 - currentRoom.center, Room.plateTexCoords[1]); vertices[index + 4] = new VertexPositionColorNormalTexture(position3 + offset, Color.White, position3 - currentRoom.center, Room.plateTexCoords[3]); vertices[index + 5] = new VertexPositionColorNormalTexture(position4 + offset, Color.White, position4 - currentRoom.center, Room.plateTexCoords[2]); } else { Color bodyColor = Color.Red; bodyColor.G = (Byte)(damageCooldown * 255 / damageCooldownMax); vertices[index] = new VertexPositionColorNormalTexture(position1, bodyColor, position1 - currentRoom.center, Room.plateTexCoords[0]); vertices[index + 1] = new VertexPositionColorNormalTexture(position2, bodyColor, position2 - currentRoom.center, Room.plateTexCoords[1]); vertices[index + 2] = new VertexPositionColorNormalTexture(position3, bodyColor, position3 - currentRoom.center, Room.plateTexCoords[3]); vertices[index + 3] = new VertexPositionColorNormalTexture(position2, bodyColor, position2 - currentRoom.center, Room.plateTexCoords[1]); vertices[index + 4] = new VertexPositionColorNormalTexture(position3, bodyColor, position3 - currentRoom.center, Room.plateTexCoords[3]); vertices[index + 5] = new VertexPositionColorNormalTexture(position4, bodyColor, position4 - currentRoom.center, Room.plateTexCoords[2]); } index+=6; } } if (armor == true) { Engine.playerTextureEffect.Texture = Monster.monsterTextures[(int)MonsterTextureId.FacePlate]; Engine.playerTextureEffect.CurrentTechnique.Passes[0].Apply(); } else { Engine.playerTextureEffect.Texture = Monster.monsterTextures[(int)MonsterTextureId.FaceWhite]; Engine.playerTextureEffect.CurrentTechnique.Passes[0].Apply(); } Game1.graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, vertices.Count()/3, VertexPositionColorNormalTexture.VertexDeclaration); }
public void UpdateVertexData(Room currentRoom) { if (baseTriangleList == null || dynamic == true || refreshVertexData == true) { Engine.debug_updateDoodadVertexData++; refreshVertexData = false; baseTriangleList = new List<VertexPositionColorNormalTexture>(); dynamicFancyTriangleList = new List<VertexPositionColorNormalTexture>(); dynamicBrickTriangleList = new List<VertexPositionColorNormalTexture>(); decalList = new List<VertexPositionColorNormalTexture>(); confirmButtonsList = new List<VertexPositionColorNormalTexture>(); loadButtonsList = new List<VertexPositionColorNormalTexture>(); useButtonList = new List<VertexPositionColorNormalTexture>(); xEquipButtonList = new List<VertexPositionColorNormalTexture>(); yEquipButtonList = new List<VertexPositionColorNormalTexture>(); spriteList = new List<VertexPositionColorNormalTexture>(); beamList = new List<VertexPositionColorNormalTexture>(); List<Vertex> vList = new List<Vertex>(); vList.Add(new Vertex(position, up + right)); vList.Add(new Vertex(position, up + left)); vList.Add(new Vertex(position, down + left)); vList.Add(new Vertex(position, down + right)); #region helpIcons if (helpIconTime != 0) { if (type == VL.DoodadType.LoadStation) { float size = 2*((float)(helpIconTime)) / helpIconMaxTime; List<Vertex> XButtonList = new List<Vertex>(); XButtonList.Add(new Vertex(position, size * up + size * right + up + 2f * left)); XButtonList.Add(new Vertex(position, size * up + size * left + up + 2f * left)); XButtonList.Add(new Vertex(position, size * down + size * left + up + 2f * left)); XButtonList.Add(new Vertex(position, size * down + size * right + up + 2f * left)); List<Vertex> YButtonList = new List<Vertex>(); YButtonList.Add(new Vertex(position, size * up + size * right + 3 * up)); YButtonList.Add(new Vertex(position, size * up + size * left + 3 * up)); YButtonList.Add(new Vertex(position, size * down + size * left + 3 * up)); YButtonList.Add(new Vertex(position, size * down + size * right + 3 * up)); List<Vertex> BButtonList = new List<Vertex>(); BButtonList.Add(new Vertex(position, size * up + size * right + 5f * up + 2f * right)); BButtonList.Add(new Vertex(position, size * up + size * left + 5f * up + 2f * right)); BButtonList.Add(new Vertex(position, size * down + size * left + 5f * up + 2f * right)); BButtonList.Add(new Vertex(position, size * down + size * right + 5f * up + 2f * right)); if (Engine.controlType == ControlType.GamePad) { currentRoom.AddBlockFrontToTriangleList(XButtonList, Color.White, .55f, Ability.texCoordList[25], decalList, true); currentRoom.AddBlockFrontToTriangleList(YButtonList, Color.White, .55f, Ability.texCoordList[27], decalList, true); } if (Engine.controlType == ControlType.KeyboardOnly) { currentRoom.AddBlockFrontToTriangleList(XButtonList, Color.Blue, .55f, Ability.texCoordList[49], decalList, true); currentRoom.AddBlockFrontToTriangleList(YButtonList, Color.Yellow, .55f, Ability.texCoordList[51], decalList, true); } if (Engine.controlType == ControlType.MouseAndKeyboard) { XButtonList = new List<Vertex>(); XButtonList.Add(new Vertex(position, size * up + size * right + 5f * up + 2f * left)); XButtonList.Add(new Vertex(position, size * up + size * left + 5f * up + 2f * left)); XButtonList.Add(new Vertex(position, size * down + size * left + 5f * up + 2f * left)); XButtonList.Add(new Vertex(position, size * down + size * right + 5f * up + 2f * left)); YButtonList = new List<Vertex>(); YButtonList.Add(new Vertex(position, size * up + size * right + 5f * up + 2f * right)); YButtonList.Add(new Vertex(position, size * up + size * left + 5f * up + 2f * right)); YButtonList.Add(new Vertex(position, size * down + size * left + 5f * up + 2f * right)); YButtonList.Add(new Vertex(position, size * down + size * right + 5f * up + 2f * right)); BButtonList = new List<Vertex>(); BButtonList.Add(new Vertex(position, size * up + size * right - 2.5f * up + 2f * right)); BButtonList.Add(new Vertex(position, size * up + size * left - 2.5f * up + 2f * left)); BButtonList.Add(new Vertex(position, size * down + size * left - 2.5f * up + 2f * left)); BButtonList.Add(new Vertex(position, size * down + size * right - 2.5f * up + 2f * right)); currentRoom.AddBlockFrontToTriangleList(XButtonList, Color.Blue, .55f, SaveGameText.okTexCoords, loadButtonsList, true); currentRoom.AddBlockFrontToTriangleList(YButtonList, Color.Yellow, .55f, SaveGameText.cancelTexCoords, loadButtonsList, true); if (SaveGameText.expertAvailable && SaveGameText.activeSaveSlot > -1 && SaveGameText.saveSummaryData[SaveGameText.activeSaveSlot].empty) currentRoom.AddBlockFrontToTriangleList(BButtonList, Color.Red, .55f, SaveGameText.extraTexCoords, loadButtonsList, true); } } else if ((isStation == true && type != VL.DoodadType.ItemStation) || type == VL.DoodadType.Holoprojector || type == VL.DoodadType.Vortex || type == VL.DoodadType.JumpPad) { float size = ((float)(helpIconTime)) / helpIconMaxTime; List<Vertex> BButtonList = new List<Vertex>(); BButtonList.Add(new Vertex(position, size * up + size * right + up + 2.3f * right)); BButtonList.Add(new Vertex(position, size * up + size * left + up + 2.3f * right)); BButtonList.Add(new Vertex(position, size * down + size * left + up + 2.3f * right)); BButtonList.Add(new Vertex(position, size * down + size * right + up + 2.3f * right)); if (Engine.controlType == ControlType.GamePad) currentRoom.AddBlockFrontToTriangleList(BButtonList, Color.White, .55f, Room.plateTexCoords, useButtonList, true); if (Engine.controlType == ControlType.KeyboardOnly) currentRoom.AddBlockFrontToTriangleList(BButtonList, Color.Red, .55f, Room.plateTexCoords, useButtonList, true); if (Engine.controlType == ControlType.MouseAndKeyboard) currentRoom.AddBlockFrontToTriangleList(BButtonList, Color.Red, .55f, Room.plateTexCoords, useButtonList, true); } else if (type == VL.DoodadType.ItemStation) { float size = ((float)(helpIconTime)) / helpIconMaxTime; List<Vertex> XButtonList = new List<Vertex>(); XButtonList.Add(new Vertex(position, size * up + size * right + up + 2f * left)); XButtonList.Add(new Vertex(position, size * up + size * left + up + 2f * left)); XButtonList.Add(new Vertex(position, size * down + size * left + up + 2f * left)); XButtonList.Add(new Vertex(position, size * down + size * right + up + 2f * left)); List<Vertex> YButtonList = new List<Vertex>(); YButtonList.Add(new Vertex(position, size * up + size * right + 3 * up)); YButtonList.Add(new Vertex(position, size * up + size * left + 3 * up)); YButtonList.Add(new Vertex(position, size * down + size * left + 3 * up)); YButtonList.Add(new Vertex(position, size * down + size * right + 3 * up)); if (Engine.controlType == ControlType.GamePad) { currentRoom.AddBlockFrontToTriangleList(XButtonList, Color.White, .55f, Room.plateTexCoords, xEquipButtonList, true); currentRoom.AddBlockFrontToTriangleList(YButtonList, Color.White, .55f, Room.plateTexCoords, yEquipButtonList, true); } if (Engine.controlType == ControlType.KeyboardOnly) { currentRoom.AddBlockFrontToTriangleList(XButtonList, Color.Blue, .55f, Room.plateTexCoords, xEquipButtonList, true); currentRoom.AddBlockFrontToTriangleList(YButtonList, Color.Yellow, .55f, Room.plateTexCoords, yEquipButtonList, true); } if (Engine.controlType == ControlType.MouseAndKeyboard) { XButtonList = new List<Vertex>(); XButtonList.Add(new Vertex(position, size * up + size * right + 2f * up + 2f * left)); XButtonList.Add(new Vertex(position, size * up + size * left + 2f * up + 2f * left)); XButtonList.Add(new Vertex(position, size * down + size * left + 2f * up + 2f * left)); XButtonList.Add(new Vertex(position, size * down + size * right + 2f * up + 2f * left)); YButtonList = new List<Vertex>(); YButtonList.Add(new Vertex(position, size * up + size * right + 2f * up + 2f * right)); YButtonList.Add(new Vertex(position, size * up + size * left + 2f * up + 2f * right)); YButtonList.Add(new Vertex(position, size * down + size * left + 2f * up + 2f * right)); YButtonList.Add(new Vertex(position, size * down + size * right + 2f * up + 2f * right)); currentRoom.AddBlockFrontToTriangleList(XButtonList, Color.Blue, .55f, Room.plateTexCoords, xEquipButtonList, true); currentRoom.AddBlockFrontToTriangleList(YButtonList, Color.Yellow, .55f, Room.plateTexCoords, yEquipButtonList, true); currentRoom.AddBlockFrontToTriangleList(XButtonList, Color.White, .55f, Room.plateTexCoords, xEquipButtonList, true); currentRoom.AddBlockFrontToTriangleList(YButtonList, Color.White, .55f, Room.plateTexCoords, yEquipButtonList, true); } } } #endregion if (isPowerStation) { if (orbsRemaining > 0) { currentRoom.AddBlockToTriangleList(vList, baseColor, depth, depth, Room.plateTexCoords, dynamicFancyTriangleList); currentRoom.BasicAddBlockSidesToTriangleList(vList, baseColor, depth, depth, Room.plateTexCoords, dynamicFancyTriangleList, false); } else { currentRoom.AddBlockToTriangleList(vList, activeColor, depth, depth, Room.plateTexCoords, dynamicFancyTriangleList); currentRoom.BasicAddBlockSidesToTriangleList(vList, activeColor, depth, depth, Room.plateTexCoords, dynamicFancyTriangleList, false); } } else if (type == VL.DoodadType.SwitchStation) { if (targetDoodad != null) { if (targetDoodad.currentBehavior.id == targetBehavior) { currentRoom.AddBlockToTriangleList(vList, activeColor, depth, depth, Room.plateTexCoords, dynamicFancyTriangleList); currentRoom.BasicAddBlockSidesToTriangleList(vList, activeColor, depth, depth, Room.plateTexCoords, dynamicFancyTriangleList, false); } else { currentRoom.AddBlockToTriangleList(vList, baseColor, depth, depth, Room.plateTexCoords, dynamicFancyTriangleList); currentRoom.BasicAddBlockSidesToTriangleList(vList, baseColor, depth, depth, Room.plateTexCoords, dynamicFancyTriangleList, false); } } if (targetBlock != null) { if (targetBlock.currentBehavior.id == targetBehavior) { currentRoom.AddBlockToTriangleList(vList, activeColor, depth, depth, Room.plateTexCoords, dynamicFancyTriangleList); currentRoom.BasicAddBlockSidesToTriangleList(vList, activeColor, depth, depth, Room.plateTexCoords, dynamicFancyTriangleList, false); } else { currentRoom.AddBlockToTriangleList(vList, baseColor, depth, depth, Room.plateTexCoords, dynamicFancyTriangleList); currentRoom.BasicAddBlockSidesToTriangleList(vList, baseColor, depth, depth, Room.plateTexCoords, dynamicFancyTriangleList, false); } } if (targetEdge != null) { if (targetEdge.currentBehavior.id == targetBehavior) { currentRoom.AddBlockToTriangleList(vList, activeColor, depth, depth, Room.plateTexCoords, dynamicFancyTriangleList); currentRoom.BasicAddBlockSidesToTriangleList(vList, activeColor, depth, depth, Room.plateTexCoords, dynamicFancyTriangleList, false); } else { currentRoom.AddBlockToTriangleList(vList, baseColor, depth, depth, Room.plateTexCoords, dynamicFancyTriangleList); currentRoom.BasicAddBlockSidesToTriangleList(vList, activeColor, depth, depth, Room.plateTexCoords, dynamicFancyTriangleList, false); } } } else if (type == VL.DoodadType.JumpStation) { float jumpVel = (Engine.player.jumpDestination - Engine.player.jumpSource).Length() / (1f * Player.launchMaxTime); float transitionTime = 1f / Math.Abs(stateTransitionVelocity); float maxExtend = jumpVel * transitionTime; if (active == true) { currentRoom.AddBlockToTriangleList(vList, activeColor, depth + maxExtend * stateTransition, depth, Room.plateTexCoords, dynamicFancyTriangleList); currentRoom.BasicAddBlockSidesToTriangleList(vList, activeColor, depth + maxExtend * stateTransition, depth, Room.plateTexCoords, dynamicFancyTriangleList); currentRoom.AddBlockFrontToTriangleList(vList, baseColor, depth + maxExtend * stateTransition + .01f, Room.plateTexCoords, decalList, true); } else { currentRoom.AddBlockToTriangleList(vList, baseColor, depth + maxExtend * stateTransition, depth, Room.plateTexCoords, dynamicFancyTriangleList); currentRoom.BasicAddBlockSidesToTriangleList(vList, baseColor, depth + maxExtend * stateTransition, depth, Room.plateTexCoords, dynamicFancyTriangleList); currentRoom.AddBlockFrontToTriangleList(vList, baseColor, depth + maxExtend * stateTransition + .01f, Room.plateTexCoords, decalList, true); } } else if (type == VL.DoodadType.JumpPad) { float jumpVel = (Engine.player.jumpDestination - Engine.player.jumpSource).Length() / (1f * Player.launchMaxTime); float transitionTime = 1f / Math.Abs(stateTransitionVelocity); float maxExtend = jumpVel * transitionTime; if (active == true) { currentRoom.AddBlockToTriangleList(vList, activeColor, depth + maxExtend * stateTransition, depth, Room.plateTexCoords, dynamicFancyTriangleList); currentRoom.BasicAddBlockSidesToTriangleList(vList, baseColor, depth + maxExtend * stateTransition, depth, Room.plateTexCoords, dynamicFancyTriangleList); currentRoom.AddBlockFrontToTriangleList(vList, activeColor, depth + maxExtend * stateTransition + .01f, Room.plateTexCoords, decalList, true); } else { currentRoom.AddBlockToTriangleList(vList, baseColor, depth + maxExtend * stateTransition, depth, Room.plateTexCoords, dynamicFancyTriangleList); currentRoom.BasicAddBlockSidesToTriangleList(vList, baseColor, depth + maxExtend * stateTransition, depth, Room.plateTexCoords, dynamicFancyTriangleList); currentRoom.AddBlockFrontToTriangleList(vList, baseColor, depth + maxExtend * stateTransition + .01f, Room.plateTexCoords, decalList, true); } } else if (type == VL.DoodadType.Brick) { if (active == true) { Color breakColor = Color.Transparent; breakColor.R = (Byte)((breakTime * breakColor.R + (maxBreakTime - breakTime) * baseColor.R) / maxBreakTime); breakColor.G = (Byte)((breakTime * breakColor.G + (maxBreakTime - breakTime) * baseColor.G) / maxBreakTime); breakColor.B = (Byte)((breakTime * breakColor.B + (maxBreakTime - breakTime) * baseColor.B) / maxBreakTime); breakColor.A = (Byte)((breakTime * breakColor.A + (maxBreakTime - breakTime) * baseColor.A) / maxBreakTime); List<Vertex> chunkList = new List<Vertex>(); Vector3 chunkOffset = (1f + (2f * breakTime) / maxBreakTime) * (up + right); chunkList.Add(new Vertex(position, up + right + chunkOffset)); chunkList.Add(new Vertex(position, up + left + chunkOffset)); chunkList.Add(new Vertex(position, down + left + chunkOffset)); chunkList.Add(new Vertex(position, down + right + chunkOffset)); currentRoom.BasicAddBlockSidesToTriangleList(chunkList, breakColor, depth, depth, Room.plateTexCoords, baseTriangleList); currentRoom.AddBlockToTriangleList(chunkList, breakColor, depth, depth, Room.plateTexCoords, baseTriangleList); chunkList = new List<Vertex>(); chunkOffset = (1f + (2f * breakTime) / maxBreakTime) * (up + left); chunkList.Add(new Vertex(position, up + right + chunkOffset)); chunkList.Add(new Vertex(position, up + left + chunkOffset)); chunkList.Add(new Vertex(position, down + left + chunkOffset)); chunkList.Add(new Vertex(position, down + right + chunkOffset)); currentRoom.BasicAddBlockSidesToTriangleList(chunkList, breakColor, depth, depth, Room.plateTexCoords, baseTriangleList); currentRoom.AddBlockToTriangleList(chunkList, breakColor, depth, depth, Room.plateTexCoords, baseTriangleList); chunkList = new List<Vertex>(); chunkOffset = (1f + (2f * breakTime) / maxBreakTime) * (down + right); chunkList.Add(new Vertex(position, up + right + chunkOffset)); chunkList.Add(new Vertex(position, up + left + chunkOffset)); chunkList.Add(new Vertex(position, down + left + chunkOffset)); chunkList.Add(new Vertex(position, down + right + chunkOffset)); currentRoom.BasicAddBlockSidesToTriangleList(chunkList, breakColor, depth, depth, Room.plateTexCoords, baseTriangleList); currentRoom.AddBlockToTriangleList(chunkList, breakColor, depth, depth, Room.plateTexCoords, baseTriangleList); chunkList = new List<Vertex>(); chunkOffset = (1f + (2f * breakTime) / maxBreakTime) * (down + left); chunkList.Add(new Vertex(position, up + right + chunkOffset)); chunkList.Add(new Vertex(position, up + left + chunkOffset)); chunkList.Add(new Vertex(position, down + left + chunkOffset)); chunkList.Add(new Vertex(position, down + right + chunkOffset)); currentRoom.BasicAddBlockSidesToTriangleList(chunkList, breakColor, depth, depth, Room.plateTexCoords, baseTriangleList); currentRoom.AddBlockToTriangleList(chunkList, breakColor, depth, depth, Room.plateTexCoords, baseTriangleList); if (position.position != Vector3.Zero) { for (int i = 0; i < 36; i++) { dynamicBrickTriangleList.Add(new VertexPositionColorNormalTexture(Vector3.Zero, Color.White, Vector3.Zero, Vector2.Zero)); } } } else { currentRoom.BasicAddBlockSidesToTriangleList(vList, baseColor, depth, depth, Room.plateTexCoords, dynamicBrickTriangleList); currentRoom.AddBlockToTriangleList(vList, baseColor, depth, depth, Room.plateTexCoords, dynamicBrickTriangleList); baseTriangleList = new List<VertexPositionColorNormalTexture>(); ; } } else if (type == VL.DoodadType.PowerOrb && tracking == false && active == false) { for (int i = 0; i < 36; i++) { dynamicFancyTriangleList.Add(new VertexPositionColorNormalTexture(Vector3.Zero, Color.White, Vector3.Zero, Vector2.Zero)); } } else if (type != VL.DoodadType.Holoprojector && type != VL.DoodadType.HologramOldMan && type != VL.DoodadType.Beam && type != VL.DoodadType.PowerPlug && type != VL.DoodadType.Vortex) { if (active && type != VL.DoodadType.LaserSwitch) { currentRoom.BasicAddBlockSidesToTriangleList(vList, activeColor, depth, depth, Room.plateTexCoords, dynamicFancyTriangleList); currentRoom.AddBlockToTriangleList(vList, activeColor, depth, depth, Room.plateTexCoords, dynamicFancyTriangleList); } else { currentRoom.BasicAddBlockSidesToTriangleList(vList, baseColor, depth, depth, Room.plateTexCoords, dynamicFancyTriangleList); currentRoom.AddBlockToTriangleList(vList, baseColor, depth, depth, Room.plateTexCoords, dynamicFancyTriangleList); } } if (type == VL.DoodadType.ItemBlock || isStation) { currentRoom.AddBlockFrontToTriangleList(vList, Color.White, depth + .01f, Room.plateTexCoords, decalList, true); } if (type == VL.DoodadType.HookTarget) { currentRoom.AddBlockFrontToTriangleList(vList, activeColor, depth, Room.plateTexCoords, decalList, true); } if (type == VL.DoodadType.PlugSlot) { currentRoom.AddBlockFrontToTriangleList(vList, baseColor, depth, Room.plateTexCoords, decalList, true); currentRoom.AddBlockFrontToTriangleList(vList, baseColor, -depth, Room.plateTexCoords, decalList, true); } if (type == VL.DoodadType.LaserSwitch) { if (active) { currentRoom.AddBlockFrontToTriangleList(vList, activeColor, depth, Room.plateTexCoords, decalList, true); currentRoom.AddBlockFrontToTriangleList(vList, activeColor, -depth, Room.plateTexCoords, decalList, true); } else { currentRoom.AddBlockFrontToTriangleList(vList, baseColor, depth, Room.plateTexCoords, decalList, true); currentRoom.AddBlockFrontToTriangleList(vList, baseColor, -depth, Room.plateTexCoords, decalList, true); } } if (type == VL.DoodadType.StationIcon) { currentRoom.AddBlockFrontToTriangleList(vList, iconColor, depth + .01f, Room.plateTexCoords, decalList, true); } if (type == VL.DoodadType.HologramOldMan) { if(hologramFade > 0) { Color hologram = Color.White; hologram.A = (Byte)(hologramFade * 255f / hologramMaxFade); hologram.B = (Byte)(hologramFade * 255f / hologramMaxFade); hologram.G = (Byte)(hologramFade * 255f / hologramMaxFade); hologram.R = (Byte)(hologramFade * 255f / hologramMaxFade); currentRoom.AddBlockFrontToTriangleList(vList, hologram, depth + .012f, Room.plateTexCoords, spriteList, true); } } if (type == VL.DoodadType.Beam) { currentRoom.AddBlockFrontToTriangleList(vList, Color.White, depth, beamTexCoords, beamList, true); } if (type == VL.DoodadType.PowerPlug) { if (active == true) { currentRoom.AddBlockFrontToTriangleList(vList, activeColor, depth, Room.plateTexCoords, decalList, true); currentRoom.AddBlockFrontToTriangleList(vList, activeColor, -depth, Room.plateTexCoords, decalList, true); } else { currentRoom.AddBlockFrontToTriangleList(vList, baseColor, depth, Room.plateTexCoords, decalList, true); //currentRoom.AddBlockFrontToTriangleList(vList, baseColor, -depth, Room.plateTexCoords, decalList, true); } } if(dynamicFancyTriangleList.Count > 0) { for (int i = 0; i < dynamicFancyTriangleList.Count; i++) { currentRoom.dynamicFancyPlateTriangleArray[cacheOffset + i] = dynamicFancyTriangleList[i]; } } if (dynamicBrickTriangleList.Count > 0) { for (int i = 0; i < dynamicBrickTriangleList.Count; i++) { currentRoom.dynamicBrickTriangleArray[cacheOffsetBrick + i] = dynamicBrickTriangleList[i]; } } baseTriangleArray = baseTriangleList.ToArray(); decalArray = decalList.ToArray(); spriteArray = spriteList.ToArray(); beamArray = beamList.ToArray(); } }
public Doodad(Doodad d, Room r, Vector3 n, Vector3 u) { position = d.position.Unfold(r, n, u); type = d.type; toggleOn = d.toggleOn; targetDoodad = d.targetDoodad; active = d.active; srcDoodad = d; stateTransition = d.stateTransition; }
public RoomSave(Room r) { }
public void Draw(Room currentRoom) { UpdateVertexData(currentRoom); if (staticObject == true) return; if (wallType == VL.WallType.Plate) Engine.playerTextureEffect.Texture = wallTexture; else if (wallType == VL.WallType.Circuit) Engine.playerTextureEffect.Texture = circuitTexture; else if (wallType == VL.WallType.Cobblestone) Engine.playerTextureEffect.Texture = cobblestoneTexture; else if (wallType == VL.WallType.FancyPlate) Engine.playerTextureEffect.Texture = fancyPlateTexture; else if (wallType == VL.WallType.Vines) Engine.playerTextureEffect.Texture = vineTexture; else if (wallType == VL.WallType.Cargo) Engine.playerTextureEffect.Texture = cargoTexture; else if (wallType == VL.WallType.Ice) Engine.playerTextureEffect.Texture = iceTexture; else if (wallType == VL.WallType.Crystal) Engine.playerTextureEffect.Texture = crystalTexture; else if (wallType == VL.WallType.Crate) Engine.playerTextureEffect.Texture = crateTexture; else Engine.playerTextureEffect.Texture = fancyPlateTexture; Engine.playerTextureEffect.CurrentTechnique.Passes[0].Apply(); Game1.graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, baseTriangleArray, 0, baseTriangleList.Count() / 3, VertexPositionColorNormalTexture.VertexDeclaration); if (scales) { Engine.playerTextureEffect.Texture = fancyPlateTexture; Engine.playerTextureEffect.CurrentTechnique.Passes[0].Apply(); } if (sideTriangleList.Count > 0) { Game1.graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, sideTriangleArray, 0, sideTriangleList.Count() / 3, VertexPositionColorNormalTexture.VertexDeclaration); } }
public void ActivateDoodad(Room currentRoom, bool state) { bool futureState = state; if (powered == false) futureState = false; if (type == VL.DoodadType.WallSwitch) { SoundFX.WallSwitchOff(position.position); } if (type == VL.DoodadType.Brick) { SoundFX.BrickBreak(position.position); } if (type == VL.DoodadType.UpgradeStation && abilityType == AbilityType.Empty) futureState = false; if ((type == VL.DoodadType.PowerStation || type == VL.DoodadType.RedPowerStation || type == VL.DoodadType.BluePowerStation) && orbsRemaining ==0) futureState = false; if (futureState != active) { refreshVertexData = true; } if(active != futureState) active = futureState; }
public void UpdateUnfoldedBlocks(Room r, Vector3 normal, Vector3 up) { List<Vertex> points = new List<Vertex>(); List<EdgeProperties> edgeTypes = new List<EdgeProperties>(); unfoldedBlocks.Clear(); for (int i = 0; i < this.edges.Count; i++) { Edge e = this.edges[i]; points.Add(e.start); edgeTypes.Add(e.properties); if (e.start.normal != e.end.normal && (e.start.normal != normal && e.end.normal != normal)) { Vector3 fullEdge = e.end.position - e.start.position; Vector3 currentComponent = Vector3.Dot(e.end.normal, fullEdge) * e.end.normal; Vector3 nextComponent = Vector3.Dot(e.start.normal, fullEdge) * e.start.normal; Vector3 constantComponent = Vector3.Dot(Vector3.Cross(e.end.normal, e.start.normal), fullEdge) * Vector3.Cross(e.end.normal, e.start.normal); float currentPercent = currentComponent.Length() / (currentComponent.Length() + nextComponent.Length()); Vector3 midPoint = e.start.position + currentComponent + currentPercent * constantComponent; points.Add(new Vertex(midPoint, e.start.normal, e.start.velocity, e.start.direction)); edgeTypes.Add(e.properties); points.Add(new Vertex(midPoint, e.end.normal, e.end.velocity, e.end.direction)); edgeTypes.Add(this.edges[(i + 1) % this.edges.Count].properties); } } if (points.Count == 4) { unfoldedBlocks.Add(new Block(points, edgeTypes, r, normal, up)); } else { Vector3 n1 = points[0].normal; List<Vertex> vList1 = new List<Vertex>(); List<Vertex> vList2 = new List<Vertex>(); for (int i = 0; i < 8; i++) { if (points[i].normal == n1) vList1.Add(points[i]); else vList2.Add(points[i]); } unfoldedBlocks.Add(new Block(vList1, edgeTypes, r, normal, up)); unfoldedBlocks.Add(new Block(vList2, edgeTypes, r, normal, up)); } foreach (Block b in unfoldedBlocks) b.UpdateBoundingBox(Engine.player.up, Engine.player.right); }
public void DrawDecals(Room currentRoom) { if (shouldRender == true) { if (decalList.Count > 0) { if(type == VL.DoodadType.PowerOrb) Engine.playerTextureEffect.Texture = powerCubeTexture; else Engine.playerTextureEffect.Texture = currentDecalTexture; Engine.playerTextureEffect.CurrentTechnique.Passes[0].Apply(); Game1.graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, decalArray, 0, decalList.Count() / 3, VertexPositionColorNormalTexture.VertexDeclaration); } } }
public void UpdateVertexList(Room r) { List<Vector2> texCoords = ringTexCoords; if (width > .6f) texCoords = tubeTexCoords; if (ringList == null) { c = r.currentColor; float outerRadiusMod = 1f; if (width <= .6f) { c = Color.Gray; } else { outerRadiusMod = .9f; } ringList = new List<VertexPositionColorNormalTexture>(); for(int i = 0; i < 4; i++) { int nextIndex = (i + 1) % 4; Vector3 pos = position + outerRadiusMod* radius * (ringVectorList[i].X * up + ringVectorList[i].Y * right); Vector3 nextPos = position + outerRadiusMod * radius * (ringVectorList[nextIndex].X * up + ringVectorList[nextIndex].Y * right); Vector3 normal = Vector3.Cross(nextPos - pos, direction); Vector3 innerPos = position + .8f * radius * (ringVectorList[i].X * up + ringVectorList[i].Y * right); Vector3 nextinnerPos = position + .8f * radius * (ringVectorList[nextIndex].X * up + ringVectorList[nextIndex].Y * right); Color shadedColor = c; ringList.Add(new VertexPositionColorNormalTexture(pos, c, normal, texCoords[0])); ringList.Add(new VertexPositionColorNormalTexture(nextPos + width * direction, c, normal, texCoords[2])); ringList.Add(new VertexPositionColorNormalTexture(pos + width * direction, c, normal, texCoords[3])); ringList.Add(new VertexPositionColorNormalTexture(pos, c, normal, texCoords[0])); ringList.Add(new VertexPositionColorNormalTexture(nextPos, c, normal, texCoords[1])); ringList.Add(new VertexPositionColorNormalTexture(nextPos + width * direction, c, normal, texCoords[2])); ringList.Add(new VertexPositionColorNormalTexture(innerPos, c, normal, texCoords[0])); ringList.Add(new VertexPositionColorNormalTexture(nextinnerPos + width * direction, c, normal, texCoords[2])); ringList.Add(new VertexPositionColorNormalTexture(innerPos + width * direction, c, normal, texCoords[3])); ringList.Add(new VertexPositionColorNormalTexture(innerPos, c, normal, texCoords[0])); ringList.Add(new VertexPositionColorNormalTexture(nextinnerPos, c, normal, texCoords[1])); ringList.Add(new VertexPositionColorNormalTexture(nextinnerPos + width * direction, c, normal, texCoords[2])); ringList.Add(new VertexPositionColorNormalTexture(innerPos, shadedColor, normal, ringTexCoords[0])); ringList.Add(new VertexPositionColorNormalTexture(nextPos, shadedColor, normal, ringTexCoords[2])); ringList.Add(new VertexPositionColorNormalTexture(pos, shadedColor, normal, ringTexCoords[3])); ringList.Add(new VertexPositionColorNormalTexture(innerPos, shadedColor, normal, ringTexCoords[0])); ringList.Add(new VertexPositionColorNormalTexture(nextinnerPos, shadedColor, normal, ringTexCoords[1])); ringList.Add(new VertexPositionColorNormalTexture(nextPos, shadedColor, normal, ringTexCoords[2])); ringList.Add(new VertexPositionColorNormalTexture(innerPos + width * direction, shadedColor, normal, ringTexCoords[0])); ringList.Add(new VertexPositionColorNormalTexture(nextPos + width * direction, shadedColor, normal, ringTexCoords[2])); ringList.Add(new VertexPositionColorNormalTexture(pos + width * direction, shadedColor, normal, ringTexCoords[3])); ringList.Add(new VertexPositionColorNormalTexture(innerPos + width * direction, shadedColor, normal, ringTexCoords[0])); ringList.Add(new VertexPositionColorNormalTexture(nextinnerPos + width * direction, shadedColor, normal, ringTexCoords[1])); ringList.Add(new VertexPositionColorNormalTexture(nextPos + width * direction, shadedColor, normal, ringTexCoords[2])); } } if (width > .6f && r.currentColor != c) { c = r.currentColor; List<VertexPositionColorNormalTexture> newList = new List<VertexPositionColorNormalTexture>(); for (int i = 0; i < ringList.Count; i++) { newList.Add(new VertexPositionColorNormalTexture(ringList[i].Position,c, ringList[i].Normal, ringList[i].TextureCoordinates)); } ringList = newList; } }
public void DrawSolids(Room currentRoom) { if (shouldRender == true) { UpdateVertexData(currentRoom); if (baseTriangleList.Count > 0) { if (type == VL.DoodadType.Brick && active == false && breakTime == 0) return; if(type == VL.DoodadType.Brick) Engine.playerTextureEffect.Texture = Block.crackedTexture; else Engine.playerTextureEffect.Texture = Block.wallTexture; Engine.playerTextureEffect.CurrentTechnique.Passes[0].Apply(); Game1.graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, baseTriangleArray, 0, baseTriangleList.Count() / 3, VertexPositionColorNormalTexture.VertexDeclaration); } //currentRoom.dynamicPlate.AddRange(baseTriangleList); } }
public void Update(Room r, int updateTime) { Update(r, updateTime, true); }
public void DrawSprites(Room currentRoom) { if (shouldRender == true) { UpdateVertexData(currentRoom); if (spriteList.Count > 0) { if (speaker == SpeakerId.FinalBoss) { Engine.playerTextureEffect.Texture = Doodad.hologram_finalBoss; } else { Engine.playerTextureEffect.Texture = Doodad.hologram_oldMan; } Engine.playerTextureEffect.CurrentTechnique.Passes[0].Apply(); Game1.graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, spriteArray, 0, spriteList.Count() / 3, VertexPositionColorNormalTexture.VertexDeclaration); } if (beamList.Count > 0) { if (styleSpriteIndex == 0) Engine.playerTextureEffect.Texture = Doodad.electric_beam_textures[animationFrame]; else Engine.playerTextureEffect.Texture = Doodad.flame_beam_textures[animationFrame]; Engine.playerTextureEffect.CurrentTechnique.Passes[0].Apply(); Game1.graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, beamArray, 0, beamList.Count() / 3, VertexPositionColorNormalTexture.VertexDeclaration); } if (loadButtonsList.Count > 0) { if (SaveGameText.state == LoadState.Normal) { Engine.playerTextureEffect.Texture = SaveGameText.loadOptions; } else { Engine.playerTextureEffect.Texture = SaveGameText.confirmOptions; } Engine.playerTextureEffect.CurrentTechnique.Passes[0].Apply(); Game1.graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, loadButtonsList.ToArray(), 0, loadButtonsList.Count() / 3, VertexPositionColorNormalTexture.VertexDeclaration); } if (useButtonList.Count > 0) { Engine.playerTextureEffect.Texture = Doodad.useButton; Engine.playerTextureEffect.CurrentTechnique.Passes[0].Apply(); Game1.graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, useButtonList.ToArray(), 0, useButtonList.Count() / 3, VertexPositionColorNormalTexture.VertexDeclaration); } if (xEquipButtonList.Count > 0) { Engine.playerTextureEffect.Texture = Doodad.leftButton; Engine.playerTextureEffect.CurrentTechnique.Passes[0].Apply(); Game1.graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, xEquipButtonList.ToArray(), 0, xEquipButtonList.Count() / 6, VertexPositionColorNormalTexture.VertexDeclaration); Engine.playerTextureEffect.Texture = Ability.GetDecal(Engine.player.primaryAbility.type); Engine.playerTextureEffect.CurrentTechnique.Passes[0].Apply(); Game1.graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, xEquipButtonList.ToArray(), 6, xEquipButtonList.Count() / 6, VertexPositionColorNormalTexture.VertexDeclaration); } if (yEquipButtonList.Count > 0) { Engine.playerTextureEffect.Texture = Doodad.rightButton; Engine.playerTextureEffect.CurrentTechnique.Passes[0].Apply(); Game1.graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, yEquipButtonList.ToArray(), 0, yEquipButtonList.Count() / 6, VertexPositionColorNormalTexture.VertexDeclaration); Engine.playerTextureEffect.Texture = Ability.GetDecal(Engine.player.secondaryAbility.type); Engine.playerTextureEffect.CurrentTechnique.Passes[0].Apply(); Game1.graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, yEquipButtonList.ToArray(), 6, yEquipButtonList.Count() / 6, VertexPositionColorNormalTexture.VertexDeclaration); } } }
public void SimpleUpdate(Room r, int updateTime) { position += updateTime * velocity; }
public void UpdateUnfoldedDoodad(Room r, Vector3 n, Vector3 u) { unfoldedPosition = position.Unfold(r, n, u); }
public Room(Room r) { center = r.center; size = r.size; hasWarp = r.hasWarp; color = r.color; id = r.id; currentOrbs = r.currentOrbs; maxOrbs = r.maxOrbs; currentBlueOrbs = r.currentBlueOrbs; currentRedOrbs = r.currentRedOrbs; maxRedOrbs = r.maxRedOrbs; maxBlueOrbs = r.maxBlueOrbs; sectorID = r.sectorID; explored = r.explored; bossCleared = r.bossCleared; stationDecal = r.stationDecal; friendlyName = r.friendlyName; warpCost = r.warpCost; blocks = new List<Block>(); foreach (Block b in r.blocks) { blocks.Add(new Block(b)); } doodads = new List<Doodad>(); foreach (Doodad d in r.doodads) { doodads.Add(new Doodad(d)); } jumpRings = new List<JumpRing>(); tunnels = new List<Tunnel>(); monsters = new List<Monster>(); foreach (Monster m in r.monsters) { monsters.Add(new Monster(m)); } projectiles = new List<Projectile>(); foreach (Projectile p in r.projectiles) { projectiles.Add(new Projectile(p)); } decorations = new List<Decoration>(); foreach (Decoration d in r.decorations) { decorations.Add(new Decoration(d)); } }
public void Draw(Room r) { List<VertexPositionColorNormal> triangleList = new List<VertexPositionColorNormal>(); List<VertexPositionColorNormalTexture> textureTriangleList = new List<VertexPositionColorNormalTexture>(); List<VertexPositionColorNormalTexture> blastTriangleList = new List<VertexPositionColorNormalTexture>(); List<Vertex> rectVertexList = new List<Vertex>(); rectVertexList.Add(new Vertex(position.position, position.normal, up + right, position.direction)); rectVertexList.Add(new Vertex(position.position, position.normal, up + left, position.direction)); rectVertexList.Add(new Vertex(position.position, position.normal, down + left, position.direction)); rectVertexList.Add(new Vertex(position.position, position.normal, down + right, position.direction)); List<Vertex> blastVertexList = new List<Vertex>(); blastVertexList.Add(new Vertex(position.position, position.normal, blastUp + blastRight, position.direction)); blastVertexList.Add(new Vertex(position.position, position.normal, blastUp + blastLeft, position.direction)); blastVertexList.Add(new Vertex(position.position, position.normal, blastDown + blastLeft, position.direction)); blastVertexList.Add(new Vertex(position.position, position.normal, blastDown + blastRight, position.direction)); foreach (Vertex v in rectVertexList) { v.Update(Engine.player.currentRoom, 1); } foreach (Vertex v in blastVertexList) { v.Update(Engine.player.currentRoom, 1); } if (type == ProjectileType.Plasma || type == ProjectileType.Player) { if (exploding == true) { //r.AddTextureToTriangleList(blastVertexList, Color.GreenYellow, depth, r.blastTriangles, Room.plateTexCoords, true); r.AddTextureToTriangleList(blastVertexList, Color.GreenYellow, depth, blastTriangleList, Room.plateTexCoords, true); } else { r.AddTextureToTriangleList(rectVertexList, Color.GreenYellow, depth, textureTriangleList, Room.plateTexCoords, true); //r.AddTextureToTriangleList(rectVertexList, Color.GreenYellow, depth, r.projectilesTriangles[(int)ProjectileType.Plasma], Room.plateTexCoords, true); } } if (type == ProjectileType.Missile) { if (exploding == true) { //r.AddTextureToTriangleList(blastVertexList, Color.Orange, depth, r.blastTriangles, Room.plateTexCoords, true); r.AddTextureToTriangleList(blastVertexList, Color.Orange, depth, blastTriangleList, Room.plateTexCoords, true); } else { r.AddTextureToTriangleList(rectVertexList, Color.White, depth, textureTriangleList, Room.plateTexCoords, true); //r.AddTextureToTriangleList(rectVertexList, Color.White, depth, r.projectilesTriangles[(int)ProjectileType.Missile], Room.plateTexCoords, true); } } if (type == ProjectileType.EyeLaser) { r.AddTextureToTriangleList(rectVertexList, Color.Red, depth, textureTriangleList, Room.plateTexCoords, true); } if (type == ProjectileType.Laser) { if (exploding == true) { //r.AddTextureToTriangleList(blastVertexList, Color.Blue, depth, r.blastTriangles, Room.plateTexCoords, true); r.AddTextureToTriangleList(blastVertexList, Color.Blue, depth, blastTriangleList, Room.plateTexCoords, true); } //r.AddTextureToTriangleList(rectVertexList, Color.White, depth, r.projectilesTriangles[(int)ProjectileType.Laser], Room.plateTexCoords, true); r.AddTextureToTriangleList(rectVertexList, Color.White, depth, textureTriangleList, Room.plateTexCoords, true); } if (blastTriangleList.Count > 0) { Engine.playerTextureEffect.Texture = Projectile.blastTexture; Engine.playerTextureEffect.CurrentTechnique.Passes[0].Apply(); Game1.graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, blastTriangleList.ToArray(), 0, blastTriangleList.Count() / 3, VertexPositionColorNormalTexture.VertexDeclaration); } if(textureTriangleList.Count > 0) { if(type == ProjectileType.Missile) Engine.playerTextureEffect.Texture = Projectile.missileTexture; else if(type == ProjectileType.Laser) Engine.playerTextureEffect.Texture = Projectile.laserTexture; else if (type == ProjectileType.EyeLaser) Engine.playerTextureEffect.Texture = Projectile.blastTexture; else Engine.playerTextureEffect.Texture = Projectile.plasmaTexture; Engine.playerTextureEffect.CurrentTechnique.Passes[0].Apply(); Game1.graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, textureTriangleList.ToArray(), 0, textureTriangleList.Count() / 3, VertexPositionColorNormalTexture.VertexDeclaration); } }