当前位置:网站首页>Small game cases of aircraft dodging bullets
Small game cases of aircraft dodging bullets
2022-07-22 09:25:00 【weixin_ fifty million one hundred and seventy-nine thousand nin】
Small game cases of aircraft dodging bullets
Today's online world , A variety of small games emerge in endlessly , But with the development of the game industry , Some small games fade out of the players' vision , Some small games are changed to other forms by programmers according to the preferences of current players , Continue to accompany the player . Although I pay less attention to these small games , But my childhood memories of playing games didn't fade out . About this case , I remember playing such a similar plane game when I was a child , Unlike what I wrote, there are no hostile planes in my game , Only bullets . The bullet will not disappear, but will bounce after touching the edge of the window , Players must operate the aircraft to move and avoid , Until I can't hide , The plane will be destroyed , The code will remember when you have to play , The survival time of ejecting the plane after you lose .
use JFrame Game window implementation , Put on the background picture 、 Picture of the plane , Regenerate shells
Sleep through threads 、 Redraw , Generate animation .
Operation of the aircraft
public void drawSelf(Graphics g) {
if(live) {
g.drawImage(img, (int)x, (int)y, null);
if(left) {
x -=speed;
}
if(right) {
x +=speed;
}
if(top) {
y -=speed;
}
if(down) {
y +=speed;
}
}else {
}
}
Modify coordinate values , When redrawing , The position of the aircraft will change .
The flight angle of the shell , And the return effect of the shell when it touches the end
double degree;
public shell() {
x = 200;
y = 200;
width = 10;
height =10;
speed = 3;
degree =Math.random()Math.PI2;
System.out.println(“ Round table rate ”+degree);
}
public void draw(Graphics g) {
// TODO Auto-generated method stub
Color c =g.getColor();
g.setColor(Color.YELLOW);
g.fillOval((int)x, (int)y, width, height);
x +=speed*Math.cos(degree);
y +=speed*Math.sin(degree);
if(x<0||x>Constant.GAME_WIDTH-width) {
degree = Math.PI-degree;
}
if(y<30||y>Constant.GAME_HIGHT-height) {
degree =-degree;
}
}
The shell touched the plane and made it explode
Intersects Will judge whether the range of two objects coincides , Return after coincidence true, Return to the position of the aircraft , Judgment for true after , Traverse the prepared pictures , Replace the picture of the aircraft in the position of the aircraft , Produce the effect of aircraft explosion .
The code is roughly like this , I'm not first-hand at the code .
边栏推荐
- CAN通信协议(一)
- Thread多线程
- SerializationException: Could not read JSON: Unrecognized token “xxx“
- 腾讯云免费升级。
- Is it safe for Huatai to scan the code to open an account? How to open a low commission account
- C语言之位操作和整形的补位
- 栈和队列常见oj题
- EasyCVR平台V2.5.0版本及以上如何配置WebRTC协议实现低延迟播放?
- 文献: Axure(简单介绍)
- Leetcode1734: arrangement after decoding XOR
猜你喜欢
随机推荐
conda 常用功能记录
OpenGL:freeglut ERROR: Function <glutCreateWindow> called without first calling ‘glutInit‘.
正则表达式的表示及基本应用
What's the use of regular ^ $
String str = new String(“abc“) 到底创建了几个变量?
c语言之数组
Seven ways to create thread pools
Advertisements inserted in solo articles are not displayed
MySQL学习之MVCC多版本并发控制
How to create threads
h5py快速入门指南
LeetCode342:4的幂
MongoDB的使用MongoTemplate操作增删改查,分页,排序,聚合(含内嵌数据),文件上传下载
快乐数~~~(其实我一点都不快乐) && 丑数
OpenGL drawing coordinate axis indicator
大批量数据excel下载—本文作者只试了51万数据的下载,用时7秒
获取 (对象数组 / 数组) 的(最小 / 最大值)
(一)抖音快手短视频去水印原理分析
odoo+测试
Luoyang comprehensive bonded zone was officially approved by the State Council to be established