private void appendObject(float x, float y) { if (tagName == "PineWheel") { rect.Y = y - 20; } else { rect.Y = y - new Random().Next(200, 1440); } AnimObject item = new AnimObject(image, frameCount, framesPerSecond, rect, srcRect, tagName, generateTime); objects.Add(item); }
public void update(int speed, int msec) { float x = 1280; while (objects.Count > 0) { AnimObject first = objects[0]; var bounds = first.bounds; if (bounds.Right < 0) { objects.RemoveAt(0); } else { break; } } if (objects.Count > 0) { var obj = objects[objects.Count - 1]; var bounds = obj.bounds; x = bounds.Right; } if (x > 0 && generate) { x = 1280; appendObject(x, generateY); generate = false; } int dx = -speed * msec; foreach (var obj in objects) { obj.move(dx, 0); obj.updateFrame(msec); if (obj.bounds.Right < 0) { startTimer = true; timeFlag = DateTime.Now; } } if (tagName == "Star") { totalTime = DateTime.Now - startTime; if (totalTime.TotalSeconds > generateTime) { startTimer = true; } } if (startTimer) { currentTime = DateTime.Now - timeFlag; if (currentTime.TotalSeconds > generateTime) { timeFlag = DateTime.Now; if (obj.Count < maxItemCount) { generate = true; } startTimer = false; } } }