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配置SpringMVC

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

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

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

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

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

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

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

  7. 基于纯Java代码的Spring容器和Web容器零配置的思考和实现(3) - 使用配置

    经过<基于纯Java代码的Spring容器和Web容器零配置的思考和实现(1) - 数据源与事务管理>和<基于纯Java代码的Spring容器和Web容器零配置的思考和实现(2) - ...

  8. Android 使用纯Java代码布局

    java布局 java代码布局和xml布局的区别 1.Java纯布局更加的灵活,比如自定义控件或一些特殊要求时,使用java代码布局 2.常用的xml布局是所见即所得的编写方式,以及xml本身拥有一些 ...

  9. simpleImageTool又纯java图片水印、缩放工具

    simpleImageTool又一个简单.好用的图片格式转换.缩放水印叠加等功能的纯Java图片工具库. simpleImageTool的由来,近期需要用到图片处理,通过网上的图片流直接进行缩放水印叠 ...

随机推荐

  1. Javascript 接口模拟

    Javascript接口模拟可以通过三种方式实现文档手段(注释).辅助类和鸭式辨. 第一种和第二种只形式上体现没有真正的实现. 鸭式辨实现原理是:"只要能像鸭子一样叫和走就是鸭子" ...

  2. jdbc框架 commons-dbutils+google guice+servlet 实现一个例子

    最近闲着无聊,于是看了一下jdbc框架 commons-dbutils与注入google guice. 我就简单的封装了一下代码,效率还是可以的.... jdbc+google guice+servl ...

  3. C语言多线程编程

    HANDLE CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes, DWORD dwStackSize, LPTHREAD_START_ROUT ...

  4. 20140704笔试面试总结(java)

    1.java数组定义 1.与其他高级语言不同,Java在数组声明时并不为数组分配存储空间,因此,在声明的[]中不能指出数组的长度 2.为数组分配空间的两种方法:数组初始化和使用new运算符 3.未分配 ...

  5. python的位置参数、默认参数、关键字参数、可变参数区别

    一.位置参数 调用函数时根据函数定义的参数位置来传递参数. #!/usr/bin/env python # coding=utf-8 def print_hello(name, sex): sex_d ...

  6. [转]OpenBLAS项目与矩阵乘法优化

    课程内容 OpenBLAS项目介绍 矩阵乘法优化算法 一步步调优实现 以下为公开课完整视频,共64分钟: 以下为公开课内容的文字及 PPT 整理. 雷锋网的朋友们大家好,我是张先轶,今天主要介绍一下我 ...

  7. vsftp

    [安装vsftpd]安装vsftpd工具步骤   1 安装vsftpd组件 [root@bogon ~]# yum -y install vsftpd 安装完后,有/etc/vsftpd/vsftpd ...

  8. 20155228 2017-5-10 课堂测试:MySort

    20155228 2017-5-10 课堂测试:MySort 题目和要求 模拟实现Linux下Sort-t:-k2的功能.参考Sort的实现.提交码云链接和代码运行截图. import java.ut ...

  9. vue中去掉url地址栏中的#符号

    要去掉vue中访问地址中的#符号可以在路由器中设置路由模式为history: export default new Router({ mode:'history', routes: [ { path: ...

  10. pixi.js 微信小游戏 入手

    pixi是什么?一款h5游戏引擎 优点:简单简洁性能第一 缺点:大多数用的国产三大引擎,pixi资料少,工具少, 为什么学,装逼 用pixi开发小游戏行吗? 行.但要简单处理下 下载官网上的 weap ...