public PowerupDrawer(DrawingPanel drawingPanel, Powerup powerup) { this.drawingPanel = drawingPanel; this.powerup = powerup; this.currentlyAnimating = false; this.marioStarGif = DrawingImages.PowerupGif.Clone() as Bitmap; }
public Form1(GameController ctl) { //Set up the general handlers and variables of the form InitializeComponent(); theController = ctl; theWorld = theController.GetWorld(); theController.UpdateWorld += OnFrame; // Set up the form. panel = new DrawingPanel(theWorld); panel.Location = new Point(0, menuSize); panel.Size = new Size(viewSize, viewSize); this.Controls.Add(panel); // Set the window size ClientSize = new Size(viewSize, viewSize + menuSize); //Save our boxes to variables IPName = hostText; playerName = playerText; // Set up key and mouse handlers this.KeyDown += HandleKeyDown; this.KeyUp += HandleKeyUp; //Allow enter button to connect to server AcceptButton = connectButton; //Set up handlers for controls panel.MouseMove += OnMouseMove; panel.MouseClick += HandleMouseClick; theController.PlayerIDGiven += InitializeWithID; theController.Error += DisplayErrorMessage; }
public Form1(GameController ctl) { InitializeComponent(); theController = ctl; theWorld = theController.GetWorld(); theController.RegisterServerUpdateHandler(OnFrame); //Register OnFrame as the controller event handler theController.RegisterConnectionErrorHandler(UnlockMenuBar); //Register UnlockMenuBar as the controller event handler ClientSize = new Size(Constant.ClientSize, Constant.ClientSize + 35); drawingPanel = new DrawingPanel(theWorld); drawingPanel.Location = new Point(0, 35); drawingPanel.Size = new Size(Constant.ViewSize, Constant.ViewSize); drawingPanel.BackColor = Color.Black; this.Controls.Add(drawingPanel); // Set KeyPreview object to true to allow the form to process // the key before the control with focus processes it. this.KeyPreview = true; this.KeyDown += new KeyEventHandler(Form1_KeyDown); this.KeyUp += new KeyEventHandler(Form1_KeyUp); drawingPanel.MouseMove += new MouseEventHandler(Form1_MouseMove); drawingPanel.MouseDown += new MouseEventHandler(Form1_MouseDown); drawingPanel.MouseUp += new MouseEventHandler(Form1_MouseUp); FormClosed += OnExit; }
/// <summary> /// Subscribes to the events and initializes the variables needed in the constructor /// </summary> public TankWarsView(GameController ctl) { InitializeComponent(); controller = ctl; FormClosed += OnExit; world = controller.GetWorld(); controller.UpdateArrived += OnFrame; controller.Error += ShowError; controller.Connected += HandleConnected; ClientSize = new Size(viewSize, viewSize + menuSize); drawingPanel = new DrawingPanel(world, controller); drawingPanel.Location = new Point(0, menuSize); drawingPanel.Size = new Size(viewSize, viewSize); drawingPanel.MouseDown += HandleMouseDown; drawingPanel.MouseUp += HandleMouseUp; drawingPanel.MouseMove += HandleMouseMovement; Controls.Add(drawingPanel); this.KeyDown += HandleKeyDown; this.KeyUp += HandleKeyUp; }
public BeamDrawer(DrawingPanel drawingPanel, Beam beam) { this.drawingPanel = drawingPanel; this.beam = beam; this.beamGif = DrawingImages.LaserBeamGif.Clone() as Bitmap; this.currentlyAnimating = false; this.numFramesAnimatedSoFar = 0; this.numFramesToAnimate = 40; }
public ExplosionDrawer(DrawingPanel drawingPanel, Tank tank) { currentlyAnimating = false; this.drawingPanel = drawingPanel; this.tank = tank; this.explosionGif = DrawingImages.ExplosionGif.Clone() as Bitmap; numFramesPassed = 0; }
/// <summary> /// This method sets up our clientsize via defClientsize, as well as setting up our /// drawingpanel size with our now provided worldsize. /// We also handle mouse tracking within our drawing panel. /// </summary> private void SetupPanel() { // Basic Settings ClientSize = new Size(defClientSize, defClientSize); drawingPanel = new DrawingPanel(theWorld, theController); drawingPanel.Location = new Point(0, 0); drawingPanel.Size = new Size(theWorld.size, theWorld.size); drawingPanel.BackColor = Color.Black; // Handling mouse location & clicking drawingPanel.MouseMove += DetectMouseLocation; drawingPanel.MouseDown += HandleMouseDown; drawingPanel.MouseUp += HandleMouseUp; this.Controls.Add(drawingPanel); }
//Initialize DrawingPanel private void InitializeDrawingPanel() { // Initialize drawingPanel drawingPanel = new DrawingPanel(controller); drawingPanel.Location = new Point(0, menuSize); drawingPanel.Size = new Size(viewSize, viewSize); //Register mouse input on drawingPanel drawingPanel.MouseDown += HandleMouseDown; drawingPanel.MouseUp += HandleMouseUp; drawingPanel.MouseMove += HandleMouseMove; // Add DrawingPanel on Main Form thread this.Invoke(new MethodInvoker(() => { this.controller.Update += OnFrame; // Register update drawingPanel this.Controls.Add(drawingPanel); // Add to this form this.KeyPreview = true; // Start listening to User Input } )); }
public Form1() { InitializeComponent(); // Initialize a GameController for the client and register handlers for its events gameController = new GameController(); theWorld = gameController.theWorld; gameController.RedrawFrameEvent += RedrawFrame; gameController.ShowErrorMessageEvent += ShowErrorMessage; gameController.DisableConnectionMenuEvent += DisableConnectionMenu; // Initialize a DrawingPanel for the client and register handler for its events drawingPanel = new DrawingPanel(gameController); drawingPanel.Location = new Point(0, 0); drawingPanel.Size = new Size(800, 800); // A drawingPanel is always 800x800 pixels on the form drawingPanel.MouseMove += GamePanel_MouseMove; drawingPanel.MouseDown += GamePanel_MouseDown; drawingPanel.MouseUp += GamePanel_MouseUp; gamePanel.Controls.Add(drawingPanel); // Add our drawingPanel to the gamePnel on the form }
/// <summary> /// Constructor that sets up the form when given a game controller /// </summary> /// <param name="ctl">controller that the form should use</param> public TankWars(GameController ctl) { InitializeComponent(); TheController = ctl; //Adds the on frame event listener and the error event listener TheController.OnFrameEvent += OnFrame; TheController.ErrorEvent += DisplayError; //Creates a drawing panel in the form ClientSize = new Size(Constants.ViewSize, Constants.ViewSize); drawingPanel = new DrawingPanel(TheController); drawingPanel.BackColor = Color.Black; drawingPanel.Location = new Point(Constants.ViewLocationX, Constants.ViewLocationY); drawingPanel.Size = new Size(ClientSize.Width, ClientSize.Height); Controls.Add(drawingPanel); //Allows mouse clicks to be detected on drawing panel drawingPanel.MouseDown += TankWars_MouseDown; drawingPanel.MouseUp += TankWars_MouseUp; drawingPanel.MouseMove += TankWars_MouseMove; }
/// <summary> /// Main form application. Sets controller, world, and clientsize. Then adds events for controller and finally adds form components /// </summary> public Form1(GameController controller) { //Initialize and set controller to parameter and world to controller's world InitializeComponent(); this.controller = controller; this.world = controller.GetWorld(); //Sets clientsize for form ClientSize = new Size(viewSize, viewSize + menuSize); //Adds listeners to events for controller-view handshake controller.OnUpdate += OnFrame; controller.IDLoaded += SetID; controller.WorldLoaded += SetWorld; // Place and add the start button startButton = new Button(); startButton.Location = new Point(245, 5); startButton.Size = new Size(70, 20); startButton.Text = "Start"; startButton.Click += StartClick; this.Controls.Add(startButton); // Place and add the name label nameLabel = new Label(); nameLabel.Text = "Name:"; nameLabel.Location = new Point(5, 10); nameLabel.Size = new Size(40, 15); this.Controls.Add(nameLabel); // Place and add the name textbox nameText = new TextBox(); nameText.Text = "player"; nameText.MaxLength = 16; nameText.Location = new Point(50, 5); nameText.Size = new Size(70, 15); this.Controls.Add(nameText); // Place and add the host label hostLabel = new Label(); hostLabel.Text = "Host:"; hostLabel.Location = new Point(125, 10); hostLabel.Size = new Size(40, 15); this.Controls.Add(hostLabel); // Place and add the host textbox hostText = new TextBox(); hostText.Text = ""; hostText.Location = new Point(165, 5); hostText.Size = new Size(70, 15); this.Controls.Add(hostText); // Place and add the drawing panel with event when beam gets fired drawingPanel = new DrawingPanel(world); drawingPanel.Location = new Point(0, menuSize); drawingPanel.Size = new Size(viewSize, viewSize); drawingPanel.SetViewSize(viewSize); this.Controls.Add(drawingPanel); controller.BeamFired += drawingPanel.DrawBeam; //Set up control events for keys and mouse inputs this.KeyDown += Moved; drawingPanel.MouseDown += Shoot; drawingPanel.MouseUp += StopShoot; drawingPanel.MouseMove += Aim; this.KeyUp += StopMove; }