Rev 43 |
Rev 46 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
package com.gebauz.pingK.game;
import com.gebauz.framework.util.Sprite2D;
import com.gebauz.framework.util.Vector2;
import com.gebauz.pingK.R;
public class Ball
{
static public final int DIRECTION_LEFT =
0;
static public final int DIRECTION_RIGHT =
1;
private GameLogic mGameLogic =
null;
private Sprite2D mBallSprite
;
// movement parameters
private float mRotation = 0.0f
;
private float mSpeed = GameConsts.
BALL_INITIAL_SPEED;
public Ball
(GameLogic gameLogic
)
{
mGameLogic = gameLogic
;
}
public void init
()
{
mBallSprite =
new Sprite2D
();
mBallSprite.
init(R.
drawable.
ball, GameConsts.
VIRTUAL_SCREEN_WIDTH/2.0f, GameConsts.
VIRTUAL_SCREEN_HEIGHT/2.0f, GameConsts.
BALL_SIZE, GameConsts.
BALL_SIZE);
reset
(DIRECTION_LEFT
);
}
public void exit
()
{
}
public void reset
(int direction
)
{
mSpeed = GameConsts.
BALL_INITIAL_SPEED;
if (direction == DIRECTION_LEFT
)
{
mRotation = 270.0f
;
}
else if (direction == DIRECTION_RIGHT
)
{
mRotation = 90.0f
;
}
}
public void update
(float deltaTime
)
{
processAngularVelocity
(deltaTime
);
moveForward
(deltaTime
);
//collectPowerUps;
//reflectFromCrystals;
reflectFromBoard
(deltaTime
);
reflectFromEntities
(deltaTime
);
//updateBallSparks;
//updateTrail
checkPlayerGainsScore
();
mBallSprite.
update(deltaTime
);
}
public void render
()
{
mBallSprite.
render();
}
public void processAngularVelocity
(float deltaTime
)
{
}
public void moveForward
(float deltaTime
)
{
Vector2 move =
new Vector2
();
move.
x =
(float)Math.
sin(Math.
toRadians(mRotation
));
move.
y =
(float)Math.
cos(Math.
toRadians(mRotation
));
move.
setLength(mSpeed
* deltaTime
);
mBallSprite.
x += move.
x;
mBallSprite.
y += move.
y;
}
public void reflectFromBoard
(float deltaTime
)
{
}
public void reflectFromEntities
(float deltaTime
)
{
}
public void checkPlayerGainsScore
()
{
}
}