{{resourceTitle}}
{{resourceBlurb}}
{{searchResultSnippet}}
// coins coins.add(new Coin(15 * TILE_SIZE, 14 * TILE_SIZE)); coins.add(new Coin(42 * TILE_SIZE, 12 * TILE_SIZE)); coins.add(new Coin(43 * TILE_SIZE, 12 * TILE_SIZE)); coins.add(new Coin(60 * TILE_SIZE, 17 * TILE_SIZE));
@Override public void keyPressed(KeyEvent e) { if (!gameRunning) return; int k = e.getKeyCode(); if (k == KeyEvent.VK_LEFT) mario.left = true; if (k == KeyEvent.VK_RIGHT) mario.right = true; if (k == KeyEvent.VK_SPACE && mario.onGround) { mario.jump(); } }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; super mario bros java game 240x320
void jump() { vy = -9; onGround = false; }
// --- Flag --- class Flag { int x, y; Flag(int x, int y) { this.x = x; this.y = y; } Rectangle getBounds() { return new Rectangle(x, y, 8, 16); } void draw(Graphics2D g, int screenX, int screenY) { g.setColor(Color.RED); g.fillRect(screenX, screenY, 4, 20); g.fillPolygon(new int[]{screenX + 4, screenX + 16, screenX + 4}, new int[]{screenY, screenY + 8, screenY + 16}, 3); } } // coins coins
// --- Coin --- class Coin { int x, y; Coin(int x, int y) { this.x = x; this.y = y; } Rectangle getBounds() { return new Rectangle(x, y, TILE_SIZE, TILE_SIZE); } void draw(Graphics2D g, int screenX, int screenY) { g.setColor(Color.YELLOW); g.fillOval(screenX, screenY, TILE_SIZE, TILE_SIZE); } }
void draw(Graphics2D g, int screenX, int screenY) { g.setColor(Color.RED); g.fillRect(screenX, screenY, width, height); g.setColor(Color.BLACK); g.fillRect(screenX + 4, screenY + 4, 2, 2); g.fillRect(screenX + 10, screenY + 4, 2, 2); } } // coins coins.add(new Coin(15 * TILE_SIZE
// --- Tile --- class Tile { enum Type { GROUND } Type type; int x, y;
{{resourceTitle}}
{{resourceBlurb}}