Super Mario Bros Java Game 240x320 < A-Z Premium >

void jump() { vy = -9; onGround = false; }

// goombas Iterator<Goomba> goombaIt = goombas.iterator(); while (goombaIt.hasNext()) { Goomba g = goombaIt.next(); g.update(); if (mario.getBounds().intersects(g.getBounds())) { if (mario.vy > 0 && mario.y + mario.height - g.y < 16) { // stomp goombaIt.remove(); score += 20; mario.vy = -8; // small bounce } else { gameRunning = false; // game over } } }

Mario(int startX, int groundY) { x = startX; y = groundY - height; } super mario bros java game 240x320

// coins Iterator<Coin> coinIt = coins.iterator(); while (coinIt.hasNext()) { Coin c = coinIt.next(); if (mario.getBounds().intersects(c.getBounds())) { coinIt.remove(); score += 10; } }

@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; void jump() { vy = -9; onGround =

import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.ArrayList; import java.util.Iterator; public class MarioGame240x320 extends JPanel implements ActionListener, KeyListener { // Screen settings (240x320) private static final int SCREEN_WIDTH = 240; private static final int SCREEN_HEIGHT = 320; private static final int TILE_SIZE = 16;

// Level data (simple) private Tile[][] tiles; private int levelWidth = 80; // tiles void jump() { vy = -9

if (mario.getBounds().intersects(tileRect)) { // from top if (mario.vy >= 0 && mario.y + mario.height - tileRect.y <= 8) { mario.y = tileRect.y - mario.height; mario.vy = 0; mario.onGround = true; } // from bottom else if (mario.vy < 0 && tileRect.y + TILE_SIZE - mario.y <= 8) { mario.y = tileRect.y + TILE_SIZE; mario.vy = 0; } // from left/right else { if (mario.x + mario.width > tileRect.x && mario.x < tileRect.x) { mario.x = tileRect.x - mario.width; } else if (mario.x < tileRect.x + TILE_SIZE && mario.x + mario.width > tileRect.x + TILE_SIZE) { mario.x = tileRect.x + TILE_SIZE; } } } } } } }