Bubble Shooter Game in Unity: Part 9

So what if you want to use multiple shooters? The class I wrote for the ray cast shooter can be easily updated so we can use as many shooters as we want in the game.
I’ll place five shooters at the bottom of the screen, and for the sake of this tutorial, each shooter will now have a fixed color type, so the color won’t change after a shot.
(Although you could easily keep the existing logic that handles that in the touch up handler, who knows, it might make things interesting to have each shooter select its color randomly and keep changing its color randomly after every shot.)

The first main changes are to the game view:

I created a shooter prefab, and placed the five shooters on the screen. Each shooter prefab will have its own bullet now.

I moved the input control to a new class, called GameController, attached to the GameScreen gameobject.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using UnityEngine;
using System.Collections;
 
public class GameController : MonoBehaviour {
 
	public RayCastShooter[] shooters;
 
	private RayCastShooter selectedShooter;
 
	private bool mouseDown = false;
 
 
 
	// Update is called once per frame
	void Update () {
		if (Input.touches.Length > 0) {
 
			Touch touch = Input.touches [0];
 
			if (touch.phase == TouchPhase.Began) {
				TouchDown (touch.position);
			} else if (touch.phase == TouchPhase.Canceled || touch.phase == TouchPhase.Ended) {
				TouchUp (Input.mousePosition);
			} else if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary) {
				TouchMove (touch.position);
			}
			TouchMove (touch.position);	
			return;
		} else if (Input.GetMouseButtonDown (0)) {
			mouseDown = true;
			TouchDown (Input.mousePosition);
		} else if (Input.GetMouseButtonUp (0)) {
			mouseDown = false;
			TouchUp (Input.mousePosition);
		} else if (mouseDown) {
			TouchMove (Input.mousePosition);
		}
	}
 
 
	void TouchDown (Vector2 touch) {
 
		selectedShooter = null;
		Vector2 point = Camera.main.ScreenToWorldPoint (touch);
 
		Debug.Log (point.y);
 
		if (point.y < -1f) {
 
 
			var minDistance = 100000.0f;
			RayCastShooter shooter = null;
 
			//look for closest shooter
			foreach (var s in shooters) {
				var d = Vector2.Distance (point, s.transform.position);
				if (d < minDistance) {
					minDistance = d;
					shooter = s;
				}
			}
			selectedShooter = shooter;
 
		}
	}
 
	void TouchUp (Vector2 touch) {
		if (selectedShooter == null)
			return;
		Vector2 point = Camera.main.ScreenToWorldPoint (touch);
		if (Vector2.Distance (point, selectedShooter.transform.position) < 0.2f) {
			selectedShooter.ClearShotPath ();
		} else {
			selectedShooter.HandleTouchUp (touch);
		}
	}
 
	void TouchMove (Vector2 touch) {
		if (selectedShooter == null)
			return;
		selectedShooter.HandleTouchMove (touch);
	}
}

I tried to make the logic selecting the closest shooter to the player’s touch as relaxed as I could manage. There is a minimum Y threshold, so bellow that line every touch will end up selecting a shooter, the closest to the touch point. So I’m not using a minimum distance between touch and shooter, so the player has more space to interact with the game.

And on touch up, if the touch is too close to the shooter, I treat it as a cancelled shot.

The new RayCastShooter looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
 
public class RayCastShooter : MonoBehaviour {
 
	public GameObject[] colorsGO;
	public Ball.BALL_TYPE type;
 
	public GameObject dotPrefab;
	public Bullet bullet;
	public Grid grid;
 
 
	private List<Vector2> dots;
	private List<GameObject> dotsPool;
	private int maxDots = 26;
 
	private float dotGap = 0.32f;
	private float bulletProgress = 0.0f;
	private float bulletIncrement = 0.0f;
	private bool mouseDown = false;
	private bool selected = false;
 
 
 
	// Use this for initialization
	void Start () {
 
		dots = new List<Vector2> ();
		dotsPool = new List<GameObject> ();
 
		var i = 0;
		var alpha = 1.0f / maxDots;
		var startAlpha = 1.0f;
		while (i < maxDots) {
			var dot = Instantiate (dotPrefab) as GameObject;
			var sp = dot.GetComponent<SpriteRenderer> ();
			var c = sp.color;
 
			c.a = startAlpha - alpha;
			startAlpha -= alpha;
			sp.color = c;
 
			dot.SetActive (false);
			dotsPool.Add (dot);
			i++;
		}
 
		//select initial type
		foreach (var go in colorsGO) {
			go.SetActive(false);
		}
 
		colorsGO [(int) type].SetActive (true);
 
	}
 
	public void HandleTouchUp (Vector2 touch) {
 
 
		if (bullet.gameObject.activeSelf)
			return;
 
		if (dots == null || dots.Count < 2)
			return;
 
		ClearShotPath ();
 
		bulletProgress = 0.0f;
		bullet.SetType (type);
		bullet.gameObject.SetActive (true);
		bullet.transform.position = transform.position;
		InitPath ();
 
		EventManager.ShootBall ();
 
	}
 
 
	public void HandleTouchMove (Vector2 touch) {
 
		if (bullet.gameObject.activeSelf)
			return;
 
		if (dots == null) {
			return;
		}
 
		dots.Clear ();
 
		foreach (var d in dotsPool)
			d.SetActive (false);
 
		Vector2 point = Camera.main.ScreenToWorldPoint (touch);
		var direction = new Vector2 (point.x - transform.position.x, point.y - transform.position.y);
 
		RaycastHit2D hit = Physics2D.Raycast(transform.position, direction);
		if (hit.collider != null) {
 
			dots.Add (transform.position);
 
			if (hit.collider.tag == "SideWall") {
				DoRayCast (hit, direction);
			} else {
				dots.Add (hit.point);
				DrawPaths ();
			}
		}
	}
 
	public void ClearShotPath () {
		foreach (var d in dotsPool)
			d.SetActive (false);
 
	}
 
	void DoRayCast (RaycastHit2D previousHit, Vector2 directionIn) {
 
		dots.Add (previousHit.point);
 
		var normal = Mathf.Atan2 (previousHit.normal.y, previousHit.normal.x);
		var newDirection = normal + (  normal - Mathf.Atan2(directionIn.y, directionIn.x) );
		var reflection = new Vector2 (-Mathf.Cos (newDirection), -Mathf.Sin (newDirection));
		var newCastPoint = previousHit.point + (2 * reflection);
 
//		directionIn.Normalize ();
//		newCastPoint = new Vector2(previousHit.point.x + 2 * (-directionIn.x), previousHit.point.y + 2 * (directionIn.y));
//		reflection = new Vector2 (-directionIn.x, directionIn.y);
 
		var hit2 = Physics2D.Raycast(newCastPoint, reflection);
		if (hit2.collider != null) {
			if (hit2.collider.tag == "SideWall") {
				//shoot another cast
				DoRayCast (hit2, reflection);
			} else {
				dots.Add (hit2.point);
				DrawPaths ();
			}
		} else {
			DrawPaths ();
		}
	}
 
 
	// Update is called once per frame
	void Update () {
 
		if (bullet.gameObject.activeSelf) {
 
			bulletProgress += bulletIncrement;
 
			if (bulletProgress > 1) {
				dots.RemoveAt (0);
				if (dots.Count < 2) {
					bullet.gameObject.SetActive (false);
					dots.Clear ();
					return;
				} else {
					InitPath ();
				}
			}
 
			var px = dots [0].x + bulletProgress * (dots [1].x - dots [0].x);
			var py = dots [0].y + bulletProgress * (dots [1].y - dots [0].y);
 
			bullet.transform.position = new Vector2 (px, py);
		}
 
	}
 
	void DrawPaths () {
 
		if (dots.Count > 1) {
 
			foreach (var d in dotsPool)
				d.SetActive (false);
 
			int index = 0;
 
			for (var i = 1; i < dots.Count; i++) {
				DrawSubPath (i - 1, i, ref index);
			}
		}
	}
 
	void DrawSubPath (int start, int end, ref int index) {
		var pathLength = Vector2.Distance (dots [start], dots [end]);
 
		int numDots = Mathf.RoundToInt ( (float)pathLength / dotGap );
		float dotProgress = 1.0f / numDots;
 
		var p = 0.0f;
 
		while (p < 1) {
			var px = dots [start].x + p * (dots [end].x - dots [start].x);
			var py = dots [start].y + p * (dots [end].y - dots [start].y);
 
			if (index < maxDots) {
				var d = dotsPool [index];
				d.transform.position = new Vector2 (px, py);
				d.SetActive (true);
				index++;
			}
 
			p += dotProgress;
		}
	}
 
	void InitPath () {
		var start = dots [0];
		var end = dots [1];
		var length = Vector2.Distance (start, end);
		var iterations = length / 0.15f;
		bulletProgress = 0.0f;
		bulletIncrement = 1.0f / iterations;
	}
 
 
}

The main difference here is that I don’t count the number of shots from inside the shooter. Instead I dispatch an event that the Grid will pick up in this line inside the HandleTouchUp method:

1
EventManager.ShootBall ();

If you prefer, you can call a public method in Grid to update the shot count, I just wanted to show how to do it with events.

The EventManager class looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
using UnityEngine;
using System.Collections;
 
public class EventManager {
 
	public delegate void Event_ShootBall ();
 
	public static event Event_ShootBall  OnShootBall;
 
	public static void ShootBall () {
		if (OnShootBall != null)
			OnShootBall ();
	}
}

And the new Grid class keeps track of the shots and adds a new line to the grid every 10 shots:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
 
public class Grid : MonoBehaviour {
 
	public int ROWS = 20;
 
	public int COLUMNS = 14;
 
	public float TILE_SIZE = 0.68f;
 
	public float changeTypeRate = 0.5f;
 
	public int lines = 20;
 
	public GameObject gridBallGO;
 
	[HideInInspector]
	public float GRID_OFFSET_X = 0;
 
	[HideInInspector]
	public  float GRID_OFFSET_Y = 0;
 
	[HideInInspector]
	public List<List<Ball>> gridBalls;
 
	private List<Ball> matchList;
 
	private List<Ball.BALL_TYPE> typePool;
 
	private Ball.BALL_TYPE lastType;
 
	private int bullets = 0;
 
	void Start () {
 
 
		EventManager.OnShootBall += HandleShootBall;
 
		matchList = new List<Ball> ();
		lastType = (Ball.BALL_TYPE)Random.Range (0, 5);
		typePool = new List<Ball.BALL_TYPE> ();
 
		var i = 0;
		var total = 10000;
		while (i < total) {
			typePool.Add (GetBallType ());
			i++;
		}
 
		Shuffle(typePool);
 
		BuildGrid ();
 
//		gridBalls [0] [0].gameObject.SetActive (false);
	}
 
	void AddLine () {
		//does top line have visible bubbles
		var emptyFirstRow = true;
		foreach (var b in gridBalls[0]) {
			if (b.gameObject.activeSelf) {
				emptyFirstRow = false;
				break;
			}
		}
 
		if (!emptyFirstRow) {
			var r = ROWS - 2;
			while (r >= 0) {
				foreach (var b in gridBalls[r]) {
					if (b.gameObject.activeSelf) {
						gridBalls [r + 1] [b.column].gameObject.SetActive (true);
						gridBalls [r + 1] [b.column].SetType (b.type);
					} else {
						gridBalls [r + 1] [b.column].gameObject.SetActive (false);
					}
				}
				r--;
			}
		}
 
		foreach (var b in gridBalls[0]) {
			b.SetType (typePool [0]);
			typePool.RemoveAt (0);
			b.gameObject.SetActive (true);
		}
	}
 
	void BuildGrid ()
	{
		gridBalls = new List<List<Ball>> ();
 
		GRID_OFFSET_X = (COLUMNS * TILE_SIZE) * 0.5f;
		GRID_OFFSET_Y = (ROWS * TILE_SIZE) * 0.5f;
 
		GRID_OFFSET_X -= TILE_SIZE * 0.5f;
		GRID_OFFSET_Y -= TILE_SIZE * 0.5f;
 
 
		for (int row = 0; row < ROWS; row++) {
 
			var rowBalls = new List<Ball>();
 
			for (int column = 0; column < COLUMNS; column++) {
 
				var item = Instantiate (gridBallGO) as GameObject;
				var ball = item.GetComponent<Ball>();
 
				ball.SetBallPosition(this, column, row);
				ball.SetType (typePool[0]);
				typePool.RemoveAt (0);
 
				ball.transform.parent = gameObject.transform;
				rowBalls.Add (ball);
 
				if (gridBalls.Count > lines) {
					ball.gameObject.SetActive (false);
				}
			}
 
			gridBalls.Add(rowBalls);
		}
	}
 
	public void AddBall (Ball collisionBall, Bullet bullet) {
 
		var neighbors = BallEmptyNeighbors(collisionBall);
		var minDistance = 10000.0f;
		Ball minBall = null;
		foreach (var n in neighbors) {
			var d = Vector2.Distance (n.transform.position, bullet.transform.position);
			if ( d < minDistance ) {
				minDistance = d;
				minBall = n;
			}
		}
		bullet.gameObject.SetActive (false);
		minBall.SetType (bullet.type);
		minBall.gameObject.SetActive (true);
 
		CheckMatchesForBall (minBall);
 
	}
 
 
	public void CheckMatchesForBall (Ball ball) {
 
		matchList.Clear ();
 
		for (int row = 0; row < ROWS; row++) {
			for (int column = 0; column < COLUMNS; column++) {
				gridBalls [row] [column].visited = false;
			}
		}
 
		//search for matches around ball
		var initialResult = GetMatches( ball );
		matchList.AddRange (initialResult);
 
		while (true) {
 
			var allVisited = true;
			for (var i = matchList.Count - 1; i >= 0 ; i--) {
				var b = matchList [i];
				if (!b.visited) {
					AddMatches (GetMatches (b));
					allVisited = false;
				}
			}
 
			if (allVisited) {
				if (matchList.Count > 2) {
 
					foreach (var b in matchList) {
						b.gameObject.SetActive (false);
					}
 
					CheckForDisconnected ();
 
					//remove disconnected balls
					var i = 0;
					while (i < ROWS) {
						foreach (var b in gridBalls[i]) {
							if (!b.connected && b.gameObject.activeSelf) {
								b.gameObject.SetActive (false);
							}
						}
						i++;
					}
				}
				return;
			}
		}
	}
 
 
	void CheckForDisconnected () {
		//set all balls as disconnected
		foreach (var r in gridBalls) {
			foreach (var b in r) {
				b.connected = false;
			}
		}
		//connect visible balls in first row 
		foreach (var b in gridBalls[0]) {
			if (b.gameObject.activeSelf)
				b.connected = true;
		}
 
		//now set connect property on the rest of the balls
		var i = 1;
		while (i < ROWS) {
			foreach (var b in gridBalls[i]) {
				if (b.gameObject.activeSelf) {
					var neighbors = BallActiveNeighbors (b);
					var connected = false;
 
					foreach (var n in neighbors) {
						if (n.connected) {
							connected = true;
							break;
						}
					}
 
					if (connected) {
						b.connected = true;
						foreach (var n in neighbors) {
							if (n.gameObject.activeSelf) {
								n.connected = true;
							}
						}
					} 
				}
			}
			i++;
		}
	}
 
 
	List<Ball> GetMatches (Ball ball) {
		ball.visited = true;
		var result = new List<Ball> () { ball };
		var n = BallActiveNeighbors (ball);
 
		foreach (var b in n) {
			if (b.type == ball.type) {
				result.Add (b);
			}
		}
 
		return result;
	}
 
	void AddMatches (List<Ball> matches) {
		foreach (var b in matches) {
			if (!matchList.Contains (b))
				matchList.Add (b);
		}
	}
 
 
 
	Ball.BALL_TYPE GetBallType () {
		var random = Random.Range (0.0f, 1.0f);
		if (random > changeTypeRate) {
			lastType = (Ball.BALL_TYPE)Random.Range (0, 5);
		}
		return lastType;
	}
 
 
 
	List<Ball> BallEmptyNeighbors (Ball ball) {
		var result = new List<Ball> ();
		if (ball.column + 1 < COLUMNS) {
			if (!gridBalls [ball.row] [ball.column + 1].gameObject.activeSelf)
				result.Add (gridBalls [ball.row] [ball.column + 1]);
		}
 
		//left
		if (ball.column - 1 >= 0) {
			if (!gridBalls [ball.row] [ball.column - 1].gameObject.activeSelf)
				result.Add (gridBalls [ball.row] [ball.column - 1]);
		}
		//top
		if (ball.row - 1 >= 0) {
			if (!gridBalls [ball.row - 1] [ball.column].gameObject.activeSelf)
				result.Add (gridBalls [ball.row - 1] [ball.column]);
		}
 
		//bottom
		if (ball.row + 1 < ROWS) {
			if (!gridBalls [ball.row + 1] [ball.column].gameObject.activeSelf)
				result.Add (gridBalls [ball.row + 1] [ball.column]);
		}
 
		if (ball.column % 2 == 0) {
			//bottom-left
			if (ball.row + 1 < ROWS && ball.column - 1 >= 0) {
				if (!gridBalls [ball.row + 1] [ball.column - 1].gameObject.activeSelf)
					result.Add (gridBalls [ball.row + 1] [ball.column - 1]);
			}
 
			//bottom-right
			if (ball.row + 1 < ROWS && ball.column + 1 < COLUMNS) {
				if (!gridBalls [ball.row + 1] [ball.column + 1].gameObject.activeSelf)
					result.Add (gridBalls [ball.row + 1] [ball.column + 1]);
			}
		} else {
			//top-left
			if (ball.row - 1 >= 0 && ball.column - 1 >= 0) {
				if (!gridBalls [ball.row - 1] [ball.column - 1].gameObject.activeSelf)
					result.Add (gridBalls [ball.row - 1] [ball.column - 1]);
			}
 
			//top-right
			if (ball.row - 1 >= 0 && ball.column + 1 < COLUMNS) {
				if (!gridBalls [ball.row - 1] [ball.column + 1].gameObject.activeSelf)
					result.Add (gridBalls [ball.row - 1] [ball.column + 1]);
			}
		}
 
 
		return result;
	}
 
	List<Ball> BallActiveNeighbors (Ball ball) {
		var result = new List<Ball> ();
		if (ball.column + 1 < COLUMNS) {
			if (gridBalls [ball.row] [ball.column + 1].gameObject.activeSelf)
				result.Add (gridBalls [ball.row] [ball.column + 1]);
		}
 
		//left
		if (ball.column - 1 >= 0) {
			if (gridBalls [ball.row] [ball.column - 1].gameObject.activeSelf)
				result.Add (gridBalls [ball.row] [ball.column - 1]);
		}
		//top
		if (ball.row - 1 >= 0) {
			if (gridBalls [ball.row - 1] [ball.column].gameObject.activeSelf)
				result.Add (gridBalls [ball.row - 1] [ball.column]);
		}
 
		//bottom
		if (ball.row + 1 < ROWS) {
			if (gridBalls [ball.row + 1] [ball.column].gameObject.activeSelf)
				result.Add (gridBalls [ball.row + 1] [ball.column]);
		}
 
 
		if (ball.column % 2 == 0) {
			//bottom-left
			if (ball.row + 1 < ROWS && ball.column - 1 >= 0) {
				if (gridBalls [ball.row + 1] [ball.column - 1].gameObject.activeSelf)
					result.Add (gridBalls [ball.row + 1] [ball.column - 1]);
			}
 
			//bottom-right
			if (ball.row + 1 < ROWS && ball.column + 1 < COLUMNS) {
				if (gridBalls [ball.row + 1] [ball.column + 1].gameObject.activeSelf)
					result.Add (gridBalls [ball.row + 1] [ball.column + 1]);
			}
		} else {
			//top-left
			if (ball.row - 1 >= 0 && ball.column - 1 >= 0) {
				if (gridBalls [ball.row - 1] [ball.column - 1].gameObject.activeSelf)
					result.Add (gridBalls [ball.row - 1] [ball.column - 1]);
			}
 
			//top-right
			if (ball.row - 1 >= 0 && ball.column + 1 < COLUMNS) {
				if (gridBalls [ball.row - 1] [ball.column + 1].gameObject.activeSelf)
					result.Add (gridBalls [ball.row - 1] [ball.column + 1]);
			}
		}
 
		return result;
	}
 
	public Ball BallCloseToPoint (Vector2 point)
	{
 
 
		int c = Mathf.FloorToInt ((point.x + GRID_OFFSET_X + ( TILE_SIZE * 0.5f )) / TILE_SIZE);
		if (c < 0)
			c = 0;
		if (c >= COLUMNS)
			c = COLUMNS - 1;
 
		int r =  Mathf.FloorToInt ((GRID_OFFSET_Y + ( TILE_SIZE * 0.5f ) - point.y )/  TILE_SIZE);
		if (r < 0) r = 0;
		if (r >= ROWS) r = ROWS - 1;
 
		return gridBalls [r] [c];
 
	}
 
	void HandleShootBall () {
		bullets++;
 
		if (bullets > 10) {
			bullets = 0;
			AddLine ();
		}
	}
 
	private static System.Random rng = new System.Random(); 
	public static void Shuffle<T>(IList<T> list)  {  
		int n = list.Count;  
		while (n > 1) {  
			n--;  
			int k = rng.Next(n + 1);  
			T value = list[k];  
			list[k] = list[n];  
			list[n] = value;  
		}  
	}
 
}

In the next post I’ll show you how to scroll the grid instead of adding new lines.

Here is the project with multiple shooters.