CAD Utilities
CAD Utilities
CAD Utilities
 
CAD Utilities CAD Utilities

Game 240x320 — Super Mario Bros Java

// UI g2.setColor(Color.BLACK); g2.setFont(new Font("Arial", Font.BOLD, 12)); g2.drawString("SCORE: " + score, 8, 20); if (!gameRunning && !gameWin) { g2.setFont(new Font("Arial", Font.BOLD, 20)); g2.drawString("GAME OVER", SCREEN_WIDTH / 2 - 50, SCREEN_HEIGHT / 2); } if (gameWin) { g2.setFont(new Font("Arial", Font.BOLD, 20)); g2.drawString("YOU WIN!", SCREEN_WIDTH / 2 - 40, SCREEN_HEIGHT / 2); } }

// draw tiles for (int x = 0; x < levelWidth; x++) { for (int y = 0; y < tiles[0].length; y++) { if (tiles[x][y] != null) { int screenX = x * TILE_SIZE - cameraX; int screenY = y * TILE_SIZE; if (screenX + TILE_SIZE > 0 && screenX < SCREEN_WIDTH) { tiles[x][y].draw(g2, screenX, screenY); } } } }

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

// Level data (simple) private Tile[][] tiles; private int levelWidth = 80; // tiles

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

onGround = false; if (y + height > SCREEN_HEIGHT) { y = SCREEN_HEIGHT - height; vy = 0; onGround = true; } }

buildLevel(); }

// --- Mario class --- class Mario { int x, y; int width = 16, height = 16; int vx = 0, vy = 0; boolean left = false, right = false; boolean onGround = false;