1

good day... im a new programmer in android... and actually its my first time doing so... but i have basic knowledge about java...

so here goes.. my game will have an icon that can be controlled by a joystick... and another icon that goes up and down the screen(non controllable) i want the speed to increase a little..... i have started the code but dont know where and how to start the collision.. another one is that the icon that is controllabe always passes the screen and pop out the opposite direction...

    public class GameSurface1 extends SurfaceView implements SurfaceHolder.Callback {

private Context _context;
private GameThread1 _thread;
private GameControl _controls;
private GameJoystick1 _joystick;
private int y = 0; 

private int xSpeed = 1;


private Bitmap _pointer, bmp;


public GameSurface1(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
    _context = context;
    init();
}


private void init(){
    //initialize our screen holder
    SurfaceHolder holder = getHolder();
    holder.addCallback( this);

    //initialize our game engine

    //initialize our Thread class. A call will be made to start it later
    _thread = new GameThread1(holder, _context, new Handler(),this);
    setFocusable(true);


    _joystick = new GameJoystick1(getContext().getResources());
    _pointer = (Bitmap)BitmapFactory.decodeResource(getResources(), R.drawable.icon1);
    bmp = (Bitmap)BitmapFactory.decodeResource(getResources(), R.drawable.bad1);
    //contols
    _controls = new GameControl();
    setOnTouchListener(_controls);
}


public void doDraw(Canvas canvas){
     if (y == getHeight() - bmp.getHeight()) {
         xSpeed = -1;
  }
  if (y == 0) {
         xSpeed = 1;
  }
  y = y + xSpeed;


    //update the pointer
    _controls.update(null);

    //draw the pointer
    canvas.drawBitmap(_pointer, _controls._pointerPosition.x, _controls._pointerPosition.y, null);

    //draw the joystick background
    canvas.drawBitmap(_joystick.get_joystickBg(), 15,215, null);

    //draw the dragable joystick
    canvas.drawBitmap(_joystick.get_joystick(),_controls._touchingPoint.x - 26, _controls._touchingPoint.y - 26, null);
    canvas.drawBitmap(bmp, 280, y, null);
}



//these methods are overridden from the SurfaceView super class. They are automatically called 
//when a SurfaceView is created, resumed or suspended.
@Override 
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {}
private boolean retry;
@Override 
public void surfaceDestroyed(SurfaceHolder arg0) {
    retry = true;
    //code to end gameloop
    _thread.state = GameThread1.STOPED;
    while (retry) {
        try {
            //code to kill Thread
            _thread.join();
            retry = false;
        } catch (InterruptedException e) {
        }
    }

}

@Override 
public void surfaceCreated(SurfaceHolder arg0) {
    if(_thread.state==GameThread1.PAUSED){
        //When game is opened again in the Android OS
        _thread = new GameThread1(getHolder(), _context, new Handler(),this);
        _thread.start();
    }else{
        //creating the game Thread for the first time
        _thread.start();
    }
}

ill appreciate all the help you can give... thank you

5
  • 1
    there are framework for things like that. andengine, libgdx, ...
    – njzk2
    Aug 12, 2013 at 15:19
  • ahm can you help me on that matter? please help me.. can you give me an examples of what does it look like?
    – newbie
    Aug 13, 2013 at 3:59
  • most of game engines have tutorials. libgdx has a far more extensive documentation than andengine, i think.
    – njzk2
    Aug 13, 2013 at 7:51
  • so what is more preferable for newbies like me
    – newbie
    Aug 13, 2013 at 12:06
  • start by taking a look at several tutorials for each
    – njzk2
    Aug 13, 2013 at 12:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.