Super Mario Bros Java Game 240x320 File
void draw(Graphics2D g, int screenX, int screenY) { g.setColor(new Color(139, 69, 19)); g.fillRect(screenX, screenY, TILE_SIZE, TILE_SIZE); g.setColor(Color.BLACK); g.drawRect(screenX, screenY, TILE_SIZE, TILE_SIZE); } }
// goombas for (Goomba g : goombas) { g.draw(g2, g.x - cameraX, g.y); }
// Mario private Mario mario; private int cameraX = 0;
void jump() { vy = -9; onGround = false; } super mario bros java game 240x320
@Override public void keyReleased(KeyEvent e) { int k = e.getKeyCode(); if (k == KeyEvent.VK_LEFT) mario.left = false; if (k == KeyEvent.VK_RIGHT) mario.right = false; }
// goombas goombas.add(new Goomba(20 * TILE_SIZE, 18 * TILE_SIZE - 16)); goombas.add(new Goomba(44 * TILE_SIZE, 13 * TILE_SIZE - 16)); goombas.add(new Goomba(65 * TILE_SIZE, 18 * TILE_SIZE - 16));
Tile(int x, int y, Type t) { this.x = x; this.y = y; this.type = t; } void draw(Graphics2D g, int screenX, int screenY) { g
Rectangle getBounds() { return new Rectangle(x, y, TILE_SIZE, TILE_SIZE); }
// --- 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); } }
// ground and platforms for (int x = 0; x < levelWidth; x++) { // ground at y = 18 tiles (288px) tiles[x][18] = new Tile(x * TILE_SIZE, 18 * TILE_SIZE, Tile.Type.GROUND); } void draw(Graphics2D g
// 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 actionPerformed(ActionEvent e) { if (gameRunning && !gameWin) { updateGame(); } repaint(); }
public MarioGame240x320() { setPreferredSize(new Dimension(SCREEN_WIDTH, SCREEN_HEIGHT)); setBackground(Color.CYAN); setFocusable(true); addKeyListener(this);





