void draw(Graphics g) { int width = world.squareWidth(), height = world.squareHeight(); int x = this.column * width, y = this.row * height; g.setColor(this.color); g.fillRect(x, y, width, height); g.setColor(Color.WHITE); g.drawRect(x, y, width, height); g.setColor(Color.BLACK); }
private static void addSlices(World world, Float3 f) { int nx = f.getN3(); int ny = f.getN2(); int nz = f.getN1(); double dx = 1.0; double dy = 1.0; double dz = 1.0; double fx = 0.0; double fy = 0.0; double fz = 0.0; double lx = fx + (nx - 1) * dx; double ly = fy + (ny - 1) * dy; double lz = fz + (nz - 1) * dz; Sampling sx = new Sampling(nx, dx, fx); Sampling sy = new Sampling(ny, dy, fy); Sampling sz = new Sampling(nz, dz, fz); Point3 qmin = new Point3(fx, fy, fz); Point3 qmax = new Point3(lx, ly, lz); Axis[] axes = new Axis[] {Axis.X, Axis.Y, Axis.Z}; for (int iaxis = 0; iaxis < axes.length; ++iaxis) { AxisAlignedQuad aaq = new AxisAlignedQuad(axes[iaxis], qmin, qmax); AxisAlignedFrame aaf = aaq.getFrame(); ImagePanel ip = new ImagePanel(sz, sy, sx, f); ip.setColorModel(ColorMap.GRAY); System.out.println("clip min=" + ip.getClipMin() + " max=" + ip.getClipMax()); aaf.addChild(ip); world.addChild(aaq); } }
public void run() { while (true) { long d = System.currentTimeMillis() - lastTick; if (d > tickTime) { lastTick = System.currentTimeMillis(); world.tick(); } else { try { Thread.sleep(d); } catch (InterruptedException e) { // ignore } } } }
public void run() { // initialize variables double angRad = 0; int x = 0; int y = 0; mars.setPicture(new Picture("Proj01.jpg")); mars.getPicture().addMessage("Charles Combs", 10, 20); // this code does the turtle dancing seen in the penguin example joe.setName("joe"); joe.setBodyColor(Color.YELLOW); joe.setShellColor(Color.RED); joe.setPenColor(Color.YELLOW); joe.setPenWidth(3); joe.forward(); joe.turn(+90); joe.setPenColor(Color.RED); joe.setPenWidth(1); // at the top of the 100 pixel run, now red and one wide, facing east for (int ang = 180; ang < 274; ang += 1) { angRad = Math.toRadians(ang); x = (96) + (int) (Math.sin(angRad) * (96)); y = (100) + (int) (Math.cos(angRad) * (100)); joe.moveTo(x + 99, y + 46); } // end for loop joe.setPenColor(Color.GREEN); joe.setPenWidth(3); for (int ang = 274; ang < 361; ang += 1) { angRad = Math.toRadians(ang); x = (100) + (int) (Math.sin(angRad) * (100)); y = (100) + (int) (Math.cos(angRad) * (100)); joe.moveTo(x + 99, y + 38); } // end for loop joe.moveTo(197, 237); sue.setName("sue"); sue.setPenWidth(2); sue.setPenColor(Color.BLUE); sue.moveTo(237, 187); sue.setPenDown(false); sue.moveTo(277, 227); sue.setPenDown(true); sue.moveTo(317, 267); } // end run method
public void changeWorld(World world, String s, EntityPlayer entityplayer) { statFileWriter.func_27175_b(); statFileWriter.syncStats(); renderViewEntity = null; loadingScreen.printText(s); loadingScreen.displayLoadingString(""); sndManager.playStreaming(null, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F); if (theWorld != null) { theWorld.saveWorldIndirectly(loadingScreen); } theWorld = world; if (world != null) { playerController.func_717_a(world); if (!isMultiplayerWorld()) { if (entityplayer == null) { thePlayer = (EntityPlayerSP) world.func_4085_a(net.minecraft.src.EntityPlayerSP.class); } } else if (thePlayer != null) { thePlayer.preparePlayerToSpawn(); if (world != null) { world.entityJoinedWorld(thePlayer); } } if (!world.multiplayerWorld) { func_6255_d(s); } if (thePlayer == null) { thePlayer = (EntityPlayerSP) playerController.createPlayer(world); thePlayer.preparePlayerToSpawn(); playerController.flipPlayer(thePlayer); } thePlayer.movementInput = new MovementInputFromOptions(gameSettings); if (renderGlobal != null) { renderGlobal.changeWorld(world); } if (effectRenderer != null) { effectRenderer.clearEffects(world); } playerController.func_6473_b(thePlayer); if (entityplayer != null) { world.emptyMethod1(); } net.minecraft.src.IChunkProvider ichunkprovider = world.getIChunkProvider(); if (ichunkprovider instanceof ChunkProviderLoadOrGenerate) { ChunkProviderLoadOrGenerate chunkproviderloadorgenerate = (ChunkProviderLoadOrGenerate) ichunkprovider; int i = MathHelper.floor_float((int) thePlayer.posX) >> 4; int j = MathHelper.floor_float((int) thePlayer.posZ) >> 4; chunkproviderloadorgenerate.setCurrentChunkOver(i, j); } world.spawnPlayerWithLoadedChunks(thePlayer); if (world.isNewWorld) { world.saveWorldIndirectly(loadingScreen); } renderViewEntity = thePlayer; } else { thePlayer = null; } System.gc(); systemTime = 0L; }
@Override protected void paintComponent(Graphics graphics) { BufferedImage backImage = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D backGraphics = backImage.createGraphics(); BufferedImage frontImage = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D frontGraphics = frontImage.createGraphics(); BufferedImage particleImage = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D particleGraphics = particleImage.createGraphics(); Graphics2D graphics2D = (Graphics2D) graphics; graphics.setColor(Color.BLACK); graphics.fillRect(0, 0, getWidth(), getHeight()); graphics2D.translate(-cameraX, -cameraY); backGraphics.translate(-cameraX, -cameraY); frontGraphics.translate(-cameraX, -cameraY); particleGraphics.translate(-cameraX, -cameraY); for (int y = cameraY / 64; y < (cameraY / 64) + (getHeight() / 64) + 2; y++) { for (int x = cameraX / 64; x < (cameraX / 64) + (getWidth() / 64) + 2; x++) { Tile tile = world.getTileAt(x, y); if (tile != null) { backGraphics.drawImage( client.getTextureManager().getTexture("grass"), x * 64, y * 64, null); Unit unit = tile.getUnit(); if (unit != null) { if (unit instanceof Dragon) { BufferedImage texture; if (unit.getDX() > 0) { texture = currentDragonFrame == 0 ? client.getTextureManager().getTexture("dragon_right_1") : client.getTextureManager().getTexture("dragon_right_2"); } else if (unit.getDX() < 0) { texture = currentDragonFrame == 0 ? client.getTextureManager().getTexture("dragon_left_1") : client.getTextureManager().getTexture("dragon_left_2"); } else if (unit.getDY() > 0) { texture = currentDragonFrame == 0 ? client.getTextureManager().getTexture("dragon_down_1") : client.getTextureManager().getTexture("dragon_down_2"); } else if (unit.getDY() < 0) { texture = currentDragonFrame == 0 ? client.getTextureManager().getTexture("dragon_up_1") : client.getTextureManager().getTexture("dragon_up_2"); } else { texture = currentDragonFrame == 0 ? client.getTextureManager().getTexture("dragon_down_1") : client.getTextureManager().getTexture("dragon_down_2"); } frontGraphics.drawImage( texture, (x * 64) + unit.getXOffset(), (y * 64) + unit.getYOffset(), null); particleGraphics.setColor(Color.BLACK); if (unit.getAttackTarget() != null && ((abs(unit.getAttackTarget().getTile().getX() - unit.getTile().getX()) == 1 && unit.getAttackTarget().getTile().getY() == unit.getTile().getY()) || (abs(unit.getAttackTarget().getTile().getY() - unit.getTile().getY()) == 1 && unit.getAttackTarget().getTile().getX() == unit.getTile().getX()))) { int xStart = min(unit.getTile().getX(), unit.getAttackTarget().getTile().getX()); int xEnd = max(unit.getTile().getX(), unit.getAttackTarget().getTile().getX()); int yStart = min(unit.getTile().getY(), unit.getAttackTarget().getTile().getY()); int yEnd = max(unit.getTile().getY(), unit.getAttackTarget().getTile().getY()); Random random = new Random(); for (int pX = (xStart * 64) + 28; pX < (xEnd * 64) + 34; pX++) { for (int pY = (yStart * 64) + 28; pY < (yEnd * 64) + 34; pY++) { switch (random.nextInt(3)) { case 0: particleGraphics.setColor(Color.RED); break; case 1: particleGraphics.setColor(Color.ORANGE); break; case 2: particleGraphics.setColor(Color.YELLOW); break; } particleGraphics.fillOval( pX - 3 + random.nextInt(3), pY - 3 + random.nextInt(3), 4, 4); } } } } else if (unit instanceof Wall) { TextureManager textureManager = client.getTextureManager(); BufferedImage texture = textureManager.getTexture("tower"); int offset = 128; Tile upTile = unit.getTile().getAdjacent(0, -1); boolean up = upTile != null && upTile.getUnit() != null && upTile.getUnit() instanceof Wall && upTile.getUnit().isComplete(); Tile downTile = unit.getTile().getAdjacent(0, 1); boolean down = downTile != null && downTile.getUnit() != null && downTile.getUnit() instanceof Wall && downTile.getUnit().isComplete(); Tile leftTile = unit.getTile().getAdjacent(-1, 0); boolean left = leftTile != null && leftTile.getUnit() != null && leftTile.getUnit() instanceof Wall && leftTile.getUnit().isComplete(); Tile rightTile = unit.getTile().getAdjacent(1, 0); boolean right = rightTile != null && rightTile.getUnit() != null && rightTile.getUnit() instanceof Wall && rightTile.getUnit().isComplete(); if (unit.isComplete()) { if (up) { if (down) { if (left) { if (right) { texture = textureManager.getTexture("tower_wall_up_down_left_right"); } else { texture = textureManager.getTexture("tower_wall_up_down_left"); } } else if (right) { texture = textureManager.getTexture("tower_wall_up_down_right"); } else { texture = textureManager.getTexture("wall_ver"); offset = 64; } } else if (left) { if (right) { texture = textureManager.getTexture("tower_wall_up_left_right"); } else { texture = textureManager.getTexture("tower_wall_up_left"); } } else if (right) { texture = textureManager.getTexture("tower_wall_up_right"); } else { texture = textureManager.getTexture("tower_wall_up"); } } else if (down) { if (left) { if (right) { texture = textureManager.getTexture("tower_wall_down_left_right"); } else { texture = textureManager.getTexture("tower_wall_down_left"); } } else if (right) { texture = textureManager.getTexture("tower_wall_down_right"); } else { texture = textureManager.getTexture("tower_wall_down"); } } else if (left) { if (right) { texture = textureManager.getTexture("wall_hor"); offset = 64; } else { texture = textureManager.getTexture("tower_wall_left"); } } else if (right) { texture = textureManager.getTexture("tower_wall_right"); } } else { texture = textureManager.getTexture("wall_in_progress"); offset = 64; } frontGraphics.drawImage( texture, (x * 64) + unit.getXOffset(), (y * 64) + unit.getYOffset() - offset, null); } else if (unit instanceof Flag) { BufferedImage texture = null; if (currentFlagFrame == 0) texture = client.getTextureManager().getTexture("flag_1"); else if (currentFlagFrame == 1) texture = client.getTextureManager().getTexture("flag_2"); else if (currentFlagFrame == 2) texture = client.getTextureManager().getTexture("flag_3"); else if (currentFlagFrame == 3) texture = client.getTextureManager().getTexture("flag_4"); if (texture != null) frontGraphics.drawImage(texture, (x * 64), (y * 64) - 64, null); } } } } } int mouseTileX = ((cameraX - (int) getLocationOnScreen().getX() + (int) MouseInfo.getPointerInfo().getLocation().getX()) / 64); int mouseTileY = ((cameraY - (int) getLocationOnScreen().getY() + (int) MouseInfo.getPointerInfo().getLocation().getY()) / 64); Tile mouseTile = getWorld().getTileAt(mouseTileX, mouseTileY); if (mouseTile != null) { if (mouseTile.getUnit() == null) { if (client.getShopPanel().getSelectedItem() == null) { backGraphics.setColor(new Color(0F, 1F, 0F, 0.5F)); } else { backGraphics.setColor(new Color(0F, 0F, 1F, 0.5F)); } } else { backGraphics.setColor(new Color(1F, 0F, 0F, 0.5F)); } backGraphics.fillRect(mouseTileX * 64, mouseTileY * 64, 64, 64); if (mouseTile.getUnit() == null) { if (client.getShopPanel().getSelectedItem() == null) { backGraphics.setColor(Color.GREEN); } else { backGraphics.setColor(Color.BLUE); } } else { backGraphics.setColor(Color.RED); } backGraphics.drawRect( ((cameraX - (int) getLocationOnScreen().getX() + (int) MouseInfo.getPointerInfo().getLocation().getX()) / 64) * 64, ((cameraY - (int) getLocationOnScreen().getY() + (int) MouseInfo.getPointerInfo().getLocation().getY()) / 64) * 64, 64, 64); } graphics2D.translate(cameraX, cameraY); backGraphics.translate(cameraX, cameraY); frontGraphics.translate(cameraX, cameraY); particleGraphics.translate(cameraX, cameraY); graphics.drawImage(backImage, 0, 0, null); graphics.drawImage(frontImage, 0, 0, null); graphics.drawImage(particleImage, 0, 0, null); backGraphics.dispose(); frontGraphics.dispose(); particleGraphics.dispose(); backImage.flush(); frontImage.flush(); particleImage.flush(); }