@hkrhässleholm, if 'getX()' returns the x-coordinate at which 'this' object is at, then 'getX() + speedX' would be the location at which the object will be after its next move. Comparing that value with the maximum limit in the x direction that the object can move determines whether it will move out of bounds or not.
Sidenote: I just looked at the scenario's code and the world is created with 'super(500, 500, 1);' and the world edge checks for right and down are now compared to 500.
A better coding would be
getX() + speedX >= getWorld().getWidth()
@hkrhässleholm, it is not horrible programming to have code in the act method, it just makes it less readable when there is alot of code there, which would becomes poor programming.
* see http://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html on how to construct a 'for' loop; and 'i++' is the same as 'i=i+1'
*"board.snake[i].setLocation(board.snake[i-1].getX(),board.snake[i-1].getY());" move the snake (segment) to the position of the one in front of it, repeating this starting from the back of the snake will move the whole snake body forward one step
*the checks in the 'if statement make sure the snake is in world limits after a tentative move, checking each edge
*the 'Actor body =..." gets the snake object that is located two places forward from the head of the snake, if one exists there. What the code is doing is looking ahead 2 places to see if the head of the snake will run into its body; in context, by using this, the code is saying "if the head moves toward the body and will hit the body on the next move if allowed to continue in the same direction, then end the game right then." The game ends on a tentative collision, not on a collision (programmer preference?).
I hope that answers your questions.
@kiwii, re-download the source and replace the code for the SWorld class back into your scenario. I had inadvertently forget to add the overrides on 'removeObject'. They were finally added in my last update. Thanks.
@To All Who Have Downloaded This Prior To Last Update, please re-download source to correct problem with 'removeObject' situations.
I do believe this project is complete. If anyone encounters any problems of any kind, or has any concerns, please do not hesitate to leave a comment. Also, if you can think of any improvements or have any suggestions, I would like to know about them. On the brighter side, if you have any raves, or if you so feel moved to, again, please do not hesitate to post up.
In your Vector class, in the 'sin_theta2' and 'cos_theta2' methods, you are bringing in 'angle' as an 'int' parameter. They need cast to 'double' while converting to radians.
[code]double a = (double) angle/180.0*PI;[/code]
@chantry2012, click on 'Scenarios' near the top of the page (second from the right, near your icon, if you are logged in). On the bottom of the scenario page, under 'Browse by tag', click on the world 'Game'.
I think what fireandIce means is that the squares within a radius of the campfire can be illuminated determined by the direct distance from the campfire (instead of the sum of the x and y offsets determining the amount of illumination for each square).
2012/11/22
Lab 6 – Snake
2012/11/22
Lab 6 – Snake
2012/11/22
Scrolling SuperWorld
2012/11/21
Scrolling SuperWorld
2012/11/21
Scrolling SuperWorld
2012/11/18
TrainingDrawLine
2012/11/14
Fractal Slideshow
2012/11/12
Adventure
2012/11/11
Light System