Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. public class GameActivity extends Activity {
  2.  
  3. @Override
  4. protected void onCreate(Bundle savedInstanceState){
  5. super.onCreate(savedInstanceState);
  6.  
  7. View gameview = new GameView(this);
  8. setContentView(gameview);
  9.  
  10. }
  11.  
  12. }
  13.  
  14. public class GameView extends View {
  15.  
  16. private static final String TAG = null; // for log.e
  17.  
  18. private Ball ball1; // ball1
  19. private GameContainer gameContainer; // frame for the game
  20. private Racket racket; // controller
  21. int viewWidth = 0; // width onchange
  22. int viewHeight = 0; // height onchange
  23. private Score score;
  24.  
  25.  
  26. // constructor
  27. public GameView(Context context) {
  28. super(context);
  29.  
  30. ball1 = new Ball(Color.GREEN, 24, 10, 2); // colour, radius,speedx, speedy
  31. ball1.setBallLocation(10, 5); // x, y of ball
  32. gameContainer = new GameContainer(Color.GRAY);
  33. racket = new Racket(Color.BLACK);
  34. score = new Score(Color.WHITE);
  35. }
  36.  
  37. @Override
  38. public void onDraw(Canvas canvas){
  39. gameContainer.container(1, 2, 100, 100);
  40. gameContainer.display(canvas);
  41.  
  42. ball1.drawBall(canvas);
  43. ball1.moveBall(gameContainer);
  44.  
  45. // check the ball if it is out display the alert box
  46. if (ball1.getEndGame()){
  47. Log.e(TAG, "END of game");
  48. }
  49. }
  50. }
  51.  
  52. public int getHeight(){
  53. return viewHeight;
  54. }
  55.  
  56. public int viewWidth = 0;
  57.  
  58. gameview.viewWidth = ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement