private void FormView_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Left) { _objPosition = objPosition.Left; } if (e.KeyCode == Keys.Right) { _objPosition = objPosition.Right; } if (e.KeyCode == Keys.Up) { _objPosition = objPosition.Up; } if (e.KeyCode == Keys.Down) { _objPosition = objPosition.Down; } if ((e.KeyCode == Keys.Space) && brojSpace > 0) { brojSpace--; lblZastaniBroj.Text = brojSpace.ToString(); _objPosition = objPosition.Stop; } }
public FormView() { brojSpace = 3; tmp = 0; _x = 50; _y = 50; _objPosition = objPosition.Stop; System.Media.SoundPlayer sp = new System.Media.SoundPlayer(Resource1.motion); //sp.PlayLooping(); sp.Play(); InitializeComponent(); }
private void tmrMoving_Tick(object sender, EventArgs e) { Random r = new Random(); broj = r.Next(1, 3); if (broj == 1 && label1.Location.Y < 400) { // label1.Location = new Point(label1.Location.X, label1.Location.Y + 10); } else if (label1.Location.Y > 10) { label1.Location = new Point(label1.Location.X, label1.Location.Y - 10); } broj = r.Next(1, 3); if (broj == 1 && label2.Location.Y < 400) { label2.Location = new Point(label2.Location.X, label2.Location.Y + 10); } else { label2.Location = new Point(label2.Location.X, label2.Location.Y - 10); } broj = r.Next(1, 3); if (broj == 1 && label11.Location.Y < 400) { label11.Location = new Point(label11.Location.X, label11.Location.Y + 10); } else { label11.Location = new Point(label11.Location.X, label11.Location.Y - 10); } broj = r.Next(1, 3); if (broj == 1 && label12.Location.Y < 400) { label12.Location = new Point(label12.Location.X, label12.Location.Y + 10); } else { label12.Location = new Point(label12.Location.X, label12.Location.Y - 10); } broj = r.Next(1, 3); if (broj == 1 && label13.Location.Y < 400) { label13.Location = new Point(label13.Location.X, label13.Location.Y + 10); } else { label13.Location = new Point(label13.Location.X, label13.Location.Y - 10); } broj = r.Next(1, 3); if (broj == 1 && label8.Location.Y < 400) { label8.Location = new Point(label8.Location.X, label8.Location.Y + 10); } else { label8.Location = new Point(label8.Location.X, label8.Location.Y - 10); } broj = r.Next(1, 3); if (broj == 1 && label5.Location.Y < 400) { label5.Location = new Point(label5.Location.X, label5.Location.Y + 10); } else { label5.Location = new Point(label5.Location.X, label5.Location.Y - 10); } broj = r.Next(1, 3); if (broj == 1 && label10.Location.Y < 400) { label10.Location = new Point(label10.Location.X, label10.Location.Y + 10); } else { label10.Location = new Point(label10.Location.X, label10.Location.Y - 10); } broj = r.Next(1, 3); if (broj == 1 && label7.Location.Y < 400) { label7.Location = new Point(label7.Location.X, label7.Location.Y + 10); } else { label7.Location = new Point(label7.Location.X, label7.Location.Y - 10); } broj = r.Next(1, 3); if (broj == 1 && label9.Location.Y < 400) { label9.Location = new Point(label9.Location.X, label9.Location.Y + 10); } else { label9.Location = new Point(label9.Location.X, label9.Location.Y - 10); } broj = r.Next(1, 3); if (broj == 1 && label4.Location.Y < 400) { label4.Location = new Point(label4.Location.X, label4.Location.Y + 10); } else { label4.Location = new Point(label4.Location.X, label4.Location.Y - 10); } //label1.Location = new Point(label1.Location.X + 5, label1.Location.Y + 5); if (_objPosition == objPosition.Stop) { _x = _x + 0; _y = _y + 0; } if (_objPosition == objPosition.Right && _x < 660) { _x += 5; lblCovek.Location = new Point(_x, _y); } if (_objPosition == objPosition.Left && _x > 0) { _x -= 5; lblCovek.Location = new Point(_x, _y); } if (_objPosition == objPosition.Up && _y > 0) { _y -= 5; lblCovek.Location = new Point(_x, _y); } if (_objPosition == objPosition.Down && _y < 330) { _y += 5; lblCovek.Location = new Point(_x, _y); } //odbivanje if (_x == 640) { _objPosition = objPosition.Left; } if (_x == 0) { _objPosition = objPosition.Right; } if (_y == 330) { _objPosition = objPosition.Up; } if (_y == 0) { _objPosition = objPosition.Down; } Invalidate(); }