final project
code:
- function varargout = game1v01(varargin)
- % GAME M-file for game.fig
- % GAME, by itself, creates a new GAME or raises the existing
- % singleton*.
- %
- % H = GAME returns the handle to a new GAME or the handle to
- % the existing singleton*.
- %
- % GAME('CALLBACK',hObject,eventData,handles,...) calls the local
- % function named CALLBACK in GAME.M with the given input arguments.
- %
- % GAME('Property','Value',...) creates a new GAME or raises the
- % existing singleton*. Starting from the left, property value pairs are
- % applied to the GUI before game_OpeningFcn gets called. An
- % unrecognized property name or invalid value makes property application
- % stop. All inputs are passed to game_OpeningFcn via varargin.
- %
- % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
- % instance to run (singleton)".
- %
- % See also: GUIDE, GUIDATA, GUIHANDLES
- % Edit the above text to modify the response to help game
- % Last Modified by GUIDE v2.5 08-Jun-2019 16:45:33
- % Begin initialization code - DO NOT EDIT
- gui_Singleton = 1;
- gui_State = struct('gui_Name', mfilename, ...
- 'gui_Singleton', gui_Singleton, ...
- 'gui_OpeningFcn', @game_OpeningFcn, ...
- 'gui_OutputFcn', @game_OutputFcn, ...
- 'gui_LayoutFcn', [] , ...
- 'gui_Callback', []);
- if nargin && ischar(varargin{1})
- gui_State.gui_Callback = str2func(varargin{1});
- end
- if nargout
- [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
- else
- gui_mainfcn(gui_State, varargin{:});
- end
- % End initialization code - DO NOT EDIT
- % --- Executes just before game is made visible.
- function game_OpeningFcn(hObject, eventdata, handles, varargin)
- % This function has no output args, see OutputFcn.
- % hObject handle to figure
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % varargin command line arguments to game (see VARARGIN)
- % Choose default command line output for game
- handles.output = hObject;
- % Update handles structure
- guidata(hObject, handles);
- % UIWAIT makes game wait for user response (see UIRESUME)
- % uiwait(handles.figure1);
- % --- Outputs from this function are returned to the command line.
- function varargout = game_OutputFcn(hObject, eventdata, handles)
- % varargout cell array for returning output args (see VARARGOUT);
- % hObject handle to figure
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- %==2019/0601
- global obj; %for mobile device used, for global used
- obj = mobiledev; %Matlab key in :connector on , mobile device run "Matlab mobile"
- obj.Logging = 1; %//Enable mobile device sensor tranimission start
- disp(obj);
- %==2019/0601
- % Get default command line output from handles structure
- varargout{1} = handles.output;
- global t;t=0.21;
- global POINTS;POINTS=0;
- set(handles.edit1,'String',['Scores : ',num2str(POINTS)]);
- SizeX=100;SizeY=100;
- %Loc=[50 49;50 50;50 51;50 52];
- Loc=[50 49;50 50;50 51;50 52;50 53;50 54;50 55;50 56;50 57;50 58;50 59;50 60;50 61;50 62;50 63;50 64;50 65;50 66;50 67;50 68];
- LocX=Loc(:,2);LocY=Loc(:,1);
- TargetX =45;TargetY =50; %0604 The first Target dot
- TargetX1=90;TargetY1=90; %0604 to enable second Target dot
- global Direction;Direction=1;
- % [1=left;2=up;3=right;4=down];
- % Generation of Target
- pause on;
- if ispc
- [y,fs]= audioread('BOTTLE.wav');
- end
- ScreenR=zeros(SizeX,SizeY);
- ScreenG=80*ones(SizeX,SizeY);
- ScreenB=zeros(SizeX,SizeY);
- %=========0608
- axes(handles.axesup)
- imgup = imread('mup.jpg');image(imgup);axis off;axis image
- axes(handles.axesdown)
- imgup = imread('mdown.jpg');image(imgup);axis off;axis image
- axes(handles.axesleft)
- imgup = imread('mleft.jpg');image(imgup);axis off;axis image
- axes(handles.axesright)
- imgup = imread('mright.jpg');image(imgup);axis off;axis image
- axes(handles.axes1);%for sanke used
- %=========end of 0608
- while(1)
- len=length(LocX);
- if sum([TargetX TargetY]==[LocY(1) LocX(1)])==2
- POINTS=POINTS+1;
- if ispc
- sound(y,fs);
- end
- set(handles.edit1,'String',['Eating Dots: ',num2str(POINTS)]);
- LocX(2:len+1)=LocX(1:len);
- LocY(2:len+1)=LocY(1:len);
- while(1)
- TargetX=randi(SizeX,1);
- if sum(LocX==TargetX)==0
- break;
- end
- end
- while(1)
- TargetY=randi(SizeY,1);
- if sum(LocY==TargetY)==0
- break;
- end
- end
- else
- LocX(2:len)=LocX(1:len-1);
- LocY(2:len)=LocY(1:len-1);
- end
- %===========20190604
- if sum([TargetX1 TargetY1]==[LocY(1) LocX(1)])==2
- POINTS=POINTS+1;
- if ispc
- sound(y,fs);
- end
- set(handles.edit1,'String',['Eating Dots : ',num2str(POINTS)]);
- LocX(2:len+1)=LocX(1:len);
- LocY(2:len+1)=LocY(1:len);
- while(1)
- TargetX1=randi(SizeX,1);
- if sum(LocX==TargetX1)==0
- break;
- end
- end
- while(1)
- TargetY1=randi(SizeY,1);
- if sum(LocY==TargetY1)==0
- break;
- end
- end
- else
- LocX(2:len)=LocX(1:len-1);
- LocY(2:len)=LocY(1:len-1);
- end
- %===========20190607 end
- %===========2019/0601 get mobile device Azimuth , pitch , roll
- disp('Azimuth'); disp(obj.Orientation(1));
- disp('Pitch'); disp(obj.Orientation(2)); Pitch=obj.Orientation(2);
- disp('Roll'); disp(obj.Orientation(3)); Roll =obj.Orientation(3);
- %===========2019/0601
- if (Roll<-20)
- Direction=1; %Left
- end
- if (Roll>20)
- Direction=3; %Right
- end
- if (Pitch<-20)
- Direction=2; %up
- end
- if (Pitch> 20)
- Direction=4; %Down
- end
- %===========2019/0601
- if Direction==1
- if (LocX(1)~=1)
- LocX(1)=LocX(1)-1;
- elseif LocX(1)==1
- LocX(1)=SizeX;
- end
- elseif Direction==2
- if (LocY(1)~=1)
- LocY(1)=LocY(1)-1;
- elseif LocY(1)==1
- LocY(1)=SizeY;
- end
- elseif Direction==3
- if (LocX(1)~=SizeX)
- LocX(1)=LocX(1)+1;
- elseif LocX(1)==SizeX
- LocX(1)=1;
- end
- elseif Direction==4
- if (LocY(1)~=SizeY)
- LocY(1)=LocY(1)+1;
- elseif LocY(1)==SizeY
- LocY(1)=1;
- end
- end
- flag=0;
- for h=2:length(LocX)
- if LocX(1)==LocX(h)&&LocY(1)==LocY(h)
- if ispc
- [y,fs]=audioread('die.wav');
- end
- errordlg('GAME OVER');
- if ispc
- sound(y,fs);
- end
- flag=1;
- break;
- end
- end
- if flag==1
- break;
- end
- ScreenRt=ScreenR;
- ScreenGt=ScreenG;
- ScreenBt=ScreenB;
- for n=1:length(LocX)
- ScreenRt(LocY(n),LocX(n))=255;
- ScreenGt(LocY(n),LocX(n))=255;
- ScreenBt(LocY(n),LocX(n))=0;
- end
- ScreenRt(TargetX,TargetY)=255;
- ScreenGt(TargetX,TargetY)=255;
- ScreenBt(TargetX,TargetY)=255;
- %=============20190604
- ScreenRt(TargetX1,TargetY1)=255;
- ScreenGt(TargetX1,TargetY1)=255;
- ScreenBt(TargetX1,TargetY1)=255;
- %=============20190604
- ScreenI=cat(3,ScreenRt,ScreenGt,ScreenBt);
- imshow(uint8(ScreenI));
- pause(t);
- end
- % --- Executes on button press in pushbutton1.
- function pushbutton1_Callback(hObject, eventdata, handles)
- % hObject handle to pushbutton1 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- global Direction;
- if Direction~=3
- Direction=1;
- end
- % --- Executes on button press in pushbutton2.
- function pushbutton2_Callback(hObject, eventdata, handles)
- % hObject handle to pushbutton2 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- global Direction;
- if Direction~=4
- Direction=2;
- end
- % --- Executes on button press in pushbutton3.
- function pushbutton3_Callback(hObject, eventdata, handles)
- % hObject handle to pushbutton3 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- global Direction;
- if Direction~=1
- Direction=3;
- end
- % --- Executes on button press in pushbutton4.
- function pushbutton4_Callback(hObject, eventdata, handles)
- % hObject handle to pushbutton4 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- global Direction;
- if Direction~=2
- Direction=4;
- end
- % --- Executes on button press in pushbutton5.
- function pushbutton5_Callback(hObject, eventdata, handles)
- % hObject handle to pushbutton5 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- pause on;
- if strcmp(get(handles.pushbutton5,'String'),'PAUSE')
- pause;
- end
- % --- Executes on button press in Quickly.
- function Quickly_Callback(hObject, eventdata, handles)
- % hObject handle to Quickly (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- global t;
- if t>=0.06
- t=t-0.05;
- end
- caUserInput = 'Quickly';
- NET.addAssembly('System.Speech');
- obj = System.Speech.Synthesis.SpeechSynthesizer;
- obj.Volume = 100;
- Speak(obj, caUserInput);
- % --- Executes on button press in slowly.
- function slowly_Callback(hObject, eventdata, handles)
- % hObject handle to slowly (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- global t;t=t+0.05;
- caUserInput = 'Slowly';
- NET.addAssembly('System.Speech');
- obj = System.Speech.Synthesis.SpeechSynthesizer;
- obj.Volume = 100;
- Speak(obj, caUserInput);
- function edit1_Callback(hObject, eventdata, handles)
- % hObject handle to edit1 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % Hints: get(hObject,'String') returns contents of edit1 as text
- % str2double(get(hObject,'String')) returns contents of edit1 as a double
- % --- Executes during object creation, after setting all properties.
- function edit1_CreateFcn(hObject, eventdata, handles)
- % hObject handle to edit1 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles empty - handles not created until after all CreateFcns called
- % Hint: edit controls usually have a white background on Windows.
- % See ISPC and COMPUTER.
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
- set(hObject,'BackgroundColor','white');
- end
- % --- Executes on slider movement.
- function slider_speed_Callback(hObject, eventdata, handles)
- % hObject handle to slider_speed (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % Hints: get(hObject,'Value') returns position of slider
- % get(hObject,'Min') and get(hObject,'Max') to determine range of slider
- %sliderValue = get(handles.slider_speed,'Value');
- sliderValue = get(hObject,'Value') ;
- %disp('speed')
- %disp(sliderValue)
- [y1,fs1]= audioread('battements.wav');
- sound(y1,fs1);
- global t;
- if (t>=0.06) && (sliderValue>0.8)
- t=0.06;
- end
- if (t>=0.06) && (sliderValue<0.5)
- t=t+0.2;
- end
- % --- Executes during object creation, after setting all properties.
- function slider_speed_CreateFcn(hObject, eventdata, handles)
- % hObject handle to slider_speed (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles empty - handles not created until after all CreateFcns called
- % Hint: slider controls usually have a light gray background.
- if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
- set(hObject,'BackgroundColor',[.9 .9 .9]);
- end
demo: