My final project is a game named:"Unlimited chop ".
As its topic, the way of playing it is chop, chop and chop......,Just keep chop ^^ .
And as your hand shake faster for each chop, you can get higher score.
1、At beginning, chop to start the game!!
%Get picture used in program.
pic1 = imread('count1.jpg');
pic2 = imread('count2.jpg');
pic3 = imread('count3.jpg');
pic4 = imread('times up.png');
start = imread('start.jpg');
start2 =imread('start2.jpg');
I1=imread('1.png');
I2=imread('3.png');
I3=imread('4.png');
%The main page.
a=audioread('bomb.mp3');
z=0;
image(start);
pause(0.1);
%To start the game.
while z<1
[rad, t] = angvellog(m);
z = rad(end,3);
pause(0.1);
if z>1
soundsc(a);
pause(0.1);
image(start2);
pause(1);
end
end
2、Count 3 seconds for the beginning of the game by using "pause":
%To count for the beginning of the game.
image(pic3);
pause(1);
image(pic2);
pause(1);
image(pic1);
pause(1);
3、View of the game:
%first picture after game began.
image(I1);
pause(0.1);
s=0;z=0;i=0;
t0 = clock;
t1 = 0;
score = 0;
Normal attack(for 0<=z<=10).
Critical strike(for z>=0).
4、Simulink&State Flow:
It is important that to choose output value as an array, not time series, or it may cause problem in getting our score.
%30 seconds for game.
while t1 <= 30
[rad, t] = angvellog(m); %Get angular vector of mobile's moving
z = rad(end,3); %Get data of z axis.
pause(0.1);
%**********Reaction to normal attack( z>=10).***********
load_system('final_simulink'); %Load the simulink.
sim('final_simulink'); %Input z to simulink and get score from it.
soundsc(a);
pause(0.1);
image(I3);
pause(0.1); %Time pause to make every process be presented.
image(I1);
%***********Reaction to critical strike(z>=10).*************
else if z>=1
load_system('final_simulink');
sim('final_simulink');
I1=imread('1.png');
I2=imread('3.png');
soundsc(a);
pause(0.1);
image(I2);
pause(0.1);
image(I1);
end
end
s = s+score(end); %To count Total score "s".
score(end) = 0;
disp(s); %Get score in each hitting.
t1 = etime(clock, t0); %Using etime function to count time cost from t0 to here.
end
5、After game ended:
%Time's up
pause(0.5);
image(pic4);
pause(2);
%To print the final reason.
if s>=400
win = imread('win.jpg');
image(win);
else
lose = imread('lose.jpg');
image(lose);
end
If total score>=400,
You win the game.
If not,
you lose the game.
6、The demo:
Thanks for your looking.