MATLAB|【MATLAB小游戏】养鱼


【MATLAB小游戏】养鱼

  • 代码
  • 其他

by 今天不飞了
【MATLAB|【MATLAB小游戏】养鱼】疫情在家闲着无聊写的,游戏本身没有可玩性,仅为给大家分享思路。
MATLAB可以设计一些低性能的游戏。
MATLAB|【MATLAB小游戏】养鱼
文章图片

视频链接《因为疫情被封控十天后,开始用MATLAB养鱼玩儿》
代码
function simple_fish(n) close all; clc global flag % 界面 flag = 0; figure('position',[0 30 1600 840],'color','w','WindowButtonMotionFcn',@currentPt,'menubar','none'); set(gcf,'WindowButtonDownFcn',@ButtonDownFcn); set(gcf,'KeyPressFcn',@KeyPressFcn); IpSld = uicontrol('style','slider','Units','normalized',... 'position',[180 992.5 300 20]/1080,'min',0.01,'max',10,'Value',1.5,'Visible',0); InSld = uicontrol('style','slider','Units','normalized',... 'position',[610 992.5 300 20]/1080,'min',0,'max',5,'Value',4.1,'Visible',0); folf = uicontrol('style','togglebutton','Units','normalized',... 'position',[.85 .85 .09 .025],'min',0,'max',1,'Value',1,'String','Follow Fish','Visible',0); bait = uicontrol('style','togglebutton','Units','normalized','callback',@danger,... 'position',[.85 .8 .09 .025],'min',0,'max',1,'Value',0,'String','Put Bait','Visible',0); goal = uicontrol('style','togglebutton','Units','normalized','callback',@food,... 'position',[.85 .4 .09 .025],'min',0,'max',1,'Value',0,'String','Shark Goal','Visible',0); tax = axes('position',[.05 .05 .9 .85],'visible','off'); hold all; axis(tax,[-10 10 -10 10]*2); ax = axes('position',[.05 .05 .9 .85],'xcolor','none','ycolor','none'); hold all; axis(ax,[-10 10 -10 10]*2); grid on; box off; colormap(ax,'hot'); caxis(ax,[.5 2]); %% 参数 total_time = 1e6; dt = 5e-2; % 数量 if nargin<1 || isempty(n) n = 50; end If = 1e-2; attrS = 1; alpha = rand(n,1)*2*pi; % 初始方向 r = 10*randn(n,2); % 初始位置 state = [r alpha]; % 状态 fishL = .6; fishH = .1; % 形状 xfish = [-.5, -.25,0, .1, .125, .1, 0,-.25]'*1; yfish = [0, .075, .1, .05, 0, -.05, -.1, -.075]'/2*1; % 可视化 pth = patch(xfish + zeros(1,n), yfish + zeros(1,n),zeros(n,1),'edgecolor','none'); baitx = []; baity = []; baith = plot(0,0,'k+','markersize',18,'linewidth',2,'visible','off'); goalx = []; goaly = []; goalh = plot(0,0,'bo','markersize',18,'linewidth',2,'visible','off'); cp = []; replD = fishL*4; replS = 200; %% 开始养鱼 t = -dt; tmax = 100; while t

其他 大概没有什么bug

    推荐阅读