in my last post i was looking for a way to fix issues i was having with implementing acceleration but i just don’t think i’m capable of fixing it with the movement system i’ve made so i’m going looking to remake it, i was using a 2d array the same dimensions as my window and just using either a 1 or 0 to decide whether an object would be drawn at a specific coordinate or not but i run into a lot of issues with out of bounds errors which i managed to sort but now have a strange bug which neither me nor chat gpt can fix 😂 , what is a simpler way of handling this movement?
#best way of handling 2d movement?
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
stem I currently have. Can you provide more details about the specific issues you are facing with implementing acceleration in your 2D movement? This will help me provide a more tailored solution for your problem.
isnt it just storing:
- position (x, y)
- velocity (in x and y direction)
- accelaration (in x and y direction)
and then just update these all the time?
tbh i’m unsure how to store the values in an array to then be able pull them again so i’ve sorta just worked around it using it as an on/off indicator for my draw function, then incrementing through the array setting 1s and 0s so it looks like it’s moving 😅
im using it along with some for and if loops for movement and collision detection
sorry i should’ve explained better yeh basically i’m working on a sand physics simulator and each grain an an object and i need to check each of there locations in relation to the other objects
Why can't you simply use coordinates?
Ah
I see
sorry just had to log in on my laptop here
this is the class im currently using, im using libgdx for rendering
I uploaded your attachments as Gist.
ah so you say each pixel is a grain of sand?
so I would do it differently in the first place
I would create a class that represents a grain of sand
it has properties like:
- position (x, y)
- velocity
- acceleration
and then you store a List<Sand> or smth
and handle the physics using that list
for drawing you just iterate through the list and draw them at their stored position
then you will need an update method to update all of their properties
ahhh yeh that’s probably better lol
thank you i’m gonna try that now and il update if i get it working 👍
@wooden lotus
Your question has been closed due to inactivity.
If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.
Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.
When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.
Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.
With enough info, someone knows the answer for sure 👍
ive run into an issue again lol, sorry this took a while i was just trying to learn how to use arraylist and ended up nesting an array to store my values but ive got abit of an issue with rendering, im trying to increment through the array list and draw all the objects but it only seems to draw the most recent index, im not super familiar still with lists so it may be something trivial but ive been stuck on this for about an hour and a half.
I uploaded your attachments as Gist.
for rendering i just run moveGrain() in my main class
your Grain class is pretty bad in the first place
a Grain should not store all grains itself using arrays, but instead should store x, y, velX, velY, accX, accY and then you later create a List<Grain> instead
OOP is a basic abstraction for the outside world
I you call something a Grain, it should be a Grain, not a list of grains
That's a different abstraction
SOLID is an acronym that stands for five principles of object-oriented programming and design. These principles are guidelines that help developers create software that is easy to understand, maintain, and extend. The five SOLID principles are:
-
Single Responsibility Principle (SRP): A class should have only one reason to change. It means that a class should have only one responsibility or job and should not be responsible for multiple unrelated tasks.
-
Open/Closed Principle (OCP): Software entities (classes, modules, functions) should be open for extension but closed for modification. This principle encourages the use of abstraction and inheritance to allow new functionality to be added without modifying existing code.
-
Liskov Substitution Principle (LSP): Subtypes must be substitutable for their base types without affecting the correctness of the program. In other words, if a program is using a base class, it should be able to use any of its derived classes without knowing it.
-
Interface Segregation Principle (ISP): Clients should not be forced to depend on interfaces they do not use. This principle states that interfaces should be specific and focused on the needs of the clients using them, rather than being large and general-purpose.
-
Dependency Inversion Principle (DIP): High-level modules/classes should not depend on low-level modules/classes directly; both should depend on abstractions. This principle promotes loose coupling between classes by introducing abstractions and relying on dependency injection.
By following these SOLID principles, developers can create code that is more modular, flexible, and maintainable, making it easier to adapt to changing requirements or add new features without introducing bugs or breaking existing functionality.
SOLID might be a bit much for this skill level tbh
But there are good books if you want to dive deeper
Not something to directly focus on, but in this case S applies
The S for solid is quite contentious, this would just be the basics
Also random remark, but I'd like to see a coordinate record, that would make your constructor more descriptive.
sorry i’m still pretty new to programming in general, what do you mean by a coordinate record?
and yeh my class for grain is abit all over the place as i was kinda teaching myself as i was making it
record Coordinate ( double x , double y ) {}
I would call it Position
and then a record for Velocity and Acceleration as well
but
probably not
all of them store x and y
but for different purposes
basically a vector 
sorry am i replacing anything with the record code or just running it along with the rest of my program 😅
also I doubt a record makes sense here actually
depending on how you use it
because you cant set in a record
they are all final values
oh okay
you could still use them to make your constructor better
Or a Coordinate/position class. But I'd say you'd give an object a new position, and not change it. Since you're moving an object in the world and telling it it's new position.
i fixed it lol i was clearing the screen after rendering an object so it would wipe all the previous objects
side note but has anyone got any course recommendations, i don't mind if its paid or like a yt course i just know that self teaching this isn't going to be as beneficial to me in the long run
MOOC is a completely free introductory Java course created by the University of Helsinki, it is a great way to learn Java from the ground up.
It consists of two parts, one at beginner, and another at intermediate level. The end of the course is marked by creating your own Asteroids game clone!
Even though the instructions show how to configure and use NetBeans for the course, you can use IntelliJ. To use IntelliJ, simply install the TMC plugin by opening IntelliJ -> File -> Settings -> Plugins and searching for TMC. You will then be able to use IntelliJ to complete MOOC.
Visit MOOC here: https://java-programming.mooc.fi/
(the course is available in both English and Finnish)
simon_verhoeven • used /tag id: mooc
·
About the course - Java Programming
And if you want a book: head first java
thank you