This is part C for the programmers,
the homework, basically for programmers.
If you're doing something like art
or audio or something else for your homework,
you still may want to
see the first part of this
because I'm going to talk about tweening.
Let's get familiar with that term.
If let's go to the Los game scene.
If you want to add a little emphasis
to an object
between starting time and
an ending time, which is fixed.
This is more baked
rather than end game control.
You can use something called a tween.
That's a behavior, and we're going to add
some liveliness to this text,
make it move around a bit,
and we're going to use somebody else's,
you have to scroll down probably to see this.
This tween thing, a whole bunch
of code already done,
and we want to tap into that.
Now that the behavior is there,
this middle column has
a whole bunch of different options for
the different actions that
tweening can work with display.
I'm going to just go
down to the position one.
Position has a couple of things here that
I'm looking to work with here.
In the y direction probably
makes the most sense.
We have to give this an identifier.
It's rather arbitrary.
It could just be like ABC
or It's an animation
in terms of movement rather
than any kin of change visually.
Starting movement.
Maybe that's one way to describe it.
So it's going to start at
some position and go to another position.
So let's say you
might change where this display is,
but we want to start where that is.
The starting place is there.
There's a whole bunch of
different options, code wise,
and it creates a bunch of points in x and y,
or, in this case,
just y. I randomly pick bounce.
Now this is in seconds,
you could write 0.5
if you wanted it to be quick.
Let's do 2.5, see what that's like.
We don't want to destroy the object
when it's done, but that's handy.
And I h, we are starting at this location.
And I'm probably going to go
down less than 600.
I want to be above the paddle.
So I'm going to just ballpark that at,
I don't know, two Whoops, 290.
Yeah. So we started display y.
We're going to move with bouncing to
290 over a period of 2.5 seconds.
And this is very typical
in math that you can get an equation
that produces x y or
x y z coordinates over time.
And those dots make a bunch
of little bitty lines
which might look curved,
but in fact, it's a bunch of straight lines.
When it happens fast enough.
In our eyes,
we don't notice that these are pixels,
and it's kind of
quantized, I guess is the word.
Okay.
So if you haven't done it,
you need to go up here and do file save as,
your homework 1.0. Maybe 1.1.
If you've already done it, you've
made a change and test
it and make sure it works and
when it does, that's good.
So now I'm wanting to discuss this.
I want to put a condition here.
I'll just go ahead and do it.
As I discuss the variable lives matters here.
When lives is equal to zero is really
the true condition for going to
this lose game scene.
I'm going to put a new event up here.
This really is what
games are typically like arcade games.
In here, this has to
move to some place where things happen.
This ball has to stop,
no matter what's going on.
That is their mechanism for movement.
The next thing that has to happen,
it's got to go to where
when you go left and right.
The position changes to
this other position here.
So, you need to bring
that position code copy
and paste it from below.
So now the ball is where it's
supposed to be for launching it again,
and it's stopped, so it can be launched,
and the velocity will be zero.
There's nothing moving.
This score thing sorry,
the variable lives below will need to be
accessed or changes in lives
need to occur up here rather
than accessed before it's tested.
Then when you have this conditional
test, not just p,
but the lives equal zero,
that's all What do you call it?
That's the perfect moment to get
the user to another scene
where other things happen.
Great. So if that's not working,
you may want to pause the video.
So now that I have done
that, from this point on,
I'm going to dedicate the rest of this
to doing something custom with
these three different colored bricks.
You can do it anyway you want.
I'm just going to show off one approach.
It's very typical that you'll have
either another object that looks
identical to something like
a brick that's being destroyed,
or what I'm going to do is have the red,
yellow, green repeated
here with animation three.
Animation four sprite.
And five.
The reason why putting green there.
These are all exactly three away.
If I have a variable called animation number,
which the index actually is zero base,
so zero through five
rather than one through six,
zero is this one plus three is this one.
If I add three to this animation number one,
it becomes four, these are
all animation t, Wait a minute.
Yeah. Animation four is this one.
That's all well and good.
But the fun thing is you
get during a collision here,
we are not required to delete the brick.
We get to get creative.
Again, you're free to experiment here,
however you want to do it.
I'm going to take
that brick and then this animation by number,
you can do math on it.
No matter what, zero, one, two,
if I'm adding three to a brick,
I'm going to be out of range.
So none of these things will be activated.
So I mean, this is
nice general purpose code. I can reuse it.
And I'm going to do
another thing to signify that
this brick is starting to
go into special effects mode.
That brick is going to have opacity,
which is a value 0-255,
where 255 represents completely visible and
zero means that it's
transparent where you see through it.
Maybe you could think of it as
Alpha blending. I think is the term.
We're going to do
specifically even number two.
That's a little bit less than 255.
And by doing that on all of these,
I'm going to make it where they're going to
start to fade out and move.
So why don't we just save and test?
Great.
If I could get back up there.
It would pass through these things.
Yeah. It's passing through
things that look like brooks.
To make it more visible,
I'm going to go up here,
put in an event to continue this.
Let's make it first here.
It doesn't matter because this is unrelated.
I'm going to subtract a little bit at a time.
From these bricks, where
if a brick has opacity,
which is less than or equal to
this new value that I came up with 254,
we know it's not a normal brick.
All three of them get some special treatment
of This thing of changing the opacity.
We're going to say
it's going to be a little bit
less and just two.
If you do it different numbers,
it'll be slower or faster.
I guess I recommend playing around with it.
You're looking for the best game
feel for whatever you're trying to create.
We want a sub event here.
Is that doable there.
Only when this happens,
is that particular brick going to
get to here or well,
the code is going to get to here.
And I'm going to do kind
of a general purpose.
Let's copy and paste that.
A second test here.
If we're done fading out,
the opacity will be
zero or negative depending
on how you tweak
these variables in the constants.
And so I think it will be a rotation.
No, wait, sorry.
We're going to delete the brick.
I'm ahead of myself.
We will delete bricks that have faded out.
I'm already thinking planning ahead
about the special effects. Okay.
Let me try. Yeah, there's the fade out.
So now when I go back up there,
it's gonna go through that hole
because it's, yeah.
So this is a lot easier test wise
to see these things
that aren't there anymore.
They start to To me, they look out of place.
If they're fading, they
need to do something a little bit more.
So this is where you can get creative.
I'm going to say, uh
Let's do two plus three would be five.
I do whips, I'm looking
for a one of these things.
If we have a brick,
where the number is five. Let's do that one.
That's where I wanted to spin it around.
So I'm going to search for rotate.
And I'm not I maybe 1,000.
We want some dramatic speed here.
I'm going to have to aim for that green one.
Okay.
It's a little slow, but
it seems like it's fading out
slowly and spinning too quickly.
And you could do more code to make this more
individualized for this opacity
depending on the brick number.
I don't know how I don't know if this
is certain game engines
would not like a floating point value,
but this is probably going
to not have a problem.
The second one, which is brick number one.
I want to do something special with that
where the ball knocks the brick,
flying off in
the direction that the ball is going.
Sort a physics experiment like Billiards.
For this, it really matters
the order of operations.
I'm going to add an action,
but then move it. You don't have to move it.
You could move it later, test it,
but let's just discuss
about the order of operations here.
If I'm going to take this brick,
and I'm changing the movement of it here.
I want to I
guess we're adding a permanent force.
L et's say that the speed Well,
actually, I want to go at a certain angle.
The angle that I'm going is
the angle of the ball.
The ball, you can play with that,
the ball is going to be at different angles.
I want to match the ball.
Angle.
And then the speed of it,
it's going to be a need for some drama here.
So if you have
a billiard ball hitting a lighter ball,
the lighter ball is going to
proportionally just fly off.
So I think this is
this weird notation of force lengths.
Yeah.
The sum of the forces
That's kind of like velocity in physics,
but it's just a weird choice of words.
So whatever direction it's going,
I want that plus or maybe times x amount.
That means if you change the ball,
speed will always do
something in proportion to that.
So maybe 1.5, I don't know.
1.2, 1.4,
something in there, and it's permanent.
But if you leave it down here,
what happens is carefully here,
the bounce of this ball off
the brick has made
the brick go some other way.
So if I'm let's say here's the brick,
the ball is coming up to the left,
then the ball goes this way
and the brick follows the ball.
What you want to do is have this
happen you first give
the information to the brick,
Hey, you need to start moving
in the direction that
the ball was moving
with a force length of that.
And since the brick was stopped,
it doesn't have any forces on it.
This angle is perfect.
This force link is going
to be nice little drama.
Again, you may need to play around with that.
Then the ball changes direction.
So I need to aim, I guess
for test purposes here.
Wow. That does not look correct at all.
That is not normal.
They're A going to zero.
Ball dot angle.
Okay. It's probably force angle here.
Force angle.
Force lengths. Wow. Wow.
How nice is that that
they give you a way to not get it right?
All right. So the ball
had a certain direction?
And those I think I think
We're getting the behavior
that we were Yes, S,
that's what I was intending
that the ball would hit a brick,
send that brick flying
in a certain direction.
Yeah, and you could play with this to make it
go faster and faster, or who knows?
Get larger and larger, smaller and smaller.
Anything's possible. Then there's
one little hack left here for this one.
We're going to say this brick,
which was at index zero,
the red one, could become something else.
Let's change that animation number because
now animation number is
actually really important.
It has a lot more let's
do random in range here has
a lot more importance when
you say the animation number
is going to be hooked up to specialized code.
It's a built in variable.
We'll have it set to
a certain thing to begin with,
and every step of the game as it changes,
you're going to get new behavior.
So this brick, which is worth the most,
creates other bricks where it was.
So that's a neat,
easy to test feature.
And it looks like I hit that one twice.
That is a bit of a drawback.
Yeah. Yeah, I probably need a delay.
But clearly, I mean,
part of this is their bounce edge
registers multiple hits in
a certain kind of way.
So this doesn't go there.
You can turn this in. I don't
really ask for any more.
But I would say this is an indication that
their bounce code doesn't
separate the objects.
That's unfortunate.
If you want to do a work around,
you're free to follow along
with this little extra bit,
I'm going to say down here,
I need another subcondition.
Here's my thinking. If I have
a brick or at some point,
I'm going to go
from this brick to
specifically brick number four.
So add three, that gets me to four.
And I need another condition
before this happens,
such that time has passed.
So let's say the opacity
of the brick is
less than something close to this.
I don't know if it's going to work,
but that's my thought.
That's a little bit of a delay there.
So that just faded.
Well, anyway, let's see what happens here.
Oh, is that the four?
I'm supposed to do this with bricks zero
plus three is three. Okay.
I think I'm H.
Mm.
Oh, now I know what's wrong.
Yay, I figured it out.
Okay. If you have a new brick, so to speak,
of not red, but yellow or green,
it's got to be reset to be fully visible.
So that makes sense. Totally makes sense.
Yeah, now that I have a new brick over there.
I have a new brick over here.
Those will continue to be part of the game
and operate just like any
other yellow or red brick.
I probably could How do I say this?
There's a hack here for test purposes.
If you hit space repeatedly,
you can get it to go back up if
you change this space thing.
Space key is released.
If this is temporarily,
you can delete that
or maybe make another event that's similar.
Yeah.
The see the test is complete.
So now I'm going to do control Z
here, and to restore that.
So that's it. Yeah. The new version
of a brick there,
which is a color,
which has other fancy code.
That means the bricks take some more work,
so to speak, to go through.
And I mean,
this is a primitive version of that idea,
that idea can be taken elsewhere,
put into other games and other contexts,
and it could be something
where hopefully it's not
too burdensome on the player
to have to do something twice,
or it's just letting them know
they've got through
the first level of shield.
You've got to sell that idea in
some way that they're going to be happy with