public void Walk(char Dir, double frame_time) { float d = (float)(Settings.PlayerSpeed * frame_time); switch (Dir) { case 'w': if (d > RayCast.Ray(x, y, a)) { break; } x = x + d * cos_a; y = y + d * sin_a; break; case 's': if (d > RayCast.Ray(x, y, a + PI)) { break; } x = x - d * cos_a; y = y - d * sin_a; break; case 'a': if (d > RayCast.Ray(x, y, a - HalfPI)) { break; } x = x + d * sin_a; y = y - d * cos_a; break; case 'd': if (d > RayCast.Ray(x, y, a + HalfPI)) { break; } x = x - d * sin_a; y = y + d * cos_a; break; case 'q': Turn(-1 * frame_time); break; case 'e': Turn(1 * frame_time); break; } }
public void Draw(RenderWindow render) { DrawBG(render); float[] dists = new float[Settings.RAY_COUNT]; float[] offsets = new float[Settings.RAY_COUNT]; double[] angles = new double[Settings.RAY_COUNT]; sw.Start(); int i = 0; double angle = a - Settings.Half_FOV; while (angle < a + Settings.Half_FOV && i < Settings.RAY_COUNT) { angles[i] = angle; angle += Settings.deltaFOV; i++; } for (int tid = 0; tid < dists.Length; tid++) { unsafe { fixed(bool *map = Map.map) { float[] mas = new float[2]; RayCast.Ray(x, y, angles[tid], map, Map.Width, mas); dists[tid] = mas[0] * (float)Math.Cos(a - angles[tid]); offsets[tid] = mas[1]; } } } sw.Stop(); CalcTime = sw.Elapsed; sw.Reset(); sw.Start(); int j = 0; float Screen_x = 0; foreach (double dist in dists) { float wall_height = (float)(Settings.Camera_Dist * Settings.WallHeight / dist * .0036F); float sky = Settings.sHalfHeight - wall_height / 2; var line = new RectangleShape(new Vector2f(Settings.Scale, wall_height)) { Texture = wall_texture, TextureRect = new IntRect((int)(offsets[j] * Settings.TextureScale), 0, 2, Settings.TextureScale), Position = new Vector2f(Screen_x, sky) }; render.Draw(line); j++; Screen_x += Settings.Scale; } sw.Stop(); DrawTime = sw.Elapsed; StaminaBar.Progress = Stamina; render.Draw(StaminaBar); }