Ignore:
Timestamp:
02/21/2012 01:23:51 PM (3 years ago)
Author:
acarter
Message:

Match game always clears

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Code/oMaE/oMaE/MiniGames/Match.cs

    r44 r58  
    2424        int[] offset = new int[]{22, 17, 0, 25, 38};
    2525        String[] energies = new String[] { "Kinetic Energy", "Electric Energy", "Chemical Energy", "Sound Energy", "Light Energy", "Thermal Energy", "Wind Energy" };
    26 
     26        Dictionary<Vector4, bool> lines = new Dictionary<Vector4, bool>();
    2727        /// <summary>
    2828        /// Initializes the match minigame.
     
    3434            for (int i = 0; i < 2; ++i)
    3535                for (int j = 0; j < energies.Length; ++j)
    36                     radioGroup.addRadioButton(new Vector2(i == 0 ? 165 : 590, 40 * j + 106), energies[j], i == 0 ? TextLocation.LEFT : TextLocation.RIGHT);
     36                    radioGroup.addRadioButton(new Vector2(i == 0 ? 170 : 470, 40 * j + 120), energies[j], i == 0 ? TextLocation.LEFT : TextLocation.RIGHT);
    3737            matchGroup = new RadioGroup();
    3838            children.Add(matchGroup);
    39             children.Add(new MatchImage(matchGroup, new Image2D("Sprites/drum", new Rectangle(310, 20, 100, 100))));
    40             children.Add(new MatchImage(matchGroup, new Image2D("Sprites/microphone", new Rectangle(325, 170, 50, 100))));
    41             children.Add(new MatchImage(matchGroup, new Image2D("Sprites/speaker", new Rectangle(300, 320, 100, 100))));
     39            children.Add(new MatchImage(matchGroup, new Image2D("Sprites/drum", new Rectangle(270, 70, 100, 100))));
     40            children.Add(new MatchImage(matchGroup, new Image2D("Sprites/microphone", new Rectangle(295, 190, 50, 100))));
     41            children.Add(new MatchImage(matchGroup, new Image2D("Sprites/speaker", new Rectangle(270, 310, 100, 100))));
    4242            base.Initialize();
     43        }
     44        public override void Update()
     45        {
     46            if (radioGroup.ActiveButton != null && matchGroup.ActiveButton != null)
     47            {
     48                Vector4 line = new Vector4(radioGroup.ActiveButton.Center.X,
     49                                           radioGroup.ActiveButton.Center.Y,
     50                                           matchGroup.ActiveButton.Center.X,
     51                                           matchGroup.ActiveButton.Center.Y);
     52                if (!lines.ContainsKey(line))
     53                    lines.Add(line, true);
     54                else
     55                    lines[line] = !lines[line];
     56                radioGroup.ClearActive();
     57                matchGroup.ClearActive();
     58            }
     59            base.Update();
    4360        }
    4461        /// <summary>
     
    5168            if (radioGroup.ActiveButton != null)
    5269                screen.DrawLine(radioGroup.ActiveButton.Center, gameState.MousePos, Color.Black);
     70            if (matchGroup.ActiveButton != null)
     71                screen.DrawLine(matchGroup.ActiveButton.Center, gameState.MousePos, Color.Black);
     72            foreach (KeyValuePair<Vector4, bool> pair in lines)
     73                if (pair.Value)
     74                    screen.DrawLine(new Vector2(pair.Key.X, pair.Key.Y), new Vector2(pair.Key.Z, pair.Key.W), Color.White);
     75            screen.DrawText("Match the images to the forms of energy that they convert", new Vector2(320, 10), TextHorizontal.CENTERED, TextVertical.TOP, Color.White);
     76            screen.DrawText("Starts as", new Vector2(220, 60), TextHorizontal.CENTERED, TextVertical.TOP, Color.White);
     77            screen.DrawText("and becomes", new Vector2(420, 60), TextHorizontal.CENTERED, TextVertical.TOP, Color.White);
    5378            base.Draw(screen, gameState);
    5479        }
Note: See TracChangeset for help on using the changeset viewer.