1
00:00:00,740 --> 00:00:01,580
Welcome back.

2
00:00:01,610 --> 00:00:03,740
How's your project coming along in this lesson?

3
00:00:03,740 --> 00:00:05,810
We're going to be taking care of the shooting.

4
00:00:06,080 --> 00:00:13,700
So we've got player fire has been set to true if we press any of these keys and then within the update,

5
00:00:13,790 --> 00:00:17,510
we can check to see if that player fire is true.

6
00:00:17,660 --> 00:00:21,660
And if it is, then we can take an action accordingly to that.

7
00:00:22,100 --> 00:00:30,200
So setting that up and we can look to check to see if player fire is true.

8
00:00:31,190 --> 00:00:34,370
If it is, that means that we have to move our projectile.

9
00:00:34,610 --> 00:00:38,240
And there's a few other things that we still need to do as well, in addition.

10
00:00:38,390 --> 00:00:41,900
And that's actually set up the firing object.

11
00:00:42,050 --> 00:00:45,230
So we need to unhide remove the class of hide from it.

12
00:00:45,440 --> 00:00:50,600
We need to set the player fire as well and also the position of where it's starting.

13
00:00:50,900 --> 00:00:56,960
So creating a function in order to handle that, we can call that ad shoot and then this is the function

14
00:00:56,990 --> 00:01:02,420
that's actually going to get invoked whenever the player presses any of these keys.

15
00:01:02,720 --> 00:01:09,200
So we can keep that in here where we do add, shoot and also remove out that player fire.

16
00:01:09,570 --> 00:01:11,900
So we're going to have this happen one time.

17
00:01:12,170 --> 00:01:20,030
And if this is the case that it is true, we want to make sure that we're selecting that elements and

18
00:01:20,960 --> 00:01:25,390
updating its class list, removing the class of height.

19
00:01:25,670 --> 00:01:27,410
So it's going to show it on the screen.

20
00:01:27,410 --> 00:01:28,400
So see what happens.

21
00:01:28,730 --> 00:01:36,080
So now when I hit Start Game and if I press the space or if I press up, you see that the shooting object

22
00:01:36,080 --> 00:01:37,870
appears, the projectile appears.

23
00:01:38,540 --> 00:01:44,180
So the next thing that we need to do, we need to select that object and we're going to create a value

24
00:01:44,180 --> 00:01:49,630
of X in that object that we can call it X position or whatever we want to call it.

25
00:01:49,640 --> 00:01:56,120
This is a brand new value that we're setting and then taking the my ship offset left.

26
00:01:56,120 --> 00:02:01,610
So just as we did in the last lesson, this is going to give us a position of where the ship is located.

27
00:02:01,850 --> 00:02:04,160
And you can try that as well in the console.

28
00:02:04,310 --> 00:02:11,180
And you can see that that's going to return back where its position is according to where it's located

29
00:02:11,180 --> 00:02:11,750
on the screen.

30
00:02:11,760 --> 00:02:15,080
So this will change depending on where you move it.

31
00:02:15,230 --> 00:02:19,280
And then if we go back to here and if we offset at sea change to 69 there.

32
00:02:19,550 --> 00:02:23,240
So we're getting the midship offset left position.

33
00:02:24,210 --> 00:02:30,900
And then what we want to do is we want to start at a roughly halfway into my ship and the way that we

34
00:02:30,900 --> 00:02:35,700
can do that is using the offset width and this time dividing it by two.

35
00:02:35,850 --> 00:02:43,830
So that will give us roughly halfway positioning of where our exposition is and then also for the Y

36
00:02:43,830 --> 00:02:44,310
position.

37
00:02:44,350 --> 00:02:50,900
So this one is going to be a little bit easier to set because we're just using the position of the ship.

38
00:02:51,510 --> 00:02:59,570
So this is going to be our default position of where the firing is starting and we can use offset top

39
00:02:59,580 --> 00:03:01,510
and do a minus 10 on that.

40
00:03:01,890 --> 00:03:06,650
So the next thing that we want to do is we don't want it showing up here on the top left hand corner.

41
00:03:06,810 --> 00:03:08,340
We want it to show up.

42
00:03:08,850 --> 00:03:11,820
And this is where we update its style properties.

43
00:03:12,150 --> 00:03:14,190
So updating its left position.

44
00:03:14,200 --> 00:03:17,190
So just like we did with the ship, we're taking fire me.

45
00:03:17,490 --> 00:03:19,620
And this is X position.

46
00:03:20,990 --> 00:03:29,060
Plus pics, and this one should be the Y position and to do adjust the vertical, we're going to use

47
00:03:29,060 --> 00:03:31,580
top and Y position.

48
00:03:32,570 --> 00:03:33,500
So let's see what happens.

49
00:03:33,530 --> 00:03:34,340
So hit start.

50
00:03:34,700 --> 00:03:39,750
And now this is the starting position of where it's going to place place it.

51
00:03:39,790 --> 00:03:46,900
And as you see, when I move it, if I hit spacebar than it, it places it there on top of my my ship.

52
00:03:46,910 --> 00:03:49,910
So wherever I've moved, that's where the starting position is.

53
00:03:50,330 --> 00:03:53,000
So the next thing that we need to do is create that action.

54
00:03:53,210 --> 00:03:59,000
And we already saw that in the last lesson where we could move the ship around and we can do the same

55
00:03:59,000 --> 00:04:05,210
thing and we can have this essentially firing as it's being projected out.

56
00:04:05,510 --> 00:04:12,080
And the other thing, too, that we want to listen for is we don't want to have the ability to add more

57
00:04:12,080 --> 00:04:21,110
shots so we can run the function or we can check to see if the value of fire or the value of player

58
00:04:21,800 --> 00:04:22,550
fire.

59
00:04:22,700 --> 00:04:27,760
And if player fire is false, then we're OK to add another shot.

60
00:04:27,980 --> 00:04:29,000
So let's see what happens.

61
00:04:29,210 --> 00:04:32,440
So now I should only be able to add at one time and it's not going to move.

62
00:04:32,660 --> 00:04:37,540
So that's what we want to do, because otherwise the player could constantly press the spacebar.

63
00:04:37,700 --> 00:04:39,650
It would readjust the positioning.

64
00:04:40,070 --> 00:04:48,590
So now we're ready to make the move with it and taking the fire me x position that we just set earlier.

65
00:04:49,160 --> 00:04:51,710
And actually we don't have to update the exposition.

66
00:04:51,710 --> 00:04:53,440
We only have to update the Y position.

67
00:04:54,230 --> 00:05:01,250
So taking that value and we can subtract it by a value of 15 and then take fire me.

68
00:05:02,210 --> 00:05:11,450
And selected style top and using that newly adjusted position, we can do y position and then don't

69
00:05:11,450 --> 00:05:12,630
forget to add the picks.

70
00:05:12,650 --> 00:05:13,840
Otherwise, it's not going to work.

71
00:05:14,150 --> 00:05:15,420
So see what happens now.

72
00:05:16,130 --> 00:05:17,350
So I hit the spacebar.

73
00:05:17,360 --> 00:05:18,480
It goes off the top.

74
00:05:19,070 --> 00:05:26,810
So we also want to check to make sure that the position is of fire me is not less than zero.

75
00:05:26,810 --> 00:05:29,300
And if it is that we just need to restart it.

76
00:05:29,310 --> 00:05:34,850
So we need to check to see if Fiame is greater than zero.

77
00:05:35,360 --> 00:05:37,970
And if it is, then we're good to subtract off of it.

78
00:05:38,390 --> 00:05:45,350
But if it's not, then that means that we've gone off screen and it was a miss so we can change the

79
00:05:45,680 --> 00:05:53,750
play fire boolean value back to false and that will reset it and allow the player to fire again and

80
00:05:53,750 --> 00:05:54,500
then fire me.

81
00:05:55,490 --> 00:05:56,540
And as we.

82
00:05:57,480 --> 00:06:04,260
Remove the class of hide, let's add in hide, so it's no longer going to be visible on the screen for

83
00:06:04,260 --> 00:06:04,680
the player.

84
00:06:05,880 --> 00:06:10,260
So even though it's right now it's going to be off the screen, the player either way isn't going to

85
00:06:10,260 --> 00:06:11,090
be able to see that.

86
00:06:11,110 --> 00:06:20,220
And we can also, just to be sure, we can readjust the position of fire me y position and we can set

87
00:06:20,220 --> 00:06:27,870
it to use in the container demn height plus one hundred so we can set its default position way outside

88
00:06:27,870 --> 00:06:33,180
of the visible area for the player and fire me y position is the one that's greater than zero.

89
00:06:33,190 --> 00:06:36,570
So we've got to make sure that those variables are checked properly.

90
00:06:36,690 --> 00:06:38,180
So now we're ready to try that out.

91
00:06:38,210 --> 00:06:44,670
So now when we start the game, we can fire, but we can only have one projectile on screen at a time.

92
00:06:44,850 --> 00:06:48,710
And you can see that once it goes off the screen that I can launch another one.

93
00:06:49,050 --> 00:06:53,430
So it does look fairly quick, but there's only one on the screen at a time and it's always the same

94
00:06:53,430 --> 00:06:53,670
one.

95
00:06:53,670 --> 00:06:55,530
It's that same element that we created.

96
00:06:55,740 --> 00:06:59,640
So go ahead and add this into your project and we're going to be ready to move on to the next step.

97
00:06:59,850 --> 00:07:05,090
We're going to clean up the start game and initiate the creation of the aliens, the bad guys.

98
00:07:05,190 --> 00:07:05,580
That's all.

99
00:07:05,580 --> 00:07:06,900
Still to come, an upcoming lesson.
