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

2012/4/16

a few questions regarding my driving track

wahaj wahaj

2012/4/16

#
im almost finished with my race track but i have a few questions. here is the image for the track as it looks right now current track refer to this image for this question removing objects as you can see in the image i have boxed in a few bricks. i need my car to go over or under these bricks (preferably over) but so they dont touch the bricks. other wise the car wont be able to move. . it needs to make the turn to end up at the bottom right hand corner.i need something like a bridge. how would i go about doing this? i didnt know how to make the "bridge" so i thought of removing the boxed in bricks when my car hit the switch ( the red dot just before the turn) and putting in new bricks to enclose the curve. but the removeObject method doesn't remove objects at specific coordinates. so what do i do here? refer to this image for this question the coloring part as you can see in the image a part of it is spray painted black. this is the path my car will take. how can i make it so that that path is a different color than rest of the unused space in the world? this is just to make things a bit more visually appealing and to make the track a bit easier to see last question. is it possible to adjust the speed slider in my code? if not then is it possible to make it so that it cant be changed by players if i display it? i would really appreciate it if you answered all three of my questions. im a new programmer so if the last one is too complicated then just say its complicated and that will be the end of it =)
danpost danpost

2012/4/16

#
Create a bridge object and use the 'public void addedToWorld(World world)' method to 'world.removeObjects(getIntersectingObjects(Brick.class));'. For painting the track, make two integer arrays to trace the Xs and Ys of the track, basically tracing a polygon. After setting the color for the background, use the two array in 'getBackground().fillPolygon(xs, ys, numberOfPoints);'. You will need to do this at least twice, first fill inside the outer walls the track color, then fill inside the inner walls back to white (areas that are not track enclosed in side the outer walls will have to be changed back to white also).
wahaj wahaj

2012/4/16

#
trace the Xs and Ys?? what do you mean by that exactly? oh and what about the speed slider ?(refer to first post)
davmac davmac

2012/4/16

#
the removeObject method doesn't remove objects at specific coordinates. so what do i do here?
You could to break this into two steps: 1. Find the object(s) at the specific coordinates. Consult the API documentation (particularly for the World class). 2. Remove those objects (again see the World class documentation).
danpost danpost

2012/4/16

#
The speed can be adjusted by the Greenfoot method 'setSpeed(int)' where 'int' is a value between 1 and 100, inclusive. If you do not want players to adjust the speed, just 'Lock the scenario' during export, which will hide the speed slider. As far as tracing Xs and Ys, look at the array below. The zero values represent non-wall areas, both the ones and twos represent wall locations, but the twos are also trace points for the polygon.
//                     1 1 1
// 0 1 2 3 4 5 6 7 8 9 0 1 2
   0 0 0 0 0 0 2 2 0 0 0 0 0 // 0
   0 0 0 0 1 1 0 0 2 0 0 0 0 // 1
   0 0 1 1 0 0 0 0 1 0 0 0 0 // 2
   2 1 0 0 0 0 0 0 2 0 0 0 0 // 3
   1 0 0 0 0 0 0 0 0 2 1 1 2 // 4
   1 0 0 0 2 1 2 0 0 0 0 0 1 // 5
   2 1 1 2 0 0 0 2 1 1 1 1 2 // 6
Starting with the two on the top line, and working clockwise, the arrays would be
int[] xs = new int[] { 6, 7, 8, 8, 9, 12, 12, 7, 6, 4, 3, 0, 0 };
int[] ys = new int[] { 0, 0, 1, 3, 4, 4, 6, 6, 5, 5, 6, 6, 3 };
getBackground().fillPolygon(xs, ys, 13); // 13 pts given in arrays
The first point is (6, 0), the second is (7, 0), the third is (8, 1), etc. There will be a little room for play as your bricks have size; choose the longest lines along the bricks and edges.
wahaj wahaj

2012/4/16

#
danpost thanks. davmac i used this code
Actor c = getOneIntersectingObject(Switch.class);
        if ( c!= null)
        {
            getWorld().removeObject(getWorld().getObjectsAt(231,509,Brick(60).class)) ;
}
this gives me an identifier expected error. i also tried getWorld().removeObject(getWorld().getObjectsAt(231,509,null)) ; didnt work either
Michionlion Michionlion

2012/4/16

#
I would think that it is because Brick(60).class is not the actual class. the class specified needs to be either Brick.class, or Brick2.class, there is no reason to actually pass anything, unless the name of the class was actually 'Brick(60).class' BTW, clean up your code, it will be easier to read then. ;)
davmac davmac

2012/4/16

#
wahaj, your first line looks fine: Actor c = getOneIntersectingObject(Switch.class); But your code after that is problematic: if ( c!= null) { getWorld().removeObject(getWorld().getObjectsAt(231,509,Brick(60).class)) ; } (Notice I fixed the indentation - making it much easier to read). Firstly, in your call to "getObjectsAt", what is "Brick(60).class" - I mean, what is the "60" supposed to represent? I think you just mean "Brick.class"? Secondly, "getObjectsAt" returns a List, but removeObject requires a single Actor parameter - you can use removeObjects instead, though. So:
    Actor c = getOneIntersectingObject(Switch.class);  
    if ( c!= null)  
    {  
        getWorld().removeObjects(getWorld().getObjectsAt(231,509,Brick.class)) ;  
    }
wahaj wahaj

2012/4/17

#
sorry about the indentation. i was working on the code when i posted this, didnt remember to press ctrl+shift+ i. and the 60 is part the parameter of the class. its there so i can rotate some of my bricks. i thought it would be there because i got an error a while back that said cant find variable "Brick". but if i remember correctly it went away when i put Brick() like in the addObject method.anyways i guess i should look at the api more closely. its so easy to miss methods. anyways thanks a lot for your help. this should be the last of the questions for the current level im workings. really appreciate the help =)
davmac davmac

2012/4/17

#
You should provide parameters when you are creating a new instance, as in "new Brick()". When you are referring to the class itself, you do not provide parameters, and add ".class" to the end, as in "Brick.class".
You need to login to post a reply.