Before we work on getting those Floaters to work, first we are going to set up the lava collections. So, you may know the procedure by now. First we declare the ArrayList of Lava in the declarations.
ArrayList lavas; /* This holds all of the lava pools that are in this level */ |
lava = Rectangle.FromLTRB(380, 520, 420, thelandheight); // Positions a lava on the display at these coordinates. |
lavas = new ArrayList(20); //Create the arraylist. lavas.Add(Rectangle.FromLTRB(380, 520, 420, thelandheight)); // Positions a lava on the display at these coordinates. |
foreach (Rectangle lava in lavas) { gfx.FillRectangle(lavabrsh, lava); gfx.DrawRectangle(Pens.DarkOrange, lava); // Draw the lava to the form. } |
foreach (Rectangle lava in lavas) { if (playerloc.IntersectsWith(lava)) { // Touched the lava, now you must die. isgoner = true; playerveloc = PFMain.thesbarinitialvelocity; // This is for a falling animation when the player is beaten. } } |
else if (e.KeyCode == Keys.L) { if (!ismousedown) { modobject = 'L'; } } |
case 'L': placed = Rectangle.FromLTRB(Math.Min(initialpt.X, finalpt.X), Math.Min(initialpt.Y, finalpt.Y), Math.Max(initialpt.X, finalpt.X), Math.Max(initialpt.Y, finalpt.Y)); lavas.Insert(0, placed); // Add the lava to the level. break; |
bw.Write(lavas.Count); // Next, write lavas to the file. foreach (Rectangle lava in lavas) { bw.Write(lava.Left); bw.Write(lava.Top); bw.Write(lava.Right); bw.Write(lava.Bottom); // Write lava LTRB to binary file. } |
lavas = new ArrayList(20); //Create the arraylist. lavas.Add(Rectangle.FromLTRB(380, 520, 420, thelandheight)); // Positions a lava on the display at these coordinates. |
lavas = new ArrayList(br.ReadInt32()); // Number of lava pools. for (lv = 0; lv < lavas.Capacity; lv++) { lavas.Add(Rectangle.FromLTRB(br.ReadInt32(), br.ReadInt32(), br.ReadInt32(), br.ReadInt32())); // Create rectangle that forms the lava pool. } |
SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Level Files|*.lvl"; sfd.InitialDirectory = Application.StartupPath; sfd.OverwritePrompt = true; sfd.Title = "Select the location where this level will be saved."; if (sfd.ShowDialog() == DialogResult.OK) { System.IO.FileStream fs = new System.IO.FileStream(sfd.FileName , System.IO.FileMode.Create); System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs); |
private void loadlevel(string filename) |
loadlevel(Application.StartupPath + @"\data.lvl"); // Load the level information from the file. |