private void UpdateTimer_Tick(object sender, EventArgs e) { this.RoadState -= (byte)this.Speed; float stepSize = this.ClientSize.Height / (float)this.ClientSize.Width * 16; if (this.MovingUp) { if (this.ViewPosition - stepSize < 0) { this.ViewPosition = 0; } else { this.ViewPosition -= stepSize; } } else if (this.MovingDown) { if (this.ViewPosition + stepSize > 256 + this.TotalCarHeight) { this.ViewPosition = 256 + this.TotalCarHeight; } else { this.ViewPosition += stepSize; } } this.CatchableItemsState += this.Speed; if (this.CatchableItemsState >= 64) { int moveByAmount = (int)Math.Floor(this.CatchableItemsState / 64); this.CatchableItemsState -= moveByAmount * 64; int maxY = (int)Math.Ceiling((TotalCarHeight + 256 + this.ToGameSize(this.ClientSize.Height)) / 64); for (int i = 0; i < this.CatchableItems.Count; i++) { int newY = this.CatchableItems[i].PositionY + moveByAmount; if (newY > maxY) { this.CatchableItems.RemoveAt(i); i--; } else { this.CatchableItems[i] = new CatchableItem(this.CatchableItems[i].Item, this.CatchableItems[i].PositionX, newY); } } for (int i = 0; i < moveByAmount; i++) { int[] Ys = Enumerable.Range(0, 4).OrderBy(item => this.R.NextDouble()).ToArray(); Item[] items = this.GetMaxFourSpawnedItems(); CatchableItem[] catchableItems = new CatchableItem[items.Length]; for (int j = 0; j < catchableItems.Length; j++) { catchableItems[j] = new CatchableItem(items[j], (byte)Ys[j], i); } this.CatchableItems.AddRange(catchableItems); } } }
private void MainForm_MouseClick(object sender, MouseEventArgs e) { float slotSize = StorageGui.GetSlotSize(this.ClientSize); float inventoryUpSide = this.ClientSize.Height / 2 - slotSize * 4; if (new Rectangle(0, (int)(inventoryUpSide - slotSize / 16), (int)(slotSize + slotSize / 16), (int)(slotSize * 8 + slotSize / 8)).Contains(e.Location)) { if (e.X >= slotSize / 16 && e.X < slotSize - slotSize / 16 && e.Y >= inventoryUpSide && e.Y < this.ClientSize.Height + slotSize * 4) { float inSlotLocationY = (e.Y - inventoryUpSide) % slotSize; if (inSlotLocationY >= slotSize / 16 && inSlotLocationY < slotSize - slotSize / 16) { int slotIndex = (int)Math.Floor((e.Y - inventoryUpSide) / slotSize); Item oldHeldItem = this.HeldItem; this.HeldItem = this.Inventory[slotIndex]; this.Inventory[slotIndex] = oldHeldItem; } } } else { if (this.CurrentGui != null) { this.CurrentGui.Click(this, e); } else { float objectPreferredLeftEdge = ToScreenSize(544); if (e.X >= objectPreferredLeftEdge && e.X < this.ToScreenSize(736)) { float gameSizeYLocation = this.ViewPosition + ToGameSize(e.Y); float pixelsReached = 128; for (int i = 0; i < this.RoadObjects.Count; i++) { pixelsReached += this.RoadObjects[i].GetHeight(192); if (pixelsReached > gameSizeYLocation) { this.RoadObjects[i].Click(this, e, new Point((int)objectPreferredLeftEdge, (int)this.ToScreenSize(pixelsReached - this.RoadObjects[i].GetHeight(192) - this.ViewPosition)), this.ToScreenSize(192)); break; } } } else if (e.X >= this.ClientSize.Width * 3 / (float)4) { int catchableItemX = (int)Math.Floor((e.X - this.ClientSize.Width * 3 / (float)4) / (this.ClientSize.Width / (float)16)); int catchableItemY = (int)Math.Floor((this.ViewPosition + this.ToGameSize(e.Y) + 64 - this.CatchableItemsState) / 64); bool found = false; for (int i = 0; i < this.CatchableItems.Count; i++) { if (this.CatchableItems[i].PositionX == catchableItemX && this.CatchableItems[i].PositionY == catchableItemY) { Item oldHeldItem = this.HeldItem; this.HeldItem = this.CatchableItems[i].Item; if (oldHeldItem != null) { CatchableItem newCatchableItem = new CatchableItem(oldHeldItem, (byte)catchableItemX, catchableItemY); this.CatchableItems[i] = newCatchableItem; } else { this.CatchableItems.RemoveAt(i); found = true; break; } } } if (!found && this.HeldItem != null) { CatchableItem newCatchableItem = new CatchableItem(this.HeldItem, (byte)catchableItemX, catchableItemY); this.CatchableItems.Add(newCatchableItem); this.HeldItem = null; } } } } }