protected override void LoadContent() { experiment = new test(); test = new smthng(new Vector2(100, 100), new Vector2(0, 0), 1); spriteBatch = new SpriteBatch(GraphicsDevice); font = Content.Load <SpriteFont>("SpriteFont1"); gnd = new Rectangle(0, 180, 1800, 5700); texture1 = Content.Load <Texture2D>("51114"); texture2 = Content.Load <Texture2D>("square"); texture3 = Content.Load <Texture2D>("mint"); rectangle = new Rectangle(360, 160, 200, 200); texture4 = Content.Load <Texture2D>("square"); texture5 = Content.Load <Texture2D>("mint"); textureblank = Content.Load <Texture2D>("pixel"); p1 = new player(texture1, GraphicsDevice.Viewport, 0, Keys.Q, Keys.E, Keys.W, Keys.S, Keys.A, Keys.D); p2 = new player(texture1, GraphicsDevice.Viewport, 560, Keys.U, Keys.O, Keys.I, Keys.K, Keys.J, Keys.L); level = new map(texture1, texture2, texture3, texture4, texture5, textureblank); }
public void nextstep(map m1) { mapp = m1; if (detected == false) { if (aim.X < 0) { nextfactor.X = (float)Math.Floor((position.X - 1) / size) * size; aimdirection.X = -1; } if (aim.X > 0) { nextfactor.X = (float)Math.Ceiling((position.X + 1) / size) * size; aimdirection.X = 1; } if (aim.Y < 0) { nextfactor.Y = (float)Math.Floor((position.Y - 1) / size) * size; aimdirection.Y = -1; } if (aim.Y > 0) { nextfactor.Y = (float)Math.Ceiling((position.Y + 1) / size) * size; aimdirection.Y = 1; } shift = new Vector2((float)Math.Abs(nextfactor.X - position.X), (float)Math.Abs(nextfactor.Y - position.Y)); referenceangle = (float)Math.Abs(Math.Atan2(aim.Y, aim.X)); delta = new Vector2((float)Math.Sqrt((shift.X * shift.X) + ((Math.Sin(referenceangle) * shift.X / Math.Cos(referenceangle))) * (Math.Sin(referenceangle) * shift.X / Math.Cos(referenceangle))), (float)Math.Sqrt((shift.Y * shift.Y) + ((Math.Cos(referenceangle) * shift.Y / Math.Sin(referenceangle)) * (Math.Cos(referenceangle) * shift.Y / Math.Sin(referenceangle))))); if (delta.X < delta.Y) { xchosen = true; skipstep = new Vector2(shift.X, (shift.X * (float)Math.Abs(Math.Tan(referenceangle)))); } if (delta.X > delta.Y) { xchosen = false; skipstep = new Vector2((shift.Y * (1 / (float)Math.Abs((Math.Tan(referenceangle))))), shift.Y); } skipstep = skipstep * aimdirection; position = position + skipstep; coarse = new Vector2((float)Math.Ceiling((position.X + aimdirection.X) / size), (float)Math.Floor((position.Y + aimdirection.Y) / size)); samedifference = new Vector2((float)Math.Abs(coarse.Y - initial.Y), (float)Math.Abs(coarse.X - initial.X)); difference = new Vector2((float)Math.Abs(position.Y - initial.Y), (float)Math.Abs(position.X - initial.X)); if (coarse.X > 0 && coarse.X < 100 && coarse.Y > 0 && coarse.Y < 100) { if (m1.array[(int)coarse.X, (int)coarse.Y] > 0) { detected = true; if (position.X > coarse.X) { hitpos.X = Math.Abs(position.X - (coarse.X * size)); } if (position.X < coarse.X) { hitpos.X = Math.Abs((coarse.X * size) - position.X); } if (position.Y > coarse.Y) { hitpos.Y = position.Y - (coarse.Y * size); } if (position.Y < coarse.Y) { hitpos.Y = (coarse.Y * size) - position.Y; } } } } }
public void update(map M) { if (velocity.X > 0) { generaldirection.X = 1; } else { generaldirection.X = -1; } if (velocity.Y > 0) { generaldirection.Y = 1; } else { generaldirection.Y = -1; } hitpoint = 0; facingPoint = new Vector2((float)Math.Cos(angle), -(float)Math.Sin(angle)); lateral = new Vector2((float)Math.Sin(-angle), -(float)Math.Cos(-angle)); hitbox.X = (int)pos.X; hitbox.Y = (int)pos.Y; perpendicular = new Vector2((float)Math.Sin(-angle), -(float)Math.Cos(-angle)); orbit = new Vector2(pos.X + (facingPoint.X * 400), pos.Y + (facingPoint.Y * 400)); ofcoarse = new Vector2((float)(Math.Floor(pos.X / 400)), (float)(Math.Floor(pos.Y / 400))); line.Clear(); laser.Clear(); fov = v.Width; for (int i = 0; i < 560; i++) { int repeat = i - 560 / 2; laser.Add(new smthng(new Vector2((int)(perpendicular.X * repeat) + (int)orbit.X, (int)(perpendicular.Y * repeat) + (int)orbit.Y), pos, i + screenposition)); line.Add(new Rectangle((int)(perpendicular.X * repeat) + (int)orbit.X, (int)(perpendicular.Y * repeat) + (int)orbit.Y, 40, 40)); // laser.Add(new smthng(new Vector2(10,10))); } KeyboardState ks = Keyboard.GetState(); for (int i = 0; i < M.thng.Count; i++) { if (M.thng[i].Intersects(hitbox)) { hitpoint++; } } if (hitpoint == 0) { pos += velocity; bounceX = false; } else { if (bounceX == false) { pos = new Vector2(3000, 3000); velocity = new Vector2(0, 0); angle = 0; } bounceX = true; } // hitpoint = 0; // pos.Y += velocity.Y; // for (int i = 0; i < M.thng.Count; i++) // { // if (M.thng[i].Intersects(hitbox)) // { // hitpoint++; // } // } // if (hitpoint == 0) // { // bounceY = false; // } //else // { // if (bounceY == true) // { // velocity.Y = -velocity.Y; // } // bounceY = true; // } if (velocity.X > 75) { velocity.X = 74; } if (velocity.Y > 75) { velocity.Y = 74; } if (velocity.X < -75) { velocity.X = -74; } if (velocity.Y < -75) { velocity.Y = -74; } /// velocity += facingPoint * 2; if (ks.IsKeyDown(moveforward)) { // velocity += facingPoint * 5; pos += facingPoint * 100; } if (ks.IsKeyDown(moveleft)) { // velocity -= lateral * 10; pos -= lateral * 100; } if (ks.IsKeyDown(reverse)) { // velocity-= facingPoint* 10; pos -= facingPoint * 100; } if (ks.IsKeyDown(moveright)) { // velocity += lateral* 20; pos += lateral * 100; } if (ks.IsKeyDown(rotateleft)) { angle -= 0.05f; } if (ks.IsKeyDown(rotateright)) { angle += 0.05f; } //for (int i = 0; i < 50; i++) //{ // line.Add(new Rectangle((int)((facingPoint.X * i) + (int)pos.X) / 4, (int)((facingPoint.Y * i) + (int)pos.Y) / 4, 1, 1)); // line.Add(new Rectangle((int)ofcoarse.X / 4, (int)ofcoarse.Y / 4, 5, 5)); //} for (int i = 0; i < 25; i++) { for (int j = 0; j < laser.Count; j++) { laser[j].nextstep(M); } } }