ファイル名「MainLoop.java」
008 | package and.roid.shooting2; |
010 | import java.util.ArrayList; |
012 | import android.content.Context; |
013 | import android.content.res.Resources; |
014 | import android.graphics.Bitmap; |
015 | import android.graphics.BitmapFactory; |
016 | import android.graphics.Canvas; |
017 | import android.graphics.Color; |
018 | import android.graphics.Paint; |
019 | import android.graphics.Rect; |
020 | import android.graphics.drawable.Drawable; |
021 | import android.util.AttributeSet; |
022 | import android.view.MotionEvent; |
023 | import android.view.SurfaceHolder; |
024 | import android.view.SurfaceView; |
026 | public class MainLoop extends SurfaceView implements SurfaceHolder.Callback,Runnable{ |
027 | private SurfaceHolder holder; |
028 | private Thread thread; |
031 | private Shooting2Activity s2a; |
033 | private float disp_w,disp_h; |
034 | private Drawable jikiimg,tamaimg; |
035 | private Bitmap jikibit,tamabit; |
037 | private boolean tamaflg; |
038 | private int tamatime; |
040 | private Rect tamabtn; |
054 | private ArrayList<Object> object = new ArrayList(); |
059 | public MainLoop(Context context) { |
064 | public MainLoop(Context context, AttributeSet attrs) { |
065 | super(context, attrs); |
069 | public void init(Context context){ |
070 | holder = getHolder(); |
071 | holder.addCallback( this ); |
072 | holder.setFixedSize(getWidth(), getHeight()); |
080 | s2a = (Shooting2Activity)context; |
085 | Resources resources = context.getResources(); |
088 | Bitmap img= BitmapFactory.decodeResource(resources,and.roid.shooting2.R.drawable.jiki); |
092 | jikibit = Bitmap.createBitmap(img,0,0,img.getWidth()/2,img.getHeight()); |
093 | tamabit = Bitmap.createBitmap(img,img.getWidth()/2,0,img.getWidth()/2,img.getHeight()); |
103 | object .add( new Jiki(disp_w,disp_h)); |
104 | object . get (0).Oint(jikibit, 240, 425, 0, 0, jikibit.getWidth(), jikibit.getHeight(),0); |
110 | tamabtn = new Rect(50,50,100,100); |
118 | Paint p = new Paint(); |
119 | p.setAntiAlias( true ); |
121 | while (thread != null ){ |
122 | c = holder.lockCanvas(); |
124 | c.drawColor(Color.BLACK); |
127 | p.setColor(Color.BLUE); |
128 | c.drawRect(tamabtn, p); |
130 | c.drawText( "tama:" + object . get (0).tamajoutai, 50, 150, p); |
140 | for ( int i=0;i< object .size();i++){ |
141 | object . get (i).ODraw(c); |
142 | object . get (i).OMove(); |
146 | if ( object . get (i).Ogetdead()== true ) object .remove(i); |
152 | if (tamaflg == false ){ |
161 | holder.unlockCanvasAndPost(c); |
165 | } catch (Exception e){} |
169 | public boolean onTouchEvent(MotionEvent event ){ |
170 | int action = event .getAction(); |
171 | int x = ( int ) event .getX(); |
172 | int y = ( int ) event .getY(); |
174 | case MotionEvent.ACTION_DOWN: |
179 | if (tamaflg == true && ms.RectTap( |
180 | x, y, object . get (0).OgetTapRect()) == true ){ |
195 | if (ms.RectTap(x, y, tamabtn)== true ){ |
196 | ++ object . get (0).tamajoutai; |
197 | object . get (0).tamajoutai = ( object . get (0).tamajoutai+3)%3; |
200 | case MotionEvent.ACTION_UP: |
202 | case MotionEvent.ACTION_MOVE: |
207 | if (ms.RectTap(x, y, object . get (0).OgetTapRect()) == true ) object . get (0).OMove(x, y); |
219 | public void Tamajoutai(){ |
221 | if ( object . get (0).tamajoutai == 0){ |
222 | object .add( new JiTama(disp_w,disp_h)); |
223 | object . get ( object .size()-1).Oint( |
224 | tamabit, object . get (0).cx, object . get (0).cy-jikibit.getHeight(), |
225 | 0, 30, tamabit.getWidth(), tamabit.getHeight(),0); |
228 | if ( object . get (0).tamajoutai == 1){ |
230 | object .add( new JiTama(disp_w,disp_h)); |
231 | object . get ( object .size()-1).Oint( |
232 | tamabit, object . get (0).cx-20, object . get (0).cy-jikibit.getHeight(), |
233 | 0, 30, tamabit.getWidth(), tamabit.getHeight(),0); |
234 | object .add( new JiTama(disp_w,disp_h)); |
235 | object . get ( object .size()-1).Oint( |
236 | tamabit, object . get (0).cx+20, object . get (0).cy-jikibit.getHeight(), |
237 | 0, 30, tamabit.getWidth(), tamabit.getHeight(),0); |
242 | if ( object . get (0).tamajoutai == 2){ |
243 | for ( int i=0;i<10;i++){ |
244 | object .add( new JiTama(disp_w,disp_h)); |
245 | object . get ( object .size()-1).Oint( |
246 | tamabit, object . get (0).cx, object . get (0).cy, |
247 | 30, 30, tamabit.getWidth(), tamabit.getHeight(),i*(360/10)); |
252 | public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {} |
254 | public void surfaceCreated(SurfaceHolder arg0) {thread = new Thread( this );thread.start();} |
256 | public void surfaceDestroyed(SurfaceHolder arg0) {thread = null ;} |
ファイル名「Object.java」
14 | package and.roid.shooting2; |
16 | import android.graphics.Bitmap; |
17 | import android.graphics.Canvas; |
18 | import android.graphics.Color; |
19 | import android.graphics.Paint; |
20 | import android.graphics.Rect; |
21 | import android.graphics.drawable.BitmapDrawable; |
22 | import android.graphics.drawable.Drawable; |
24 | public abstract class Object { |
25 | public Mesod ms = new Mesod(); |
26 | public float disp_w,disp_h; |
40 | public int tamajoutai; |
45 | public Object( float dw, float dh){ |
58 | public abstract void ODraw(Canvas c); |
60 | public abstract void Oint(Bitmap imgb, float x, float y, float sx, float sy, int w, int h); |
61 | public abstract void Oint(Bitmap imgb, float x, float y, float sx, float sy, int w, int h, int tj); |
62 | public abstract void OMove(); |
63 | public abstract void OMove( int x, int y); |
64 | public abstract Rect OgetTapRect(); |
68 | public boolean OsotoX( int ww){ return (cx-ww<0 || cx+ww>disp_w);} |
69 | public boolean OsotoY( int hh){ return (cy-hh<0 || cy+hh>disp_h);} |
70 | public boolean Ogetdead(){ return dead;} |
ファイル名「Jiki.java」
05 | package and.roid.shooting2; |
07 | import android.graphics.Bitmap; |
08 | import android.graphics.Canvas; |
09 | import android.graphics.Rect; |
10 | import android.graphics.drawable.BitmapDrawable; |
12 | public class Jiki extends Object{ |
15 | public Jiki( float dw, float dh){ |
19 | public void Oint(Bitmap imgb, float x, float y, float sx, float sy, int w, int h, int tj){ |
20 | img = new BitmapDrawable(imgb); |
21 | cx = ms.setSizeX(disp_w, x); |
22 | cy = ms.setSizeY(disp_h, y); |
31 | public void ODraw(Canvas c){ |
37 | img.setBounds(( int )(cx-imgw/2),( int )(cy-imgh/2), |
38 | ( int )(cx+imgw/2),( int )(cy+imgh/2)); |
45 | public void OMove( int x, int y) { |
51 | if (OsotoX(imgw/2)== true ) cx = cxx; |
52 | if (OsotoY(imgh/2)== true ) cy = cyy; |
54 | public void OMove() {} |
63 | public Rect OgetTapRect(){ |
64 | Rect taprect = new Rect( |
65 | img.getBounds().left-50,img.getBounds().top-50, |
66 | img.getBounds().right+50,img.getBounds().bottom+50); |
70 | public void Oint(Bitmap imgb, float x, float y, float sx, float sy, int w, int h) {} |
ファイル名「JiTama.java」
07 | package and.roid.shooting2; |
09 | import android.graphics.Bitmap; |
10 | import android.graphics.Canvas; |
11 | import android.graphics.Rect; |
12 | import android.graphics.drawable.BitmapDrawable; |
14 | public class JiTama extends Object{ |
18 | public int tamakakudo; |
21 | public JiTama( float dw, float dh){ |
24 | public void ODraw(Canvas c){ |
37 | img.setBounds(( int )(cx-imgw/2),( int )(cy-imgh/2), |
38 | ( int )(cx+imgw/2),( int )(cy+imgh/2)); |
39 | c.rotate(tamar, cx, cy); |
52 | cx += ( float ) Math.cos(ms.toRadian(tamar-90)) * spx; |
53 | cy += ( float ) Math.sin(ms.toRadian(tamar-90)) * spy; |
57 | if (OsotoX(-imgw/2)== true ) dead = true ; |
58 | if (OsotoY(-imgh/2)== true ) dead = true ; |
61 | public void OMove( int x, int y) {} |
62 | public Rect OgetTapRect() { return null ;} |
65 | public void Oint(Bitmap imgb, float x, float y, float sx, float sy, int w, int h, int r) { |
66 | img = new BitmapDrawable(imgb); |
67 | cx = ms.setSizeX(disp_w, x); |
68 | cy = ms.setSizeY(disp_h, y); |
77 | public void Oint(Bitmap imgb, float x, float y, float sx, float sy, int w, int h) {} |
ファイル名「Mesod.java」
07 | package and.roid.shooting2; |
09 | import android.graphics.Rect; |
18 | static public final float XPERIA_W = 480f; |
19 | static public final float XPERIA_H = 854f; |
21 | static public final float ZERO = 0f; |
22 | private static final double PIE = 3.1415926; |
34 | public double toRadian( double deg){ return (deg * PIE / 180);} |
38 | public boolean RectTap( int x, int y,Rect gazou){ |
39 | return gazou.left < x && gazou.top < y && gazou.right > x && gazou.bottom > y; |
44 | public int setSizeX( float disp_w, float zahyou){ return ( int ) (zahyou * (disp_w / XPERIA_W));} |
45 | public int setSizeY( float disp_h, float zahyou){ return ( int ) (zahyou * (disp_h / XPERIA_H));} |
 

|