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. nginx隐藏版本号

    在实际运用nginx中我们最好将我们的版本号直接隐藏,因为有些版本号的nginx被爆出了漏洞,所以我们为了安全起见,最好将我们的版本号隐藏. 1.对于未安装的nginx我们使用源码编译安装才可以将版本 ...

  2. 怎样在VS2010-2017中使用LightningChart绘图控件?

    为了方便开发人员能更快速的使用开发工具,下面给大家提供LightningChart® Ultimate SDK v.8 使用手册: 1.   安装软件 -          运行 setup.exe ...

  3. Bruce Eckel的资源

    1 GitHub的技术博客 2 On Java 8 – Bruce Eckel 3 artima_weblogs - Bruce Eckel 4 back issues 5 eckel-oo-prog ...

  4. 洛谷P1345 [USACO5.4]奶牛的电信Telecowmunication【最小割】分析+题解代码

    洛谷P1345 [USACO5.4]奶牛的电信Telecowmunication[最小割]分析+题解代码 题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流. ...

  5. Java上传Excel并解析

    1.上传: public String uploadFile(CommonsMultipartFile file,String uploadPath,String realUploadPath){ I ...

  6. 在jdbc中使用properites文件进行使用

    首先先在源代码中创建一个properites文件 db_url=jdbc\:mysql\://localhost\:3306/db_friend db_user=root db_password= d ...

  7. 基于数据形式说明杜兰特的技术特点的分析(含Python实现讲解部分)

    ---恢复内容开始--- 注: 本博文系原创,转载请标明原处. 题外话:春节过后,回到学校无所事事,感觉整个人都生锈一般,没什么动力,姑且称为"春节后遗症".在科赛官网得到关于NB ...

  8. .NET Core阿里大于短信发送SDK修改以及使用

    一.问题背景 继上次七牛云SDK的问题之后(参考:http://www.cnblogs.com/OMango/p/8447480.html),在发送短信的功能上又出现了问题,我们短信服务使用的是阿里大 ...

  9. java2 - 语言基础

    一.结构流程图制作工具 xmind 的使用 二.Java 基础数据类型 回答以下问题: java 基本数据类型有几种? 整数类型是哪几种? 浮点数类型是哪几种? 字符类型关键字? 布尔类型关键字? 为 ...

  10. ELF哈希技术

    ELFhash详情见点击打开链接 代码如下: unsigned int ELFhash(char *str) { unsigned int hash=0; unsigned int x=0; whil ...