Eclipse Community Forums Forum Search:

Home » Newcomers » Newcomers » Making something go towards a certain point and then detect collision ( Making something go towards a certain point and then detect collision )
Making something go towards a certain point and then detect collision Wed, 28 November 2018 01:44
 lee mrMessages: 2Registered: November 2018 Junior Member
So lets say I want a sprite to go to (100, 1000) and then when it reaches that point, it detects if there is anything there. If there is, then
randomvariable = randomvariable + 1
happens. How exactly would I do this? I like to look at code, and learn what the person did, so it would be nice if someone could write the code, since I am new. Sorry if my english is bad.
https://www.eclipse.org/forums/index.php/r/frm_id/89/?
Re: Making something go towards a certain point and then detect collision [message #1799102 is a reply to message #1798959] Thu, 29 November 2018 17:37
 Patrick MoranMessages: 142Registered: March 2018 Senior Member
I think you will have to learn how to draw lines, extend lines, etc.
https://stackoverflow.com/questions/5801734/how-to-draw-lines-in-java

Then perhaps you can do something like this. Check for whether line A(x,y) and line B(w,z) have a situation where x,y == wz, and if so, go back a step, terminate line A and start line Aa going off on some other direction. Make it simple to start with, e.g., just rotate 45° and go along that new line, always checking each time you do a new x = x + 1, y = y +1.

Hoping for some beginner using Eclipse to make a program for you would probably result in that person's making the kind of thing that works for them but won't work for you in the long run because they have only fulfilled the stated part of your problem, and they haven't seen that the next step in your mind will make their approach a sort of dead end.

If you can use Eclipse, then make a project called, e.g., Bevis_1. Then make a class that will produce a GUI window to work on. Select "src" under Bevis_1,, then File/New/Other/Window Builder/Swing Designer/Application Window. Call it something like Drawer. Eclipse will open the "Source" view of Drawer.java for you. Switch to the Design tab, and you will see a screen with a window that you can start working with.

I would start by making two JTextField "text boxes," one called Starting point, and another called Ending point, and a button called "Draw line." Then try to incorporate the most basic thing you could do given the stuff linked to above. What you want is to fill in two numbers, hit the button, and have the line drawn.

When you get that going, then make a new button called "Draw to starting point +1," which is a little different from the first button because now you don't explicitly go from x to x', you just go from x to x + 1.

When I am setting things up for myself, that is about as far ahead as I let myself think, since once I get into implementing what I think I want I will probably see some complication that I hadn't imagined, prefigured in my mind or whatever you want to call that lack of perfect foresight. So. I will stop at this point.k
 Previous Topic: Setting up OpenOCD for Eclipse 2018 Next Topic: Fewer than 5 messages error when I post here.
Goto Forum:

Current Time: Sat Feb 22 17:10:13 GMT 2020