Greetings, and welcome to the World Affairs Board!
The World Affairs Board is the premier forum for the discussion of the pressing geopolitical issues of our time. Topics include military and defense developments, international terrorism, insurgency & COIN doctrine, international security and policing, weapons proliferation, and military technological development.
Our membership includes many from military, defense, academic, and government backgrounds with expert knowledge on a wide range of topics. Registration is fast, simple and absolutely free so why not register a World Affairs Board account and join our community today?
Thanks for the tip. Right now, I don't know how to make the computer do something when you press a key, so maybe you could tell me how to put in something that'll do that.
I got a slope changer working (MAN that was annoying; I had to resort to printing-out the code and inspecting it to get the last problem fixed).
I'm going to put in a grid system now, then add bricks.
as i told u early u got to have two threads running in parallel, in one thread ur main activity of ball bouncing should go on for Infinity(well u have to check the variables for every iteration, that is wether the ball has reached the boundry or wether the ball has touched any brick or so on and so forth). now in the other thread the function should loop to infinity for user input(if its me i would wait till he presses E/e its so bcos i would assume that by pressing E/e the user intends to end the program) i would read the input in this thread and update the necessary variables so as to maintain the communication between the thread that runs the bouncing of ball and this thread.
BTW the code for the plank that moves in the bottom will be in a seperate thread too
Alright. Got the grid system, I can draw the bricks, but now I don't know how to make the ball bounce off of the brick.
I have two variable that contrl movement: xDir, and slope.
When xDir is positive, the ball is moving to the right. When it's negative, it moves left.
When slope is +, the ball moves down. When it is -, the ball moves up (on the screen, not coordinates).
So I need a way to distinguish the ball hitting the brick from the bottom (or top) from the sides.
for this one i would have a function that returns a value 0 or 1, u would have to access it every time u make a move with ur ball.
If i were u i would start with storing all the bricks information in an array and this function for each call goes through that information to check if any brick was hit. BTW if i were u i would store the bricks top most coordinate and the height of the brick(assuming ur brick is a rectangle)
the image below would help u out how to detect where on the brick has the ball hit, but there u have a catch, what would u do if the ball hits the brick at one of the corner its up to u to figure it out, BTW if u cant i would give u the answer two days from now.
the figure below assumes that u have assigned the vertical coordinates to Y-axis and the horizontal one to the X-axis. and u have assigned the origin that is the coordinate (0,0) to the top most left side of the window(hope u are doing this on java swing components)
Wow, your help came very useful to me in the detecting of certain sides.
I'm done for a while now (programming for 3 hours straight strains your mind and eyes a lot), so if you want to help me get the corners done, that'd be great. After that, making them dissappear correctly is next.
Here are some things you need to know:
1. I have a grid system going for the bricks, so I can create them much easier. I also have the same thing for the balls - I have 4 points (top, bottom, left, right) on them that I assign a grid coordinate for - the picture below will illustrate this.
2. Each grid part is 25 pixels x 12 pixles.
3. Here is the code for the brick-intercept tester:
public int Brick(int xPos, int yPos, int xDir, double slope, int j, int[]lev ) {//detects if a collision has occured
brick = 3;
for(int i=0; i<lev.length/3; i++) {
if(xGrids==lev[i*3]&&yGrid==lev[i*3+1]) {//coming from bottom
brick = 0;
System.out.print("bottom\t\t");
slope = slope*-1;
xDir = xDir*-1;
} if(xGridt==lev[i*3]&&yGrids==lev[i*3+1]) {//coming from left
brick = 0;
System.out.print("left\t\t");
xDir = xDir*-1;
} if(xGrids==lev[i*3]&&yGridt==lev[i*3+1]) {//coming from top
brick = 0;
System.out.print("top\t\t");
slope = slope*-1;
xDir = xDir*-1;
} if(xGrid==lev[i*3]&&yGrids==lev[i*3+1]) {//coming from right
brick = 0;
System.out.print("right\t\t");
xDir = xDir*-1;
}
}
ball[j].slope = slope;
ball[j].xDir = xDir;
return brick;
}
I have the System.out.println's for testing purposes only.
Thanks so much for the help so far.
Wow, your help came very useful to me in the detecting of certain sides.
I'm done for a while now (programming for 3 hours straight strains your mind and eyes a lot), so if you want to help me get the corners done, that'd be great. After that, making them dissappear correctly is next.
Here are some things you need to know:
1. I have a grid system going for the bricks, so I can create them much easier. I also have the same thing for the balls - I have 4 points (top, bottom, left, right) on them that I assign a grid coordinate for - the picture below will illustrate this.
2. Each grid part is 25 pixels x 12 pixles.
3. Here is the code for the brick-intercept tester:
public int Brick(int xPos, int yPos, int xDir, double slope, int j, int[]lev ) {//detects if a collision has occured
brick = 3;
for(int i=0; i<lev.length/3; i++) {
if(xGrids==lev[i*3]&&yGrid==lev[i*3+1]) {//coming from bottom
brick = 0;
System.out.print("bottom\t\t");
slope = slope*-1;
xDir = xDir*-1;
} if(xGridt==lev[i*3]&&yGrids==lev[i*3+1]) {//coming from left
brick = 0;
System.out.print("left\t\t");
xDir = xDir*-1;
} if(xGrids==lev[i*3]&&yGridt==lev[i*3+1]) {//coming from top
brick = 0;
System.out.print("top\t\t");
slope = slope*-1;
xDir = xDir*-1;
} if(xGrid==lev[i*3]&&yGrids==lev[i*3+1]) {//coming from right
brick = 0;
System.out.print("right\t\t");
xDir = xDir*-1;
}
}
ball[j].slope = slope;
ball[j].xDir = xDir;
return brick;
}
I have the System.out.println's for testing purposes only.
Thanks so much for the help so far.
i am too tired from work, will answer ur query tommorow till then try to figure out how u would handle the corner collision
-raj
Wow, your help came very useful to me in the detecting of certain sides.
I'm done for a while now (programming for 3 hours straight strains your mind and eyes a lot), so if you want to help me get the corners done, that'd be great. After that, making them dissappear correctly is next.
Here are some things you need to know:
1. I have a grid system going for the bricks, so I can create them much easier. I also have the same thing for the balls - I have 4 points (top, bottom, left, right) on them that I assign a grid coordinate for - the picture below will illustrate this.
2. Each grid part is 25 pixels x 12 pixles.
3. Here is the code for the brick-intercept tester:
public int Brick(int xPos, int yPos, int xDir, double slope, int j, int[]lev ) {//detects if a collision has occured
brick = 3;
for(int i=0; i<lev.length/3; i++) {
if(xGrids==lev[i*3]&&yGrid==lev[i*3+1]) {//coming from bottom
brick = 0;
System.out.print("bottom\t\t");
slope = slope*-1;
xDir = xDir*-1;
} if(xGridt==lev[i*3]&&yGrids==lev[i*3+1]) {//coming from left
brick = 0;
System.out.print("left\t\t");
xDir = xDir*-1;
} if(xGrids==lev[i*3]&&yGridt==lev[i*3+1]) {//coming from top
brick = 0;
System.out.print("top\t\t");
slope = slope*-1;
xDir = xDir*-1;
} if(xGrid==lev[i*3]&&yGrids==lev[i*3+1]) {//coming from right
brick = 0;
System.out.print("right\t\t");
xDir = xDir*-1;
}
}
ball[j].slope = slope;
ball[j].xDir = xDir;
return brick;
}
I have the System.out.println's for testing purposes only.
Thanks so much for the help so far.
nice to see u progressing, BTW please do remember the first law of software engineering(its tough for one guy to read other guys code).
as i said i would now tell u how to deal with the corner problem, the problem with corner is that as with the reflection of the ball with the sides along a 90degrees angle , if the ball hits the corner it just retraces the same path back. after the brick dissapears.
as i said before even if u have a grid system, u should have to store some variables in an array or a vector where u store which brick is active and which has been vanished.
-raj
I have to mess with my brick-disappearing system that when it is hit, it turns the grid coordinates to (-1, -1), which in my drawing thread, will not draw those bricks.
And sorry to post that code, I thought it was neccesary to do so. It's really hard to explain stuff that complex for me right now.
Remember, I have only taken a semester of Comp. Sci, with the first 4 weeks being the history of the computer and HTML stuff.
Of course I always had my brother to help, but now he's got a high-paying job (up to $30 per hour now, plus he's getting a new laptop soon for free; one of those MacBook Pros ), so he has no time anymore.
I have to mess with my brick-disappearing system that when it is hit, it turns the grid coordinates to (-1, -1), which in my drawing thread, will not draw those bricks.
And sorry to post that code, I thought it was neccesary to do so. It's really hard to explain stuff that complex for me right now.
Remember, I have only taken a semester of Comp. Sci, with the first 4 weeks being the history of the computer and HTML stuff.
Of course I always had my brother to help, but now he's got a high-paying job (up to $30 per hour now, plus he's getting a new laptop soon for free; one of those MacBook Pros ), so he has no time anymore.
congratulations for u brothers job, BTW when will u be posting ur screen shots, i would love to see them.
BTW u have taken up a good project, this would help u a lot in understanding the basic programming techniques more than 2-3 sems of course work
Comment