Skip to content

Commit

Permalink
daffdafds
Browse files Browse the repository at this point in the history
  • Loading branch information
Andriy Katkov committed Feb 8, 2014
2 parents 57001ab + d2f97ae commit 8e1fb5b
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 25 deletions.
Binary file not shown.
Binary file modified bin/classes/com/example/avalanchegame/CustomSurfaceView.class
Binary file not shown.
Binary file modified bin/classes/com/example/avalanchegame/Player.class
Binary file not shown.
3 changes: 2 additions & 1 deletion src/com/example/avalanchegame/Box.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ public int intersects(RectF collided)
int minimumIntersectIndex = -1;
if (this.bottom < collided.top
&& this.bottom > collided.bottom
&& ((this.right < collided.right && this.right > collided.left) || (this.left > collided.left && this.left < collided.right) || (this.right > collided.right && this.left < collided.left)))
&& ((this.right < collided.right && this.right > collided.left)
|| (this.left > collided.left && this.left < collided.right) || (this.right > collided.right && this.left < collided.left)))
{
minimumIntersectIndex = 2;
}
Expand Down
29 changes: 19 additions & 10 deletions src/com/example/avalanchegame/CustomSurfaceView.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,14 @@ class GameThread

private int minWidth;


private int maxWidth;
private Box testBlock;
private Box testBlock2 = new Box(mCanvasWidth/2, mCanvasHeight/2, 300, -50f);
private Box testBlock2 =
new Box(
mCanvasWidth / 2,
mCanvasHeight / 2,
300,
-50f);

private long lastTime =
System
Expand All @@ -121,6 +125,8 @@ class GameThread

private float boxFallSpeed = -200f;

private boolean triedToJump = false;


// ----------------------------------------------------------
/**
Expand Down Expand Up @@ -162,8 +168,8 @@ public void generateBoxes(float startingHeight, float additionalHeight)
seededRandom.nextFloat() * mCanvasHeight / 2 + mCanvasHeight
/ 2)
{
Log.d("ass", spawnHeight+"");
int amountPerHeight = seededRandom.nextInt(2)+1;
Log.d("ass", spawnHeight + "");
int amountPerHeight = seededRandom.nextInt(2) + 1;
for (int i = 0; i < amountPerHeight; i++)
{
int width = randInt(minWidth, maxWidth) * 2;
Expand Down Expand Up @@ -527,7 +533,7 @@ private void updateLogic()
{
Box ground = new Box(mCanvasWidth / 2, -5000, 10000, 0);
boxes.add(ground);
generateBoxes(mCanvasHeight, mCanvasHeight*40);
generateBoxes(mCanvasHeight, mCanvasHeight * 40);
}
firstTime = false;
player.adjustPosition((int)(System.currentTimeMillis() - lastTime));
Expand Down Expand Up @@ -556,6 +562,9 @@ private void updateLogic()
// fix grounding within player
}
}
if (triedToJump)
player.tryToJump();
triedToJump = false;

lastTime = System.currentTimeMillis();
}
Expand Down Expand Up @@ -600,16 +609,16 @@ private void doDraw(Canvas canvas)
*/
public boolean onTouchEvent(MotionEvent e)
{
synchronized (mSurfaceHolder)
{
//synchronized (mSurfaceHolder)
//{
switch (e.getAction())
{
case MotionEvent.ACTION_DOWN:
player.tryToJump();
break;
triedToJump = !player.tryToJump();
break;
}
return true;
}
//}
}


Expand Down
40 changes: 26 additions & 14 deletions src/com/example/avalanchegame/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class Player
private final float startingSideJumpVelocity = 1000f;
private float additionalSideJumpVelocity = 0f;
private float jumpVelocity = 1500f;
private boolean midJump = false;


public Player(RectF r, int cW, int cH)
Expand Down Expand Up @@ -84,6 +85,7 @@ public void draw(Canvas c)
playerRect.right,
ground - playerRect.bottom);
localRect.offset(0, playerRect.bottom - (ground - cutoff));

c.drawRect(localRect, playerPaint);
}

Expand Down Expand Up @@ -176,7 +178,7 @@ public void fixIntersection(RectF other, int whichSide)
{
playerRect.top = other.bottom - 0.5f; // + 10;
playerRect.bottom = playerRect.top - height;
vy = 0;
vy = -100f;
py = playerRect.centerY();
// Log.d("CENTER", playerRect + "");
}
Expand All @@ -185,9 +187,12 @@ else if (whichSide == 1) // right
playerRect.right = other.left - 0.5f;
playerRect.left = playerRect.right - width;
vx = 0;
vy = 0;
px = playerRect.centerX();
canJumpFromRight = true;
if (!midJump)
{
vy = 0;
px = playerRect.centerX();
canJumpFromRight = true;
}
// Log.d("CENTER", playerRect + "");
}
else if (whichSide == 2) // bottom
Expand All @@ -196,6 +201,7 @@ else if (whichSide == 2) // bottom
playerRect.top = playerRect.bottom + height;
vy = 0;
py = playerRect.centerY();
midJump = false;
grounded = true;
// Log.d("CENTER", playerRect+"");
}
Expand All @@ -204,9 +210,12 @@ else if (whichSide == 3) // left
playerRect.left = other.right + 0.5f;
playerRect.right = playerRect.left + width;
vx = 0;
vy = 0;
px = playerRect.centerX();
canJumpFromLeft = true;
if (!midJump)
{
vy = 0;
px = playerRect.centerX();
canJumpFromLeft = true;
}
// Log.d("CENTER", playerRect + "");
}
}
Expand All @@ -223,6 +232,8 @@ else if (whichSide == 3) // left
public void adjustPosition(int deltaT)
{
vy += ay * (deltaT / 1000.0f);
if (midJump && vy <= 0)
midJump = false;
float pytemp =
py + vy * (deltaT / 1000.0f)
+ (-ay * (deltaT / 1000.0f) * (deltaT / 1000.0f));
Expand Down Expand Up @@ -279,26 +290,31 @@ public void setXVelocity(float dvx)
}


public void tryToJump()
public boolean tryToJump()
{
if (grounded)
{
jump();
return true;
}
else if (canJumpFromLeft)
{
jumpFromLeft();
return true;
}
else if (canJumpFromRight)
{
jumpFromRight();
return true;
}
return false;
}


private void jumpFromLeft()
{
vy += jumpVelocity;
midJump = true;
additionalSideJumpVelocity = startingSideJumpVelocity;
setNotGrounded();
}
Expand All @@ -307,6 +323,7 @@ private void jumpFromLeft()
private void jumpFromRight()
{
vy += jumpVelocity;
midJump = true;
additionalSideJumpVelocity = -startingSideJumpVelocity;
setNotGrounded();
}
Expand All @@ -315,6 +332,7 @@ private void jumpFromRight()
private void jump()
{
vy += jumpVelocity;
midJump = true;
setNotGrounded();
}

Expand All @@ -323,10 +341,4 @@ public boolean isGrounded()
{
return grounded;
}


public void setGrounded(boolean newState)
{
grounded = newState;
}
}

0 comments on commit 8e1fb5b

Please sign in to comment.