Game Development Toolbox

A Game Development Toolbox (GDT) é um pacote de software criado para auxiliar o desenvolvimento de jogos na linguagem Matlab. Essencialmente, este software disponibiliza um conjunto de funcionalidades básicas para o desenvolvimento de jogos, incluindo a visualização de objectos de jogo, a reprodução de sons e a leitura de interfaces com o utilizador.

Eis um exemplo do jogo PONG programado em Matlab usando a toolbox GDT:

Usando a toolbox a programação deste jogo é tão simples quanto:

{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} DEFINE SPRITES AND SOUNDS LOCATIONS {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}

 

if ~exist(‘spriteLocations’,‘var’)

assetsDir  = ‘C:\Users\FranciscoMateus\Documents\libgdxWorkspace\assets\’;

spriteLocations =  { ‘ball’ ,    [assetsDir ‘ball_00.png’]};

end

 

if ~exist(‘soundLocations’,‘var’)

soundLocations =  { ‘peeeeeep’ [ assetsDir ‘\peeeeeep.ogg’];

                    ‘plop’ [ spriteDir ‘\plop.ogg’];

                    ‘beeep’ [ spriteDir ‘\beeep.ogg’]};

end

 

gameWindowSize = [300 200]; {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} game window size in pixels

 

{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} INIT PLAYER {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}

 

player_width = 3; player_height = 20;

player1.pos = [30 gameWindowSize(2)/2-player_height/2];

player2.pos = [gameWindowSize(1)-30 gameWindowSize(2)/2-player_height/2];

score1 = 0;

score2 = 0;

 

{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} INIT BALL {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}

 

ball.pos = [gameWindowSize(1)/2 gameWindowSize(2)/2];   {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} ball initial position

ball.direction = [sign(rand(1)-.5) rand(1)-.5];         {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} set random direction for the ball

vectorNorm = sqrt(ball.direction(1)^2+ball.direction(2)^2);

ball.direction(1) = ball.direction(1) / vectorNorm;

ball.direction(2) = ball.direction(1) / vectorNorm;     {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} set direction vector length to one

ballRadius = 4;

ballSpeed = 4; {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} ball speed in pixels per frame

 

{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} SETUP GAME WINDOW {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}

pixelSize = 2;

backGroundColor = [0 0 0];

setupGameWindow(gameWindowSize, pixelSize, backGroundColor)

 

 

{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} START GAME CYCLE {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}{435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}

doExit=0;

while (~doExit)

    

    {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} Draw center line

    drawLine(gameWindowSize(1)/2,0,gameWindowSize(1)/2,gameWindowSize(2),[.8 .8 0],1);

   

    eventData = readGameInputs(); {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} Read inputs

    

    if eventData(33)==1           {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} 33 is the code for ‘e’ key

        exitGameWindow();

        doExit = 1;

    end

        

    {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} MANAGE PLAYERS

    {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} 45 is the code for ‘q’ key -> player 1 Moves UP

     if eventData(45)==1 & player1.pos(2)<gameWindowSize(2)-4-player_height 

        player1.pos(2) = player1.pos(2) + 4;

     end

    {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} 29 is the code for ‘q’ key -> player 1 Moves DOWN

    if eventData(29)==1 & player1.pos(2)>4 

        player1.pos(2) = player1.pos(2) – 4;

    end

    {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} 19 is the code for the cursor up key -> player 2 Moves UP

    if eventData(19)==1 & player2.pos(2)<gameWindowSize(2)-4-player_height {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} MOVE UP

        player2.pos(2) = player2.pos(2) + 4;

    end

    {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} 20 is the code for the cursor down key -> player 2 Moves DOWN

    if eventData(20)==1 & player2.pos(2)>4 {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} MOVE DOWN

        player2.pos(2) = player2.pos(2) – 4;

    end

    

    drawLine(player1.pos(1),player1.pos(2),player1.pos(1),player1.pos(2)+player_height,

        [1 1 1],player_width); {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}Draw player 1 paddle

   

    drawLine(player2.pos(1),player2.pos(2),player2.pos(1),player2.pos(2)+player_height,

        [1 1 1],player_width); {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}Draw player 2 paddle

   

    {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}MANAGE BALL

 

    ball.pos = ball.pos+ball.direction*ballSpeed;

    

    if ball.pos(1)<1  {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} ball reaches the left side of the window – player 2 scores

        score2 = score2 + 1;

        playSoundEffect(‘peeeeeep’);

        pause(.5)

        ball.pos = [gameWindowSize(1)/2 gameWindowSize(2)/2];   {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} reset ball position

        ball.direction = [sign(rand(1)-.5) rand(1)-.5

        vectorNorm = sqrt(ball.direction(1)^2+ball.direction(2)^2);

        ball.direction(1) = ball.direction(1) / vectorNorm;

        ball.direction(2) = ball.direction(1) / vectorNorm;     

    end

     

    if ball.pos(1)+ballRadius>gameWindowSize(1) {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} ball reaches the right side of the window –   

                                                {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}  player 1 scores

        score1 = score1 + 1;

        playSoundEffect(‘peeeeeep’);

        pause(.5)

        ball.pos = [gameWindowSize(1)/2 gameWindowSize(2)/2];   {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} reset ball position

        ball.direction = [sign(rand(1)-.5) rand(1)-.5];         

        vectorNorm = sqrt(ball.direction(1)^2+ball.direction(2)^2);

        ball.direction(1) = ball.direction(1) / vectorNorm;

        ball.direction(2) = ball.direction(1) / vectorNorm;    

    end

    

    {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} CHECK COLLISIONS WITH PADDLES

    

    ycenter = ball.pos(2)+ballRadius;

    xcenter = ball.pos(1)+ballRadius;

    player1_ycenter = player1.pos(2) + player_height/2;

    player2_ycenter = player2.pos(2) + player_height/2;

    

    {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} PLAYER 1 HITS THE BALL

    if abs(ycenter-player1_ycenter)<player_height/2 + ballRadius &

            abs(ball.pos(1)-player1.pos(1))<ballSpeed &ball.direction(1)<0

        ball.direction(1)= -ball.direction(1);

        ball.direction(2) = (ycenter – player1_ycenter)/12; {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}12 here is just a magic number

        ball.direction = ball.direction./norm(ball.direction);

        playSoundEffect(‘beeep’);

    end

    

    {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} PLAYER 2 HITS THE BALL

    if abs(ycenter-player2_ycenter)<player_height/2 + ballRadius &

            abs(ball.pos(1)+2*ballRadius-player2.pos(1))<ballSpeed&ball.direction(1)>0

        ball.direction(1)= -ball.direction(1);

        ball.direction(2) = (ycenter – player2_ycenter)/12;

        ball.direction = ball.direction./norm(ball.direction);

        playSoundEffect(‘beeep’);

    end

    

    {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} BALL HITS THE TOP OR BOTTOM WALLS

    if (ball.pos(2)<1&ball.direction(2)<0)|

            (ball.pos(2)>gameWindowSize(2)-ballRadius*2 & ball.direction(2)>0) 

        ball.direction(2)= -ball.direction(2); {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1}reverse y direction

        playSoundEffect(‘plop’);

    end

    

    drawSprite(‘ball’, round(ball.pos));    {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} draw the ball

    

    drawText(num2str(score1),[50,180]);     {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} draw the scores

    drawText(num2str(score2),[gameWindowSize(1)-50,180]);

    

    renderGame(); {435e0a867061e904a2ee6e296c052ea7654a5439d474fc82ada599ae312b70b1} Update the display 

end

Neste exemplo, propositadamente, incluiu-se todo o código num m-file. O programa pode, naturalmente, ser simplificado, usando o recurso a funções.