Initial commit

This commit is contained in:
CoolGuy27
2026-02-27 20:10:29 +00:00
commit 3739ae0d65
12 changed files with 202 additions and 0 deletions

26
.replit Normal file
View File

@@ -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"

BIN
Display.class Normal file

Binary file not shown.

20
Display.java Normal file
View File

@@ -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();
}
}

BIN
Moveable.class Normal file

Binary file not shown.

6
Moveable.java Normal file
View File

@@ -0,0 +1,6 @@
public interface Moveable{
int JUMP_HEIGHT = 10;
public void moveX(int moveX);
public void moveY(int moveY);
}

BIN
Platformer.class Normal file

Binary file not shown.

97
Platformer.java Normal file
View File

@@ -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<Tile> 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){
}
}

BIN
Player.class Normal file

Binary file not shown.

18
Player.java Normal file
View File

@@ -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;
}
}

BIN
Tile.class Normal file

Binary file not shown.

16
Tile.java Normal file
View File

@@ -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);
}
}

19
replit.md Normal file
View File

@@ -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
```