matlab 飞机大战小游戏
MATLAB 小游戏 大战 飞机
2023-09-11 14:20:29 时间
matlab 飞机小游戏
需要把m文件和下面两张图放在同一文件夹
图一
图二
游戏截图
代码部分
function plane
planeown=imread('plane4.jpg');
plane_op=imread('plane1.jpg');
background=uint8(zeros(540,370,3));
change=uint8(zeros(50,50,3));
image=background;image(461:560,151:220,:)=planeown;
x=[510,185];bullet=[1000,200];direction=[0,-50];redline=[1,461;370,461];
set(gcf,'WindowButtonMotionFcn',@move)
set(gcf,'WindowButtonDownFcn',@kickfcn)
set(gcf,'tag','co','CloseRequestFcn',@clo)
set(gcf, 'KeyPressFcn', @key)
function key(~,event)
switch event.Key
case 'uparrow'
if level~=4
level=level+1;
end
case 'downarrow'
if level~=1
level=level-1;
end
end
end
function clo(~,~)
control=0;
delete(findobj('tag','co'))
clf
close
end
function movebullet(~,~)
planeop=[25,randi(345)+25];
while control==1
image(planeop(1)-25+1:planeop(1)+25,planeop(2)-25+1:planeop(2)+25,:)=plane_op;
bullet(bullet(:,2)<50,:)=[];
len=length(sum(bullet,2));
bullet=bullet+[0,0;ones(len-1,1)*direction];
show()
image(planeop(1)-25+1:planeop(1)+25,planeop(2)-25+1:planeop(2)+25,:)=change;
planeop=planeop+[10,0];part1=bullet(:,2); part2=bullet(:,1);
a=find((part1<planeop(1)+25)&(part1>planeop(1)-25));
b=find((part2<planeop(2)+25)&(part2>planeop(2)-25));
c=intersect(a,b);
if ~isempty(c)
planeop=[25,randi(345)+25];
bullet(c,:)=[];
end
pause(0.05)
if planeop(1)>435
control=0;
buttonName1=questdlg('You lose. What do you mean to do?','You lose','close','restart','close');
if isempty(buttonName1)
buttonName1='end';
end
if strcmp(buttonName1,'restart')
clf; plane();
else if strcmp(buttonName1,'close')
close all;
end
end
end
end
end
function show(~,~)
imshow(image)
hold on
scatter(gca,bullet(:,1),bullet(:,2),30,[0.75,0.75,0.75],'s','filled')
scatter(gca,bullet(:,1),bullet(:,2)-5,12,[0.75,0.75,0.75],'^','filled')
plot(redline(:,1),redline(:,2),'color',[0.3,0,0],'Linewidth',1.5)
end
function move(~,~)
xy=get(gca,'CurrentPoint');
x=xy(1);
x=round(x);
if x<335&&x>35
image=background;
image(461:560,x-35+1:x+35,:)=planeown;
end
end
function kickfcn(~,~)
if strcmp(get(gcf,'SelectionType'),'alt')
if control==1
control=-1;
end
control=control+1;
if control==1
movebullet()
end
end
if level==1
bullet=[bullet;x,500];
end
if level==2
bullet=[bullet;x-25,550;x+25,550];
end
if level==3
bullet=[bullet;x-25,550;x+25,550;x,500;x-10,520;x+10,520];
end
if level==4
bullet=[bullet;x-25,550;x+25,550;x,500;x-10,515;x+10,515;x-20,530;x+20,530];
end
end
level=1;
control=1;
movebullet()
end
————————————————————————
谁能想到这款小游戏竟然有了贴图版(第二版)
↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
第二版链接:matlab飞机大战小游戏(第二版)
相关文章
- MATLAB学习笔记 皮尔逊相关系数和模板匹配
- 【STM32F407的DSP教程】第2章 Matlab R2018a的安装
- 内点法求最优潮流和微电网调度(风、光、蓄电池、燃油机)(Matlab实现)
- 基于Dijkstra和A*算法的机器人路径规划(Matlab代码实现)
- 基于遗传算法的BP神经网络在汇率预测中的应用研究(Matlab代码实现)
- 使用星凸随机超曲面模型对扩展对象和分组目标进行形状跟踪(Matlab代码实现)
- 【分布式能源的选址与定容】基于非支配排序多目标遗传优化算法求解分布式能源的选址与定容(Matlab代码实现)
- 【水光互补优化调度】基于非支配排序遗传算法的多目标水光互补优化调度(Matlab代码实现)
- 含光热电站、有机有机朗肯循环、P2G的综合能源优化调度(Matlab代码实现)
- 高光谱解混和图片去噪(Matlab代码实现)
- m基于matlab的短波宽带通信系统的信道建模,对比了Watterson信道和ITS信道
- m基于ID3决策树算法的能量管理系统matlab仿真
- MATLAB | 特殊绘图小合集(一) | 渐变面积图、环形树状图、不规则等高线填充图
- 【MATLAB】matlab 文档使用 ( 文档查询 | 文档层次 | 自带搜索工具 | 帮助命令 | 学习导引 )
- Matlab使用笔记(九):matlab实现交通流仿真/车感知/城市交通交叉路口
- 基于平均不同分辨率的共振峰跟踪算法matlab仿真
- Matlab Tips: 结构体递归式打印--Dump matlab struct content recursively
- Matlab使用笔记(九):matlab实现交通流仿真/车感知/城市交通交叉路口