We don't need an array of turtles, so we'll just make a
new turtle sprite, and make it invisible.
var turtle= new MySprite("http://s2js.com/img/etc/turtle.png");
turtle.visible= false;
We'll have a function that gets called whenever we want
the turtle to appear:
function Appear_Turtle () {
set_random_side(turtle); // start the turtle on a random side, just like a fish
turtle.velocity_y = Math.random()*6-3; // slight vertical velocity so it goes a bit diagonal
turtle.visible= true; // and make it visible
}
Note we're making use of
set_random_side again -- it's useful for the fish, and also the turtle. We'll make the turtle visible, and we'll give it a slight random y-velocity so it ends up moving
diagonally across the screen.
Next we'll set a timer so the first turtle appears three seconds after the game starts.
setTimeout(Appear_Turtle, 3000); // first turtle after 3 sec
Note we're doing setTimeout instead of setInterval, so this timer
only fires once, not every three seconds. This is because we want greater control in order to ensure the turtle doesn't re-appear until it's finished it's last appearance.
We'll also need to remember to call:
turtle.Do_Frame_Things();