Unless there is a compelling reason to use floating point, don't. Yes, changing location.x = xCoord, would be preferred over using floating point. Is there an int version of PVector? You'd have to consider how normalize() should work if you are using int's.Lilly Deel wrote:I have use PVector because as I understand if I use int I will need to set location, concretePlant coordinates location.x = xCoord, location.y = yCoord etc... and PVector seems to make it possible to get these coordinate together in the brackets for easy reading? But maybe I am wrong. Should I change the PVectors to int then and write all coordinates like location.x etc?
I wouldn't expect anything to change in the way of behavior.I have changed float to double now, still does the same.
If you are moving horizontal, vertical, or diagonal (45degrees) then integer is easy. If you are moving in any arbitrary angle then you might be stuck with floating point, in which case you may need both a locationFloat.x and a locationInt.x because the float may not fall exactly on a integer grid, e.g. pixels.dir.normalize() is to make the vector a unit, which coordinates will be used to make the lorry move to the site. I tried using velocity like with the other examples but that just makes it go in any direction. I don't know how to implement the velocity along with the direction vector.
Example:I don't understand the 'private' and getters. Does it mean I need to write Private in front of the class?
As I mentioned, using '==' to compare floating point values doesn't always work because of rounding errors. This would be a non-issue if you use int for your vector type.The idea behind the reachDestination function is to tell the lorry that when it reaches the destination, then it needs to go to the next site. But it doesn't work.
I can't quite tell, the small amount of code you posted doesn't give me the big picture and I can't compile it and run it myself.Is there a better way to do it? I was thinking maybe instead of making it automatically go to the next sit, maybe the mousePress function can also make it go to the next site?
Unless there is a compelling reason to use floating point, don't. Yes, changing location.x = xCoord, would be preferred over using floating point. Is there an int version of PVector? You'd have to consider how normalize() should work if you are using int's.
If you are moving horizontal, vertical, or diagonal (45degrees) then integer is easy. If you are moving in any arbitrary angle then you might be stuck with floating point, in which case you may need both a locationFloat.x and a locationInt.x because the float may not fall exactly on a integer grid, e.g. pixels.
I can't quite tell, the small amount of code you posted doesn't give me the big picture and I can't compile it and run it myself.
Ah, this is what I was trying to determine but couldn't from the code. So, you won't be able to use integers for your location. However you'll need to convert to an int when you need a pixel location, as in "(int)location.x". Your site has been arrived at by using the mouse to click on a pixel, so this is NOT floating point. To see if you're at the destination you'd needI'm moving towards the site that has been created randomly on the screen. So i cannot fix an angle.
There are three kinds of actuaries: those who can count, and those who can't.
Lilly Deel wrote:I have made it work! ... So I've changed it to say that instead of = I have set it as if it reaches 1pixel from it and now it works
I wrote:I have a pretty good idea of how you did this but I'd like you to consider a different way of "making it work".
That applies to the current app which appears to use Swing, but in JavaFX locations are denominated as double pairs.Carey Brown wrote:. . . the float may not fall exactly on a integer grid, e.g. pixels. . . .
The point of all these examples I'm giving is to show that you can restructure your code (what's called "refactoring") so that it's easier to read and more logically organized. Refactoring improves the design of your program by eliminating code smells like duplication and misplaced responsibilities and makes your program easier to maintain and modify.
Work out the algorithm for getting your lorry from the cement factory to the site, presumably with the drum still turning and before the concrete sets solid What is going to happen if you encounter an obstruction? Consider the information you need in the lorry object. Forget about pictures and fonts; you can add them later. Just get the lorry working.
I think you need to turn your screen off and work with pencil paper and eraser. Make sure to get a large eraser; you will need it.
How fast you go fromLilly Deel wrote:What are 1ToRSpeed and downToUpSpeed?
Please don't try to run before you can walk. Create a situation with one lorry, one starting point, and one destination. Once that is working add a second destination. Then work out how to go home to the cement works.Lilly Deel wrote:. . . a lorry is selected when:
The truck that is the nearest (by checking the distance); . . .
I would start even simpler. Simply print out the coordinates you would be at every minute/second during the journey. Start by simply moving horizontally or vertically, so only one coordinate changes and there isn't any complicated arithmetic.Carey Brown wrote:. . . you should have started with a very simple program that moves a rectangle across the screen. . . .
The knights of nee want a shrubbery. And a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|