22
33import gregtech .api .GTValues ;
44import gregtech .api .mui .GTGuiTextures ;
5- import gregtech .api .util .Rectangle ;
5+ import gregtech .api .util .GTUtility ;
66
77import net .minecraft .client .renderer .GlStateManager ;
88import net .minecraft .util .text .TextFormatting ;
2323import org .jetbrains .annotations .NotNull ;
2424import org .jetbrains .annotations .Nullable ;
2525
26+ import java .awt .geom .Rectangle2D ;
2627import java .util .List ;
2728
2829public class FlappyGreg extends Widget <FlappyGreg > implements Interactable {
@@ -37,11 +38,11 @@ public class FlappyGreg extends Widget<FlappyGreg> implements Interactable {
3738 protected static final int MAX_OBSTACLES = 5 ;
3839 protected static final float OBSTACLE_MOVEMENT_SPEED = 2.0f ;
3940 protected static final int OBSTACLE_COLOR = Color .GREEN .main ;
40- protected final List <Rectangle > obstacles = new ObjectArrayList <>(MAX_OBSTACLES * 2 );
41+ protected final List <Rectangle2D . Float > obstacles = new ObjectArrayList <>(MAX_OBSTACLES * 2 );
4142 protected float obstacleWidth ;
4243
4344 protected static final float GREG_SIZE = 18.0f ;
44- protected Rectangle gregArea = new Rectangle ();
45+ protected Rectangle2D . Float gregArea = new Rectangle2D . Float ();
4546 protected float gregYSpeed = TERMINAL_VELOCITY ;
4647
4748 @ Nullable
@@ -101,28 +102,29 @@ protected void initializeState() {
101102 int width = area .width ;
102103 int height = area .height ;
103104
104- gregArea = new Rectangle ((width / 3.0f ) - (GREG_SIZE / 2.0f ), (height / 2.0f ) - (GREG_SIZE / 2.0f ), GREG_SIZE );
105+ gregArea .setRect ((width / 3.0f ) - (GREG_SIZE / 2.0f ), (height / 2.0f ) - (GREG_SIZE / 2.0f ), GREG_SIZE ,
106+ GREG_SIZE );
105107
106108 float lastXPos = width * 0.95f ;
107109 this .obstacleWidth = width / 20.0f ;
108110 for (int i = 0 ; i < MAX_OBSTACLES ; i ++) {
109- Rectangle top = new Rectangle ();
111+ Rectangle2D . Float top = new Rectangle2D . Float ();
110112 obstacles .add (top );
111113
112- Rectangle bottom = new Rectangle ();
114+ Rectangle2D . Float bottom = new Rectangle2D . Float ();
113115 obstacles .add (bottom );
114116
115- top .setX ( lastXPos ) ;
116- bottom .setX ( lastXPos ) ;
117- top .setWidth ( obstacleWidth ) ;
118- bottom .setWidth ( obstacleWidth ) ;
117+ top .x = lastXPos ;
118+ bottom .x = lastXPos ;
119+ top .width = obstacleWidth ;
120+ bottom .width = obstacleWidth ;
119121
120122 final float topYEnd = (height * 0.55f ) - (height * 0.20f * GTValues .RNG .nextFloat ());
121- top .setHeight ( topYEnd ) ;
123+ top .height = topYEnd ;
122124
123- final float bottomYStart = topYEnd + (gregArea .getHeight () * 1.75f );
124- bottom .setHeight ( height - bottomYStart ) ;
125- bottom .setY ( bottomYStart ) ;
125+ final float bottomYStart = topYEnd + (gregArea .height * 1.75f );
126+ bottom .height = height - bottomYStart ;
127+ bottom .y = bottomYStart ;
126128
127129 lastXPos += (width / 2.5f ) + ((width / 15.0f ) * GTValues .RNG .nextFloat ());
128130 }
@@ -146,7 +148,7 @@ public void onUpdate() {
146148 @ SideOnly (Side .CLIENT )
147149 protected void updateGregPosition () {
148150 if (gregArea .getY () < (getArea ().height - gregArea .getHeight ())) {
149- gregArea .setY ( gregArea .getY () + gregYSpeed ) ;
151+ gregArea .y = gregArea .y + gregYSpeed ;
150152 }
151153
152154 if (gregYSpeed < TERMINAL_VELOCITY ) {
@@ -156,8 +158,12 @@ protected void updateGregPosition() {
156158
157159 @ SideOnly (Side .CLIENT )
158160 protected void checkObstacleCollisions () {
159- for (Rectangle obstacle : obstacles ) {
160- if (obstacle .collides (gregArea , OBSTACLE_MOVEMENT_SPEED )) {
161+ Rectangle2D .Float gregTest = new Rectangle2D .Float ();
162+ gregTest .setRect (gregArea );
163+ gregTest .x += OBSTACLE_MOVEMENT_SPEED ;
164+
165+ for (Rectangle2D .Float obstacle : obstacles ) {
166+ if (GTUtility .rectanglesCollide (obstacle , gregTest )) {
161167 gameState = GameState .COLLIDED ;
162168 break ;
163169 }
@@ -166,17 +172,17 @@ protected void checkObstacleCollisions() {
166172
167173 @ SideOnly (Side .CLIENT )
168174 protected void updateObstaclePositions () {
169- for (Rectangle obstacle : obstacles ) {
170- obstacle .decrementX ( OBSTACLE_MOVEMENT_SPEED ) ;
175+ for (Rectangle2D . Float obstacle : obstacles ) {
176+ obstacle .x -= OBSTACLE_MOVEMENT_SPEED ;
171177 }
172178 }
173179
174180 @ SideOnly (Side .CLIENT )
175181 protected void checkWinState () {
176182 if (obstacles .isEmpty ()) return ;
177183
178- Rectangle obstacle = obstacles .get (obstacles .size () - 1 );
179- if ((obstacle .getX () + obstacleWidth + WIN_DISTANCE ) <= gregArea .getX ()) {
184+ Rectangle2D . Float obstacle = obstacles .get (obstacles .size () - 1 );
185+ if ((obstacle .x + obstacleWidth + WIN_DISTANCE ) <= gregArea .getX ()) {
180186 gameState = GameState .FINISHED ;
181187 onFinish ();
182188 }
@@ -193,14 +199,13 @@ public void draw(ModularGuiContext context, WidgetThemeEntry<?> widgetTheme) {
193199
194200 // Obstacles
195201 Stencil .applyAtZero (area , context );
196- for (Rectangle obstacle : obstacles ) {
197- GuiDraw .drawRect (obstacle .getX (), obstacle .getY (), obstacle .getWidth (), obstacle .getHeight (),
198- OBSTACLE_COLOR );
202+ for (Rectangle2D .Float obstacle : obstacles ) {
203+ GuiDraw .drawRect (obstacle .x , obstacle .y , obstacle .width , obstacle .height , OBSTACLE_COLOR );
199204 }
200205 Stencil .remove ();
201206
202207 // "Character"
203- GTGuiTextures .GREGTECH_LOGO .draw (gregArea .getX () , gregArea .getY () , gregArea .getWidth () , gregArea .getHeight () );
208+ GTGuiTextures .GREGTECH_LOGO .draw (gregArea .x , gregArea .y , gregArea .width , gregArea .height );
204209
205210 WidgetTheme theme = widgetTheme .getTheme ();
206211 switch (gameState ) {
0 commit comments