/** Overrides <code>Graphics.clearRect</code>. */ public void clearRect(int x, int y, int width, int height) { DebugGraphicsInfo info = info(); if (debugLog()) { info().log(toShortString() + " Clearing rect: " + new Rectangle(x, y, width, height)); } if (isDrawingBuffer()) { if (debugBuffered()) { Graphics debugGraphics = debugGraphics(); debugGraphics.clearRect(x, y, width, height); debugGraphics.dispose(); } } else if (debugFlash()) { Color oldColor = getColor(); int i, count = (info.flashCount * 2) - 1; for (i = 0; i < count; i++) { graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor); graphics.clearRect(x, y, width, height); Toolkit.getDefaultToolkit().sync(); sleep(info.flashTime); } graphics.setColor(oldColor); } graphics.clearRect(x, y, width, height); }
protected synchronized void paintComponent(Graphics gc) { Dimension d = getSize(); gc.clearRect(0, 0, d.width, d.height); if (tmpChar[0] == 0) return; int charWidth = fm.charWidth(tmpChar[0]); gc.drawChars(tmpChar, 0, 1, curX++, fontHeight); }
public void draw() { Graphics g = environment.getScreenHandler().getCurrentGraphics(); g.clearRect( 0, 0, environment.getScreenHandler().getWidth(), environment.getScreenHandler().getHeight()); fps.update(); fps.draw(g, Color.red, 10, 10); g.setColor(Color.white); g.drawString(model.getInfoString(), 50, 10); g.setColor(Color.white); if (cheatMode) { g.setColor(Color.white); g.drawString("CHEATMODE", 80, 10); } g.setClip(cont.getOffsetX(), cont.getOffsetY(), cont.getDrawingSizeX(), cont.getDrawingSizeY()); if (model.isInitialized()) { model.getMap().draw(g, 0); model.getMyCar().draw(g, 0); CarDrawInterface cars[] = model.getOpponentCars(); for (int i = 0; i < cars.length; i++) { cars[i].draw(g, 0); } if (!model.isStarted()) { g.setColor(Color.white); g.clearRect(50, 50, 400, 150); g.drawString("Accellerate to start game", 100, 100); if (model.isMultiplayer()) { if (model.getNoOfHumanCars() > 1) { g.drawString( "Currently " + (model.getNoOfHumanCars() - 1) + " other human player(s) connected", 100, 120); } else { g.drawString("Only you and computer contolled cars are connected", 100, 120); } g.drawString("You can wait for more human players to connect", 100, 140); } } } else { g.setColor(Color.white); g.clearRect(50, 50, 400, 150); g.drawString("Loading game data, please wait...", 100, 100); } }
public void paint(Graphics g) { if (loadflag && (!runflag)) { g.clearRect(0, 0, 530, 330); Graphics2D g2D = (Graphics2D) g; g2D.translate(0, 50); // 设置图像左上角为当前点 g.drawImage(iImage, 0, 0, null); // 画输入图 } }
public void update(Graphics g) { flags |= IS_IN_UPDATE; // clear and draw yourself g.clearRect(0, 0, width, height); paint(g); flags &= ~IS_IN_UPDATE; }
/** * Updates the canvas in response to a request to <code>repaint()</code> it. The canvas is cleared * with the current background colour, before <code>paint()</code> is called to add the new * contents. Subclasses which override this method should either call this method via <code> * super.update(graphics)</code> or re-implement this behaviour, so as to ensure that the canvas * is clear before painting takes place. * * @param graphics the graphics context. */ public void update(Graphics graphics) { Dimension size; /* Clear the canvas */ size = getSize(); graphics.clearRect(0, 0, size.width, size.height); /* Call the paint method */ paint(graphics); }
/** Clear all contents */ public void clear() { if (gr == null) return; gr.clearRect(0, 0, getSize().width, getSize().height); repaint(); if (state != null) { synchronized (state) { state.clear(); } } }
public void init() { Graphics g = getGraphics(); Rectangle b = getBounds(); g.clearRect(0, 0, b.width, b.height); // last_data_pos = ((NslVariable)variable_list.elementAt(0)).last_data_pos; // data = ((NslVariable)variable_list.elementAt(0)).data; paint(g); // draw_time = -1; }
public void paint(Graphics g) { if (iImage != null) { g.clearRect(0, 0, 260, 350); g.drawImage(iImage, 5, 50, null); g.drawString("pic1", 120, 320); } }
@Override protected void paintComponent(Graphics g) { g.clearRect(0, 0, getWidth(), getHeight()); g.setColor(Color.BLACK); g.drawRect(CELL_SIZE, CELL_SIZE, maze.width * CELL_SIZE, maze.height * CELL_SIZE); drawWalls(g, maze); boolean even = true; PathCell pathIt = path.first; while (pathIt != null) { even = !even; g.setColor(even ? Color.GREEN : Color.CYAN); g.fillRect( CELL_SIZE + pathIt.node.x * CELL_SIZE + 1, CELL_SIZE + pathIt.node.y * CELL_SIZE + 1, pathIt.node.width * CELL_SIZE - 1, pathIt.node.height * CELL_SIZE - 1); MazeNode door = pathIt.doorNode; g.setColor(Color.YELLOW); if (door != null) { if (door.division == Division.VERTICAL) { g.drawLine( CELL_SIZE + door.doorX * CELL_SIZE, CELL_SIZE + door.doorY * CELL_SIZE + 1, CELL_SIZE + door.doorX * CELL_SIZE, CELL_SIZE + (door.doorY + 1) * CELL_SIZE - 1); } else { g.drawLine( CELL_SIZE + door.doorX * CELL_SIZE + 1, CELL_SIZE + door.doorY * CELL_SIZE, CELL_SIZE + (door.doorX + 1) * CELL_SIZE - 1, CELL_SIZE + door.doorY * CELL_SIZE); } } pathIt = pathIt.next; } g.setColor(Color.ORANGE); g.fillRect( CELL_SIZE + sx * CELL_SIZE + 2, CELL_SIZE + sy * CELL_SIZE + 2, CELL_SIZE - 3, CELL_SIZE - 3); g.setColor(Color.RED); g.fillRect( CELL_SIZE + dx * CELL_SIZE + 2, CELL_SIZE + dy * CELL_SIZE + 2, CELL_SIZE - 3, CELL_SIZE - 3); }
public void paint(Graphics g) { System.out.println("paint"); Graphics2D g2d = (Graphics2D) g; Point1 p1, p2; n = paintInfo.size(); if (toolFlag == 2) g2d.clearRect(0, 0, getSize().width - 100, getSize().height - 100); // 清除 for (int i = 0; i < n - 1; i++) { p1 = (Point1) paintInfo.elementAt(i); p2 = (Point1) paintInfo.elementAt(i + 1); size = new BasicStroke(p1.boarder, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); g2d.setColor(p1.col); g2d.setStroke(size); if (p1.tool == p2.tool) { switch (p1.tool) { case 0: // 画笔 Line2D line1 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y); g2d.draw(line1); break; case 1: // 橡皮 g.clearRect(p1.x, p1.y, p1.boarder, p1.boarder); break; case 3: // 画直线 Line2D line2 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y); g2d.draw(line2); break; case 4: // 画圆 Ellipse2D ellipse = new Ellipse2D.Double(p1.x, p1.y, Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y)); g2d.draw(ellipse); break; case 5: // 画矩形 Rectangle2D rect = new Rectangle2D.Double(p1.x, p1.y, Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y)); g2d.draw(rect); break; case 6: // 截断,跳过 i = i + 1; break; default: } // end switch } // end if } // end for }
public void paintComponent(Graphics frontBuffer) { // Clear the back buffer backBuffer.clearRect(this.getX(), this.getY(), this.getWidth(), this.getHeight()); // Draw all objects to the back buffer in order from back-to-front paintBackground(); paintEntities(); // Draw the back buffer onto the front buffer all at once to avoid flickering from repeated draw // commands frontBuffer.drawImage(backBufferImage, this.getX(), this.getY(), this); }
/** * Called to recursively paint the check box for the specified item. * * @param item row number * @param g graphics object to paint. * @param bookmark to check selected value. * @return the next row number to paint. */ public int paintCheckbox(final int item, final Graphics g, final Bookmark bookmark) { int nextItem = item + 1; if (bookmark != null) { final Rectangle checkboxBounds = getCheckboxBounds(item, bookmark, getDepthMap().get(bookmark)); final int yCheckboxMidPoint = checkboxBounds.y + (checkboxBounds.height / 2); final int xCheckboxMidPoint = checkboxBounds.x + (checkboxBounds.width / 2); final Enumeration e = bookmark.elements(); if (e.hasMoreElements()) { // clear any lines crossing through the checkbox. g.clearRect( checkboxBounds.x, checkboxBounds.y, checkboxBounds.width, checkboxBounds.height); // draw box around checkbox g.drawRect(checkboxBounds.x, checkboxBounds.y, checkboxBounds.width, checkboxBounds.height); // draw dash inside checkbox g.drawLine( checkboxBounds.x + 2, yCheckboxMidPoint, (checkboxBounds.x + checkboxBounds.width) - 2, yCheckboxMidPoint); boolean drawPlus = true; do { final Bookmark child = (Bookmark) e.nextElement(); final Bookmark next = getBookmark(nextItem); if (child != next) { break; } drawPlus = false; nextItem = paintCheckbox(nextItem, g, child); } while (e.hasMoreElements()); if (drawPlus) { g.drawLine( xCheckboxMidPoint, checkboxBounds.y + 2, xCheckboxMidPoint, (checkboxBounds.y + checkboxBounds.height) - 2); } } } return nextItem; }
public void update(Graphics g) { Dimension newSize = getSize(); if (size.equals(newSize)) { // Erase old box g.setColor(getBackground()); g.drawRect(mx, my, (size.width / 10) - 1, (size.height / 10) - 1); } else { size = newSize; g.clearRect(0, 0, size.width, size.height); } // Calculate new position mx = (int) (Math.random() * 1000) % (size.width - (size.width / 10)); my = (int) (Math.random() * 1000) % (size.height - (size.height / 10)); paint(g); }
private void displayGameOver(Graphics g) { g.clearRect(100, 100, 350, 350); g.drawString("GAME OVER", 150, 150); String textScore = score.getStringScore(); String textHighScore = score.getStringHighScore(); String newHighScore = score.newHighScore(); g.drawString("SCORE = " + textScore, 150, 250); g.drawString("HIGH SCORE = " + textHighScore, 150, 300); g.drawString(newHighScore, 150, 400); g.drawString("press a key to play again", 150, 350); g.drawString("Press q to quit the game", 150, 400); }
public void paint(Graphics g) { g.clearRect(0, 25, width, height); int[] coords = new int[2]; for (int i = 0; i < map.charMap.size(); i++) { for (int j = 0; j < map.charMap.get(i).size(); j++) { if (map.charMap.get(i).get(j) == 'p' || map.charMap.get(i).get(j) == 'k') { coords[0] = i; coords[1] = j; } } } int antx = coords[0] - 14; int anty = coords[1] - 17; gress = tk.getImage(getClass().getResource("graphics/gress.jpg")); viking = tk.getImage(getClass().getResource("graphics/vikings.jpg")); village = tk.getImage(getClass().getResource("graphics/village.gif")); marked = tk.getImage(getClass().getResource("graphics/marked.gif")); bridge = tk.getImage(getClass().getResource("graphics/bridge.gif")); vikingOnBridge = tk.getImage(getClass().getResource("graphics/vikingOnBridge.gif")); tree = tk.getImage(getClass().getResource("graphics/tree.gif")); stone = tk.getImage(getClass().getResource("graphics/stone.gif")); destroyedVillage = tk.getImage(getClass().getResource("graphics/destroyedVillage.gif")); for (int i = 25, x = antx; i < height; i += 20, x++) { for (int j = 0, y = anty; j < width; j += 20, y++) { if (map.charMap.get(x).get(y) == 'p') g.drawImage(viking, j, i, this); else if (map.charMap.get(x).get(y) == 'k') g.drawImage(vikingOnBridge, j, i, this); else if (map.charMap.get(x).get(y) == 'g') g.drawImage(gress, j, i, this); else if (map.charMap.get(x).get(y) == 'l') g.drawImage(village, j, i, this); else if (map.charMap.get(x).get(y) == 'm') g.drawImage(marked, j, i, this); else if (map.charMap.get(x).get(y) == 't') g.drawImage(tree, j, i, this); else if (map.charMap.get(x).get(y) == 's') g.drawImage(stone, j, i, this); else if (map.charMap.get(x).get(y) == 'c') g.drawImage(bridge, j, i, this); else if (map.charMap.get(x).get(y) == '0') g.drawImage(destroyedVillage, j, i, this); else if (map.charMap.get(x).get(y) == 'v') { g.setColor(Color.blue); g.fillRect(j, i, 20, 20); g.setColor(Color.WHITE); } } } }
public void update(double slowdown, double arrival) { freeway.update(slowdown, arrival); if (buffer == null) { xsize = size().width; ysize = size().height; buffer = createImage(xsize, ysize); } Graphics bg = buffer.getGraphics(); freeway.paint(bg, row, XDOTDIST, DOTSIZE); if (row < ysize - 2 * DOTSIZE + 1) row += DOTSIZE; else { bg.copyArea(0, DOTSIZE, xsize, ysize - DOTSIZE, 0, -DOTSIZE); bg.clearRect(0, ysize - DOTSIZE, xsize, DOTSIZE); } bg.dispose(); repaint(); }
public void paint(Graphics g) { g.clearRect(0, 0, 800, 640); Toolkit tk = Toolkit.getDefaultToolkit(); System.out.println("Loading: " + loading); System.out.println("GameOver:" + gameOver); if (gameOver) { // g.drawString("Game over! \n(press space to restart)", 400, 320); g.drawImage(tk.getImage(getClass().getResource("graphics/defeat.gif")), 0, 0, 800, 640, this); } else if (loading) { System.out.println("Skulle tegnet loadingscreen nå"); g.drawImage( tk.getImage(getClass().getResource("graphics/loading.gif")), 0, 0, 800, 640, this); } /* else if(starting){ g.drawString("Starter..." , 500, 320); }*/ }
public void paintComponent(Graphics g) { // display if (isFirst) { myWidth = getWidth(); myHeight = getHeight(); define(); isFirst = false; } g.clearRect(0, 0, getWidth(), getHeight()); room.draw(g); // draw map store.draw(g); // draw sidebar // b.draw(g); theMinion.draw(g); if (to != null) { // tower selected movement to.draw(g, xval, yval, to); } for (Tower i : tplace) { i.draw(g, i); } }
private void displayGameGrid(Graphics g) { int maxX = SnakeGame.xPixelMaxDimension; int maxY = SnakeGame.yPixelMaxDimension; int squareSize = SnakeGame.squareSize; SnakeGame.snakeFrame.setBackground(Color.BLUE); g.clearRect(0, 0, maxX, maxY); g.setColor(Color.WHITE); // Draw grid - horizontal lines for (int y = 0; y <= maxY; y += squareSize) { g.drawLine(0, y, maxX, y); } // Draw grid - vertical lines for (int x = 0; x <= maxX; x += squareSize) { g.drawLine(x, 0, x, maxY); } }
public void paint(Graphics g) { // prepare screen setBackground(Color.white); offscreenG.setColor(Color.black); offscreenG.clearRect(0, 0, size().width, size().height); // Draw control points and polygon if (poly) { for (int i = 0; i < numpoints; i++) { offscreenG.fillOval(coordlist[i].x - 2, coordlist[i].y - 2, 4, 4); if (numpoints > 1 && i < (numpoints - 1)) offscreenG.drawLine( coordlist[i].x, coordlist[i].y, coordlist[i + 1].x, coordlist[i + 1].y); } } // Calculate and draw bezier curve if (numpoints == 4) { double x1, x2, y1, y2; x1 = coordlist[0].x; y1 = coordlist[0].y; for (t = k; t <= 1 + k; t += k) { // use Berstein polynomials x2 = (coordlist[0].x + t * (-coordlist[0].x * 3 + t * (3 * coordlist[0].x - coordlist[0].x * t))) + t * (3 * coordlist[1].x + t * (-6 * coordlist[1].x + coordlist[1].x * 3 * t)) + t * t * (coordlist[2].x * 3 - coordlist[2].x * 3 * t) + coordlist[3].x * t * t * t; y2 = (coordlist[0].y + t * (-coordlist[0].y * 3 + t * (3 * coordlist[0].y - coordlist[0].y * t))) + t * (3 * coordlist[1].y + t * (-6 * coordlist[1].y + coordlist[1].y * 3 * t)) + t * t * (coordlist[2].y * 3 - coordlist[2].y * 3 * t) + coordlist[3].y * t * t * t; // draw curve offscreenG.drawLine((int) x1, (int) y1, (int) x2, (int) y2); x1 = x2; y1 = y2; } } g.drawImage(offscreenImg, 0, 0, this); }
public void paint(Graphics g) { g = this.startPaint(g); int width = this.getSize().width; int height = this.getSize().height; g.clearRect(0, 0, width, height); int cell_size, xstart, ystart; double panel_aspect_ratio = (double) width / height; double grid_aspect_ratio = (double) grid[0].length / grid.length; if (panel_aspect_ratio > grid_aspect_ratio) { cell_size = (int) ((double) height / grid.length + 0.5); xstart = (int) (width / 2 - (grid[0].length / 2.0 * cell_size + 0.5)); ystart = 0; } else { cell_size = (int) ((double) width / grid[0].length + 0.5); xstart = 0; ystart = (int) (height / 2 - (grid.length / 2.0 * cell_size + 0.5)); } if (paint_background) { g.setColor( BACKGROUND_COLORS[ (num_rows_deleted / DELETED_ROWS_PER_LEVEL) % BACKGROUND_COLORS.length]); g.fillRect(xstart, ystart, COLUMNS * cell_size, ROWS * cell_size); } for (int i = 0; i < grid.length; i++) { for (int j = 0; j < grid[0].length; j++) { if (grid[i][j] != EMPTY) { g.setColor(PIECE_COLORS[grid[i][j]]); int x = xstart + j * cell_size; int y = ystart + i * cell_size; g.fill3DRect(x, y, cell_size, cell_size, true); } } } this.endPaint(); }
@Override // Paints circles to the canvas, according to the parameters X, Y, Color, isFill, as declared by // the prepareCircle method; public void paint(Graphics canvas) { // Clear the canvas for future painting; canvas.clearRect(0, 0, canvas.getWidth(), canvas.getHeight()); // Prepares all of the circles to print to the screen when the program is initialized; if (!isFirstTime) { for (int i = 0; i < nCircles; i++) { prepareCircle(canvas, i); } isFirstTime = true; } // Moves the least recently adjusted circle to a new random location with a new random color; else { prepareCircle(canvas, currentCircle); } // Paints the circles to the screen; Multiple for loops ensure that the most recently painted // circles remain on top; for (int i = currentCircle + 1; i < nCircles; i++) { paintCircle(canvas, i); } for (int i = 0; i <= currentCircle; i++) { paintCircle(canvas, i); } // Pushes currentCircle forward through the Arrays; resets currentCircle at the end of the // cycle; currentCircle++; if (currentCircle == nCircles) { currentCircle = 0; } }
private void displayGameWon(Graphics g) { // TODO Replace this with something really special! g.clearRect(100, 100, 350, 350); g.drawString("YOU WON SNAKE!!!", 150, 150); }
public void paint(Graphics g) { if (!start & !start2) { reg.hide(); end.hide(); if (!lose) { if (norm) { if (!flea & (int) (Math.random() * 5000) == 0) { flea = true; fleaX = 10 * (int) (Math.random() * 29); fleaY = 0; fleaSize = 10; } if (spidNum <= 10) { if (spidNum <= level - 1 & (int) (Math.random() * 500) == 0) { if ((int) (Math.random() * 2) == 0) spid[findEmpt(spid)][0] = 0; else spid[findEmpt(spid)][0] = 290; spid[findEmpt(spid)][1] = 300 + (int) (Math.random() * 50); spid[findEmpt(spid)][2] = (int) (Math.random() * 6); spidNum++; } } if (!scorp & level >= 6 & (int) (Math.random() * 10000) == 0) { scorp = true; scorpY = 10 * (int) (Math.random() * 29); scorpX = 0; } } else { int rate = 200 + (dif * 100); rate = ((200 + (dif * 100)) - ((level - 1) * 20)); if (rate < 100) rate = 100; for (int k = 0; k < centNum; k++) if (cent[k][2] != -1) if (centFire[k][1] == -1 & (int) (Math.random() * rate) == 0) { if (cent[k][2] == 0) centFire[k][0] = cent[k][0]; if (cent[k][2] == 1 || cent[k][2] == -2) centFire[k][0] = cent[k][0]; centFire[k][1] = cent[k][1]; } } buf.clearRect(0, 0, dimX, dimY); drawYou(); if (fire) drawFire(); if (!norm) drawCentFire(); drawMush(); drawCent(); if (norm) { drawSpider(); if (flea) drawFlea(); if (scorp) drawScorpion(); } checkHit(); drawStatus(); all.drawImage(img, 0, 0, this); if (move) run(); } else { buf.clearRect(0, 0, dimX, dimY); drawYou(); if (fire) drawFire(); if (!norm) drawCentFire(); drawMush(); drawCent(); if (flea & norm) drawFlea(); if (norm) drawSpider(); checkHit(); drawStatus(); buf.setColor(Color.black); buf.drawString("YOU LOSE!", 125, 200); all.drawImage(img, 0, 0, this); if (score > high || score > endHigh[dif]) { who.show(); who.setText("High Score!"); who.setLocation(100, 400); who.setSize(100, 20); } } } if (start) { end.setLocation(70, 180); reg.setLocation(70, 200); g.setColor(Color.black); g.drawString("CENTIPEDE", 120, 20); g.drawString("Hit ENTER to select the version", 50, 170); g.setColor(Color.white); g.fillOval(80, 208, 10, 10); g.fillOval(90, 248, 10, 10); } if (start2) { end.hide(); reg.hide(); hard.show(); hard.setSize(15, 20); hard.setLocation(140, 200); g.drawString("select difficulty (1-5, 1 being hardest)", 50, 180); } }
/** Draw all the game graphics */ public void draw() { Graphics g = environment.getScreenHandler().getCurrentGraphics(); g.clearRect( 0, 0, environment.getScreenHandler().getWidth(), environment.getScreenHandler().getHeight()); int gameSizeX = (contAllowed.getSizeX() + contNotAllowed.getSizeX() + 3) * blockSize + 2; int gameSizeY = contAllowed.getSizeY() * blockSize + 2; g.setColor(Color.white); g.drawString( "Allowed:", contAllowed.getDrawingPositionX(0), contAllowed.getDrawingPositionY(0) - 3); g.drawString( "Not allowed:", contNotAllowed.getDrawingPositionX(0), contNotAllowed.getDrawingPositionY(0) - 3); g.setColor(Color.blue); g.drawRect( contAllowed.getDrawingPositionX(0), contAllowed.getDrawingPositionY(0), contAllowed.getSizeX() * contAllowed.getSquareSize(), contAllowed.getSizeY() * contAllowed.getSquareSize()); g.drawRect( contNotAllowed.getDrawingPositionX(0), contNotAllowed.getDrawingPositionY(0), contNotAllowed.getSizeX() * contNotAllowed.getSquareSize(), contNotAllowed.getSizeY() * contNotAllowed.getSquareSize()); if (blocksAllowed != null) { for (int i = 0; i < blocksAllowed.length; i++) { blocksAllowed[i].draw(g); } } if (blocksNotAllowed != null) { for (int i = 0; i < blocksNotAllowed.length; i++) { blocksNotAllowed[i].draw(g); } } if (selectedBlock != null) { g.setColor(Color.white); BlockContainerInterface cont; if (selectedAllowed) { cont = contAllowed; } else { cont = contNotAllowed; } g.drawRect( selectedBlock.getMovingDrawingPosX(), selectedBlock.getMovingDrawingPosY(), cont.getSquareSize(), cont.getSquareSize()); } g.setColor(Color.white); int rightColumnX = contNotAllowed.getDrawingPositionX(0) + contNotAllowed.getSizeX() * blockSize + 10; g.drawString("Number of empty blocks:", rightColumnX, 100 + 15); g.drawString("Number of start blocks:", rightColumnX, 100 + 40); g.drawString("Initial time until water:", rightColumnX, 100 + 65); g.drawString("Initial water speed:", rightColumnX, 100 + 90); g.drawString("Initial blocks to fill:", rightColumnX, 100 + 115); rightColumnX = offsetX + gameSizeX + 20; g.setColor(Color.red); g.drawString("by Erland Isaksson", rightColumnX, offsetY + gameSizeY); environment.getScreenHandler().paintComponents(g); }
public void keyPressed(KeyEvent e) { if (e.getSource() == hard & e.getKeyCode() != e.VK_ENTER) if (hard.getText().length() > 0) hard.setText(""); if (start) { if (e.getKeyCode() == e.VK_ENTER) { if (end.getState()) { norm = false; start2 = true; hard.show(); hard.setText(""); all.clearRect(0, 0, dimX, dimY); } if (reg.getState()) norm = true; start = false; } repaint(); } else { if (dir == -1) { if (e.getKeyCode() == e.VK_LEFT) dir = 0; if (e.getKeyCode() == e.VK_UP) dir = 1; if (e.getKeyCode() == e.VK_RIGHT) dir = 2; if (e.getKeyCode() == e.VK_DOWN) dir = 3; } if (dir == 0) { if (e.getKeyCode() == e.VK_UP) dir2 = 1; if (e.getKeyCode() == e.VK_RIGHT) dir2 = 2; if (e.getKeyCode() == e.VK_DOWN) dir2 = 3; } else if (dir == 1) { if (e.getKeyCode() == e.VK_LEFT) dir2 = 0; if (e.getKeyCode() == e.VK_RIGHT) dir2 = 2; if (e.getKeyCode() == e.VK_DOWN) dir2 = 3; } else if (dir == 2) { if (e.getKeyCode() == e.VK_LEFT) dir2 = 0; if (e.getKeyCode() == e.VK_UP) dir2 = 1; if (e.getKeyCode() == e.VK_DOWN) dir2 = 3; } else if (dir == 3) { if (e.getKeyCode() == e.VK_LEFT) dir2 = 0; if (e.getKeyCode() == e.VK_UP) dir2 = 1; if (e.getKeyCode() == e.VK_RIGHT) dir2 = 2; } repaint(); if (e.getKeyCode() == e.VK_SPACE & !fire) { fire = true; fireX = youX + 5; fireY = youY - 5; } if (e.getKeyCode() == e.VK_P) { if (move) move = false; else move = true; } if (e.getKeyCode() == e.VK_N) { lose = false; flea = false; score = 0; level = 1; lives = 3; setup(); } if (e.getKeyCode() == e.VK_T) { buf.clearRect(0, 0, dimX, dimY); all.drawImage(img, 0, 0, this); start = true; lose = false; score = 0; level = 1; lives = 3; reg.show(); end.show(); setup(); repaint(); } } }
public void paint(Graphics g) // function that puts everything on the screen { Graphics2D scene = (Graphics2D) g; // Not really sure what this is. Blame Victor // use scene to draw the background scene.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.clearRect(0, 0, SCREENWIDTH, SCREENHEIGHT); // Clears the screen Font q = new Font( "Source Sans Pro", Font.PLAIN, 40); // Makes the font we use for options and story text g.setFont(q); // Sets the default font g.setColor(Color.white); if (state == 1) // Story text { drawTag(g); g.drawImage(textBox, 0, 0, null); // draw the story boxes Font n = new Font("Source Sans Pro", Font.BOLD, 48); // Makes the font for the names g.setFont(n); // Sets the name font scene.drawString(nameC, 53, 435); // Draws the current name g.setFont(q); // sets the quote font fm = g.getFontMetrics(); ArrayList<String> lines = new ArrayList<String>(); String line = ""; for (int i = 0; i < quoteC.length(); i++) { line += quoteC.charAt(i); if (fm.stringWidth(line) > 1180) { String lineCopy = line; line = line.substring(0, lineCopy.lastIndexOf(' ')); i -= lineCopy.length() - lineCopy.lastIndexOf(' ') - 1; lines.add(line); line = ""; } } lines.add(line); for (int i = 0; i < lines.size(); i++) { scene.drawString(lines.get(i), 40, 535 + 65 * i); } } else if (state == 2) // Draws the options { scene.drawImage(bg, screenShakeX, screenShakeY, null); scene.drawImage(obox, screenShakeX, screenShakeY, null); // options thing scene.drawString(options.get(0), 220, 255); scene.drawString(options.get(1), 220, 375); scene.drawString(options.get(2), 220, 495); } else if (state == 3) // Game is over { scene.drawImage(oldbg, screenShakeX, screenShakeY, null); float opacity = fadeCounter / FADETIMELIMIT; if (opacity > 1.0f) opacity = 1.0f; scene.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity)); scene.drawImage(bg, screenShakeX, screenShakeY, null); // draws the background image scene.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); scene.drawString("The end", 40, 520); // End screen } }
public void paint(Graphics g) { // int numDoors=0; int rX = player.getRelativeX(); int rY = player.getRelativeY(); boolean notInBuilding = true; bufferGraphics.clearRect(0, 0, dim.width, dim.width); bufferGraphics.setColor(Color.WHITE); r2.setLocation(20 + rX, 20 + rY); // Iterator<Objects> iterator1 = entities.iterator();//size is the last index, therefore it // starts at the end // while(iterator1.hasNext()){ // iterator1.next().update(rX, rY); // bufferGraphics.drawImage(iterator1.next().image, iterator1.next().blockX+rX, // iterator1.next().blockX+rY, null); // } for (int x = 0; x < buildings.size(); x++) { buildings.get(x).update(rX, rY); player.onDoor(player.r, buildings.get(x).door); player.collideOn(player.r, buildings.get(x)); if (player.inHouse(player.r, buildings.get(x).inside)) { notInBuilding = false; } // if(notInBuilding){ // bufferGraphics.drawImage(buildings.get(x).image, // buildings.get(x).blockX+rX,buildings.get(x).blockY+rY, null); // }else{ // bufferGraphics.drawImage(buildings.get(x).innerImage, // buildings.get(x).blockX+rX,buildings.get(x).blockY+rY, null); // } // bufferGraphics.fillRect(entities.get(x).bounds.x, entities.get(x).bounds.y, // entities.get(x).bounds.width, entities.get(x).bounds.height); } bufferGraphics.setFont(new Font("Arial", Font.PLAIN, 20)); // String m1 = new Boolean(player.canMove('w')).toString(); bufferGraphics.drawString(message, 0, 170); // bufferGraphics.fillRect(r2.x, r2.y, r2.width, r2.height); // player.collideOn(player.r, r2); // ***Image log1 = new ImageIcon(getClass().getResource("logTest.png")).getImage(); // ***bufferGraphics.drawImage(log1, (int)r2.getX(), (int)r2.getY(), null); // bufferGraphics.drawLine((int)player.N.getX1(), (int)player.N.getY1(), (int)player.N.getX2(), // (int)player.N.getY2()); // bufferGraphics.drawLine((int)player.E.getX1(), (int)player.E.getY1(), (int)player.E.getX2(), // (int)player.E.getY2()); // bufferGraphics.drawLine((int)player.S.getX1(), (int)player.S.getY1(), (int)player.S.getX2(), // (int)player.S.getY2()); // bufferGraphics.drawLine((int)player.W.getX1(), (int)player.W.getY1(), (int)player.W.getX2(), // (int)player.W.getY2()); // bufferGraphics.setColor(Color.RED); // bufferGraphics.drawLine((int)player.NI.getX1(), (int)player.NI.getY1(), // (int)player.NI.getX2(), (int)player.NI.getY2()); // bufferGraphics.drawLine((int)player.EI.getX1(), (int)player.EI.getY1(), // (int)player.EI.getX2(), (int)player.EI.getY2()); // bufferGraphics.drawLine((int)player.SI.getX1(), (int)player.SI.getY1(), // (int)player.SI.getX2(), (int)player.SI.getY2()); // bufferGraphics.drawLine((int)player.WI.getX1(), (int)player.WI.getY1(), // (int)player.WI.getX2(), (int)player.WI.getY2()); if (notInBuilding) { Image thebg = new ImageIcon(getClass().getResource("grassbackingdev.png")).getImage(); bufferGraphics.drawImage(thebg, 0 + rX, 0 + rY, null); } player.update(); int setX = Math.abs(player.relativeX); int setY = Math.abs(player.relativeY); if (player.relativeX > 0) { setX = -setX; } if (player.relativeY > 0) { setY = -setY; } if (notInBuilding) { for (int x = 0; x < entities.size(); x++) { entities.get(x).update(rX, rY); bufferGraphics.drawImage( entities.get(x).image, entities.get(x).blockX + rX, entities.get(x).blockY + rY, null); player.collideOn(player.r, entities.get(x)); if (entities.get(x).health <= 0) { if (entities.get(x).material == "Wood") wood += entities.get(x).matsReturn; if (entities.get(x).material == "Stone") stone += entities.get(x).matsReturn; entities.remove(x); } // bufferGraphics.fillRect(entities.get(x).bounds.x, entities.get(x).bounds.y, // entities.get(x).bounds.width, entities.get(x).bounds.height); } } for (int x = 0; x < buildings.size(); x++) { if (notInBuilding) { bufferGraphics.drawImage( buildings.get(x).image, buildings.get(x).blockX + rX, buildings.get(x).blockY + rY, null); } else { bufferGraphics.drawImage( buildings.get(x).innerImage, buildings.get(x).blockX + rX, buildings.get(x).blockY + rY, null); } } if (notInBuilding) { for (int x = 0; x < npcArray.size(); x++) { for (int e = 0; e < entities.size(); e++) { npcArray.get(x).detectEntities(entities.get(e)); if (entities.get(e).health <= 0) { entities.remove(e); } } npcArray.get(x).update(rX, rY, setX + 92, setY + 82); bufferGraphics.drawImage( npcArray.get(x).graphic, npcArray.get(x).npcX + rX, npcArray.get(x).npcY + rY, null); if (npcArray.get(x).isDead()) { npcArray.remove(x); } else if (npcArray.get(x).hitBox.intersects(player.r)) { player.health -= 25; npcArray.remove(x); } } } for (int x = 0; x < playerAttack.size(); x++) { playerAttack.get(x).update(rX, rY); bufferGraphics.drawImage( playerAttack.get(x).graphic, playerAttack.get(x).currentX + rX, playerAttack.get(x).currentY + rY, null); for (int y = 0; y < npcArray.size(); y++) { if (playerAttack.get(x).hitBox.intersects(npcArray.get(y).hitBox)) { npcArray.get(y).health -= 25; playerAttack.get(x).hasHit = true; } } if (playerAttack.get(x).isDead()) { playerAttack.remove(x); } } player.notOnDoor = true; if (player.moving) { bufferGraphics.drawImage( player.getImage().getImage(), player.getCharx(), player.getChary(), null); // TODO } else { bufferGraphics.drawImage(player.getIdle(), player.getCharx(), player.getChary(), null); } if (Ghosting) { if (player.face == 1) { bufferGraphics.drawImage(player.getResource(resource), 104, 87, null); // EAST } if (player.face == 2) { bufferGraphics.drawImage(player.getResource(resource), 94, 106, null); // SOUTH*94,106 } if (player.face == 3) { bufferGraphics.drawImage(player.getResource(resource), 84, 87, null); // WEST84,87 } if (player.face == 4) { bufferGraphics.drawImage(player.getResource(resource), 94, 75, null); // NORTH94,75 } } if (player.health <= 0) { bufferGraphics.drawString("You are dead", 10, 90); stop(); } bufferGraphics.setFont(new Font("Arial", Font.PLAIN, 9)); bufferGraphics.setColor(new Color(160, 82, 45)); bufferGraphics.fillRect(0, 2, 8, 8); bufferGraphics.setColor(new Color(105, 105, 105)); bufferGraphics.fillRect(0, 12, 8, 8); bufferGraphics.drawImage(statusBar, 0, 22, null); bufferGraphics.setColor(Color.WHITE); bufferGraphics.drawString(String.format("%d", wood), 18, 10); bufferGraphics.drawString(String.format("%d", stone), 18, 20); bufferGraphics.drawString(String.format("%d", player.health), 18, 30); // bufferGraphics.fillRect((int)player.r.getX(), (int)player.r.getY(), // (int)player.r.getWidth(),(int)player.r.getHeight()); // bufferGraphics.fillRect(player.r.x, player.r.x, player.r.width, player.r.height); g.drawImage(offScreen, 0, 0, this); // if(drawConsole){ // message = String.format("wood: %d", wood); // } }
public void run() { buf.clearRect(0, 0, dimX, dimY); if (!cant[0] & dir == 0 & youX > 0) youX--; if (!cant[1] & dir == 1 & youY > 300) youY--; if (!cant[2] & dir == 2 & youX < dimX - 10) youX++; if (!cant[3] & dir == 3 & youY < 399) youY++; if (!cant[0] & dir2 == 0 & youX > 0) youX--; if (!cant[1] & dir2 == 1 & youY > 300) youY--; if (!cant[2] & dir2 == 2 & youX < dimX - 10) youX++; if (!cant[3] & dir2 == 3 & youY < 399) youY++; if (fire) fireY -= 2; if (time == 0) { for (int k = 0; k < centNum; k++) { if (cent[k][2] != -1) { if (cent[k][2] != -2) { if (change[k]) { if (!up[k]) cent[k][1]++; else cent[k][1]--; turn[k]++; if (cent[k][1] % 10 == 0) change[k] = false; } else { if (cent[k][2] == 0) cent[k][0]++; if (cent[k][2] == 1) cent[k][0]--; } } else { cent[k][1]++; if (cent[k][1] == 390) cent[k][2] = (int) (Math.random() * 2); } } } time = 1; } else time = 0; if (norm) { if (time2 == 0) // flea { if (flea) { fleaY += 10; if (fleaY < 350 & (int) (Math.random() * 5) == 0) { mush[findEmpt(mush)][0] = fix(fleaX); mush[findEmpt(mush)][1] = fix(fleaY); if (mush[findEmpt(mush)][0] == 290 & mush[findEmpt(mush)][1] == 0) mush[findEmpt(mush)][0] = 280; mush[findEmpt(mush)][2] = 9; } } time2++; } else { if (time2 == 10) time2 = -1; time2++; } if (flea) drawFlea(); for (int k = 0; k < 10; k++) // spider { if (spid[k][2] != -1) { if (time3[k] <= 20) { if (spid[k][2] != -1) { if (spid[k][2] == 0) { spid[k][0]--; spid[k][1]--; } if (spid[k][2] == 1) spid[k][1]--; if (spid[k][2] == 2) { spid[k][0]++; spid[k][1]--; } if (spid[k][2] == 3) { spid[k][0]--; spid[k][1]++; } if (spid[k][2] == 4) spid[k][1]++; if (spid[k][2] == 5) { spid[k][0]--; spid[k][1]++; } } time3[k]++; } else { if (time3[k] == 150) { time3[k] = -1; boolean fine[] = new boolean[10]; do { spid[k][2] = (int) (Math.random() * 6); // 0 = up-left, 1 = up, 2 = up-right, 3 = down-right, 4 = down, 5 // = down-left if (spid[k][2] == 0 || spid[k][2] == 1 || spid[k][2] == 2) if (spid[k][1] - 20 > 300) fine[k] = true; if (spid[k][2] == 3 || spid[k][2] == 4 || spid[k][2] == 5) if (spid[k][1] + 20 < 400) fine[k] = true; } while (!fine[k]); } time3[k]++; } } } drawSpider(); if (scorp) scorpX++; if (scorp) drawScorpion(); } else { for (int k = 0; k < centNum; k++) if (centFire[k][1] != -1) centFire[k][1] += 2; } drawYou(); if (fire) drawFire(); if (!norm) drawCentFire(); drawMush(); drawCent(); checkHit(); drawStatus(); all.drawImage(img, 0, 0, this); try { Thread.sleep(1); } catch (InterruptedException e) { } if (die) { try { Thread.sleep(1000); } catch (InterruptedException e) { } reset(); } repaint(); }