init
This commit is contained in:
commit
04f8b8b399
9 files changed
+272
No files matched your search
@@ -0,0 +1 @@
|
|||||||
|
target/
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>xfe</groupId>
|
||||||
|
<artifactId>jmtd</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.release>17</maven.compiler.release>
|
||||||
|
<lombok.version>1.18.38</lombok.version>
|
||||||
|
<maven.compiler.plugin.version>3.13.0</maven.compiler.plugin.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>${lombok.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>${maven.compiler.plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<release>${maven.compiler.release}</release>
|
||||||
|
<annotationProcessorPaths>
|
||||||
|
<path>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>${lombok.version}</version>
|
||||||
|
</path>
|
||||||
|
</annotationProcessorPaths>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package xfe;
|
||||||
|
|
||||||
|
public class JMTD {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package main.java.xfe.model;
|
||||||
|
|
||||||
|
public class Camera {
|
||||||
|
private Integer xPos;
|
||||||
|
private Integer yPos;
|
||||||
|
|
||||||
|
private boolean movingUp;
|
||||||
|
private boolean movingDown;
|
||||||
|
private boolean movingRight;
|
||||||
|
private boolean movingLeft;
|
||||||
|
|
||||||
|
public static final Integer CAMERA_SPEED = 2;
|
||||||
|
|
||||||
|
public Camera() {
|
||||||
|
this.xPos = 0;
|
||||||
|
this.yPos = 0;
|
||||||
|
|
||||||
|
this.movingDown = false;
|
||||||
|
this.movingUp = false;
|
||||||
|
this.movingLeft = false;
|
||||||
|
this.movingRight = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void doTick() {
|
||||||
|
if (movingDown) {
|
||||||
|
yPos -= CAMERA_SPEED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (movingUp) {
|
||||||
|
yPos += CAMERA_SPEED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (movingLeft) {
|
||||||
|
xPos -= CAMERA_SPEED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (movingRight) {
|
||||||
|
xPos += CAMERA_SPEED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getters & Setters
|
||||||
|
|
||||||
|
public Integer getXPos() {
|
||||||
|
return this.xPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getYPos() {
|
||||||
|
return this.yPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setXPos(Integer newX) {
|
||||||
|
this.xPos = newX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setYPos(Integer newY) {
|
||||||
|
this.yPos = newY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleMovingUp() {
|
||||||
|
this.movingUp = !this.movingUp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleMovingDown() {
|
||||||
|
this.movingDown = !this.movingDown;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleMovingLeft() {
|
||||||
|
this.movingLeft = !this.movingLeft;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleMovingRight() {
|
||||||
|
this.movingRight = !this.movingRight;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package main.java.xfe.model;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Point;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public abstract class Entity {
|
||||||
|
private Integer x;
|
||||||
|
private Integer y;
|
||||||
|
|
||||||
|
public abstract void draw(Graphics2D g2d, Point p);
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package main.java.xfe.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Point;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class World {
|
||||||
|
private Camera camera;
|
||||||
|
private List<Entity> entities;
|
||||||
|
|
||||||
|
public World() {
|
||||||
|
this.camera = new Camera();
|
||||||
|
this.entities = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addEntity(Entity entity) {
|
||||||
|
this.entities.add(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void doTick() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw(Graphics2D g2d) {
|
||||||
|
for (Entity entity : this.entities) {
|
||||||
|
Point entityPos = new Point(entity.getX(), entity.getY());
|
||||||
|
|
||||||
|
entity.draw(g2d, translatePoint(entityPos));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Point translatePoint(Point p) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package main.java.xfe.model.entities;
|
||||||
|
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Point;
|
||||||
|
|
||||||
|
import main.java.xfe.model.Entity;
|
||||||
|
|
||||||
|
public class Turret extends Entity {
|
||||||
|
|
||||||
|
public void draw(Graphics2D g2d, Point p) {
|
||||||
|
g2d.drawOval(p.x, p.y, 10, 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package xfe.panels;
|
||||||
|
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
import main.java.xfe.model.World;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.awt.event.KeyListener;
|
||||||
|
import java.awt.event.MouseListener;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
|
||||||
|
public class GamePanel extends JPanel {
|
||||||
|
World world;
|
||||||
|
|
||||||
|
public GamePanel() {
|
||||||
|
this.addKeyListener(new GameKeyListener());
|
||||||
|
this.addMouseListener(new GameMouseListener());
|
||||||
|
|
||||||
|
this.world = new World();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintComponent(Graphics g) {
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
|
||||||
|
g2d.setColor(Color.BLACK);
|
||||||
|
g2d.fillRect(0, 0, getWidth(), getHeight());
|
||||||
|
|
||||||
|
// Main draw function here
|
||||||
|
this.world.draw(g2d);
|
||||||
|
}
|
||||||
|
|
||||||
|
class GameKeyListener implements KeyListener {
|
||||||
|
@Override
|
||||||
|
public void keyTyped(KeyEvent e) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyPressed(KeyEvent e) {
|
||||||
|
switch (e.getKeyCode()) {
|
||||||
|
case KeyEvent.VK_W -> world.getCamera().toggleMovingUp();
|
||||||
|
case KeyEvent.VK_S -> world.getCamera().toggleMovingDown();
|
||||||
|
case KeyEvent.VK_D -> world.getCamera().toggleMovingRight();
|
||||||
|
case KeyEvent.VK_A -> world.getCamera().toggleMovingLeft();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyReleased(KeyEvent e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class GameMouseListener implements MouseListener {
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent e) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent e) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(MouseEvent e) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent e) {}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user