Games are just a big pile of IF->Then statements
What is an IF->Then Statement?
Let me show you with an example, think of a soccer ball, if it is at the left side of the screen, then the field is blue, but if it is at the right side of the screen, the field is red.
how would that simple statement look in code?
if(ball is after Middle)
{
make field color blue
}
else
{
make field color red
}
Now this is not the real code, if you put this on the computer it will ask you to please identify many things.
for example the computer doesn't know what "is after" means, so instead we use a symbol
>
This is the greater than symbol,
other symbols are less than, equal to, greater than or equal, less than or equal. Try and search for what those look like.
Another thing the computer won't know is what middle is, there are two options here, one is creating a variable called Middle and giving it a number, or the other is to just put a number here.
Also notice that we just had "ball" > Middle, but ball is not a number, ball is an object, what we need is to know the ball x position on screen. (x is horizontal position, y is vertical position, the top left corner is x=0 y=0 and the bottom right is x=550 y = 400)
so in this case we want the ball.x to be > 275
now the last part is the changing of the color. what you need to do now, is have a movie clip called field with two frames (don't worry you don't need to know about frames for this workshop), so what we do is tell the object field to go to a certain frame (or color).
here is what the final code would look like:
now here is how that looks:
For this work shop I want you to make a timer go down. Let it start at 100 and every frame it needs to go down by one.
you can use the trace function to show the timer going down.
when the timer reaches 0 it should stop, it should not get to -1.
Extra credit:
- Make the time show up on screen by using Dynamic Text Fields
Once again thank you, and good luck on this workshop, I will be very glad to see what you come up with, what solutions you make and what obstacles you overcome.
Remember you can use the Problem Solving Method to facilitate your experience.



No comments:
Post a Comment