package ninjarush.mainsurfaceview;
import java.text.AttributedCharacterIterator.Attribute;
import java.util.Vector;
import ninarush.enemy.Enemy;
import ninjarush.bulletclass.Bullet;
import ninjarush.dead.Dead;
import ninjarush.mainactivity.R;
import ninjarush.mainactivity.UserAchieve;
import ninjarush.music.GameMusic;
import ninjarush.relatedclass.Boss;
import ninjarush.relatedclass.GameMap;
import ninjarush.relatedclass.Game_Menu;
import ninjarush.relatedclass.Game_Over;
import ninjarush.relatedclass.Gameing_Bg;
import ninjarush.relatedclass.Loading;
import ninjarush.relatedclass.MyButton;
import ninjarush.relatedclass.Pause;
import ninjarush.relatedclass.Player;
import ninjarush.relatedclass.Tools;
import ninjarushh.food.Food;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.media.SoundPool;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class NinjaRushSurfaceView extends SurfaceView implements Runnable,
SurfaceHolder.Callback {
private Context context;
private SurfaceHolder holder;
private Canvas canvas;
private Paint paint;
private BitmapFactory.Options ops;
// 是否为第一次加载
private boolean isFirstLoadLoading;
private boolean isFirstLoadImage;
public static boolean flag;// 线程标记
public static int status;// 游戏界面的状态
public static int screenW, screenH;// 屏幕的宽和高
public static boolean isreset;// 是否重置
// 定义背景对象
private Gameing_Bg gameing_bg;
private Game_Over gameover;
// 定义Boss图片
public static Vector<Bitmap> vcboss;
private Bitmap bossBitmap;
// 定义Boss
private ninjarush.relatedclass.Boss boss;
//记录boss的死亡次数
private int bossDeadCount;
// 定义按钮对象
private MyButton mybutton;
// 游戏中背景三张图,以及暂停,和发飚按钮
private Bitmap bmpbg1, bmpbg2, bmpbg3, bmpbulletbnt, bmppause;
// 初始化游戏结束(失败)背景图片
private Bitmap bmpbg;
// Loading界面
private Bitmap bmploading_bg;
private Loading loading;
private Bitmap bmpover_quit_up, bmpover_quit_down, bmpover_try_up,
bmpover_try_down, bmpover_submit_up, bmpover_submit_down,
bmpover_achi_up, bmpover_achi_down;// 图片
// 白云
private Bitmap bmpcloud_0, bmpcloud_1, bmpcloud_2, bmpcloud_3;
// ---------------------- GameMenu
private Bitmap bmpinitbg;// GameMenu 背景图片
private Bitmap bmpmore1;// GameMenu “更多”未按下图片
private Bitmap bmpmore2;// GameMenu “更多”按下背景图片
private Bitmap bmpplay_up;// GameMenu 开始未按下图片
private Bitmap bmpplay_down;// GameMenu 开始按下图片
private Bitmap bmpachi_up;// GameMenu 成就未按下图片
private Bitmap bmpachi_down;// GameMenu 成就按下图片
private Bitmap bmpopen_up;// GameMenu GameBox未按下图片
private Bitmap bmpopen_down;// GameMenu GameBox按下背景图片
private Game_Menu gameMenu;// GameMenu 对象
// ---------------------------Pause
private Bitmap blackground;// Pause 背景图片
private Bitmap voice; // Pause 静音图片
private Bitmap resume;// Pause 继续图片
private Bitmap quit;// Pause 退出图片
private Pause pause;// Pause 对象
// ///////////////////////
// 计数器
private int count;
private Vector<GameMap> vcMap;
private GameMap gameMap;
// 桥
private Bitmap bam_left, bam_mid, bam_right, bam_under;
private Bitmap fly_bam_right, fly_bam_mid, fly_bam_left, dre4;
// 旗杆 刀
private Bitmap dao, light;
// 桥类型
private int style;
// 忍者的相关参数----------------------------------------------------------------------------------------------------
private Bitmap blood, changeToDart, dartMan, hurtBlood, changeff, dartShow,
bulletMan, rope, ropef, protectDart, leaf, ropeMan;
private Player player;
// 忍者的相关参数-----------------------------------------------------------------------------------------------------
// 333333333-----------------------------------------
// 子弹
private Bullet bullet;
private Vector<Bullet> vetorBullet;
private Vector<Bullet> vetorBulletBoss;
private Bitmap bmpBulletPlayer, bmpBulletBoss;
private int playerBulletCount, BossBulletCount;
private boolean bulletFire;
private Rect rect;
private int BulletKillCount = 0;
// 乌鸦
private Bitmap bmpCrow;
private Bitmap bmpCrowFeather;
private Bitmap bmpHurtBlood;
private Vector<Enemy> veEnemy;
private Vector<Dead> veDead;
private Bitmap bmpAntDead;
private Bitmap bmpAnt;
// 食物
private Bitmap bmpFoodHeart, bmpFoodBullet;
private Vector<Food> vcFood;
private int countMusic = 0;// 音乐计数器
// /////////////////////////
public NinjaRushSurfaceView(Context context, AttributeSet attribute) {
super(context, attribute);
this.context = context;
holder = getHolder();
holder.addCallback(this);
paint = new Paint();
paint.setColor(Color.WHITE);
isFirstLoadLoading = true;
isFirstLoadImage = true;
// 用来完成对图片空间的控制
ops = new BitmapFactory.Options();
status = Tools.GAME_MENU;// 初始化游戏界面的状态
flag = true;// 初始化线程标记
this.setFocusable(true);
this.setFocusableInTouchMode(true);
}
public void myDraw() {
try {
canvas = holder.lockCanvas();
if (canvas != null) {
switch (status) {
// 绘制loading界面
case Tools.GAME_LOADING:
loading.draw(canvas, paint);
break;
// 绘制 GAME_MENU 界面
case Tools.GAME_MENU:
gameMenu.draw(canvas, paint);
break;
// 绘制GAME_PLAYING 界面
case Tools.GAME_PLAYING:
gameing_bg.draw(canvas, paint);
for (int i = 0; i < veEnemy.size(); i++) {
veEnemy.elementAt(i).onDraw(canvas, paint);
}
mapDraw();
mybutton.draw(canvas, paint);
player.draw(canvas, paint);
// 子弹
for (int i = 0; i < vetorBullet.size(); i++) {
vetorBullet.elementAt(i).onDraw(canvas, paint);
}
// 死亡效果
for (int i = 0; i < veDead.size(); i++) {
veDead.elementAt(i).onDraw(canvas, paint);
}
// 食物
for (int i = 0; i < vcFood.size(); i++) {
vcFood.elementAt(i).onDraw(canvas, paint);
}
// 绘制Boss
if (boss != null) {
if (boss.isDead() == false) {
boss.draw(canvas, paint);
}
}
// boss子弹
if (boss != null) {
for (int i = 0; i < vetorBulletBoss.size(); i++) {
vetorBulletBoss.elementAt(i).onDraw(canvas, paint);
}
}
break;
// 绘制GAME_OVER 界面
case Tools.GAME_OVER:
// 将最后的米数给gameover界面
Game_Over.latestmeter = gameing_bg.getMeter();
gameover.draw(canvas, paint);
break;
// 绘制 GAME_PAUSE 界面
case Tools.GAME_PAUSE:
gameing_bg.draw(canvas, paint);
mapDraw();
pause.draw(canvas, paint);
break;
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (canvas != null) {
holder.unlockCanvasAndPost(canvas);
}
}
}
public void logic() {
switch (status) {
// loading界面逻辑
case Tools.GAME_LOADING:
if (isFirstLoadLoading) {
initImage();
isFirstLoadLoading = false;
}
init();
status = Tools.GAME_PLAYING;
if (countMusic++ == 0) {
GameMusic.startMusic();// 播放 GAME_PLAYING 界面 背景音乐;
GameMusic.playSound(R.raw.land, 0);// 播放一次落地 音效
} else {
GameMusic.nextMusic(R.raw.bg);
GameMusic.playSound(R.raw.land, 0);// 播放一次落地 音效
}
break;
// GAME_MENU 界面 逻辑
case Tools.GAME_MENU:
gameMenu.logic();
break;
// GAME_PLAYING 界面逻辑
case Tools.GAME_PLAYING:
gameing_bg.logic();
// ///////////
for (int i = 0; i < vcMap.size(); i++
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Xumyninjarush.rar (66个子文件)
codefans.net
Android游戏源码——忍者快跑
Xumyninjarush
bin
res
drawable-ldpi
drawable-hdpi
drawable-mdpi
classes
ninjarush
mainactivity
music
mainsurfaceview
dead
relatedclass
bulletclass
ninjarushh
food
ninarush
dialog
enemy
res
drawable-ldpi
raw
land.ogg 17KB
boss_die.ogg 17KB
dead.ogg 24KB
woop.ogg 9KB
sword.ogg 14KB
eat.ogg 11KB
changing.ogg 29KB
enemy_die.ogg 13KB
changed.ogg 53KB
boss_hurt.ogg 14KB
run.ogg 77KB
shoot.ogg 14KB
bg.ogg 525KB
jump.ogg 10KB
crow_hurt.ogg 5KB
hurt.ogg 11KB
drawable-hdpi
values
strings.xml 114B
drawable-mdpi
over_try_down.png 34KB
more2.png 632KB
over_submit_up.png 29KB
over_quit_up.png 22KB
over_achi_down.png 28KB
pausebt.png 5KB
open_down.png 31KB
over_achi_up.png 29KB
over_try_up.png 35KB
ropeman.png 7KB
over_quit_down.png 21KB
over_submit_down.png 29KB
play_up.png 29KB
play_down.png 28KB
skip1.png 2KB
uncompleted.png 6KB
weapon.png 432B
open_up.png 32KB
layout
listview_item_gamescore.xml 691B
listview.xml 542B
achieve.xml 786B
developer_items.xml 802B
paihangdialog.xml 935B
main.xml 366B
developer.xml 743B
gamescorelistview.xml 779B
assets
gen
ninjarush
mainactivity
.settings
src
ninjarush
mainactivity
GameScoreActivity.java 5KB
MyninjarushActivity.java 746B
UserAchieve.java 4KB
DeveloperActivity.java 2KB
music
GameMusic.java 5KB
mainsurfaceview
NinjaRushSurfaceView.java 33KB
dead
Dead.java 6KB
relatedclass
Tools.java 3KB
Boss.java 2KB
GameMap.java 6KB
Game_Over.java 5KB
Game_Menu.java 6KB
Player.java 24KB
Gameing_Bg.java 7KB
InitBg.java 219B
MyButton.java 4KB
Loading.java 971B
Pause.java 7KB
bulletclass
Bullet.java 3KB
ninjarushh
food
Food.java 2KB
ninarush
dialog
UserScore.java 512B
MyDialog.java 2KB
enemy
Enemy.java 5KB
共 66 条
- 1
资源评论
- SportHappy2013-10-18游戏源码不能用,不知道是怎么回事?
- deibo2015-08-09比较有用的源码 自己仔细看了额很久才搞懂
lxllb8
- 粉丝: 66
- 资源: 577
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功