//
//  Sprite.m
//  SimpleGLESgame
//
//  Created by Vedran Murgić on 25.01.2014..
//  Copyright (c) 2014. Vedran Murgić. All rights reserved.
//

#import "Sprite.h"

@interface Sprite()

@property (nonatomic, weak) GLKBaseEffect *baseEffect;

@end

@implementation Sprite

-(id) initWithEffect:(GLKBaseEffect *)baseEffect
{
    if((self = [super init])){
        self.baseEffect = baseEffect;
    }
    return self;
}

-(void) render:(NSString *) s{
    
    self.baseEffect.texture2d0.name = self.textureInfo.name;
    self.baseEffect.texture2d0.target = self.textureInfo.target;
    
    GLKMatrix4 modelviewMatrix = GLKMatrix4Translate(GLKMatrix4Identity,self.position.x, self.position.y, 0);
    modelviewMatrix = GLKMatrix4Rotate(modelviewMatrix,GLKMathDegreesToRadians(self.rotation), 0.0f, 0.0f, 1.0f);
    self.baseEffect.transform.modelviewMatrix = modelviewMatrix;
    
    if([s isEqualToString:@"att"]){
        self.baseEffect.constantColor = GLKVector4Make(20.0f/255.0f, 133.0f/255.0f, 204.0f/255.0f, 1.0f);
    }else if([s isEqualToString:@"med"]){
        self.baseEffect.constantColor = GLKVector4Make(255.0f/255.0f, 252.0f/255.0f, 25.0f/255.0f, 1.0f);
    }else if([s isEqualToString:@"blink1"]){
        self.baseEffect.constantColor = GLKVector4Make(1.0f, 0.0f, 0.0f, 1.0f);
    }

    //self.baseEffect.constantColor = GLKVector4Make(1.0f, 0.0f, 0.0f, 1.0f);
    [self.baseEffect prepareToDraw];
    
    //NSLog(@"%@", s);
    if([s isEqualToString:@"mozak"]){
        glDrawArrays(GL_TRIANGLES, 0, 6);
    }else if([s isEqualToString:@"back"]){
        glDrawArrays(GL_TRIANGLES,6, 6);
    }
    else if([s isEqualToString:@"att"]){
        glDrawArrays(GL_TRIANGLES,12, 6);
    }else if([s isEqualToString:@"med"]){
        glDrawArrays(GL_TRIANGLES,18, 6);
    }else if([s isEqualToString:@"attBack"]){
        glDrawArrays(GL_TRIANGLES,24, 6);
    }else if([s isEqualToString:@"medBack"]){
        glDrawArrays(GL_TRIANGLES,30, 6);
    }else if([s isEqualToString:@"blink0"] || [s isEqualToString:@"blink1"]){
        glDrawArrays(GL_TRIANGLES,36, 6);
    }
    
    self.baseEffect.constantColor = GLKVector4Make(1.0f, 1.0f, 1.0f, 1.0f);
}

-(void) update{
    
}
@end
