-
-
Save sephto/89cd5a3e00fbac56f6ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void updateRunning(List<TouchEvent> touchEvents, float deltaTime) { | |
int len = touchEvents.size(); | |
for (int i = 0; i < len; i++) { | |
TouchEvent event = touchEvents.get(i); | |
if (event.type == TouchEvent.TOUCH_UP) { | |
if (event.x < 64 && event.y < 64) { | |
if (Settings.soundEnabled) | |
Assets.click.play(1); | |
state = GameState.Paused; | |
return; | |
} | |
} | |
eventX = event.x; | |
eventY = event.y; | |
p1X = astro.x; | |
p1Y = astro.y; | |
angle = (float)(Math.atan2(eventY - p1Y, eventX - p1X )); | |
angle = (float)(angle * (180/Math.PI)); | |
Matrix matrix = new Matrix(); | |
matrix.preRotate(angle); | |
switch (event.type) { | |
case TouchEvent.TOUCH_DOWN: | |
case TouchEvent.TOUCH_DRAGGED: | |
// speed *=((astro.y-event.y)/100); | |
// angle = Math.atan2(event.y-astro.y, event.x-astro.x); | |
// angle = angle * (180/Math.PI); | |
// | |
// | |
// astro.xSpeed = (float)(Math.cos((angle) * Math.PI /180) * (speed * deltaTime)); | |
// astro.ySpeed = (float)(Math.cos((angle) * Math.PI/180) * (speed * deltaTime)); | |
float smooth =0; | |
if(astro.speedOn == false){ | |
smooth = .05f; | |
}else{ | |
smooth = .1f; | |
} | |
astro.ySpeed=0; | |
astro.xSpeed =0; | |
astro.ySpeed = astro.ySpeed + (event.y-astro.y)*smooth; | |
astro.xSpeed = astro.xSpeed + (event.x-astro.x)*smooth; | |
if (event != null) { | |
minX = eventX - p1X; | |
minY = eventY - p1Y; | |
} | |
if (p1X > eventX) { | |
astro.turnLeft(); | |
left = true; | |
right = false; | |
} | |
if (p1X < eventX) { | |
astro.turnRight(); | |
right = true; | |
left = false; | |
} | |
if (p1Y < eventY) { | |
astro.turnDown(); | |
down = true; | |
up = false; | |
} | |
if (p1Y > eventY) { | |
astro.turnUp(); | |
up = true; | |
down = false; | |
} | |
if (minX < 10 && minX > -10) { | |
astro.xSpeed = 0; | |
left = false; | |
right = false; | |
} | |
if (minY < 10 && minY > -10) { | |
astro.ySpeed = 0; | |
up = false; | |
down = false; | |
} | |
break; | |
case TouchEvent.TOUCH_UP: | |
float tempX = event.x; | |
float tempY = event.y; | |
if(p1X - 32 <= tempX && p1X + 32 >= tempX | |
&& p1Y - 32 <= tempY && p1Y + 32 >= tempY){ | |
astro.ySpeed=0; | |
astro.xSpeed=0; | |
} | |
// if (p1X - 32 <= eventX && p1X + 32 >= eventX | |
// && p1Y - 32 <= eventY && p1Y + 32 >= eventY) { | |
// | |
// astro.ySpeed = 0; | |
// astro.xSpeed = 0; | |
// } | |
String msg = " where my finger is. " + event.x + " and " | |
+ event.y; | |
String player = " where astro is " + astro.x + " and " + astro.y; | |
String min = " tempx: " + tempX + " tempy " + tempY; | |
Log.d("location of touch", msg); | |
Log.d("location of astro", player); | |
Log.d("MINimum : ", min); | |
} | |
} | |
world.update(deltaTime); | |
if (world.hit == true) { | |
world.hit = false; | |
if (Settings.soundEnabled) | |
Assets.bitten.play(1); | |
// state = GameState.GameOver; | |
} | |
if (oldScore != world.score) { | |
oldScore = world.score; | |
score = "" + oldScore; | |
if (Settings.soundEnabled) | |
Assets.eat.play(1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment