240x320: Super Mario Bros Java Game
import javax.microedition.lcdui.*; import javax.microedition.midlet.*;public class MarioGame extends MIDlet implements CommandListener { private Display display; private GameCanvas canvas; private Command exitCommand;
public void startApp() display = Display.getDisplay(this); canvas = new GameCanvas(); exitCommand = new Command("Exit", Command.EXIT, 1); canvas.addCommand(exitCommand); canvas.setCommandListener(this); display.setCurrent(canvas); canvas.start(); public void pauseApp() {} public void destroyApp(boolean unconditional) {} public void commandAction(Command c, Displayable d) if (c == exitCommand) destroyApp(true); notifyDestroyed();}
class GameCanvas extends Canvas implements Runnable { // Screen dimensions private static final int SCREEN_W = 240; private static final int SCREEN_H = 320;
// Mario physics private int marioX = 50, marioY = 200; private int marioVelX = 0, marioVelY = 0; private boolean onGround = false; private static final int GRAVITY = 1; private static final int JUMP_POWER = -12; // World private int cameraX = 0; private static final int WORLD_WIDTH = 2000; // Platforms: x, y, width, height private int[][] platforms = 0, 280, 300, 20, 350, 250, 80, 20, 500, 200, 80, 20, 650, 150, 80, 20, 800, 250, 100, 20, 1000, 200, 80, 20, 1200, 150, 80, 20, 1400, 100, 80, 20, 1600, 250, 150, 20, 1800, 300, 200, 20 ; // Coins private int[][] coins = 370, 230, 1, 520, 180, 1, 670, 130, 1, 820, 230, 1, 1020, 180, 1, 1220, 130, 1, 1420, 80, 1, 1620, 230, 1 ; private boolean[] coinCollected; // Enemy: x, y, width, height, direction (1=right, -1=left) private int[][] enemies = 400, 230, 20, 20, 1, 700, 130, 20, 20, -1, 1100, 180, 20, 20, 1, 1500, 80, 20, 20, -1 ; private int score = 0; private boolean gameRunning = true; private Thread gameThread; public GameCanvas() coinCollected = new boolean[coins.length]; public void start() gameThread = new Thread(this); gameThread.start(); public void run() { while (gameRunning) { update(); repaint(); try Thread.sleep(20); catch (Exception e) {} } } private void update() // Handle input int keyState = getGameAction(getKeyStates()); marioVelX = 0; if (keyState == LEFT) marioVelX = -4; if (keyState == RIGHT) marioVelX = 4; if (keyState == FIRE && onGround) marioVelY = JUMP_POWER; onGround = false; // Apply gravity and velocity marioVelY += GRAVITY; marioX += marioVelX; marioY += marioVelY; // Horizontal collision & camera if (marioX < 20) marioX = 20; if (marioX > WORLD_WIDTH - 20) marioX = WORLD_WIDTH - 20; cameraX = marioX - SCREEN_W / 2; if (cameraX < 0) cameraX = 0; if (cameraX > WORLD_WIDTH - SCREEN_W) cameraX = WORLD_WIDTH - SCREEN_W; // Platform collision onGround = false; for (int i = 0; i < platforms.length; i++) int pX = platforms[i][0]; int pY = platforms[i][1]; int pW = platforms[i][2]; int pH = platforms[i][3]; if (marioY + 20 > pY && marioY < pY + pH && marioX + 15 > pX && marioX < pX + pW) // Top collision if (marioVelY > 0 && marioY + 20 - marioVelY <= pY) marioY = pY - 20; marioVelY = 0; onGround = true; // Side/head bump else if (marioVelY < 0 && marioY >= pY + pH) marioY = pY + pH; marioVelY = 0; else if (marioX + 15 > pX && marioX < pX + pW) if (marioVelX > 0) marioX = pX - 15; else if (marioVelX < 0) marioX = pX + pW; // Fall death if (marioY > SCREEN_H + 50) resetGame(); // Coin collection for (int i = 0; i < coins.length; i++) if (!coinCollected[i]) int cX = coins[i][0]; int cY = coins[i][1]; if (Math.abs(marioX - cX) < 15 && Math.abs(marioY - cY) < 15) coinCollected[i] = true; score += 10; // Enemy collision for (int i = 0; i < enemies.length; i++) eX > WORLD_WIDTH - 100) enemies[i][4] *= -1; // Mario vs enemy if (Math.abs(marioX - eX) < 18 && Math.abs(marioY - eY) < 18) if (marioVelY > 0 && marioY + 15 < eY + eH/2) // Stomp enemy enemies[i][0] = -1000; // remove enemy marioVelY = -8; score += 20; else // Hurt / die resetGame(); private void resetGame() marioX = 50; marioY = 200; marioVelX = 0; marioVelY = 0; cameraX = 0; score = 0; coinCollected = new boolean[coins.length]; // Reset enemies enemies[0][0] = 400; enemies[1][0] = 700; enemies[2][0] = 1100; enemies[3][0] = 1500; protected void paint(Graphics g) Graphics.LEFT); g.drawString("MARIO", SCREEN_W - 60, 5, Graphics.TOP protected void keyPressed(int keyCode) {}
}
To understand the significance of the "240x320" specification, we must first understand Java Platform, Micro Edition (Java ME). Before Android and iOS dominated, Java was the universal language of feature phones. Every manufacturer supported it.
The resolution 240x320 (portrait mode) was the sweet spot. It was large enough to show detailed sprites but small enough to keep performance high on processors running at just 100-200MHz. When developers created a "Super Mario Bros Java game," they had to tailor it precisely to this resolution. If you downloaded a version meant for 128x160 pixels, the game would look tiny or distorted. The 240x320 version was the definitive way to play Mario on a non-touch phone.
Used Graphics from getGraphics() with manual flush to avoid flicker:
Graphics g = getGraphics();
drawGame(g);
flushGraphics();
Score: 7/10 (Context: Mobile Gaming Circa 2008) super mario bros java game 240x320
If you are playing this on a retro phone or an emulator for nostalgia, the 240x320 Java version of Super Mario Bros is one of the best "time-killer" games you can have. While it is legally a "clone" (not officially licensed by Nintendo), the best versions of this J2ME port capture about 90% of the original magic.
Find a used Sony Ericsson W995 or Nokia N86 on eBay (ensure the battery holds a charge). Use a mini-USB cable to transfer the .jar file to the "Other" or "Applications" folder. You may need to free up space by deleting ringtones.
Goomba: The lowest rank in Bowser's army. They simply walk forward. One stomp defeats them.
Koopa Troopa: Turtles with shells. Jump on them once to make them hide in their shell. Jump again to kick the shell and wipe out other enemies! import javax
Piranha Plant: A carnivorous plant that lives in pipes. Wait for it to go down before passing!
Hammer Bros: Tough enemies that throw hammers in an arc. Time your jumps carefully!
Bowser: The King of the Koopas. He awaits at the end of every castle. He breathes fire and jumps high. You must grab the axe behind him to destroy the bridge!
To understand the significance of this specific resolution, we have to go back to the hardware limitations of 2005–2010. Mobile screens were divided into three tiers: } class GameCanvas extends Canvas implements Runnable {
The 240x320 resolution was a breakthrough because it provided an aspect ratio close to 3:4, which, when playing a landscape game (by tilting the phone sideways or using a virtual horizontal view), allowed developers to render Mario at a scale where you could actually see his hat, eyes, and mustache. More importantly, it gave enough horizontal buffer to see incoming Goombas before they hit you—a luxury smaller resolutions couldn't afford.
Super Mario Bros — Java Game (240×320)
