Está en la página 1de 2

PROYECTO EN MATLAB: SQUASH

Pablo Arturo Soto Matamoros, Hector santiago Troya Perez Kevin Andrés Santacruz López, GR1
pablo.soto@epn.edu.ec, hector.troya@epn.edu.ec, kevin.santacruz@epn.edu.ec
Software de simulación, Escuela Politécnica Nacional
Ing. Diego Pilaquinga

h.t=text(0.01,.97,'Bienvenido','color',[.5 .8
0],'fontweight','bold','fontsize',20);
h.tt=text(0.86,.97,'Tiempo','color',[.5 .8
I. INTRODUCCIÓN 0],'fontweight','bold','fontsize',20);
h.mili=text(0.5,.97,'Tiempo en s:','color',[.5 .8
0],'fontweight','bold','fontsize',20);
El proyecto consiste en crear un juego llamado Squash en App set(h.f,'keypressFcn',{@Down,h});
start(h.timer);
Designer o en un script que permita el movimiento de una %----------------------------------------------------------
----------------
pelota dentro de un intervalo en X y Y, la velocidad con la que %movimiento de la barra
function Down(~,evnt,h)
parte la pelota es variable, así como su ángulo y existirá una global Step D
%strcmpi compara caracteres devuleve 1 o 0
barra en la parte inferior que evitara que la pelota toque el if strcmpi(evnt.Key,'leftarrow')
if D
suelo, si la pelota llega a tocar el suelo el juego finaliza. Step=-0.001;
%la funcion ~devueleve valores del mismo tamaño que D
D=~D;
else
II. PROCEDIMIENTO Step=Step-0.0005;
end
elseif strcmpi(evnt.Key,'rightarrow')
if D
Se uso las siguientes funciones: Step=0.001;

function pingpong4(ang0,v0,col,r) D=~D;


else
global Vx Vy w Step count h D timerCount Ax Ay Xo Yo v1 v2
t1 t2 Step=Step+0.0005;
close all;clc end
v0=0.001*v0;
r=0.01*r; else
Vx=v0*(cosd(ang0));Vy=v0*(sind(ang0));w=600;Step=0.001;coun return;
t=0;D=1; end
timerCount=0;Ax=0.35;Ay=0.08;Xo=0.35;Yo=0.08;
s=get(0,'screensize'); set(h.p,'xdata',get(h.p,'xdata')+Step);
v1=[]; drawnow;
v2=[]; %----------------------------------------------------------
t1=[]; ----------------
t2=[]; %MOVIMIENTO DE LA PELOTA EN LOS LIMITES
v2(end+1)=Vx; function Beat(varargin)
v1(end+1)=Vy; %varagngi permite que la funcion acepte cualquier variable
t1(end+1)=0; de entrada
t2(end+1)=0; global Vx Vy Step count h D timerCount Ax Ay Xo Yo v1 v2 t1
t2
%---------------------------------------------------------- Bx=unique(get(h.b,'xdata'));Bx=Bx([1,end]);
--------------- By=unique(get(h.b,'ydata'));By=By([1,end]);
%CREAR LA INTERFACE DEL JUEGO Rx=unique(get(h.p,'xdata'));Rx=Rx([1,end]);
%crea el cuadro donde se mueve la pelota Ry=unique(get(h.p,'ydata'));Ry=Ry([1,end]);
h.f=figure('menubar','none','numbertitle','off','name','Pin
gPong','position',[s(3)/2-300,s(4)/2-300,w,w]); if (By(1)<=Ry(2) && Bx(2)>=Rx(1) && Bx(1)<=Rx(2))
h.a=axes('xlim',[0 1],'ylim',[0 v1(end+1)=Vy;
1],'xtick',0:0.1:1,'ytick',0:0.1:1,'box','on','position',[0 Vy=-Vy;
0 1 1]);axis square v1(end+1)=Vy;
grid t1(end+1)=get(h.timer,'AveragePeriod')+t1(end);
t1(end+1)=t1(end);
%crea la pelota y el camino por donde va a ir v2(end+1)=Vx;
h.camino=patch(Xo+[0 0],Yo+[0 0],[1 0 0]); Vx=Vx+Step;
h.p=patch([.25 .25 .4 .4],[.01 .04 .04 .01],[0 0 0 ]); v2(end+1)=Vx;
h.b=patch(Xo+r*sin(0:0.01:1*2*pi),Yo+r*cos(0:0.01:1*2*pi),c t2(end+1)=get(h.timer,'AveragePeriod')+t2(end);
ol); t2(end+1)=t2(end);
Xo=Ax; %
%crea el contador y el titulo del axes Yo=Ay;
h.timer=timer('TimerFcn',@Beat,'ExecutionMode','fixedDelay' count=count+1;
,'Period',.01); set(h.t,'string',num2str(count));drawnow
end

1
if Bx(1)<=0
v2(end+1)=Vx;
Vx=-Vx;
v2(end+1)=Vx;
t2(end+1)=get(h.timer,'AveragePeriod')+t2(end);
t2(end+1)=t2(end);
Xo=Ax; %camino
Yo=Ay; %camino
D=~D;

elseif Bx(2)>=1
v2(end+1)=Vx;
Vx=-Vx;
v2(end+1)=Vx;
t2(end+1)=get(h.timer,'AveragePeriod')+t2(end);
t2(end+1)=t2(end);
Xo=Ax; %camino
Yo=Ay; %camino
D=~D;
end
if By(1)<=0
set(h.t,'string','Game Over !');drawnow
stop(h.timer);
elseif By(2)>=1
v1(end+1)=Vy;
Vy=-Vy;
v1(end+1)=Vy;
t1(end+1)=get(h.timer,'AveragePeriod')+t1(end);
t1(end+1)=t1(end);
Xo=Ax; %camino
Yo=Ay; %camino
end
Px=unique(get(h.p,'xdata'));Px=Px([1,end]);
if Px(1)<=0
Step=0.001;
elseif Px(2)>=1
Step=-0.001;
end
Ax=Ax+Vx; %camino
Ay=Ay+Vy; %camino

set(h.camino,'xdata',[Xo Ax]); %camino


set(h.camino,'ydata',[Yo Ay]); %camino

set(h.tt,'string',num2str(timerCount/100));

set(h.b,'xdata',get(h.b,'xdata')+Vx);
set(h.b,'ydata',get(h.b,'ydata')+Vy);
set(h.p,'xdata',get(h.p,'xdata')+Step);
timerCount=timerCount+1;

drawnow;

IV. RESULTADOS
La interfaz grafica del juego es la siguiente:

V. CONCLUSIONES

También podría gustarte