Filter löschen
Filter löschen

How do you make a grid you can move around in?

4 Ansichten (letzte 30 Tage)
Alexander MacBlane
Alexander MacBlane am 14 Sep. 2023
Bearbeitet: John D'Errico am 18 Sep. 2023
I am attempting to make a game using MATLAB that involves being able to move a player character/token around in a grid, but I don't know the first step to do something like that.
Essentially what I envision is there is a (m x n) grid with a "player" (ciricle/dot/placeholder) in the center of a grid square. Then, the code accepts inputs for Up, Down, Left, Right, and the token moves to the next square over. This will then repeat, and the token can move all around the confides of the grid.
I'm not even sure if this is possible on MATLAB, and I'm very new to coding, so I'll be grateful for any advice.
(I would also be thankful if anyone could explain advanced functions that aren't beginner MATLAB functions that I may need to use)
  2 Kommentare
William Rose
William Rose am 14 Sep. 2023
Yes it can be done in Matlab.
The code for moving around in discrete steps is the easy part. The code for allowing the user to select Up/Down/Right/Left is trickier. The interactive graphical display of what is going on is also tricky.
If I had to do this, I would use Labview, because creating an interactive graphical user interface is easy in Labview.
Matlab has created the AppDesigner to make this process easier. I have not used it. Google "create GUI matlab" for tutorials and videos. Avoid videos about GUIDE, an older Matlab tool, which has been phased out.
John D'Errico
John D'Errico am 18 Sep. 2023
Bearbeitet: John D'Errico am 18 Sep. 2023
It seems pretty basic.
  1. Can you plot a grid as just a rectangular mesh of lines? OF COURSE. That should be trivial. Jut use plot, or line.
  2. Can you plot a symbol at any point, denoting the current location? Again, of course. Just use plot.
  3. Can you MOVE the point you just plotted? Again, trivial, since you can access (AND CHANGE AT WILL) the x and y coordinates of that point using handle graphics. This will update the current figure.
If you can do those things, now you need to design a user interface. It might be just 4 buttons, that you can click on with the mouse. Or, you can write an interface that will accept input, made by a key click. Or be fancier yet, and look for clicks of the mouse in the current figure, indicating the direction you will move next.
When you decide where the new point is to be (making sure that the new point has not wandered outside of the acceptable grid, just keep a record of the current location in your code.
So it is all literally trivial to do, though triviality is often in the eye of the programmer. And it is YOU who must do that programming, since this is your assignment. There is nothing overtly difficult in this though. You need to learn to program. That means in the case of a big problem, to break it down into small pieces, each of which you can solve. Then you put it all together.
So start writing.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Just for fun finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by