When I resize my world, I want it so everything within "MyWorld" will shrink as well.
Don't give me a direct answer, just some hints guiding me on what I should do.
Here is my code:
and here is my code for my actor receiving all this information:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * A Minecraft Landscape built through various amounts of rectangles * * ----- * * (2020 - 02 - 11) */ public class MyWorld extends World { private GreenfootImage myImage; /** * Constructor for objects of class MyWorld. * */ public MyWorld() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super ( 600 , 400 , 1 ); myImage = new GreenfootImage( 600 , 400 ); //--------------------------------------------------------------------------------- /* * BACKGROUND * Creating a blue sky by making a rectangle that occupies the whole canvas */ background( 0 , 0 , 600 , 400 ); //--------------------------------------------------------------------------------- /* * CLOUDS * Creating an outline of each cloud with different values * Colouring each cloud white */ // Colouring each cloud (White) creatingClouds( 40 , 75 , 100 , 45 ); creatingClouds( 150 , 20 , 125 , 35 ); creatingClouds( 360 , 50 , 115 , 40 ); // Outline of each cloud creatingClouds( 40 , 75 , 100 , 45 ); creatingClouds( 150 , 20 , 125 , 35 ); creatingClouds( 360 , 50 , 115 , 40 ); //--------------------------------------------------------------------------------- /* * ZOMBIE * Creating an outline of the zombie * Zombie is made through several rectangles creating a zombie figure * Colouring each rectangle making up the zombie * Some rectangles contain different RGB values */ // Colouring zombie (Dark Green, RGB: 64, 128, 64) colouringMobsRGB( 442 , 210 , 50 , 50 , 64 , 128 , 64 ); colouringMobsRGB( 505 , 270 , 15 , 15 , 64 , 128 , 64 ); colouringMobsRGB( 450 , 335 , 32 , 14 , 64 , 128 , 64 ); colouringMobsRGB( 482 , 270 , 23 , 15 , 64 , 128 , 64 ); // Colouring zombie torso (Faded Light Blue, RGB: 112, 146, 190) colouringMobsRGB( 451 , 261 , 31 , 59 , 112 , 146 , 190 ); colouringMobsRGB( 482 , 270 , 23 , 15 , 112 , 146 , 190 ); // Colouring zombie pants (Dark Blue, RGB: 63, 72, 204) colouringMobsRGB( 450 , 320 , 32 , 15 , 63 , 72 , 204 ); // Colouring zombie eye and mouth (White) colouringMobsGeneric( 482 , 250 , 10 , 10 , Color.WHITE); colouringMobsGeneric( 470 , 225 , 15 , 7 , Color.WHITE); // Outline of each zombie body part drawingMobs( 442 , 210 , 50 , 50 ); drawingMobs( 450 , 260 , 32 , 60 ); drawingMobs( 482 , 270 , 23 , 15 ); drawingMobs( 505 , 270 , 15 , 15 ); drawingMobs( 442 , 210 , 50 , 50 ); drawingMobs( 450 , 335 , 32 , 14 ); drawingMobs( 470 , 225 , 15 , 7 ); drawingMobs( 482 , 250 , 10 , 10 ); drawingMobs( 450 , 320 , 32 , 15 ); //--------------------------------------------------------------------------------- /* * CREEPER * Creating an outline of creeper * Creeper is made of several rectangles creating it's figure * Colouring each rectangle making up the creeper */ // Colouring creeper skin (Semi - Dark Green, RGB: 34, 177, 76) colouringMobsRGB( 81 , 201 , 49 , 48 , 34 , 177 , 76 ); colouringMobsRGB( 92 , 251 , 27 , 79 , 34 , 177 , 76 ); colouringMobsRGB( 75 , 331 , 24 , 18 , 34 , 177 , 76 ); colouringMobsRGB( 111 , 331 , 24 , 18 , 34 , 177 , 76 ); // Colouring the creeper's eye and mouth (White) colouringMobsGeneric( 111 , 216 , 14 , 7 , Color.WHITE); colouringMobsGeneric( 119 , 241 , 11 , 9 , Color.WHITE); // Outlining each creeper body part drawingMobs( 80 , 200 , 50 , 50 ); drawingMobs( 91 , 250 , 28 , 80 ); drawingMobs( 74 , 330 , 25 , 19 ); drawingMobs( 110 , 330 , 25 , 19 ); drawingMobs( 110 , 215 , 15 , 8 ); drawingMobs( 118 , 240 , 12 , 10 ); //--------------------------------------------------------------------------------- /* * SUN * Creating an outline of the sun * Colouring the rectangle the makes the sun */ // Colouring the sun createSun( 500 , 30 , 80 , 80 ); // Outlining the sun createSun( 500 , 30 , 80 , 80 ); //--------------------------------------------------------------------------------- /* * TREE * Creating an outline of the tree trunk + the leaves of the tree * Tree trunk is made of rectangle while the leaves are made of a polygon * Colouring the rectangle and polygon that make up the tree trunk and leaves */ // Colouring and outlining the rectangle making up the tree trunk createTreeTrunk( 280 , 200 , 50 , 149 ); // Colouring and outlining the polygon making up the leaves of the tree createTree( 200 , 200 ); //--------------------------------------------------------------------------------- /* * GRASS * Creating an outline of a rectangle making up the grass / ground * Colouring in the rectangle green to make up grass */ // Colouring the rectangle making up the grass createGrass( 0 , 350 , 600 , 50 ); // Outlining the rectangle making up the grass createGrass( 0 , 350 , 600 , 50 ); //--------------------------------------------------------------------------------- /* * TEXT * Writing text * X, Y values determing it's position * Font used is "Garmant" */ // Writing "Hello World" writeText( "Hello World!" , 255 , 385 ); // Writing "Creeper" writeText( "Creeper?" , 150 , 235 ); // Writing "Awww mannn" writeText( "Awww mannn" , 155 , 275 ); //--------------------------------------------------------------------------------- Picture minecraftLandscape = new Picture(myImage); addObject(minecraftLandscape, 300 , 200 ); } public void createGrass( int x, int y, int width, int height) { myImage.setColor( new Color( 89 , 197 , 121 )); myImage.fillRect(x, y, width, height); myImage.setColor(Color.BLACK); myImage.drawRect(x, y, width, height); } public void background( int x, int y, int width, int height) { myImage.setColor( new Color( 0 , 162 , 232 )); myImage.fillRect(x, y, width, height); } public void writeText(String message, int x, int y) { myImage.setColor(Color.YELLOW); Font myFont = new Font( "Garmant" , true , true , 18 ); myImage.setFont(myFont); myImage.drawString(message,x ,y); } public void creatingClouds( int x, int y, int width, int height) { myImage.setColor(Color.WHITE); myImage.fillRect(x, y, width, height); myImage.setColor(Color.BLACK); myImage.drawRect(x, y, width, height); } public void drawingMobs( int x, int y, int width, int height) { myImage.setColor(Color.BLACK); myImage.drawRect(x, y, width, height); } public void colouringMobsRGB( int x, int y, int width, int height, int r, int g, int b) { myImage.setColor( new Color(r,g,b)); myImage.fillRect(x, y, width, height); } public void colouringMobsGeneric( int x, int y, int width, int height, Color c) { myImage.setColor(c); myImage.fillRect(x, y, width, height); } public void createSun( int x, int y, int width, int height) { myImage.setColor(Color.YELLOW); myImage.fillRect(x, y, width, height); myImage.setColor(Color.BLACK); myImage.drawRect(x, y, width, height); } public void createTree( int bottomLeftX, int bottomLeftY) { int change = 80 ; int change1 = 28 ; int change3 = 5 ; int change4 = 35 ; int change5 = 30 ; int change6 = 50 ; int [] xValues = {bottomLeftX, bottomLeftX, bottomLeftX + change, bottomLeftX + change, bottomLeftX + change* 2 - change1, bottomLeftX + change* 2 - change1, bottomLeftX + change* 3 - change5, bottomLeftX + change* 3 - change5}; int [] yValues = {bottomLeftY, bottomLeftY - change - change3, bottomLeftY - change - change3, bottomLeftY - change - change6, bottomLeftY - change - change6, bottomLeftY - change - change3, bottomLeftY - change - change3, bottomLeftY}; int points = 8 ; myImage.setColor( new Color( 34 , 177 , 76 )); myImage.fillPolygon(xValues,yValues,points); myImage.setColor(Color.BLACK); myImage.drawPolygon(xValues,yValues,points); } public void createTreeTrunk( int x, int y, int width, int height) { myImage.setColor( new Color( 185 , 122 , 87 )); myImage.fillRect(x, y, width, height); myImage.setColor(Color.BLACK); myImage.drawRect(x, y, width, height); } public void changingSize( int width, int height) { } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Picture here. * * @author (your name) * @version (a version number or a date) */ public class Picture extends Actor { public Picture(GreenfootImage myImage) { setImage(myImage); // Add your action code here. } } |