This site requires JavaScript, please enable it in your browser!
Greenfoot back
virginia001
virginia001 wrote ...

2013/12/12

Help with my game....

virginia001 virginia001

2013/12/12

#
guys.....first of all i am a beginner at working with greenfoot. I have to make a game for a project and i don't know how to solve my problem. I want the two platforms that i have (both written in code) to be unaccessable; So that my boats cant sail over these platforms.. This is the code i have until now: getBackground().setColor(java.awt.Color.white); getBackground().fillRect(200, 0, 380, 170); getBackground().setColor(java.awt.Color.DARK_GRAY); getBackground().fillRect(200, 170, 380, 40); getBackground().setColor(java.awt.Color.DARK_GRAY); getBackground().fillRect(200, 550, 380, 40); getBackground().setColor(java.awt.Color.gray); getBackground().fillRect(200, 590, 380, 200); And my second question is i want the boats to collide against eachother when they touch, and not sailing over eachother. I'm sorry that my english is not so good but i hope you guys can understand what im saying.
danpost danpost

2013/12/12

#
It would be best to use actors to make your platforms. Then use the collision detection methods provided in the Actor class to test and avoid moving over other actors.
virginia001 virginia001

2013/12/12

#
everything is changed to actors now....only problem is how to write the collision thing because everybody says something different i don't know what to do anymore
danpost danpost

2013/12/12

#
Basically, you want to hold the change in location in local fields (so you can negate the move if necessary), make the move, check for intersections, and move back if intersector(s) are present. As an alternative, you could save the location of the actor, move, and reset to saved location if intersector(s) present.
You need to login to post a reply.