Changeset 33342 in osm for applications/editors/josm/plugins/wms-turbo-challenge2/src/wmsturbochallenge/GameWindow.java
- Timestamp:
- 2017-05-27T22:56:30+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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. We 498 /** 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 }
Note:
See TracChangeset
for help on using the changeset viewer.
