有没有办法使值等于一组更新值?

时间:2014-12-03 23:33:15

标签: matlab

我知道这不是最好的措辞,但我真的需要一些帮助......

我有一个PingPong游戏,我希望自动化。我想尝试使桨的中心坐标((Py1 + Py2)/ 2){顶部Y +底部Y / 2}等于球的中心坐标((By1 + By2)/ 2){与桨相同}。

我想知道是否有办法不断改变球拍坐标以适应球的坐标。整个程序使用“推进器”作为方向和速度。

Thruster(2) = Fast
Thruster(1) = Slows down, and eventually changes direction
Thruster(0) = Keeps momentum
Thruster(-1) = Changes direction.

http://www.mathworks.com/matlabcentral/fileexchange/45619-pingpong-game 很确定这是原始档案..

我是整个编码的新手,如果不明显的话...... 感谢

代码:

function GAME_PINGPONG

% PingPong game
% Every time the player gets 2 correct deflections the speed of play
% increases.
% [x,y] = Get_Ball_Coordinates()
% This function returns the x and y coordinates of the ball
% [y,V] = Get_Paddle_Info()
% This will return the y coordinates of the paddle (y) and its speed (V)
% Thruster()
% This controls the speed of the paddle. 
% Thruster(2) increases the speed of the paddle in the up
% direction/decreases in down
% Thruster(1) decreases the speed of the paddle in the up direction/
% increases in down
% Thruster(0) maintains the speed of the paddle
% Thruster(-1) reverses the direction of the paddle (maintains speed)

%% Set up simulation
global Game_Over Mode h
close all;clc;

SET_UP_SIM;     % Set up the simulation and associated timers etc.
Game_Over =0;   % When this changes to 1 the game is over!!!

%% Mode of operation
% Auto mode: write a script to control the bat
% Manual mode: use uparrow and downarrow to control the bat
Mode = 0;       % Mode= 1 is AUTO, Mode=0 is MANUAL

%% Auto mode: Control algorithm
while(Mode==1)  % While auto mode is selected the following actions will be carried out

    [Bx,By] = Get_Ball_Coordinates();   % Use function Get_Ball_Coordinates() to return x and y values of the ball
    [Py,PV] = Get_Paddle_Info();        % Use function Get_Paddle_Info() to return the y coordinates of the paddle and it's speed.

    if  Game_Over==1    % Suggest a logic test to break out of continuous auto mode when the game is over!
        break
    end

end

0 个答案:

没有答案