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

2015/6/12

Help with collision detecting

Blewitt Blewitt

2015/6/12

#
So me and my friend are both VERY new to greenfoot and have given a project in school to create anything we want and will be awarded marks for creativity and complexity and have decided to create a game that resembles the 'tron' light cycle game. In which, two cars will drive around the world and leave a trail of their color behind them. If you touch the edge of the world or the other players color or the other player themselves then your car is removed from the world and the other player would win. But we are instantly faced with two issues. 1. Every time the two cars touch, the yellow car ALWAYS wins (we think this is because it's first in the actors list. Secondly we have no idea how to get a trail to follow the cars. Any help with this would be great. Code for the collision and removal: Code
1
2
3
4
5
6
7
8
Actor carBlue;
carBlue = getOneObjectAtOffset(0, 0, carBlue.class);
if (carBlue != null)
 {
     World world;
     world = getWorld();
     world.removeObject(carBlue);
 }
danpost danpost

2015/6/12

#
As far as the yellow car always winning -- I think you need to show a bit more of the code for the car classes. If each car first moved and then checked for collision, then you should not have that specific problem. As far as a trail -- do not think of them as following the cars, but being left behind by the cars. If the car places a trail object at its new location after each move, then as the cars continue to move, they will be left behind leaving "a trail to follow the cars".
You need to login to post a reply.