package com.alphaae.gl.fighting;
import com.alphaae.gl.fighting.model.*;
import com.jogamp.opengl.GL2;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.Console;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
public class GameScene {
private GL2 gl;
private AircraftPlayer player;
private Boss boss;
private Background background;
private List<Ammunition> ammunitionList = new ArrayList<>();
private List<AircraftEnemy> aircraftEnemies = new ArrayList<>();
int time = 0;
boolean randerAircraftEnemyNO = true;
boolean bossNO = false;
private int score = 0;
public GameScene(GL2 gl) {
this.gl = gl;
background = new Background(gl);
player = new AircraftPlayer(gl);
//测试用
// if (boss == null) boss = new Boss(gl);
}
//主渲染进程
public void rander() {
time++;
background.rander();
player.rander();
if (boss != null) boss.rander();
randerAircraftEnemy();
randerAmmunition();
collision();
}
//子弹间隔计时变量
private int ammunitionSpace = 0;
private void randerAmmunition() {
ammunitionSpace++;
if (ammunitionSpace > 10) {
ammunitionSpace = 0;
ammunitionList.add(new Ammunition(gl, player.getPosition()));
}
for (Ammunition amm : ammunitionList) {
amm.rander();
}
}
private void randerAircraftEnemy() {
if (randerAircraftEnemyNO) {
if (time % 20 == 0) {
float randPosX = new Random().nextFloat() * 1600;
aircraftEnemies.add(new AircraftEnemy(gl, new float[]{randPosX, 1600}));
}
}
for (AircraftEnemy temp : aircraftEnemies) {
temp.rander();
}
}
private void collision() {
Iterator<AircraftEnemy> aircraftEnemyIterator = aircraftEnemies.iterator();
Iterator<Ammunition> ammunitionIterator = ammunitionList.iterator();
//遍历判断碰撞 适当减小碰撞体积以达到理想效果
for (int i = 0; i < aircraftEnemies.size(); i++) {
for (int j = 0; j < ammunitionList.size(); j++) {
if (Utils.isIntersect(aircraftEnemies.get(i).getPosition(),
aircraftEnemies.get(i).getCollisionBox(),
ammunitionList.get(j).getPosition(),
1)) {
//判断死亡则移除
if (aircraftEnemies.get(i).beAttacked()) {
score++;
System.out.println("score:" + score);
//boss!!!!!!!!
if (score > 5) {
randerAircraftEnemyNO = false;
bossNO = true;
if (boss == null) boss = new Boss(gl);
}
}
ammunitionList.remove(j);
break;
}
}
}
}
public KeyListener getKeyListener() {
return new TheKey();
}
class TheKey implements KeyListener {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_W:
player.controlUpPressed();
break;
case KeyEvent.VK_S:
player.controlDownPressed();
break;
case KeyEvent.VK_A:
player.controlLeftPressed();
break;
case KeyEvent.VK_D:
player.controlRigthPressed();
break;
}
}
@Override
public void keyReleased(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_W:
player.controlUpReleased();
break;
case KeyEvent.VK_S:
player.controlDownReleased();
break;
case KeyEvent.VK_A:
player.controlLeftReleased();
break;
case KeyEvent.VK_D:
player.controlRigthReleased();
break;
}
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Java JOGL Demo 雷电游戏.zip
共39个文件
gif:12个
png:8个
java:8个
需积分: 5 0 下载量 129 浏览量
2023-10-11
18:38:14
上传
评论
收藏 3.72MB ZIP 举报
温馨提示
Java JOGL Demo 雷电游戏.zipJava JOGL Demo 雷电游戏.zip Java JOGL Demo 雷电游戏.zipJava JOGL Demo 雷电游戏.zip Java JOGL Demo 雷电游戏.zipJava JOGL Demo 雷电游戏.zip Java JOGL Demo 雷电游戏.zipJava JOGL Demo 雷电游戏.zip Java JOGL Demo 雷电游戏.zipJava JOGL Demo 雷电游戏.zip Java JOGL Demo 雷电游戏.zipJava JOGL Demo 雷电游戏.zip Java JOGL Demo 雷电游戏.zipJava JOGL Demo 雷电游戏.zip Java JOGL Demo 雷电游戏.zipJava JOGL Demo 雷电游戏.zip Java JOGL Demo 雷电游戏.zipJava JOGL Demo 雷电游戏.zip Java JOGL Demo 雷电游戏.zipJava JOGL Demo 雷电游戏.zip
资源推荐
资源详情
资源评论
收起资源包目录
Java JOGL Demo 雷电游戏.zip (39个子文件)
project_code_0628
lib
jogl-all.jar 3.26MB
gluegen-rt-natives-windows-amd64.jar 8KB
jogl-all-natives-windows-amd64.jar 235KB
gluegen-rt.jar 338KB
image
bomb
bomb4.gif 1KB
bomb11.gif 919B
bomb3.gif 1KB
bomb1.gif 961B
bomb12.gif 871B
bomb8.gif 1KB
bomb7.gif 1KB
bomb10.gif 1004B
bomb6.gif 1KB
bomb2.gif 1KB
bomb5.gif 1KB
bomb9.gif 1KB
player_right.png 16KB
player_left.png 16KB
player.png 16KB
ammunition.png 18KB
background.png 63KB
ammunition_boss.png 3KB
enemy.png 16KB
boss.png 37KB
src
com
alphaae
gl
fighting
Utils.java 2KB
GameScene.java 4KB
FightingDemo.java 3KB
model
AircraftPlayer.java 3KB
Background.java 1KB
AircraftEnemy.java 3KB
Ammunition.java 1KB
Boss.java 2KB
.idea
libraries
lib.xml 257B
vcs.xml 167B
misc.xml 273B
modules.xml 264B
.gitignore 38B
FightingDemo.iml 484B
.gitignore 29B
共 39 条
- 1
资源评论
辣椒种子
- 粉丝: 4139
- 资源: 5745
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功