Game to achieve particle collisions, pure Java

Source: Internet
Author: User
Tags drawtext gety

Package com.totoo.TouhouMassLight;

Import Android.content.Context;
Import Android.graphics.Bitmap;
Import Android.graphics.Canvas;
Import Android.graphics.Color;
Import Android.graphics.Paint;
Import android.graphics.drawable.BitmapDrawable;
Import Android.util.AttributeSet;
Import Android.view.View;

Import java.util.ArrayList;
Import java.util.List;
Import Java.util.Random;

Import com.totoo.touhoumasslight.creature.*;

public class Gameviewnew extends View {
int touchx =-1;
int touchy =-1;
Float StartX = 0, Starty = 0, EndX = 0, EndY = 0;

Bitmap Playerimage;
Bitmap Bossimage;
int steplength = 34;
Newhero molisha;//???
Newhero reimei;//Boss
buling buling[] = new BULING[16];
list<newmagic> magiclistx = new arraylist<newmagic> ();//????????
list<newmagic> magiclisty = new arraylist<newmagic> ();//????????
Public list<newmagic> newmagiclist = new arraylist<newmagic> ();
int SW = 480;//?????
int SH = 768;//??
int Mapbodderx;
int mapboddery;
int TOUCHARCEH;
int toucharcew;
com.totoo.touhoumasslight.creature._things_moveable[][] WorldMap = new _things_moveable[][]{};
Int[][] MapCache;
Int[] Tagetxy;
Final Double uitpersent = 0.25;
Final Double UIpersent2 = 0.2;
Final Double UITpersent2 = 0.1;
public static final int steplength = 34;
int earthline = 800;
int leftdivede = 0;
int rightdivede = 0;
int highdivede = 0;
int middledivede = 0;
int startbardivedex = 200;
int startbardivedex_weight = 2;
int Center = 0;
int Lowdivede;
Newsupershow RSS;
Newsupershow MSS;
_things_moveable[] creatrues;
int playerheath = 50;
String alretstring = "wamring";
Paint drawsome = null;
Long Count;
Long Countvaluemax = 100;
Private float width, height;
Private Magicbox Magicbox;
Private Boolean Initflag;
int flagcount = 0;
Random ran = new random ();
private int _pixiv = 8;

Public Gameviewnew (context context, AttributeSet attr) {//???? D??? Y?
Super (context, attr);
Initflag = init ();
}

Private Boolean init () {

Mapbodderx = SW/4;
Mapboddery = SH/4;

Getboder (SW, SH);

Initcontorluipic ();
return true;
}

public void Flashthem (int x, int y, int x2, int y2) {
Molisha.flashinmap (WorldMap, x, Y,
Molisha.getxinmap () + 1, Molisha.getyinmap () + 1,
(int) StartX, (int) starty, (int) endx, (int) endY);//??????????????
Reimei.flashinmap (WorldMap, x2, Y2,
Reimei.getxinmap () + 1, Reimei.getyinmap () + 1,
(int) StartX, (int) starty, (int) endx, (int) endY);
}

void Getboder (int _sw, int _sh) {
Getboder (_SW, _sh, 0);
}

void Getboder (int _sw, int _sh, int pixiv) {
if (0! = pixiv)
_PIXIV = PIXIV;
if (_sw > _sh) {//????
StartX = (_SW-_sh)/2;
Starty = 0;
EndX = _SW-(_SW-_sh)/2;
EndY = _sh;
} else {//????
StartX = 0;
Starty = (_sh-_SW)/2;
EndX = _SW;
EndY = _sh-(_sh-_SW)/2;
}
SW = _SW;
SH = _sh;
Magicbox.width = Endx-startx;
Magicbox.height = Endy-starty;
Molisha = new Newhero (40/steplength, 400/steplength, StartX, starty);
Reimei = new Newhero (300/steplength, 400/steplength, StartX, starty);
MSS = new Newsupershow (Molisha, steplength);
RSS = new Newsupershow (Reimei, steplength);
// ??????
WorldMap = new _THINGS_MOVEABLE[_PIXIV][_PIXIV];
for (int i = 0; i < _pixiv; i++) {
for (int j = 0; J < _pixiv; J + +)
WORLDMAP[I][J] = new _things_moveable ();

}
int GetX, GetY;
for (int i = 0; i < i++) {//????????
GetX = Ran.nextint (_PIXIV);
GetY = Ran.nextint (_PIXIV);
Switch (Ran.nextint (2) + 1) {
Case 1:
Worldmap[getx][gety]. Cricletype = boxcolor.whitebuliding;//?????,???????
Break
Case 2:
Worldmap[getx][gety]. Cricletype = boxcolor.bluewater;//?????,???????
Break

Default
Break
}
Buling[i] = new buling ((int) (Magicbox.getcellinmap (GetX) + StartX),
(int) (Magicbox.getcellinmap (GetY) + starty), StartX, Starty, alretstring, 1,
Worldmap[getx][gety]. Cricletype);
Buling[i].setboxcell (GetX, GetY);
for (int k = 0; k < 8; k++) {
for (int j = 0; J < 8; J + +)

// }
}
// ????????
Boolean isblock = false;
for (int i = 0; i <; i++) {
for (int j = 0; J <; J + +) {
if (1 = = Buling[i].getedx-buling[j].getedx | |-1 = =
Buling[i].getedx-buling[j].getedx) {//X????
if (0 = = Buling[i].getedy-buling[j].getedy) {//Y????
Isblock = true;
Magiclistx.add (New Newmagic (Alretstring, J, J, Molisha, J, J));
// }
// }
if (1 = = Buling[i].getedy-buling[j].getedy | |-1 = =
Buling[i].getedy-buling[j].getedy) {//Y????
if (0 = = Buling[i].getedx-buling[j].getedx) {//x????
Magiclisty.add (New Newmagic (Alretstring, J, J, Molisha, J, J));
// }
// }
//
// }
//
// }
if (_sw > _sh)
Flashthem ((int) (StartX * 2), (int) (MAGICBOX.HEIGHT/2), (int) (ENDX-STARTX),
(int) (MAGICBOX.HEIGHT/2));
Else
Flashthem ((int) (MAGICBOX.WIDTH/2), (int) (Starty * 2), (int) (MAGICBOX.WIDTH/2),
(int) (Endy-starty));
}

@Override
protected void OnDraw (canvas canvas) {//???????
if (!initflag) {
DRAWBG (canvas);
Drawcontorl (canvas);
Initflag = true;
} else {
flagcount++;
if (Flagcount > 100) {
Initflag = false;
// }
// }
for (int i = 0; i <; i++) {
if (null! = Buling[i])
if (Boxcolor.bluewater = = Buling[i].type)
Drawmap (canvas, Buling[i], playerimage, MSS);
}
if (null! = Molisha) {
if (null! = Fullscreenactivity.contorlview)
Molisha.go (int) fullscreenactivity.contorlview._fx, (int) fullscreenactivity.contorlview._fy, WorldMap,
(int) StartX, (int) starty, (int) endx, (int) endY);

if (! ( Molisha. Heath > 0))
Molisha.setflag (TRUE);

Drawplayer (Canvas, Molisha, Playerimage, MSS);
}

if (null! = Reimei)
Drawplayer (Canvas, Reimei, Bossimage, RSS);
for (int i = 0; i <; i++) {
if (null! = Buling[i])
if (boxcolor.whitebuliding = = Buling[i].type)
Drawbuling (canvas, Buling[i], playerimage, MSS);
}
Drawmagic (canvas);

}

private void Initcontorluipic () {//? d??? [?? D?
Bgpic = ((bitmapdrawable)
Getresources (). getdrawable (r.drawable.bg)). Getbitmap ();
Playerimage = ((bitmapdrawable) getresources (). getdrawable (R.DRAWABLE.PA)). Getbitmap ();
Bossimage = ((bitmapdrawable) getresources (). getdrawable (R.DRAWABLE.PB)). Getbitmap ();
}

Boolean DRAWBG (Canvas canvas) {//?????? L?u
Canvas.drawcolor (Color.Black);
DrawImage (canvas, bgpic, 0, 0);
if (null! = alretstring)
Canvas.drawtext (alretstring, Steplength, Steplength, drawsome);
return false;
}

void Drawmap (Canvas C, Newhero H, Bitmap Img, Newsupershow SS) {//? [??????? L?u
Paint p = new paint ();
for (int i = 0; i < Mapbodderx; i++) {
for (int j = 0; J < Mapboddery; J + +) {
if (0! = Worldmap[i][j])
P.setcolor (Color.Blue);
C.drawrect (x * WIDTH/8 + StartX,//
Y * height/8 + starty,//
x + 1) * WIDTH/8 + StartX,//
Y + 1) * HEIGHT/8 + starty,//
p);
Canvas.drawtext ("" + worldmap[i][j], I * steplength, J *
Steplength, Drawsome);
// }
// }
return false;
Drawcreatrue (c, H, IMG, SS, 2);
}

void Drawbuling (Canvas C, Newhero H, Bitmap Img, Newsupershow SS) {
Drawcreatrue (c, H, IMG, SS, 1);
}

void Drawplayer (Canvas C, Newhero H, Bitmap Img, Newsupershow SS) {
Drawcreatrue (c, H, IMG, SS, 0);
}

public void Drawcreatrue (Canvas C, Newhero H, Bitmap Img, newsupershow SS, int type) {

Paint p = new paint ();
try {//?????? L?u
if ( -1! = H.getxinmap ()) {
if ( -1! = H.getyinmap ()) {
h = ss.slowmove (h);
x = Ss.getxslow ();
y = Ss.getyslow ();

H.magicbox.showbox (c, p, h, type, worldmap);
if (0 = = type)
DrawImage (c, IMG, H.getxinmap ()-Img.getwidth ()/2, H.getyinmap ()-Img.getheight ()/2
Touchx-steplength/2
, touchy
);
if (0 = = type)//tpye?0??????????
P.setcolor (Color.White);
C.drawtext ("x:" + Touchx + "y:" + touchy, Touchx,
Touchy, p);
TZ (H.getdescription () + "" + ss.getxslow () + "
"+ss.getyslow ());
}
}
} catch (Exception e) {
}

}

Newmagic temp;
private int tempcount = _PIXIV;

public void drawmagic (canvas canvas) {//???????? L?u

Paint p = new paint ();
P.setcolor (color.red);
P.setantialias (TRUE);//?????
P.setalpha (90);
Tempcount = Newmagiclist.size ();
for (int i = 0; i < Tempcount; i++) {
temp = Newmagiclist.get (i);
if (!temp.checklocava (temp. Xinmap, temp. Yinmap, (int) StartX, (int) starty, (int) endx, (int) EndY)) {
tempcount--;
Newmagiclist.remove (temp);
Continue
}
Canvas.drawcircle (temp. Xinmap, temp. Yinmap, p);
Temp. Xinmap + = Temp.getspeedinx (TOUCHX);
Temp. Yinmap + = Temp.getspeediny (touchy);
}
}

public void Drawcontorl (canvas canvas) {//???????? L?u
Paint p = new paint ();
P.setcolor (Color.Black);
P.setantialias (TRUE);
Canvas.drawrect (StartX, Starty, EndX, EndY, p);
P.setstyle (Paint.Style.STROKE);
Canvas.drawtext ("?????? A ", Rightdivede +, Middledivede +, p);
Canvas.drawline (leftdivede, 0, Leftdivede, SH, p);
Canvas.drawtext ("????? SS ", 0 +, 0 +, p);
Canvas.drawline (rightdivede, 0, Rightdivede, SH, p);
Canvas.drawtext ("????? WS ", 0 +, Highdivede +, p);
Canvas.drawline (0, Highdivede, Leftdivede, Highdivede, p);
Canvas.drawtext ("? w?? F ", 0 +, Middledivede +, p);
Canvas.drawline (Rightdivede, Highdivede, SW, Highdivede, p);
Canvas.drawtext ("L????", 0 +, Lowdivede +, p);
Canvas.drawline (0, Middledivede, Leftdivede, Middledivede, p);
Canvas.drawtext ("U????", Leftdivede + 0, p);
Canvas.drawline (Rightdivede, Middledivede, SW, Middledivede, p);
Canvas.drawtext ("D????", Leftdivede +, Center +, p);
Canvas.drawline (0, Lowdivede, Leftdivede, Lowdivede, p);
Canvas.drawtext ("??? R ", Rightdivede +, Lowdivede +, p);
Canvas.drawline (Rightdivede, Lowdivede, SW, Lowdivede, p);
Canvas.drawtext ("????? OSC1 ", Rightdivede +, 0 +, p);
Canvas.drawline (Leftdivede, center, Rightdivede, center, p);
Canvas.drawtext ("????? PSC2 ", Rightdivede +, Highdivede +, p);
P.setcolor (Color.green);
P.setstrokewidth (1);
for (int i = 0; i < 8; i++) {
//
Canvas.drawline (
(i) * MAGICBOX.WIDTH/8
_pixiv
+ StartX,
Starty,//X=x
(i) * Magicbox.width/_pixiv + StartX, endy//
, p);//Downhere,xup,yequals
}
for (int j = 0; J < 8; J + +) {

Canvas.drawline (StartX,
(j) * MAGICBOX.WIDTH/8
_pixiv
+ Starty,//Y=y
EndX, (j) * Magicbox.width/_PIXIV + starty,//
p);//Gohere
}
P.setcolor (Color.White);
P.setstrokewidth (10);
P.setalpha (90);
Canvas.drawrect (StartX, Starty, EndX, EndY, p);
}

void DrawImage (Canvas c, Bitmap b, int x, int y) {
C.drawbitmap (b, x, y, null);
}

void Shoottip (String str) {
Toast.maketext (this, str, toast.length_short). Show ();
}
}

Game to achieve particle collisions, pure Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.