public Laser(ContentManager content, float x, float y, float width, float height, float angleSpeed = 0) : base(content, x, y, width, height) { this.angleSpeed = angleSpeed; textureTest = content.Load <Texture2D>("themes/" + Game1.world.currentTheme + "/items/laser"); //Game1.penumbra.Lights.Add(light); raycast = new Raycast(pos, new Vector2(0, 0), 3000); initParticles(); }
private void CheckForClimbable(Raycast climber) { if (climber.GameObject != null) { if (climber.GameObject.Tags.Contains("Climbable")) { if (Input.IsKeyDown(Keys.Space) && _currentJumpTime >= _jumpTimeLimit) { _me.Body.ApplyForce(ref _jump); _currentJumpTime = 0f; } } } }
public void applySpeed() { Vector2 speedVec = new Vector2((float)((speed) * Math.Round(MapTools.getXMultiplier())), (float)((speed) * Math.Round(MapTools.getYMultiplier()))); if ((speed > 0 && !collidesRight(false))) { raycast = new Raycast(rightPoints()[0], MapTools.getMultiplierVec() + new Vector2(0.0000001f, 0.0000001f), 1000, true); CollisionInfo hit = raycast.getHit(); if ((hit.pos - rightPoints()[0]).Length() < speedVec.Length()) { speedVec = hit.pos + MapTools.getMultiplierVec() * 0.1f - rightPoints()[0]; } pos += speedVec; } else if ((speed < 0 && !collidesLeft(false))) { raycast = new Raycast(leftPoints()[0], -MapTools.getMultiplierVec() + new Vector2(0.0000001f, 0.0000001f), 1000, true); CollisionInfo hit = raycast.getHit(); if ((hit.pos - leftPoints()[0]).Length() < speedVec.Length()) { speedVec = hit.pos - MapTools.getMultiplierVec() * 0.1f - leftPoints()[0]; } pos += speedVec; } else { speed = 0; } if ((collisionInfoDownBeginOfFrame.getRealSpeed() > 0 && !collidesRight(false)) || (collisionInfoDownBeginOfFrame.getRealSpeed() < 0 && !collidesLeft(false))) { pos.X += (float)((collisionInfoDownBeginOfFrame.getRealSpeed()) * Math.Round(MapTools.getXMultiplier())); pos.Y += (float)((collisionInfoDownBeginOfFrame.getRealSpeed()) * Math.Round(MapTools.getYMultiplier())); } rect.X = (int)pos.X; rect.Y = (int)pos.Y; }
public void applyFallSpeed(float delta) { if (!isGrounded().collided) { if (fallSpeed < maxFallSpeed) { if (framesSpacePressed >= 30) { fallSpeed += fallAcceleration * 1f; } else { fallSpeed += fallAcceleration * 0.3f; } } framesInAir++; } else if (!Keyboard.GetState().IsKeyDown(Keys.Space) && fallSpeed > 0) { fallSpeed = 0; } if (collidesUp().collided) { fallSpeed = 1; } if (isGrounded().collided&& fallSpeed > 0) { fallSpeed = 0; } if ((fallSpeed) > 0) { Vector2 fallVec = new Vector2((float)((fallSpeed) * (float)(Math.Round(WorldInfo.gravity.X))), (float)((fallSpeed) * (float)(Math.Round(WorldInfo.gravity.Y)))); raycast = new Raycast(downPoint(), WorldInfo.gravity + new Vector2(0.0000001f, 0.0000001f), 1000, true); CollisionInfo hit = raycast.getHit(); if ((hit.pos - downPoint()).Length() < fallVec.Length()) { fallVec = (hit.pos - downPoint()); } pos += fallVec; } else if ((fallSpeed) < 0) { pos.X += (float)((fallSpeed) * (float)(Math.Round(WorldInfo.gravity.X))); pos.Y += (float)((fallSpeed) * (float)(Math.Round(WorldInfo.gravity.Y))); } pos += new Vector2((float)((collisionInfoDownBeginOfFrame.getFallSpeed()) * (float)(Math.Round(WorldInfo.gravity.X))), (float)((collisionInfoDownBeginOfFrame.getFallSpeed()) * (float)(Math.Round(WorldInfo.gravity.Y)))); /* * if(fallSpeed > 0) { * for(int i = 0; i < fallSpeed; i++) { * if (isGrounded().collided) * { * fallSpeed = isGrounded().getFallSpeed() + 1; * //pos += isGrounded().speed; * if (!state.IsKeyDown(Keys.Space)) * framesSpacePressed = 0; * framesInAir = 0; * //break; * } else { * pos.X += (float)(WorldInfo.gravity.X); * pos.Y += (float)(WorldInfo.gravity.Y); * } * } * } * else if (fallSpeed < 0) * { * for (int i = 0; i > fallSpeed; i--) * { * * if (collidesUp()) * { * framesSpacePressed = 30; * fallSpeed = 3; * //break; * } * else * { * pos.X -= (float)(WorldInfo.gravity.X); * pos.Y -= (float)(WorldInfo.gravity.Y); * } * } * } */ }