Transcript
Hi! You've learned to add an image to the
background of your sketch and also to use an image as your cursor. You're able
to move this creature on the canvas like it would be a main character of your
game. But it's not much of a game yet because the character is the only object
on the canvas. Usually the point of the game is to gather points or avoid
enemies and right now there isn't anything to gather or avoid. So let's add
some moving shapes to this program. ...and then in draw... Like this. Okay so the familiar ball moves across
the canvas and let's add an if-structure here so if the ball gets out of the
canvas it should appear again from above. Okay so this number 652 it's the height
of my canvas now as you can see in the size command. But I'll show you a new
trick. Instead of writing and having to remember this number you can just write
"height". Uh-huh, like that. And this is a system variable that keeps track of the height
of the canvas automatically. I can also pick a random x-coordinate for the ball
every time before it emerges from above. And I can write here "width" which is a
system variable that keeps track of the width of the canvas. Aha, the familiar
error: "cannot convert from float to int". so the random-command gives us a decimal
number between zero and the width of the canvas but ballX is of the integer type.
So we could fix this again by using the familiar int-command or we could just do
it the easy way. Let's change ballX and ballY to be
float instead of int. It's totally ok to use decimal numbers inside the
ellipse command so now it's not going to be a problem. So let's see. Let's run the
code. Okay, so now the ball gets a new
horizontal position every time before appearing from the top! So even if I move
my creature there now it doesn't yet have any effect so what if the idea of
this game would be for example to try and collect these balls and gather
points every time I do that? We'll make this happen on the next video!