//---------------------------------------------------//
/*
 *Copyright Bryce Thorup, William Thorup, BitJag 2014
 *
 * Contact: contact@bitjag.com
 *
 *All content developed by BitJag (graphics & Code) is
 *for your personal use only.  Feel free to burn it to a CD, 
 *flash to a SkunkBoard, or use in an emulator.  We 
 *hope you also take the chance to learn from it if needed.
 * 
 *Do not redistribute, duplicate, charge for "handling" 
 *or cost to print, or charge for profit.
 * 
 *If there is someone you know who wants a copy,
 *physical or digital, please direct them to our website.
 *Any other questions about the use of the demo, please
 *shoot us an email.  We will be liberal, promise.
 *
 * http://bitjag.com/
 * 
 *This demo was developed with the Removers Library,
 *which is used under the LGPL licence 2.1, included
 *with the source.  The Removers library is free to 
 *download and use at this location.
 * 
 * http://removers.free.fr/softs/download.php?lang=en
 *
//---------------------------------------------------*/

#include "vert_bounce.h"

  //Motion Struct Initializer
  motion* motion_init(){
    
    motion *m;
    
    m = malloc(sizeof(motion));
    
      m->delay = 9; //Used to controll the rise and fall of the object
  
      m->durration = 4;//
      
      m->controller_delay = 0;//Used to reduce button repeats
      
      m->controller_lock = 0;// lock controls until they are release.  0 = unlock & 1 = locked
      
      m->up_or_down = 0; //0 = down & up = 1
      
      m->height = 36; //Used to determine how high the ball rises after a bounce.  Max is 35.
      
      m->begin = 0;
      
      return m;
    
  }
  
//Motion function
  int move_me(sprite *sprite, int control, motion *move){
    
    move->controller_delay += 1;
   	
    //Fall down
    if(move->up_or_down == 0){
      
      move->delay += 1;
      
      move->begin = (move->delay) / (move->durration);
      
      sprite->y = (move->begin) + sprite->y;
      
    }


    //bounce up
    if(move->up_or_down == 1){
      
      move->delay -= 1;
      
      move->begin = (move->delay) / (move->durration);
      
      sprite->y = -(move->begin) + sprite->y;
	      
    }
    
    //Fly up
    if(control == 1 && move->controller_delay > 20 && move->controller_lock == 0){
      
      move->delay = move->height;
      
      move->controller_delay = 0;
      
      move->up_or_down = 1;
      
    }
    
    //Lock controller input until release
    if(1){
      
      if(control == 1){
	
	move->controller_lock = 1;
	
      }
      
      else{
	
	move->controller_lock = 0;
	
      }
	      
    }
    
    //Move ball left and right
    if(control == 2){
      
      sprite->x += 1; 
      
    }
    
    if(control == 3){
      
      sprite->x -= 1; 
      
    }
    
  }
