var game = new Phaser.Game(800, 600, Phaser.AUTO, 'game', { preload: preload, create: create, update: update });

var background;

var plots;
var flowers;
var weeds;

function preload() {
    // Load the background image and game sprites
    game.load.image('background', 'assets/background.png');
    game.load.image('test_flower', 'assets/test_flower.png');
    game.load.image('plot', 'assets/plot.png');
}

function create() {
    // Enable the physics engine
    game.physics.startSystem(Phaser.Physics.ARCADE);

    // Apply the background sprite and set the initial color tint
    background = game.add.sprite(0,0, 'background');
    background.tint = 0x0EE68;
    
    // Generate the flower/weed plots
    plots = game.add.group();
    for (var i = 0; i < 10; i++) {
        // Determine valid X/Y coordinates in the game area
        var x = Math.floor(Math.random() * (800 - (i * 8)) + 1);
        var y = Math.floor(Math.random() * (600 - (i * 6)) + 1);
        
        // Prevent sprite from extending off of the right or bottom
        if (x > 736) {
            x = 736;
        }
        if (y > 400) {
            // Leave room for bottom text and interaction area
            y = 400;
        } else if (y < 64) {
            // Leave enough room for flower to prevent clipping
            y = 64;
        }

        plot = plots.create(x, y, 'plot');
    }

    // Define the flowers group and add physics properties
    flowers = game.add.group();
    flowers.enableBody = true;
    flowers.physicsBodyType = Phaser.Physics.ARCADE;
    
    // Define the weeds group and add physics properties
    weeds = game.add.group();
    weeds.enableBody = true;
    weeds.physicsBodyType = Phaser.Physics.ARCADE;
    
    // Manually add test plot/flower
    //game.add.sprite(64,64, 'plot');
    //game.add.sprite(64,8, 'test_flower');
}

function update() {
    //background.tint = 0x123456;
}
@@ -160,16 +160,27 @@
 weeds;%0A%0A
+var time;%0A%0A
 function
@@ -715,16 +715,73 @@
 d plots%0A
+    // TODO: Prevent overlapping plots during generation%0A
     plot
@@ -1288,18 +1288,19 @@
 if (y %3C 
-64
+110
 ) %7B%0A    
@@ -1375,18 +1375,19 @@
     y = 
-64
+110
 ;%0A      
@@ -1608,32 +1608,133 @@
 Physics.ARCADE;%0A
+    for (var i = 0; i %3C 10; i++) %7B%0A        flower = flowers.create(-100, -100, 'test_flower');%0A    %7D%0A
     %0A    // Defi
@@ -1889,28 +1889,24 @@
 ARCADE;%0A
-    
 %0A    // 
 Manually
@@ -1901,174 +1901,807 @@
  // 
-Manually add test plot/flower%0A    //game.add.sprite(64,64, 'plot');%0A    //game.add.sprite(64,8, 'test_flower');%0A%7D%0A%0Afunction update() %7B%0A    //background.tint = 0x123456;
+Set up inital clock for update();%0A    time = game.time.now;%0A%7D%0A%0Afunction update() %7B%0A    if (game.time.now %3E time + 2000) %7B%0A        // Every two seconds, spawn a flower or weed on an empty plot%0A        var done = false;%0A        while (!done) %7B%0A            // Modify a random plot%0A            // TODO: Refactor to generate an index between 0 and 9%0A            var currentPlot = Math.floor(Math.random() * 10 + 1);%0A            if (currentPlot %3E 9) %7B%0A                currentPlot = 0;%0A            %7D%0A            %0A            // If the plot isn't occupied, add a flower or weed%0A            flowers.children%5BcurrentPlot%5D.x = plots.children%5BcurrentPlot%5D.x;%0A            flowers.children%5BcurrentPlot%5D.y = plots.children%5BcurrentPlot%5D.y - 110;%0A%0A            done = true;%0A        %7D%0A        time = game.time.now;%0A    %7D
 %0A%7D

Add basic spawning on a timer