Changeset 32914 in osm for applications/editors/josm/plugins/wms-turbo-challenge2/src/wmsturbochallenge
- Timestamp:
- 2016-09-03T17:08:38+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/wms-turbo-challenge2/src/wmsturbochallenge
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wms-turbo-challenge2/src/wmsturbochallenge/EngineSound.java
r32322 r32914 30 30 31 31 AudioFormat output_format = 32 new AudioFormat(S_RATE, 16, 1, true, true); 32 new AudioFormat(S_RATE, 16, 1, true, true); 33 33 DataLine.Info info = 34 new DataLine.Info(SourceDataLine.class, output_format); 34 new DataLine.Info(SourceDataLine.class, output_format); 35 35 36 36 /* Get the data line, open it and initialise the device */ … … 109 109 110 110 protected class audio_task extends TimerTask { 111 @Override 111 112 public void run() { 112 113 if (output == null) … … 127 128 int wavelen = (int) (S_RATE / freq); 128 129 int bufferlen = MIN_BUFFER - (MIN_BUFFER % wavelen) + 129 wavelen; 130 wavelen; 130 131 int value = (int) (0x7fff * volume); 131 132 … … 147 148 148 149 frames_written += 149 output.write(buffer, 0, bufferlen) / 2; 150 output.write(buffer, 0, bufferlen) / 2; 150 151 151 152 reschedule(frames_current); … … 158 159 * about half into the last frame). */ 159 160 long delay = (frames_written - frames - MIN_BUFFER / 2) * 160 1000 / S_RATE; 161 1000 / S_RATE; 161 162 if (delay < 0) 162 163 delay = 0; -
applications/editors/josm/plugins/wms-turbo-challenge2/src/wmsturbochallenge/FakeMapView.java
r32194 r32914 43 43 ProjectionBounds parent_bounds = parent.getProjectionBounds(); 44 44 max_east_west = 45 parent_bounds.maxEast - parent_bounds.minEast; 45 parent_bounds.maxEast - parent_bounds.minEast; 46 46 } 47 47 … … 61 61 parent.zoomTo(new ProjectionBounds( 62 62 new EastNorth( 63 parent_center.east() - 64 max_east_west / 2, 65 parent_center.north()), 63 parent_center.east() - 64 max_east_west / 2, 65 parent_center.north()), 66 66 new EastNorth( 67 parent_center.east() + 68 max_east_west / 2, 69 parent_center.north()))); 67 parent_center.east() + 68 max_east_west / 2, 69 parent_center.north()))); 70 70 71 71 /* Request again because NavigatableContent adds … … 73 73 */ 74 74 ProjectionBounds new_bounds = 75 parent.getProjectionBounds(); 75 parent.getProjectionBounds(); 76 76 max_east_west = 77 new_bounds.maxEast - new_bounds.minEast; 77 new_bounds.maxEast - new_bounds.minEast; 78 78 } 79 79 … … 100 100 } 101 101 102 @Override 102 103 public ProjectionBounds getProjectionBounds() { 103 104 return view_bounds; 104 105 } 105 106 107 @Override 106 108 public Point getPoint(EastNorth p) { 107 109 double x = p.east() - view_bounds.minEast; … … 113 115 } 114 116 117 @Override 115 118 public EastNorth getEastNorth(int x, int y) { 116 119 return new EastNorth( 117 view_bounds.minEast + x * this.scale, 118 view_bounds.minNorth - y * this.scale); 120 view_bounds.minEast + x * this.scale, 121 view_bounds.minNorth - y * this.scale); 119 122 } 120 123 … … 123 126 } 124 127 128 @Override 125 129 public Graphics getGraphics() { 126 130 return graphics; 127 131 } 128 132 133 @Override 129 134 public void repaint() { 130 135 } -
applications/editors/josm/plugins/wms-turbo-challenge2/src/wmsturbochallenge/GameWindow.java
r32518 r32914 99 99 protected Collection<Collection<WayPoint>> trackSegs; 100 100 101 @Override 101 102 public void actionPerformed(ActionEvent e) { 102 103 /* We should count the satellites here, see if we … … 128 129 GpxData data = new GpxData(); 129 130 data.tracks.add(new ImmutableGpxTrack(trackSegs, 130 131 new HashMap<String, Object>())); 131 132 132 133 ground_view.parent.getLayerManager().addLayer( … … 164 165 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 165 166 WMSRacer.class.getResource( 166 "/images/car0-l.png"))), 167 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 168 WMSRacer.class.getResource( 169 "/images/car0.png"))), 170 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 171 WMSRacer.class.getResource( 172 "/images/car0-r.png"))), 173 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 174 WMSRacer.class.getResource( 175 "/images/car1-l.png"))), 176 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 177 WMSRacer.class.getResource( 178 "/images/car1.png"))), 179 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 180 WMSRacer.class.getResource( 181 "/images/car1-r.png"))), 167 "/images/car0-l.png"))), 168 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 169 WMSRacer.class.getResource( 170 "/images/car0.png"))), 171 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 172 WMSRacer.class.getResource( 173 "/images/car0-r.png"))), 174 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 175 WMSRacer.class.getResource( 176 "/images/car1-l.png"))), 177 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 178 WMSRacer.class.getResource( 179 "/images/car1.png"))), 180 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 181 WMSRacer.class.getResource( 182 "/images/car1-r.png"))), 182 183 }; 183 184 protected static final ImageIcon bg[] = new ImageIcon[] { 184 185 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 185 186 WMSRacer.class.getResource( 186 "/images/bg0.png"))), 187 "/images/bg0.png"))), 187 188 }; 188 189 protected static final ImageIcon skyline[] = new ImageIcon[] { 189 190 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 190 191 WMSRacer.class.getResource( 191 "/images/horizon.png"))), 192 "/images/horizon.png"))), 192 193 }; 193 194 protected static final ImageIcon cactus[] = new ImageIcon[] { 194 195 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 195 196 WMSRacer.class.getResource( 196 "/images/cactus0.png"))), 197 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 198 WMSRacer.class.getResource( 199 "/images/cactus1.png"))), 200 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 201 WMSRacer.class.getResource( 202 "/images/cactus2.png"))), 197 "/images/cactus0.png"))), 198 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 199 WMSRacer.class.getResource( 200 "/images/cactus1.png"))), 201 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 202 WMSRacer.class.getResource( 203 "/images/cactus2.png"))), 203 204 }; 204 205 protected static final ImageIcon cloud[] = new ImageIcon[] { 205 206 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 206 207 WMSRacer.class.getResource( 207 "/images/cloud0.png"))), 208 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 209 WMSRacer.class.getResource( 210 "/images/cloud1.png"))), 211 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 212 WMSRacer.class.getResource( 213 "/images/cloud2.png"))), 214 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 215 WMSRacer.class.getResource( 216 "/images/cloud3.png"))), 217 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 218 WMSRacer.class.getResource( 219 "/images/cloud4.png"))), 208 "/images/cloud0.png"))), 209 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 210 WMSRacer.class.getResource( 211 "/images/cloud1.png"))), 212 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 213 WMSRacer.class.getResource( 214 "/images/cloud2.png"))), 215 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 216 WMSRacer.class.getResource( 217 "/images/cloud3.png"))), 218 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 219 WMSRacer.class.getResource( 220 "/images/cloud4.png"))), 220 221 }; 221 222 protected static final ImageIcon aircraft[] = new ImageIcon[] { 222 223 new ImageIcon(Toolkit.getDefaultToolkit().createImage( 223 224 WMSRacer.class.getResource( 224 "/images/aircraft0.png"))), 225 "/images/aircraft0.png"))), 225 226 }; 226 227 protected static final ImageIcon loading = new ImageIcon( 227 228 Toolkit.getDefaultToolkit().createImage( 228 229 WMSRacer.class.getResource( 229 "/images/loading.png"))); 230 "/images/loading.png"))); 230 231 protected static Toolkit s = Toolkit.getDefaultToolkit(); 231 232 protected int current_bg = 0; … … 242 243 protected double speed = 0.0; 243 244 protected boolean key_down[] = new boolean[] { 244 false, false, false, false, }; 245 false, false, false, false, }; 245 246 246 247 protected void move() { … … 262 263 if (key_down[2]) 263 264 speed += speed >= 0.0 ? 1.0 / (2.0 + speed) : 0.5; 264 /* Down */ 265 if (key_down[3]) { 266 if (speed >= 0.5) /* Brake (TODO: sound) */ 267 speed -= 0.5; 268 else if (speed >= 0.01) /* Brake (TODO: sound) */ 269 speed = 0.0; 270 else /* Reverse */ 271 speed -= 0.5 / (4.0 - speed); 272 } 273 274 speed *= 0.97; 275 car_engine.set_speed(speed); 276 277 if (speed > -0.1 && speed < 0.1) 278 speed = 0; 279 280 heading += wheelangle * speed; 281 282 boolean chop = false; 283 double newlat = lat + Math.cos(heading) * speed * ele * 0.2; 284 double newlon = lon + Math.sin(heading) * speed * ele * 0.2; 285 for (EastNorth pos : cacti) { 286 double alat = Math.abs(pos.north() - newlat); 287 double alon = Math.abs(pos.east() - newlon); 288 if (alat + alon < ele * 1.0) { 289 if (Math.abs(speed) < 2.0) { 290 if (speed > 0.0) 291 speed = -0.5; 292 else 293 speed = 0.3; 294 newlat = lat; 295 newlon = lon; 296 break; 265 /* Down */ 266 if (key_down[3]) { 267 if (speed >= 0.5) /* Brake (TODO: sound) */ 268 speed -= 0.5; 269 else if (speed >= 0.01) /* Brake (TODO: sound) */ 270 speed = 0.0; 271 else /* Reverse */ 272 speed -= 0.5 / (4.0 - speed); 273 } 274 275 speed *= 0.97; 276 car_engine.set_speed(speed); 277 278 if (speed > -0.1 && speed < 0.1) 279 speed = 0; 280 281 heading += wheelangle * speed; 282 283 boolean chop = false; 284 double newlat = lat + Math.cos(heading) * speed * ele * 0.2; 285 double newlon = lon + Math.sin(heading) * speed * ele * 0.2; 286 for (EastNorth pos : cacti) { 287 double alat = Math.abs(pos.north() - newlat); 288 double alon = Math.abs(pos.east() - newlon); 289 if (alat + alon < ele * 1.0) { 290 if (Math.abs(speed) < 2.0) { 291 if (speed > 0.0) 292 speed = -0.5; 293 else 294 speed = 0.3; 295 newlat = lat; 296 newlon = lon; 297 break; 298 } 299 300 chop = true; 301 splashframe = 0; 302 splashcactus = pos; 303 todelete.add(pos); 297 304 } 298 305 } 306 307 lat = newlat; 308 lon = newlon; 309 310 /* Seed a new cactus if we're moving. 311 * TODO: hook into data layers and avoid putting the cactus on 312 * the road! 313 */ 314 if (cacti_on && Math.random() * 30.0 < speed) { 315 double left_x = maxdist * (width - centre) / height; 316 double right_x = maxdist * (0 - centre) / height; 317 double x = left_x + Math.random() * (right_x - left_x); 318 double clat = lat + (maxdist - cardist) * 319 Math.cos(heading) - x * Math.sin(heading); 320 double clon = lon + (maxdist - cardist) * 321 Math.sin(heading) + x * Math.cos(heading); 322 323 cacti.add(new EastNorth(clon, clat)); 299 324 chop = true; 300 splashframe = 0; 301 splashcactus = pos; 302 todelete.add(pos); 303 } 304 } 305 306 lat = newlat; 307 lon = newlon; 308 309 /* Seed a new cactus if we're moving. 310 * TODO: hook into data layers and avoid putting the cactus on 311 * the road! 312 */ 313 if (cacti_on && Math.random() * 30.0 < speed) { 314 double left_x = maxdist * (width - centre) / height; 315 double right_x = maxdist * (0 - centre) / height; 316 double x = left_x + Math.random() * (right_x - left_x); 317 double clat = lat + (maxdist - cardist) * 318 Math.cos(heading) - x * Math.sin(heading); 319 double clon = lon + (maxdist - cardist) * 320 Math.sin(heading) + x * Math.cos(heading); 321 322 cacti.add(new EastNorth(clon, clat)); 323 chop = true; 324 } 325 326 /* Chop down any cactus far enough that it can't 327 * be seen. ``If a cactus falls in a forest and 328 * there is nobody around did it make a sound?'' 329 */ 330 if (chop) { 331 for (EastNorth pos : cacti) { 332 double alat = Math.abs(pos.north() - lat); 333 double alon = Math.abs(pos.east() - lon); 334 if (alat + alon > 2 * maxdist) 335 todelete.add(pos); 336 } 337 cacti.removeAll(todelete); 338 todelete = new ArrayList<>(); 339 } 325 } 326 327 /* Chop down any cactus far enough that it can't 328 * be seen. ``If a cactus falls in a forest and 329 * there is nobody around did it make a sound?'' 330 */ 331 if (chop) { 332 for (EastNorth pos : cacti) { 333 double alat = Math.abs(pos.north() - lat); 334 double alon = Math.abs(pos.east() - lon); 335 if (alat + alon > 2 * maxdist) 336 todelete.add(pos); 337 } 338 cacti.removeAll(todelete); 339 todelete = new ArrayList<>(); 340 } 340 341 } 341 342 … … 379 380 double right_x = maxdist * (0 - centre) / height; 380 381 double e_lat[] = new double[] { 381 lat + (maxdist - cardist) * cos - left_x * sin, 382 lat + (maxdist - cardist) * cos - right_x * sin, 383 lat - cardist * cos, }; 382 lat + (maxdist - cardist) * cos - left_x * sin, 383 lat + (maxdist - cardist) * cos - right_x * sin, 384 lat - cardist * cos, }; 384 385 double e_lon[] = new double[] { 385 lon + (maxdist - cardist) * sin + left_x * cos, 386 lon + (maxdist - cardist) * sin + right_x * cos, 387 lon - cardist * sin, }; 386 lon + (maxdist - cardist) * sin + left_x * cos, 387 lon + (maxdist - cardist) * sin + right_x * cos, 388 lon - cardist * sin, }; 388 389 ground_view.setProjectionBounds(new ProjectionBounds( 389 390 new EastNorth(min3(e_lon), min3(e_lat)), … … 403 404 e_lon[0], e_lat[0]))); 404 405 } 405 */ 406 */ 406 407 /* Request the image from ground layer */ 407 408 ground.paint(ground_view.graphics, ground_view, null); … … 450 451 int t = 0; 451 452 int x = (int) (300 + Math.random() * (sw - 500 - 452 453 aircraft[t].getIconWidth())); 453 454 sky.drawImage(aircraft[t].getImage(), x, 0, this); 454 455 } … … 474 475 } 475 476 476 protected class sprite_pos implements Comparable<sprite_pos> { 477 protected static class sprite_pos implements Comparable<sprite_pos> { 477 478 double dist; 478 479 … … 483 484 } 484 485 486 @Override 485 487 public int compareTo(sprite_pos x) { 486 488 return (int) ((x.dist - this.dist) * 1000000.0); … … 559 561 560 562 int type = (((int) (splashcactus.north() * 561 563 10000000.0) & 31) % 3); 562 564 int sx = cactus[type].getIconWidth(); 563 565 int sy = cactus[type].getIconHeight(); … … 629 631 */ 630 632 protected Timer timer; 633 @Override 631 634 public void actionPerformed(ActionEvent e) { 632 635 move(); -
applications/editors/josm/plugins/wms-turbo-challenge2/src/wmsturbochallenge/WMSRacer.java
r32518 r32914 39 39 * an entry in the new layer's context menus in layerAdded 40 40 * but there doesn't seem to be any way to do that :( */ 41 protected class DriveAction extends JosmAction { 41 protected static class DriveAction extends JosmAction { 42 42 public MapFrame frame = null; 43 43 public Layer currentLayer = null;
Note:
See TracChangeset
for help on using the changeset viewer.