# controller.py
# Walker White (wmw2), and Steve Marschner (srm2)
# April 29, 2014
"""Breakout-like Controller module for lecture demos."""
import colormodel
import random
import math
from game2d import *

### CONSTANTS ###

# Window Size
WINDOW_WIDTH  = 512
WINDOW_HEIGHT = 512

### CONTROLLER CLASS ###

class Controller(Game):
    """Demo controller class for CS1110 game2d framework.
        
    Instance Attributes:
        view:      the view (inherited from Game) [GView]
        rectangles [list of GRectangle]
        last_touch
    """

    # THREE MAIN METHODS
    
    def init(self):
        """Initialize the program state."""
        self.rectangles = []
        self.last_touch = None

    def update(self,dt):
        """Animate a single frame. Called every 1/60 of a second."""
        if self.last_touch is None and self.view.touch is not None:
            r = GRectangle(x=self.view.touch.x, y=self.view.touch.y,
                           width=0, height=0)
            self.rectangles.append(r)
        if self.last_touch is not None and self.view.touch is not None:
            r = self.rectangles[-1]
            new_width = self.view.touch.x - r.x
            new_height = self.view.touch.y - r.y
            r.width = new_width
            r.height = new_height
        self.last_touch = self.view.touch

    def draw(self):
        """Draw all particles in the view."""
        for rect in self.rectangles:
            rect.draw(self.view)
        
    # HELPER METHODS


### MODEL CLASSES ###



# Script Code
if __name__ == '__main__':
    Controller(width=WINDOW_WIDTH,height=WINDOW_HEIGHT,fps=30.0).run()