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 < 16; 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 < 16; i++) {
// for (int j = 0; j < 16; 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 < 16; 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 < 16; 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, 10, 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 + 20, MiddleDivede + 20, p);
// canvas.drawLine(LeftDivede, 0, LeftDivede, SH, p);
// canvas.drawText("?????SS", 0 + 20, 0 + 20, p);
// canvas.drawLine(RightDivede, 0, RightDivede, SH, p);
// canvas.drawText("?????WS", 0 + 20, HighDivede + 20, p);
// canvas.drawLine(0, HighDivede, LeftDivede, HighDivede, p);
// canvas.drawText("?w??F", 0 + 20, MiddleDivede + 20, p);
// canvas.drawLine(RightDivede, HighDivede, SW, HighDivede, p);
// canvas.drawText("L????", 0 + 20, LowDivede + 20, p);
// canvas.drawLine(0, MiddleDivede, LeftDivede, MiddleDivede, p);
// canvas.drawText("U????", LeftDivede + 20, 0 + 20, p);
// canvas.drawLine(RightDivede, MiddleDivede, SW, MiddleDivede, p);
// canvas.drawText("D????", LeftDivede + 20, Center + 20, p);
// canvas.drawLine(0, LowDivede, LeftDivede, LowDivede, p);
// canvas.drawText("???R", RightDivede + 20, LowDivede + 20, p);
// canvas.drawLine(RightDivede, LowDivede, SW, LowDivede, p);
// canvas.drawText("?????oSC1", RightDivede + 20, 0 + 20, p);
// canvas.drawLine(LeftDivede, Center, RightDivede, Center, p);
// canvas.drawText("?????pSC2", RightDivede + 20, HighDivede + 20, 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();
}
}

游戏中实现粒子碰撞,纯java的更多相关文章

  1. 游戏服务端中使用Servlet和Java注解的一个好设计

    SNS类游戏基本都是使用HTTP短连接,用Java来开发服务端时能够使用Servlet+Tomcat非常轻松的架构起服务端来.在这里介绍一种使用Servlet比較好的一种设计,我也见过非常多基于HTT ...

  2. Hanlp中使用纯JAVA实现CRF分词

    Hanlp中使用纯JAVA实现CRF分词 与基于隐马尔可夫模型的最短路径分词.N-最短路径分词相比,基于条件随机场(CRF)的分词对未登录词有更好的支持.本文(HanLP)使用纯Java实现CRF模型 ...

  3. 一行Java代码实现游戏中交换装备

    摘要:JDK 1.5 开始 JUC 包下提供的 Exchanger 类可用于两个线程之间交换信息. 本文分享自华为云社区<一行Java代码实现两玩家交换装备[并发编程]>,作者:陈皮的Ja ...

  4. 编写Java程序,创建Dota游戏中的兵营类,兵营类有一个类成员变量count、一个实例变量name和另一个实例变量selfCount。

    返回本章节 返回作业目录 需求说明: 创建Dota游戏中的兵营类 兵营类有一个类成员变量count.一个实例变量name和另一个实例变量selfCount. count表示的是兵营已经创建士兵的总数: ...

  5. 编写Java程序,创建Dota游戏中的防御塔类,通过两个坐属性显示防御塔所在的位置

    返回本章节 返回作业目录 需求说明: 创建Dota游戏中的防御塔类 通过两个坐属性显示防御塔所在的位置 实现思路: 创建防御塔(TowerDefense)类 在该类中定义了两个属性,分别是int类型横 ...

  6. 纯java配置SpringMVC

    一般情况下,我们会在web.xml下配置好Spring和SpringMVC,并指定好它们的配置文件 是最常用的也是最方便的方法 例如: web.xml <!-- The definition o ...

  7. spring纯java注解式开发(一)

    习惯了用XML文件来配置spring,现在开始尝试使用纯java代码来配置spring. 其实,spring的纯java配置,简单来说就是将bean标签的内容通过注解转换成bean对象的过程,没什么神 ...

  8. 游戏中VIP会员模块的简单实现

    哈哈  今天周末有时间,再整理一篇博文上来,虽然已经不做游戏老长时间了,但还是要把以前做过的东西总结一下,借此可以回顾以前的东西,也可以分享给大家. 今天说一下游戏中VIP会员模块的实现思路.每款游戏 ...

  9. AS3游戏中可视对象上限及位图相关的内存消耗实测

    前些天连续做了一些测试,以加深对AS3的掌握和在项目中对 游戏 性能.效率优化方面的一些处理,有很多测试实际意义不大,都不过是证明一些猜想是正确的,除此没有什么. 但前天进行的一系列测试中,有一些对游 ...

随机推荐

  1. [Python Study Notes]计算cpu使用率v0.1

    V0.1 更新日志: 1.加入平台判断,支持windows与linux 2.自动清屏显示,显示更加直观 '''''''''''''''''''''''''''''''''''''''''''''''' ...

  2. spark集成hbase与hive数据转换与代码练习

    帮一个朋友写个样例,顺便练手啦~一直在做平台的各种事,但是代码后续还要精进啊... import java.util.Date import org.apache.hadoop.hbase.HBase ...

  3. 用最简单的例子实现jQuery图片即时上传

    [http://www.cnblogs.com/Zjmainstay/archive/2012/08/09/jQuery_upload_image.html] 最近看了一些jQuery即时上传的插件, ...

  4. mybatis自动生成mapper,dao映射文件

    利用Mybatis-Generator来帮我们自动生成mapper.xml文件,dao文件,model文件. 1.所需文件 关于Mybatis-Generator的下载可以到这个地址:https:// ...

  5. Python自动化--语言基础5--面向对象、迭代器、range和切片的区分

    面向对象 一.面向对象代码示例: 1 class Test(): #类的定义 2 car = "buick" #类变量,定义在类里方法外,可被对象直接调用,具有全局效果 3 def ...

  6. Python常用数据结构之heapq模块

    Python数据结构常用模块:collections.heapq.operator.itertools heapq 堆是一种特殊的树形结构,通常我们所说的堆的数据结构指的是完全二叉树,并且根节点的值小 ...

  7. 对于文件File类型中的目录分隔符

    当我们在使用File f=new File(path); 对于这个path来说是一个很痛苦的事情,在不同的系统上面的分隔符号是不一样的 在windows下面的话是一个"\"而在un ...

  8. 机器学习之Adaboost (自适应增强)算法

    注:本篇博文是根据其他优秀博文编写的,我只是对其改变了知识的排序,另外代码是<机器学习实战>中的.转载请标明出处及参考资料. 1 Adaboost 算法实现过程 1.1 什么是 Adabo ...

  9. HDU - 1241 dfs or bfs [kuangbin带你飞]专题一

    8个方向求联通块,经典问题. AC代码 #include<cstdio> #include<cstring> #include<algorithm> #includ ...

  10. Fantasia (Tarjan+树形DP)

    Time Limit: 1000 ms   Memory Limit: 256 MB Description 给定一张N个点.M条边的无向图 $G$ .每个点有个权值Wi. 我们定义 $G_i$ 为图 ...