Difference between revisions of "Watermelon/Code"
Jump to navigation
Jump to search
(Free code: Debug graphics: Painting waves) |
|||
Line 48: | Line 48: | ||
* int NUM_WAVEBUCKETS - have a guess? :) | * int NUM_WAVEBUCKETS - have a guess? :) | ||
* double[number of segments][NUM_WAVEBUCKETS] waveBuckets - array of segmentation data | * double[number of segments][NUM_WAVEBUCKETS] waveBuckets - array of segmentation data | ||
+ | |||
+ | ===Looks Like=== | ||
+ | [[File:WatermelonDebugGraphics.png|frame|left|[[Watermelon]] and [[LifelongObsession]] duking it out.]] |
Revision as of 06:20, 10 June 2009
Code on this page is freely available for whoever wants to use it. .
Debug Graphics
public void doPaint(Graphics2D g) { g.setStroke(new java.awt.BasicStroke(2f)); if (bot.getOthers() == 1) { double radius, arcSegment, segmentHeading; double time = bot.getTime(); for (Wave w : waves) { if (w.paint) { radius = (time - w.ctime) * w.velocity; arcSegment = w.extent / NUM_WAVEBUCKETS; for (int i = 0; i < NUM_WAVEBUCKETS; i++) { segmentHeading = w.heading + w.clockwise * (arcSegment * i - w.extent / 2); g.setColor(Color.getHSBColor( // this is Hue, Saturation, and Brightness 0.058333f, 1.0f, (float) (0.15 + 0.85 * waveBuckets[w.segment][i] / bucketMax[w.segment]) )); g.draw(new Line2D.Double( w.origin.x + (radius+2) * Math.sin(segmentHeading - arcSegment/2), w.origin.y + (radius+2) * Math.cos(segmentHeading - arcSegment/2), w.origin.x + (radius+2) * Math.sin(segmentHeading + arcSegment/2), w.origin.y + (radius+2) * Math.cos(segmentHeading + arcSegment/2) )); } } } } }
This function is called in the main robot's onPaint(Graphics2D).
Already defined:
- bot - reference to this AdvancedRobot.
- waves - collection of Waves with properties:
- double extent - the size of an angle covering -1 to +1 on the wave in radians
- boolean paint - I don't always paint all my waves
- long ctime - tick when the wave was fired
- double velocity - the bullet speed of this wave - how fast it's traveling
- double heading - wave's heading
- int clockwise - +1 for clockwise, -1 for counterclockwise (widdershins)
- int segment - which segment applies to this wave
- Point2D.Double origin - wave's origin
- int NUM_WAVEBUCKETS - have a guess? :)
- double[number of segments][NUM_WAVEBUCKETS] waveBuckets - array of segmentation data