package edu.uci.ics.inf125.pixeljamz.gestures;
import java.util.Random;
import android.util.Log;
import edu.uci.ics.inf125.pixeljamz.view.Pixel;
public class TiltGesture extends AbstractPixelJamzGesture {
private String direction;
public TiltGesture(int x, int y, long timeBorn) {
super(x, y, timeBorn);
Random RNG = new Random();
int directionNum = RNG.nextInt(4);
// Draw a tilt icon using the leftmost pixel as the "center" pixel
switch(directionNum) {
case 0: // Up direction
direction = "UP";
getmUsedPixels().add(new Pixel(x,y));
getmUsedPixels().add(new Pixel(x+1,y-1));
getmUsedPixels().add(new Pixel(x+2,y-2));
getmUsedPixels().add(new Pixel(x+3,y-1));
getmUsedPixels().add(new Pixel(x+4,y));
getmUsedPixels().add(new Pixel(x+2,y-1));
getmUsedPixels().add(new Pixel(x+2,y));
getmUsedPixels().add(new Pixel(x+2,y+1));
getmUsedPixels().add(new Pixel(x+2,y+2));
break;
case 1: // Left direction
direction = "LEFT";
getmUsedPixels().add(new Pixel(x+2,y-2));
getmUsedPixels().add(new Pixel(x+1,y-1));
getmUsedPixels().add(new Pixel(x,y));
getmUsedPixels().add(new Pixel(x+1,y+1));
getmUsedPixels().add(new Pixel(x+2,y+2));
getmUsedPixels().add(new Pixel(x+1,y));
getmUsedPixels().add(new Pixel(x+2,y));
getmUsedPixels().add(new Pixel(x+3,y));
getmUsedPixels().add(new Pixel(x+4,y));
break;
case 2: // Down direction
direction = "DOWN";
getmUsedPixels().add(new Pixel(x,y));
getmUsedPixels().add(new Pixel(x+1,y+1));
getmUsedPixels().add(new Pixel(x+2,y+2));
getmUsedPixels().add(new Pixel(x+3,y+1));
getmUsedPixels().add(new Pixel(x+4,y));
getmUsedPixels().add(new Pixel(x+2,y+1));
getmUsedPixels().add(new Pixel(x+2,y));
getmUsedPixels().add(new Pixel(x+2,y-1));
getmUsedPixels().add(new Pixel(x+2,y-2));
break;
case 3: // Right direction
direction = "RIGHT";
getmUsedPixels().add(new Pixel(x+2,y-2));
getmUsedPixels().add(new Pixel(x+3,y-1));
getmUsedPixels().add(new Pixel(x+4,y));
getmUsedPixels().add(new Pixel(x+3,y+1));
getmUsedPixels().add(new Pixel(x+2,y+2));
getmUsedPixels().add(new Pixel(x,y));
getmUsedPixels().add(new Pixel(x+1,y));
getmUsedPixels().add(new Pixel(x+2,y));
getmUsedPixels().add(new Pixel(x+3,y));
getmUsedPixels().add(new Pixel(x+4,y));
break;
// no default case since the random number generator should never return a value outside of 0-3
}
}
@Override
public boolean fulfillGesture(float x, float y, float z) {
boolean result = false;
Log.d("FlickGesture", "TEST: "+x+","+y+","+z);
if(direction=="UP")
{
if(z <= -45) // Placeholder values
return true;
else return false;
}
if(direction=="DOWN")
{
if(z >= 45) // Placeholder values
return true;
else return false;
}
if(direction=="LEFT")
{
if(y <= -45) // Placeholder values
return true;
else return false;
}
if(direction=="RIGHT")
{
if(y >= 45) // Placeholder values
return true;
else return false;
}
return result;
}
}
|