| | | |
| 1 | | - | public static void main() |
| 1 | + | public override void Update(GameTime time) |
| 2 | 2 | | { |
| 3 | | - | int a = 5; |
| 3 | + | if (time == null) |
| 4 | | - | int b = 10; |
| 4 | + | throw new ArgumentNullException("Time mustn't be null"); |
| 5 | | - | int c = addiere(a, b); |
| 6 | | - | } |
| 8 | | - | public int addiere(int x1, int x2) |
| 6 | + | particles.Clear(); |
| 9 | | - | { |
| 10 | | - | return x1 + x2; |
| 11 | | - | } |
| 8 | + | float distanceY, scale, sinOffset, angleRadians; |
| 9 | + | int timeOffsetY, timeOffsetX, snowSpaceX, snowSpaceY, |
| 10 | + | startX, startY, rndOffsetX, rndOffsetY, posX, posY; |
| 11 | + | Rectangle sourceRect, view, drawRect; |
| 12 | + | Particle particle; |
| 13 | + | Color ambientColor = new Color(10, 10, 20); |
| 14 | + | Color drawColor = new Color(Math.Max(lights.AmbientColor.R / 255f, 0.4f), |
| 15 | + | Math.Max(lights.AmbientColor.G / 255f, 0.4f), |
| 16 | + | Math.Max(lights.AmbientColor.B / 255f, 0.4f)); |
| 17 | + | Random rnd = new Random(20); |
| 19 | + | angleRadians = MathHelper.ToRadians(-windAngle); |
| 20 | + | counter += (uint)time.ElapsedGameTime.Milliseconds; |
| 21 | + | distanceY = (float)((counter * Math.Max(speed, minSpeed)) / 1000f); |
| 22 | + | sourceRect = new Rectangle(0, 0, snow_part.Width, snow_part.Height); |
| 23 | + | view = new Rectangle(0, 0, window.Width, window.Height); |
| 24 | + | timeOffsetY = (int)((float)Settings.CurrentBackbufferHeight * distanceY); |
| 25 | + | timeOffsetX = (int)(timeOffsetY * (float)Math.Tan(angleRadians)); |
| 26 | + | snowSpaceX = (Settings.CurrentBackbufferWidth / horizontalDrops) + (Settings.CurrentBackbufferWidth / 10); |
| 27 | + | snowSpaceY = (Settings.CurrentBackbufferHeight / verticalDrops) + (Settings.CurrentBackbufferHeight / 10); |
| 28 | + | for (int x = 0; x < horizontalDrops; x++) |
| 29 | + | { |
| 30 | + | for (int y = 0; y < verticalDrops; y++) |
| 31 | + | { |
| 32 | + | scale = (float)Math.Max(rnd.NextDouble(), minScale) * Settings.Scale; |
| 33 | + | sinOffset = 0.3f * (float)(((float)snowSpaceX / 2f) * Math.Sin(counter / 4500f * (1f / Math.Max(speed, minSpeed)) + (x + 1f) / (y + 1f))); |
| 34 | + | startX = snowSpaceX * x; |
| 35 | + | startY = snowSpaceY * y; |
| 36 | + | rndOffsetX = 2 * (rnd.Next(snowSpaceX) - snowSpaceX / 2); |
| 37 | + | rndOffsetY = 2 * (rnd.Next(snowSpaceY) - snowSpaceY / 2); |
| 38 | + | posX = (startX + rndOffsetX + timeOffsetX + (int)(sinOffset * (float)Math.Cos(angleRadians))) % Settings.CurrentBackbufferWidth; |
| 39 | + | posY = startY + rndOffsetY + timeOffsetY; |
| 40 | + | if (windAngle > -45f && windAngle <= 45f) |
| 41 | + | { |
| 42 | + | posY = (posY - (int)(sinOffset * (float)Math.Sin(angleRadians))) % Settings.CurrentBackbufferHeight; |
| 43 | + | } |
| 44 | + | else |
| 45 | + | { |
| 46 | + | if (windAngle > 45f) |
| 47 | + | { |
| 48 | + | sinOffset = -sinOffset; |
| 49 | + | } |
| 50 | + | posY = (posY - (int)(sinOffset * (float)Math.Cos(angleRadians))) % Settings.CurrentBackbufferHeight; |
| 51 | + | } |
| 52 | + | while (posX < 0) |
| 53 | + | posX += Settings.CurrentBackbufferWidth; |
| 54 | + | while (posY < 0) |
| 55 | + | posY += Settings.CurrentBackbufferHeight; |
| 57 | + | drawRect = new Rectangle(posX, posY, (int)(sourceRect.Width * Settings.Scale), (int)(sourceRect.Height * Settings.Scale)); |
| 58 | + | if (view.Contains(drawRect) || view.Intersects(drawRect)) |
| 59 | + | { |
| 60 | + | particle = new Particle(new Vector2(drawRect.X, drawRect.Y), snow_part, drawColor, scale); |
| 61 | + | particles.AddFirst(particle); |
| 62 | + | } |
| 63 | + | } |
| 64 | + | } |
| 65 | + | } |