Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GameActivity extends Activity {
- @Override
- protected void onCreate(Bundle savedInstanceState){
- super.onCreate(savedInstanceState);
- View gameview = new GameView(this);
- setContentView(gameview);
- }
- }
- public class GameView extends View {
- private static final String TAG = null; // for log.e
- private Ball ball1; // ball1
- private GameContainer gameContainer; // frame for the game
- private Racket racket; // controller
- int viewWidth = 0; // width onchange
- int viewHeight = 0; // height onchange
- private Score score;
- // constructor
- public GameView(Context context) {
- super(context);
- ball1 = new Ball(Color.GREEN, 24, 10, 2); // colour, radius,speedx, speedy
- ball1.setBallLocation(10, 5); // x, y of ball
- gameContainer = new GameContainer(Color.GRAY);
- racket = new Racket(Color.BLACK);
- score = new Score(Color.WHITE);
- }
- @Override
- public void onDraw(Canvas canvas){
- gameContainer.container(1, 2, 100, 100);
- gameContainer.display(canvas);
- ball1.drawBall(canvas);
- ball1.moveBall(gameContainer);
- // check the ball if it is out display the alert box
- if (ball1.getEndGame()){
- Log.e(TAG, "END of game");
- }
- }
- }
- public int getHeight(){
- return viewHeight;
- }
- public int viewWidth = 0;
- gameview.viewWidth = ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement