001 package com.croftsoft.apps.road.model.seri; 002 003 import java.awt.*; 004 005 import com.croftsoft.core.animation.model.ModelId; 006 import com.croftsoft.core.animation.model.seri.SeriModel; 007 import com.croftsoft.core.lang.NullArgumentException; 008 009 import com.croftsoft.apps.road.Constants; 010 import com.croftsoft.apps.road.model.Car; 011 012 /********************************************************************* 013 * Roadrunner hero car model. 014 * 015 * @version 016 * 2003-11-09 017 * @since 018 * 2003-11-09 019 * @author 020 * <a href="https://www.croftsoft.com/">David Wallace Croft</a> 021 *********************************************************************/ 022 023 public final class SeriCar 024 extends SeriModel 025 implements Car, Constants 026 ////////////////////////////////////////////////////////////////////// 027 ////////////////////////////////////////////////////////////////////// 028 { 029 030 private static final long serialVersionUID = 0L; 031 032 // 033 034 private final Rectangle bounds; 035 036 // 037 038 private Point destinationPoint; 039 040 private double x; 041 042 private double y; 043 044 ////////////////////////////////////////////////////////////////////// 045 ////////////////////////////////////////////////////////////////////// 046 047 public SeriCar ( 048 ModelId modelId, 049 Rectangle bounds ) 050 ////////////////////////////////////////////////////////////////////// 051 { 052 super ( modelId ); 053 054 NullArgumentException.check ( this.bounds = bounds ); 055 } 056 057 ////////////////////////////////////////////////////////////////////// 058 ////////////////////////////////////////////////////////////////////// 059 060 public boolean isActive ( ) { return true; } 061 062 public double getCenterX ( ) { return x; } 063 064 public double getCenterY ( ) { return y; } 065 066 public Shape getShape ( ) { return null; } 067 068 public boolean isUpdated ( ) { return true; } 069 070 public double getZ ( ) { return 0.0; } 071 072 ////////////////////////////////////////////////////////////////////// 073 ////////////////////////////////////////////////////////////////////// 074 075 public void setDestinationPoint ( Point destinationPoint ) 076 ////////////////////////////////////////////////////////////////////// 077 { 078 this.destinationPoint = destinationPoint; 079 } 080 081 ////////////////////////////////////////////////////////////////////// 082 ////////////////////////////////////////////////////////////////////// 083 084 public void setCenter ( 085 double x, 086 double y ) 087 ////////////////////////////////////////////////////////////////////// 088 { 089 this.x = x; 090 091 this.y = y; 092 } 093 094 public void prepare ( ) 095 ////////////////////////////////////////////////////////////////////// 096 { 097 } 098 099 public void update ( double timeDelta ) 100 ////////////////////////////////////////////////////////////////////// 101 { 102 if ( destinationPoint != null ) 103 { 104 double deltaX = destinationPoint.x - x - TILE_SIZE / 2; 105 106 double deltaY = destinationPoint.y - y - TILE_SIZE / 2; 107 108 if ( timeDelta > TIME_DELTA_MAX ) 109 { 110 timeDelta = TIME_DELTA_MAX; 111 } 112 113 double spaceDelta = timeDelta * RUNNER_VELOCITY; 114 115 if ( deltaX > 0 ) 116 { 117 x = spaceDelta > deltaX ? x + deltaX : x + spaceDelta; 118 } 119 else if ( deltaX < 0 ) 120 { 121 x = spaceDelta > -deltaX ? x + deltaX : x - spaceDelta; 122 } 123 124 if ( deltaY > 0 ) 125 { 126 y = spaceDelta > deltaY ? y + deltaY : y + spaceDelta; 127 } 128 else if ( deltaY < 0 ) 129 { 130 y = spaceDelta > -deltaY ? y + deltaY : y - spaceDelta; 131 } 132 } 133 134 if ( x < bounds.x ) 135 { 136 x = bounds.x; 137 138 y += 3; 139 } 140 else if ( x < bounds.x + TILE_SIZE ) 141 { 142 x += 1; 143 144 y += 2; 145 } 146 else if ( x < bounds.x + 2 * TILE_SIZE ) 147 { 148 y += 1; 149 } 150 else if ( x > bounds.x + bounds.width ) 151 { 152 x = bounds.x + bounds.width; 153 154 y += 3; 155 } 156 else if ( x > bounds.x + bounds.width - TILE_SIZE ) 157 { 158 x -= 1; 159 160 y += 2; 161 } 162 else if ( x > bounds.x + bounds.width - 2 * TILE_SIZE ) 163 { 164 y += 1; 165 } 166 167 if ( y > bounds.y + bounds.height - TILE_SIZE ) 168 { 169 y = bounds.y + bounds.height - TILE_SIZE; 170 } 171 } 172 173 ////////////////////////////////////////////////////////////////////// 174 ////////////////////////////////////////////////////////////////////// 175 }