Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.flodro.minigame;
- import java.awt.Canvas;
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.Point;
- import javax.swing.JFrame;
- import net.flodro.minigame.graphics.Images;
- @SuppressWarnings("serial")
- public class MiniGame extends Canvas implements Runnable {
- public static int score = 0;
- public static int pixelSize = 2;
- public static int WIN_WIDTH = 400;
- public static int WIN_HEIGHT = 250;
- public Dimension size = new Dimension(WIN_WIDTH, WIN_HEIGHT);
- public Dimension pixel = new Dimension(size.width / 2, size.height / 2);
- private Image screen;
- private Thread thread;
- private boolean running = false;
- public static int currentScreen = 1;
- public static Player player;
- public static boolean playerJumping = false;
- public static Point mse = new Point(0, 0);
- public MiniGame() {
- new Images();
- player = new Player(20, 0, Images.player.getWidth(), Images.player.getHeight());
- addKeyListener(player);
- }
- private void start() {
- requestFocus();
- running = true;
- thread = new Thread(this);
- thread.start();
- }
- @SuppressWarnings("unused")
- private void stop() {
- if (!running)
- return;
- running = false;
- try {
- thread.join();
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(0);
- }
- }
- public void run() {
- screen = createVolatileImage(pixel.width, pixel.height);
- while (running) {
- tick();
- render();
- }
- }
- private void tick() {
- player.tick();
- }
- private void render() {
- Graphics g = screen.getGraphics();
- g.setColor(Color.BLACK);
- if(currentScreen == 1) {
- g.drawImage(Images.screen1, 0, 0, Images.screen1.getWidth(), Images.screen1.getHeight(), null);
- g.setColor(Color.BLACK);
- g.fillRect(150, 220, 150, 30);
- } else if(player.x >= 370) {
- g.drawImage(Images.screen2, 0, 0, Images.screen2.getWidth(), Images.screen2.getHeight(), null);
- }
- player.render(g);
- // X Position, Y Position, X Width, Y Height
- // g.setColor(Color.CYAN);
- // g.fillRect(150, 220, 150, 30);
- g = getGraphics();
- g.drawImage(screen, 0, 0, size.width, size.height, 0, 0, pixel.width, pixel.height, null);
- g.dispose();
- }
- public static void main(String[] args) {
- String OS = System.getProperty("os.name");
- if(OS.startsWith("Mac")) {
- WIN_WIDTH = 800; WIN_HEIGHT = 500;
- } else {
- WIN_WIDTH = 806; WIN_HEIGHT = 506;
- }
- MiniGame game = new MiniGame();
- JFrame frame = new JFrame();
- frame.add(game);
- frame.pack();
- frame.setResizable(false);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setVisible(true);
- frame.setSize(WIN_WIDTH, WIN_HEIGHT);
- frame.setTitle("Mini Game");
- frame.setLocationRelativeTo(null);
- game.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement