commit 3739ae0d65ed27c0c659d9764bad0b3b2a5cfaab Author: CoolGuy27 <4052244-CoolGuy27@users.noreply.replit.com> Date: Fri Feb 27 20:10:29 2026 +0000 Initial commit diff --git a/.replit b/.replit new file mode 100644 index 0000000..0a18f95 --- /dev/null +++ b/.replit @@ -0,0 +1,26 @@ +modules = ["java-graalvm22.3"] +[agent] +expertMode = true + +[workflows] +runButton = "Project" + +[[workflows.workflow]] +name = "Project" +mode = "parallel" +author = "agent" + +[[workflows.workflow.tasks]] +task = "workflow.run" +args = "Start application" + +[[workflows.workflow]] +name = "Start application" +author = "agent" + +[[workflows.workflow.tasks]] +task = "shell.exec" +args = "javac Display.java Platformer.java Player.java Tile.java Moveable.java && java Display" + +[workflows.workflow.metadata] +outputType = "vnc" diff --git a/Display.class b/Display.class new file mode 100644 index 0000000..0b5e034 Binary files /dev/null and b/Display.class differ diff --git a/Display.java b/Display.java new file mode 100644 index 0000000..8e14159 --- /dev/null +++ b/Display.java @@ -0,0 +1,20 @@ +import javax.swing.*; + +public class Display { + public static void main(String[] args) { + int boardWidth = 400; + int boardHeight = 400; + int tileSize = 20; + + JFrame game = new JFrame(); + game.setSize(boardWidth, boardHeight); + game.setVisible(true); + game.setLocationRelativeTo(null); + game.setResizable(false); + + Platformer platformer = new Platformer(boardWidth, boardHeight, tileSize); + game.add(platformer); + game.pack(); + platformer.requestFocus(); + } +} \ No newline at end of file diff --git a/Moveable.class b/Moveable.class new file mode 100644 index 0000000..6db2a09 Binary files /dev/null and b/Moveable.class differ diff --git a/Moveable.java b/Moveable.java new file mode 100644 index 0000000..56ed1bf --- /dev/null +++ b/Moveable.java @@ -0,0 +1,6 @@ +public interface Moveable{ + int JUMP_HEIGHT = 10; + + public void moveX(int moveX); + public void moveY(int moveY); +} \ No newline at end of file diff --git a/Platformer.class b/Platformer.class new file mode 100644 index 0000000..dd6d661 Binary files /dev/null and b/Platformer.class differ diff --git a/Platformer.java b/Platformer.java new file mode 100644 index 0000000..0d18d6b --- /dev/null +++ b/Platformer.java @@ -0,0 +1,97 @@ +import java.util.Random; +import java.util.ArrayList; +import java.util.List; +import java.io.*; +import java.awt.*; +import java.awt.event.*; +import java.awt.Graphics; +import javax.swing.*; + +public class Platformer extends JPanel implements KeyListener, ActionListener{ + + //finals + static final int GRAVITY = 10; + static final Color playerColor = Color.RED; + static final Color tileColor = Color.BLUE; + + Player player; + ArrayList tiles; + //display vars + int boardWidth; + int boardHeight; + int tileSize; + Timer gameTimer; + + + public Platformer(int boardWidth, int boardHeight, int tileSize){ + //setup game + this.boardWidth = boardWidth; + this.boardHeight = boardHeight; + this.tileSize = tileSize; + setPreferredSize(new Dimension(this.boardWidth, this.boardHeight)); + addKeyListener(this); + this.setFocusable(true); + gameTimer = new Timer(15,this); + player = new Player(20,20,20,20); + tiles = new ArrayList<>(); + tiles.add(new Tile (0,300,tileSize * 20,tileSize)); + } + + //gameloop + public void gameLoop(){ + player.moveY(GRAVITY); + } + + //paintComponent + public void paintComponent(Graphics g){ + super.paintComponent(g); + draw(g); + } + + //draw function + public void draw(Graphics g){ + + //draw player + g.setColor(playerColor); + g.fillRect(player.x,player.y,player.width,player.height); + + //draw tiles + g.setColor(tileColor); + for (Tile t : tiles){ + t.draw(g); + } + } + + //every tick + @Override + public void actionPerformed(ActionEvent e){ + gameLoop(); + repaint(); + } + + //check for key presses + @Override + public void keyPressed(KeyEvent e){ + if (e.getKeyCode() == KeyEvent.VK_S){ + gameTimer.start(); + } + + if (e.getKeyCode() == KeyEvent.VK_R){ + gameTimer.stop(); + player.x = 20; + player.y = 20; + repaint(); + } + } + + @Override + public void keyReleased(KeyEvent e){ + + } + + //dont need + @Override + public void keyTyped(KeyEvent e){ + + } +} \ No newline at end of file diff --git a/Player.class b/Player.class new file mode 100644 index 0000000..88e7c59 Binary files /dev/null and b/Player.class differ diff --git a/Player.java b/Player.java new file mode 100644 index 0000000..55e7126 --- /dev/null +++ b/Player.java @@ -0,0 +1,18 @@ +public class Player implements Moveable{ + int x,y,width,height; + + public Player(int x1, int y1, int w, int h){ + x = x1; + y = y1; + width = w; + height = h; + } + + public void moveX(int moveX){ + this.x += moveX; + } + + public void moveY(int moveY){ + this.y += moveY; + } +} \ No newline at end of file diff --git a/Tile.class b/Tile.class new file mode 100644 index 0000000..99b7535 Binary files /dev/null and b/Tile.class differ diff --git a/Tile.java b/Tile.java new file mode 100644 index 0000000..cf96e5d --- /dev/null +++ b/Tile.java @@ -0,0 +1,16 @@ +import java.awt.Graphics; + +public class Tile { + int x,y,width,height; + + public Tile(int x, int y, int width, int height){ + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } + + public void draw(Graphics g){ + g.fillRect(x,y,width,height); + } +} \ No newline at end of file diff --git a/replit.md b/replit.md new file mode 100644 index 0000000..78f1786 --- /dev/null +++ b/replit.md @@ -0,0 +1,19 @@ +# Platformer Game + +A simple Java platformer game. + +## Main Entry Point +The main entry point of the application is `Display.java`. + +## Structure +- `Display.java`: Entry point and window setup. +- `Platformer.java`: Game engine and logic. +- `Player.java`: Player character class. +- `Tile.java`: Platform class. +- `Moveable.java`: Interface for moveable objects. + +## How to Run +Use the "Start application" workflow or run: +```bash +javac Display.java Platformer.java Player.java Tile.java Moveable.java && java Display +```