Here comes a new episode in the frog adventure series. This time, he is mostly submerged in water that should not occur completely foreign to a frogs nature. Frogs are adept swimmers. Now why he has jumped out as a pearl diver is because it is opportune for him to do so in connection with his journey.
The frog is subject to certain laws of nature on this particular mission.
1. He has got limited time available for diving throughout a game ( this is equivalent to resist a regular working day -it takes effort to dive , free pearl divers can attest to this)
2. Each of his dives has a limited length of time
3. When surfacing he must each time return to the raft to recover and to protect himself against sharks (so he must be the precautionary not to swim too far away from the raft)
4. He is exposed to the dangers of hostile creatures: sharks and an octopus.
5. Sharks occur frequently but the water is clear so he can calculate the distance to them and avoid them
6. Major problem arises when an octopus appear which belches ink that gradually obscures the clear water and thereby hide the sharks (this is signal to return to raft)
5. How many pearls he has succeeded to harvest during the game is revealed at the of the game
Free-divers are often forced to descend to great depths on a single breath exposing themselves to shallow water blackout risks or decompression
sickness (DCS) (=the dangerous and occasionally lethal condition caused by nitrogen bubbles that form in the blood of divers who surface too quickly.)
Our frog is not exposed to these hazards.
He only descend to moderate depth.
There is only one canvas in use in the game.
However, there are two decoration base background environments to operate with in the game
1) one representing scene out of the water
2) and the other one representing in the water
When the frog is on the y-coord: y <= -20, all scene decoration switches to scene above waterline and all underwater decoration is suppressed in the meantime.
The opposite goes when the Enter key is pressed, then the above-the-water decoration is suppressed and the underwater scenario takes over.
The oxygen bubbles
The oxygen blue bubbles are dynamic.
The source base where the oxygen bubbles is formed is constantly synchronized to the frog's coordinates.
The oxygen bubbles runs in the primary animation loop.
The horizontal dispersion of bubbles is random.
The spread increases as the bubbles mounts.
To get the right effect also their opacity values increase as the bubbles mounts.
Global variables
The game spans over 10 dives. Every dive can last at maximum : 60 'timeunits' ,these which are defined by a countdown feature included in the basic kinetic animation loop . The frog will have go up before this time glass runs out (=60 timeunits). When he does not it will bring him in a critical state of condition and the game stops.
Pearl oysters
50 oysters are spread randomly in the range:
var horizontal=randomNumberRange(-400,700);
var vertical= randomNumberRange(300,540);
To create the illusion of depth effect (3D) the pearl oysters are given different sizes - the largest in the foreground and the smallest in the background.
As we already known their y position we can calculate their sizes:
function getSize(y) { var count=0; for (n=300; n<541;n += 20) { count=count+1; if(y >= n && y < n+20) { return count; } } return 13; }
We do keep record of each oyster by registering them in an array. To collect an oyster the frog have to put himself into position so that the center of the oyster (diagonal intersection point)match to the center of the frog with a tolerance of : +-10 (diagonal intersection point frog).
When the frog succeed to collect an oyster the precise same oyster is marked as 'collected' in the array on the corresponding element, so it can not be recollected.
And the player will notice that the oyster disappear from the scene as we set its opacity equal to: 0.
The octopus
The octopus occurs once during the game . That happens in the excat same moment when a predefined ouster (randomly designated at startup) is picked up by the frog. the octopus creates a dangerously dark ink cloud which gets darker and blurs all vision and hence hides the sharks. Therefore, the frog much reach up to the raft in good time.
The raft
Frog can only climb on the raft if he approaches it in a maximum distance of 50 px. This can be crucial cause he during a dive sometimes need to cross and go behind the fixed canvas barriers (vertical borders) : 0/400 to hunt the oysters. He must not lose orientation.
How to create the illusion of swimming behind the borders.?
When the frog reaches the left border of the canvas his left-movements will be cancelled, whereas the oysters and the raft are all moved in the opposite direction with the same 10 px as pr. left key press. And the seaflower image also moves in opposite direction when the designated seaflower loop is activated. It appears all as it is the frog is moving on behind the limits of the canvas. While the seaflowers moves slidably forward in a constant streaming way this gives the frog the opportunity to see and collect the hidden oysters.
The same regime applies just with opposite consequences when the frog meets the right edge of the canvas.
The sharks
They are managed in their own Animation loop. Here we also detect for collision, for example:
if(sharkleft.getY()+63 > frog.y() && sharkleft.getY() < frog.y()+50 && sharkleft.getX() < frog.x()+50 && sharkleft.getX()+10 > frog.x() ){ ..then do...}
Such as sharks behave in the game on the assumed premises they are only dangerous for the frog when they run head-on into him. (this could be changed). when the frog collide with a shark the game stops and player is forced back to upwater scene with a message: Attacked by shark ! - game over.
© Arrangement, February 2015, netscale.dk