How would you go about making a Tron game on Matlab using GUI.

조회 수: 2 (최근 30일)
Mandaw
Mandaw 2023년 5월 5일
답변: Dinesh 2023년 5월 8일
I am trying to make a very simple redimentary Tron type game on Matlab using GUI. How would I go about iniatlizing players that leave a trail?

채택된 답변

Dinesh
Dinesh 2023년 5월 8일
Hi Mandaw.
You could go about thinking how to get started to build this game by following the example that I run through below.
To initialize players that leave a trail in a Tron-like game, first you have to define the players' starting positions by choosing coordinates on the game grid.
Then, set initial player directions and assign a starting direction (up, down, left, or right for simplicity) for each player.
The next step is to create data structures for player trails. For each player, initialize a data structure (for example a cell array or a matrix) to store the coordinates of the trail. Add the player's starting position to this data structure.
Then, draw initial player positions on the game area using different colors for each player.
As the game progresses, update the player positions and their respective trail data structures with each movement. The updated trail information will be used to render the trails on the game area and to detect collisions between the players and their trails.
The following is an example code that initializes a Tron-like game with a 100x100 grid with two players. This is just a starting point and you can build on top of it.
% Initialize game parameters
gridSize = 100;
numPlayers = 2;
playerColors = {'blue', 'red'};
% Define player starting positions and initial directions
playerPositions = [50, 25; 50, 75]; % positions are correspondingly x1, y1, x2 & y2
playerDirections = [0, 1; 0, -1]; % directions of movement correspondingly are dx1, dy1, dx2 & dy2.
% Create data structures for player trails
playerTrails = cell(numPlayers, 1);
for i = 1:numPlayers
playerTrails{i} = playerPositions(i, :);
end
% Create game area
figure
axis([1, gridSize, 1, gridSize])
grid on
hold on
% Draw initial player positions
for i = 1:numPlayers
plot(playerPositions(i, 1), playerPositions(i, 2), 's', 'Color', playerColors{i}, 'MarkerFaceColor', playerColors{i})
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Just for fun에 대해 자세히 알아보기

태그

제품


릴리스

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by