Skip to content

Commit

Permalink
可正常运行,不出意外应该是最后一个版本
Browse files Browse the repository at this point in the history
  • Loading branch information
ShellBin committed Jul 2, 2018
1 parent 09fa6c9 commit cabbc0a
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 49 deletions.
6 changes: 3 additions & 3 deletions src/main/MyCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class MyCanvas extends Canvas implements Runnable{
MyCanvas() {
keyinput = new KeyInput();
addKeyListener(keyinput);
// setFocusable(true); //获得焦点可以操作
setFocusable(true); //获得焦点可以操作
random = new Random(); //随机数对象
title = new Title();
score = new Score();
Expand Down Expand Up @@ -74,7 +74,7 @@ public void run() {
for(counter = 0; ; counter++) {
shotkey_state = keyinput.checkShotKey();

gBuf.setColor(Color.white);
gBuf.setColor(Color.black); //背景色设置
gBuf.fillRect(0, 0, 500, 500);

switch (scene) {
Expand All @@ -93,7 +93,7 @@ public void run() {
repaint(); //重绘

try {
Thread.sleep(15); //通过延时调整游戏速度
Thread.sleep(17); //通过延时调整游戏速度
}
catch(InterruptedException e)
{}
Expand Down
32 changes: 14 additions & 18 deletions src/main/ObjectPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,30 @@
*玩家,子弹,敌人等对象状态管理
*碰撞检测
*/
public class ObjectPool {
public class ObjectPool {
boolean GodMode = false; //无敌模式(调试用)

static EnemyBullet[] EnemyBullet; //提前生成保存敌弹队列
static Enemy[] enemy; //提前生成保存敌机队列
static PlayerBullet[] PlayerBullet; //预生成玩家弹列
static Particle[] particle; //预生成爆炸效果
Player player; //玩家实例化

//TP
//碰撞盒大小范围
static final int DIST_PLAYER_TO_EnemyBullet = 8;
static final int DIST_PLAYER_TO_ENEMY = 16;
static final int DIST_ENEMY_TO_PlayerBullet = 16;

//最大数量设定
//单位最大数量设定
static final int EnemyBullet_MAX = 100;
static final int ENEMY_MAX = 50;
static final int PARTICLE_MAX = 100;
static final int PARTICLE_MAX = 400;
static final int PlayerBullet_MAX = 10;


ObjectPool() {
//初始化玩家
player = new Player(250, 400, 5); //位置及速度
player = new Player(250, 400, 4); //位置及速度
player.active = true;

//数量限制
Expand Down Expand Up @@ -167,19 +169,15 @@ public double getDistance(GameObject ga, GameObject gb) {


public void getColision() { //碰撞检测
//子弹与玩家的碰撞
for (int i = 0; i < EnemyBullet.length; i++) {
if ((EnemyBullet[i].active)&&(player.active)) {
//中弹判断
//敌人子弹与玩家的碰撞
for (int i = 0; i < EnemyBullet.length && GodMode == false; i++) {
if ((EnemyBullet[i].active)&&(player.active)) { //中弹判断
if (getDistance(player, EnemyBullet[i]) < DIST_PLAYER_TO_EnemyBullet) {
//玩家消失
player.active = false;
//产生爆炸
for (int j = 0; j < 360; j += 20) {
player.active = false; //玩家消失
for (int j = 0; j < 360; j += 20) { //产生爆炸
newParticle(player.x, player.y, j, 2);
}
//弾消滅
EnemyBullet[i].active = false;
EnemyBullet[i].active = false; //子弹消失
}
}
}
Expand All @@ -203,7 +201,7 @@ public void getColision() { //碰撞检测
}

//敌人和玩家的碰撞检测
for (int i = 0; i < enemy.length; i++) {
for (int i = 0; i < enemy.length && GodMode == false; i++) {
if ((enemy[i].active)&&(player.active)) {
//碰撞判断
if (getDistance(player, enemy[i]) < DIST_PLAYER_TO_ENEMY) {
Expand All @@ -213,7 +211,6 @@ public void getColision() { //碰撞检测
for (int j = 0; j < 360; j += 20) {
newParticle(player.x, player.y, j, 2);
}
//敌方GG
}
}
}
Expand All @@ -222,7 +219,6 @@ public void getColision() { //碰撞检测

/**
* 返回游戏结果
* 返回:游戏结束为真
*/
public boolean isGameover() {
return !player.active;
Expand Down
4 changes: 2 additions & 2 deletions src/model/Enemy.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ public void draw(Graphics g) { //循环一次绘制一次
} else {
switch (type) {
case 0:
g.setColor(Color.black);
g.setColor(Color.white);
break;
case 1:
g.setColor(Color.blue);
g.setColor(Color.white);
break;
default:
}
Expand Down
2 changes: 1 addition & 1 deletion src/model/EnemyBullet.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void move() {
}

public void draw(Graphics g) {
g.setColor(Color.blue);
g.setColor(Color.red);
g.drawRect((int)(x-3), (int)(y-3), (int)6, (int)6);
}

Expand Down
2 changes: 1 addition & 1 deletion src/model/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static int getLevel(){
}

public static void addLevel() { //关卡增加方法,最高10关
if (level < 10) {
if (level < 8) {
level++;
}
System.out.println("level:"+level); //debug用
Expand Down
2 changes: 1 addition & 1 deletion src/model/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void move(int mx, int my) {

public void draw(Graphics g) { //循环一次绘制一次
if (active){
g.setColor(Color.red);
g.setColor(Color.green);
//绘制玩家三角形
g.drawLine((int)(x), (int)(y-14), (int)(x-10), (int)(y+7));
g.drawLine((int)(x), (int)(y-14), (int)(x+10), (int)(y+7));
Expand Down
4 changes: 2 additions & 2 deletions src/model/PlayerBullet.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void move() { //玩家子弹的移动
}

public void draw(Graphics g) { //循环一次执行一次
g.setColor(Color.gray);
g.setColor(Color.blue);
//绘制长方形
g.drawRect((int)x-3, (int)y-10, (int)6, (int)20);
}
Expand All @@ -28,6 +28,6 @@ public void draw(Graphics g) { //循环一次执行一次
public void activate(double ix, double iy) {
x = ix;
y = iy;
active = true; //启用子弹
active = true; //可视化子弹
}
}
28 changes: 9 additions & 19 deletions src/model/Score.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package model;

import java.awt.*;
import java.io.*;

//得分的控制和显示
public class Score {
Expand All @@ -12,26 +11,23 @@ public class Score {
public Score() {
scoreFont = new Font("SimHei", Font.BOLD, 15); //黑体
myscore = 0;
}

}

public void drawScore(Graphics g) { //得分的显示
g.setColor(Color.black);
g.setColor(Color.white);
g.setFont(scoreFont);
g.drawString("得分:"+myscore, 10, 30);
}

public void drawHiScore(Graphics g) { //最高分显示
g.setColor(Color.black);
g.setColor(Color.white);
g.setFont(scoreFont);
g.drawString("最高分:"+hiscore, 350, 30);
}

}

public static void addScore(int gain) { //计分添加
myscore += gain;
}

}

public static void compareScore() { //最高分更新处理
if (myscore > hiscore) {
Expand All @@ -42,23 +38,17 @@ public static void compareScore() { //最高分更新处理


/**
* 得分保存为 data.dat
* 暂时停用的特性
* 得分保存为 data.dat(未实现)
*/
static void saveScore() {
// DataOutputStream dout = new DataOutputStream(new FileOutputStream("data.dat"));
// dout.writeInt(hiscore);
// dout.close();

}

/**
* 从data.dat读取分数
* 暂时停用的特性
* 从data.dat读取分数(未实现)
*/
public static void loadScore() {
// DataInputStream din = new DataInputStream(new FileInputStream("data.dat"));
// hiscore = din.readInt();
// din.close();

}


Expand Down
4 changes: 2 additions & 2 deletions src/model/Title.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public Title() { //为标题实例化字体类


public void drawTitle(Graphics g) { //游戏开始界面
g.setColor(Color.black);
g.setColor(Color.white);
count++;
g.setFont(titleFont);
g.drawString("SimpleNative Danmaku",130,150);
Expand All @@ -26,7 +26,7 @@ public void drawTitle(Graphics g) { //游戏开始界面


public void drawGameover(Graphics g) { //游戏结束界面
g.setColor(Color.black);
g.setColor(Color.white);
count++;
g.setFont(titleFont);
g.drawString("GAMEOVER",200,150);
Expand Down

0 comments on commit cabbc0a

Please sign in to comment.