Imagine an electronic chess game, here you play against a computer opponent. A bit the same applies here just in something more simplified version. Here it is for the two teams about to play against each other in a match to be named the fastest team to score 10 goals.
Player must lead the turtles up the field and constantly make sure to bring them on the scoring list.
Rules
It triggers a penalty if a turtle creates a collision with a rabbit and the involved turtle is sent back to turtles own half from where he can engage in the game again and participate equally in turn with the other turtle players.
Turtles may thus receive a maximum of 15 penalty points during a game. If they exceed this limit they lose the game to the rabbits.
Every time a rabbit picks up the ball it results in a goal on the scoreboard in the rabbits' favour
Player can constantly spot where the ball is located because the ball possessing turtles are marked with a yellow background. When a turtle has the ball he can not be moved with. Player make a free turtle pulls the ball to himself by a mouse click on the actual turtle. In this way the ball is advanced on the field. All the player has to do is to bring the turtles in a favourable position in front of the rabbits' goal. The turtles permanent 5th. player is always placed behind the rabbits' keeper. From here he is the the last one to pull a goal for the turtles at the right time.
Base definitions
All players are defined as Kinetic class objects.
We define the turtles to be draggable by associating the draggable method.
We also bind onclick() event listener to them.
This way we can make them act on players decision. The turtles and rabbits are all registered in two separate arrays.
We distinguish between (1) ball is moved forward and (2) ball is moved backwards. In both cases we initiate a refresh of all turtles status and we do call one of the two ball-loop routines (kinetic.animation) that moves the ball across the field between the two players: ball_sender and ball-receiver.
We mark the next turtle field player that comes to hold the ball . At that very same moment we the do the relay:
slopexkonstant=(football.getX() - ball_receiver_x)/50; slopeykonstant=(football.getY() - ball_receiver_y)/50;
for (k=0; k < arrplayer.length;k++)
{ arrplayer[k].setFill(''); arrplayer[k].setName('rectangle'); arrplayer[k].setDraggable(true); } shape.setFill('yellow'); shape.setName('rectanglewithball'); shape.setDraggable(false); ballloop.start(); layer.draw(); }
Remark, we do find the slopes of the line that the ball will take, and that will be used in either the ballloop (forward) animation loop or the corresponding (backward) ballloop animation loop routine.
The rabbits are defending their goal by running vertically from the top to the bottom of the playing field. Only the rabbits keeper goes in both direction: up and down!. The horizontal distance between to two rabbits are always big enough , for a turtle, when dragged carefully, can be placed between them.
For this task we have got 3 kinetic animation loops running in the game. Besides this task they also make the collision detection: (1) of when when a rabbit intercept and conquer the ball to their own advantage and (2) when a turtle provoke a player punishment to the turtles own disadvantage. Each event is fed to log in global variables
var turtlepenalties=0;
var rabbitgoalscore=0;
var turtlegoalscore=0;
In the ballloop animation routine we always ask : if(football.getX() > 546 ), which means turtles have made the football pass the outer edge of the rabbits' goal resulting in an goal score: turtlegoalscore=turtlegoalscore+1.
Similarly we note consecutively to the other two variables: rabbitgoalscore=rabbitgoalscore+1 and turtlepenalties=turtlepenalties+1 in the 3 rabbit loop animation routines when doing our collision detection.
We do monitor all 3 variables in a status loop kinetic animation routine that runs all the time to check on whether one of them exceeds the limit:
if(turtlepenalties > 15) - rabbits win the game.
if(rabbitgoalscor>10) - rabbits win the game
if(turtlegoalscore>10) - turtles win the game.
We could introduce a global match play time. Another thing to go for, might be to make the rabbits move in both horizontal and vertical direction. When rabbits gets more pressed by turtles offensive attack we could justify a more conscious defensive initiative of the rabbits: rabbits recede more in front of their own goal; they begin to move randomly both up and down vertically etc.. We could favour many (turtle) ball passings i.e.. higher frequency of ball interaction.
© Arrangement, Marts 2015, netscale.dk