Changeset 33342 in osm for applications/editors
- Timestamp:
- 2017-05-27T22:56:30+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
r32914 r33342 1 1 /* 2 2 * GPLv2 or 3, Copyright (c) 2010 Andrzej Zaborowski 3 *4 * This class simulates a car engine. What does a car engine do? It5 * makes a pc-speaker-like buzz. The PC Speaker could only emit6 * a (nearly) square wave and we simulate it here for maximum realism.7 3 */ 8 4 package wmsturbochallenge; … … 16 12 import javax.sound.sampled.SourceDataLine; 17 13 14 /** 15 * This class simulates a car engine. What does a car engine do? It 16 * makes a pc-speaker-like buzz. The PC Speaker could only emit 17 * a (nearly) square wave and we simulate it here for maximum realism. 18 */ 18 19 class EngineSound { 19 publicEngineSound() {20 EngineSound() { 20 21 rpm = 0.0; 21 22 } … … 79 80 if (accel > 0.0 && rpm > 1.0 + n * 0.2 && speed > 0.0) { 80 81 rpm = 0.3 + n * 0.2; 81 n 82 n++; 82 83 } else if (accel < 0.0 && rpm < 0.3) { 83 84 if (n > 0) { 84 85 rpm = 0.7 + n * 0.1; 85 n 86 n--; 86 87 } else 87 88 rpm = 0.2; … … 133 134 bufferlen *= 2; 134 135 byte[] buffer = new byte[bufferlen]; 135 for (int b = 0; b < bufferlen; 136 for (int b = 0; b < bufferlen;) { 136 137 int j; 137 for (j = wavelen / 2; j > 0; j 138 buffer[b 139 buffer[b 138 for (j = wavelen / 2; j > 0; j--) { 139 buffer[b++] = (byte) (value >> 8); 140 buffer[b++] = (byte) (value & 0xff); 140 141 } 141 142 value = 0x10000 - value; 142 for (j = wavelen - wavelen / 2; j > 0; j 143 buffer[b 144 buffer[b 143 for (j = wavelen - wavelen / 2; j > 0; j--) { 144 buffer[b++] = (byte) (value >> 8); 145 buffer[b++] = (byte) (value & 0xff); 145 146 } 146 147 value = 0x10000 - value; -
applications/editors/josm/plugins/wms-turbo-challenge2/src/wmsturbochallenge/FakeMapView.java
r32914 r33342 1 1 /* 2 2 * GPLv2 or 3, Copyright (c) 2010 Andrzej Zaborowski 3 * 3 */ 4 package wmsturbochallenge; 5 6 import java.awt.Graphics; 7 import java.awt.Graphics2D; 8 import java.awt.Point; 9 import java.awt.image.BufferedImage; 10 11 import org.openstreetmap.josm.data.ProjectionBounds; 12 import org.openstreetmap.josm.data.coor.EastNorth; 13 import org.openstreetmap.josm.gui.MapView; 14 15 /** 4 16 * Implements a fake MapView that we can pass to WMSLayer's .paint, 5 17 * this will give us two things: … … 14 26 * this happened and could only guess. 15 27 */ 16 package wmsturbochallenge;17 18 import java.awt.Graphics;19 import java.awt.Graphics2D;20 import java.awt.Point;21 import java.awt.image.BufferedImage;22 23 import org.openstreetmap.josm.data.ProjectionBounds;24 import org.openstreetmap.josm.data.coor.EastNorth;25 import org.openstreetmap.josm.gui.MapView;26 27 28 class FakeMapView extends MapView { 28 29 public ProjectionBounds view_bounds; … … 36 37 public double max_east_west; 37 38 38 public FakeMapView(MapView parent, double scale) { 39 super(null, null, null); //TODO MapView constructor contains registering listeners and other code, that probably shouldn't be called in fake map view 39 FakeMapView(MapView parent, double scale) { 40 // TODO: MapView constructor contains registering listeners and other code, that probably shouldn't be called in fake map view 41 super(null, null, null); 40 42 this.parent = parent; 41 43 this.scale = scale; -
applications/editors/josm/plugins/wms-turbo-challenge2/src/wmsturbochallenge/GameWindow.java
r32914 r33342 1 1 /* 2 2 * GPLv2 or 3, Copyright (c) 2010 Andrzej Zaborowski 3 *4 * This implements the game logic.5 3 */ 6 4 package wmsturbochallenge; … … 38 36 import org.openstreetmap.josm.gui.layer.Layer; 39 37 38 /** 39 * This implements the game logic. 40 */ 40 41 public class GameWindow extends JFrame implements ActionListener { 41 42 public GameWindow(Layer ground) { … … 48 49 49 50 while (s.getScreenSize().width < width * scale || 50 s.getScreenSize().height < height * scale) 51 scale --; 51 s.getScreenSize().height < height * scale) { 52 scale--; 53 } 52 54 add(panel); 53 55 … … 79 81 car_engine.start(); 80 82 81 for (int i = 0; i < maxsprites; i ++)83 for (int i = 0; i < maxsprites; i++) { 82 84 sprites[i] = new sprite_pos(); 85 } 83 86 84 87 generate_sky(); … … 120 123 public void save_trace() { 121 124 int len = 0; 122 for (Collection<WayPoint> seg : trackSegs) 125 for (Collection<WayPoint> seg : trackSegs) { 123 126 len += seg.size(); 127 } 124 128 125 129 /* Don't save traces shorter than 5s */ … … 343 347 int frame; 344 348 boolean downloading = false; 349 345 350 protected void screen_repaint() { 346 351 /* Draw background first */ … … 351 356 352 357 /* Messages */ 353 frame 354 if ((frame & 8) == 0 && downloading) 358 frame++; 359 if ((frame & 8) == 0 && downloading) { 355 360 screen.drawImage(loading.getImage(), centre - 356 361 loading.getIconWidth() / 2, 50, this); 362 } 357 363 358 364 /* Sprites */ … … 408 414 ground.paint(ground_view.graphics, ground_view, null); 409 415 410 for (int y = (int) (height * horizon + 0.1); y < height; y 416 for (int y = (int) (height * horizon + 0.1); y < height; y++) { 411 417 /* Assume a 60 deg vertical Field of View when 412 418 * calculating the distance at given pixel. */ … … 415 421 double lon_off = lon + (dist - cardist) * sin; 416 422 417 for (int x = 0; x < width; x 423 for (int x = 0; x < width; x++) { 418 424 double p_x = dist * (x - centre) / height; 419 425 … … 439 445 440 446 int n = (int) (Math.random() * sw * 0.03); 441 for (int i = 0; i < n; i 447 for (int i = 0; i < n; i++) { 442 448 int t = (int) (Math.random() * 5.0); 443 449 int x = (int) (Math.random() * … … 490 496 } 491 497 492 /* sizes decides how many zoom levels the sprites have. We498 /** sizes decides how many zoom levels the sprites have. We 493 499 * could do just normal scalling according to distance but 494 500 * that's not what old games did, they had prescaled sprites 495 501 * for the different distances and you could see the feature 496 502 * grow discretely as you approached it. */ 497 protected final staticint sizes = 8;498 499 protected final staticint maxsprites = 32;503 protected static final int sizes = 8; 504 505 protected static final int maxsprites = 32; 500 506 protected sprite_pos sprites[] = new sprite_pos[maxsprites]; 501 507 … … 537 543 int sy = cactus[type].getIconHeight(); 538 544 539 sprite_pos pos = sprites[i 545 sprite_pos pos = sprites[i++]; 540 546 pos.dist = dist; 541 547 pos.sprite = cactus[type].getImage(); … … 548 554 Arrays.sort(sprites, 0, i); 549 555 for (sprite_pos sprite : sprites) 550 if (i --> 0)556 if (i-- > 0) 551 557 screen.drawImage(sprite.sprite, 552 558 sprite.x, sprite.y, … … 556 562 557 563 if (splashframe >= 0) { 558 splashframe 564 splashframe++; 559 565 if (splashframe >= 8) 560 566 splashframe = -1; … … 566 572 Image image = cactus[type].getImage(); 567 573 568 for (i = 0; i < 50; i 574 for (i = 0; i < 50; i++) { 569 575 int x = (int) (Math.random() * sx); 570 576 int y = (int) (Math.random() * sy); … … 584 590 585 591 public boolean no_super_repaint = false; 592 586 593 protected class GamePanel extends JPanel { 587 594 public GamePanel() { … … 607 614 } 608 615 } 616 609 617 JPanel panel = new GamePanel(); 610 618 … … 631 639 */ 632 640 protected Timer timer; 641 633 642 @Override 634 643 public void actionPerformed(ActionEvent e) { … … 681 690 /* Switch vehicle */ 682 691 if (key == KeyEvent.VK_V) 683 if (current_car ++>= 1)692 if (current_car++ >= 1) 684 693 current_car = 0; 685 694 } … … 702 711 } 703 712 } 713 704 714 protected FakeMapView ground_view; 705 715 } -
applications/editors/josm/plugins/wms-turbo-challenge2/src/wmsturbochallenge/WMSRacer.java
r32914 r33342 1 1 /* 2 2 * GPLv2 or 3, Copyright (c) 2010 Andrzej Zaborowski 3 *4 * This is the main class for the game plugin.5 3 */ 6 4 package wmsturbochallenge; … … 26 24 import org.openstreetmap.josm.plugins.PluginInformation; 27 25 26 /** 27 * This is the main class for the game plugin. 28 */ 28 29 public class WMSRacer extends Plugin implements LayerChangeListener, ActiveLayerChangeListener { 29 30 public WMSRacer(PluginInformation info) { … … 86 87 * horizontal scanlines (lines equidistant from 87 88 * camera eye)) */ 88 for (Layer l : frame.mapView.getLayerManager().getLayers()) 89 for (Layer l : frame.mapView.getLayerManager().getLayers()) { 89 90 if (l.isBackgroundLayer()) { 90 91 groundLayer = l; … … 92 93 return; 93 94 } 95 } 94 96 95 97 groundLayer = null;
Note:
See TracChangeset
for help on using the changeset viewer.