Initial Commit.
This commit is contained in:
commit
678ba3e1b8
10 changed files with 349 additions and 0 deletions
6
wat/.classpath
Normal file
6
wat/.classpath
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
17
wat/.project
Normal file
17
wat/.project
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>wat</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
11
wat/.settings/org.eclipse.jdt.core.prefs
Normal file
11
wat/.settings/org.eclipse.jdt.core.prefs
Normal file
|
@ -0,0 +1,11 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
1
wat/bin/.gitignore
vendored
Normal file
1
wat/bin/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/bz/
|
17
wat/src/bz/bronze/wat/Collisions.java
Normal file
17
wat/src/bz/bronze/wat/Collisions.java
Normal file
|
@ -0,0 +1,17 @@
|
|||
package bz.bronze.wat;
|
||||
|
||||
public class Collisions {
|
||||
public void check()
|
||||
{
|
||||
if (Player.x1 == Player.x2 - Player.width2)
|
||||
{
|
||||
if (Player.isAlive2)
|
||||
{
|
||||
System.out.println("GET REKT BRO!");
|
||||
Player.width1 += 50;
|
||||
Player.height1 += 50;
|
||||
Player.isAlive2 = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
125
wat/src/bz/bronze/wat/Controls.java
Normal file
125
wat/src/bz/bronze/wat/Controls.java
Normal file
|
@ -0,0 +1,125 @@
|
|||
package bz.bronze.wat;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
|
||||
public class Controls implements KeyListener {
|
||||
// Player 1 Booleans \\
|
||||
|
||||
static boolean moveUp1;
|
||||
static boolean moveDown1;
|
||||
static boolean moveLeft1;
|
||||
static boolean moveRight1;
|
||||
|
||||
// Player 2 Booleans \\
|
||||
|
||||
static boolean moveUp2;
|
||||
static boolean moveDown2;
|
||||
static boolean moveLeft2;
|
||||
static boolean moveRight2;
|
||||
|
||||
// Shared Booleans \\
|
||||
|
||||
static boolean reset;
|
||||
|
||||
public void keyTyped(KeyEvent e) {
|
||||
|
||||
}
|
||||
|
||||
public void keyPressed(KeyEvent e) {
|
||||
int keyCode = e.getKeyCode();
|
||||
|
||||
System.out.println("Key Code Pressed: " + keyCode);
|
||||
|
||||
switch (keyCode)
|
||||
{
|
||||
// Player 1 Controls \\
|
||||
|
||||
case 87:
|
||||
moveUp1 = true;
|
||||
break;
|
||||
case 83:
|
||||
moveDown1 = true;
|
||||
break;
|
||||
case 68:
|
||||
moveRight1 = true;
|
||||
break;
|
||||
case 65:
|
||||
moveLeft1 = true;
|
||||
break;
|
||||
|
||||
// Player 2 Controls \\
|
||||
|
||||
case 38:
|
||||
moveUp2 = true;
|
||||
break;
|
||||
case 40:
|
||||
moveDown2 = true;
|
||||
break;
|
||||
case 39:
|
||||
moveRight2 = true;
|
||||
break;
|
||||
case 37:
|
||||
moveLeft2 = true;
|
||||
break;
|
||||
|
||||
// Shared Controls \\
|
||||
|
||||
case 32:
|
||||
reset = true;
|
||||
break;
|
||||
case 16:
|
||||
Player.speedModifier = 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void keyReleased(KeyEvent e) {
|
||||
int keyCode = e.getKeyCode();
|
||||
|
||||
System.out.println("Key Code Released: " + keyCode);
|
||||
|
||||
switch (keyCode)
|
||||
{
|
||||
// Player 1 Controls
|
||||
|
||||
case 87:
|
||||
moveUp1 = false;
|
||||
break;
|
||||
case 83:
|
||||
moveDown1 = false;
|
||||
break;
|
||||
case 68:
|
||||
moveRight1 = false;
|
||||
break;
|
||||
case 65:
|
||||
moveLeft1 = false;
|
||||
break;
|
||||
|
||||
// Player 2 Controls
|
||||
|
||||
case 38:
|
||||
moveUp2 = false;
|
||||
break;
|
||||
case 40:
|
||||
moveDown2 = false;
|
||||
break;
|
||||
case 39:
|
||||
moveRight2 = false;
|
||||
break;
|
||||
case 37:
|
||||
moveLeft2 = false;
|
||||
break;
|
||||
|
||||
// Shared Controls \\
|
||||
|
||||
case 32:
|
||||
reset = false;
|
||||
break;
|
||||
case 16:
|
||||
Player.speedModifier = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
64
wat/src/bz/bronze/wat/Game.java
Normal file
64
wat/src/bz/bronze/wat/Game.java
Normal file
|
@ -0,0 +1,64 @@
|
|||
package bz.bronze.wat;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class Game {
|
||||
static JFrame window = new JFrame();
|
||||
static JPanel container = new JPanel();
|
||||
static Renderer renderer = new Renderer();
|
||||
static Player player = new Player();
|
||||
static Collisions collisions = new Collisions();
|
||||
|
||||
static String title = "io.agar";
|
||||
|
||||
static int width = 800;
|
||||
static int height = 600;
|
||||
|
||||
static int tickRate = 60;
|
||||
static int SKIPTICKS = 1000 / tickRate;
|
||||
static long SLEEPTIME = 0;
|
||||
static long NEXT = System.currentTimeMillis();
|
||||
|
||||
static boolean isRunning;
|
||||
|
||||
public void tick()
|
||||
{
|
||||
while (isRunning)
|
||||
{
|
||||
NEXT += SKIPTICKS;
|
||||
SLEEPTIME = NEXT - System.currentTimeMillis();
|
||||
|
||||
if(SLEEPTIME >= 0) {
|
||||
try {
|
||||
player.move();
|
||||
collisions.check();
|
||||
Thread.sleep(SLEEPTIME);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Running behind!
|
||||
System.out.println("Running Behind!");
|
||||
}
|
||||
|
||||
renderer.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
public void init()
|
||||
{
|
||||
isRunning = true;
|
||||
|
||||
window.addKeyListener(new Controls());
|
||||
|
||||
window.add(renderer);
|
||||
|
||||
window.setTitle(title);
|
||||
window.setSize(width, height);
|
||||
window.setLocationRelativeTo(null);
|
||||
window.setResizable(false);
|
||||
window.setVisible(true);
|
||||
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
}
|
||||
}
|
11
wat/src/bz/bronze/wat/Main.java
Normal file
11
wat/src/bz/bronze/wat/Main.java
Normal file
|
@ -0,0 +1,11 @@
|
|||
package bz.bronze.wat;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args)
|
||||
{
|
||||
Game aa = new Game();
|
||||
|
||||
aa.init();
|
||||
aa.tick();
|
||||
}
|
||||
}
|
69
wat/src/bz/bronze/wat/Player.java
Normal file
69
wat/src/bz/bronze/wat/Player.java
Normal file
|
@ -0,0 +1,69 @@
|
|||
package bz.bronze.wat;
|
||||
|
||||
public class Player {
|
||||
static int x1 = 0;
|
||||
static int y1 = 0;
|
||||
static int width1 = 200;
|
||||
static int height1 = 200;
|
||||
static int moveSpeed1 = 1;
|
||||
static boolean isAlive1 = true;
|
||||
|
||||
static int x2 = 500;
|
||||
static int y2 = 400;
|
||||
static int width2 = 150;
|
||||
static int height2 = 150;
|
||||
static int moveSpeed2 = 2;
|
||||
static boolean isAlive2 = true;
|
||||
|
||||
static int speedModifier = 1;
|
||||
|
||||
public void move()
|
||||
{
|
||||
// Player 1 Movement \\
|
||||
|
||||
if (Controls.moveUp1)
|
||||
{
|
||||
y1 -= moveSpeed1 * speedModifier;
|
||||
}
|
||||
if (Controls.moveDown1)
|
||||
{
|
||||
y1 += moveSpeed1 * speedModifier;
|
||||
}
|
||||
if (Controls.moveRight1)
|
||||
{
|
||||
x1 += moveSpeed1 * speedModifier;
|
||||
}
|
||||
if (Controls.moveLeft1)
|
||||
{
|
||||
x1 -= moveSpeed1 * speedModifier;
|
||||
}
|
||||
|
||||
// Player 2 Movement \\
|
||||
|
||||
if (Controls.moveUp2)
|
||||
{
|
||||
y2 -= moveSpeed2 * speedModifier;
|
||||
}
|
||||
if (Controls.moveDown2)
|
||||
{
|
||||
y2 += moveSpeed2 * speedModifier;
|
||||
}
|
||||
if (Controls.moveRight2)
|
||||
{
|
||||
x2 += moveSpeed2 * speedModifier;
|
||||
}
|
||||
if (Controls.moveLeft2)
|
||||
{
|
||||
x2 -= moveSpeed2 * speedModifier;
|
||||
}
|
||||
|
||||
// Shared Player Methods \\
|
||||
if (Controls.reset)
|
||||
{
|
||||
x1 = 0;
|
||||
y1 = 0;
|
||||
x2 = 500;
|
||||
y2 = 400;
|
||||
}
|
||||
}
|
||||
}
|
28
wat/src/bz/bronze/wat/Renderer.java
Normal file
28
wat/src/bz/bronze/wat/Renderer.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
package bz.bronze.wat;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class Renderer extends JPanel {
|
||||
private static final long serialVersionUID = -9142234797559997422L;
|
||||
|
||||
public void paintComponent(Graphics g)
|
||||
{
|
||||
super.paintComponent(g); // Wipes Previous Frames
|
||||
|
||||
g.setColor(Color.CYAN); // Set Player 1 Color
|
||||
|
||||
if (Player.isAlive1)
|
||||
{
|
||||
g.fillOval(Player.x1, Player.y1, Player.width1, Player.height1);
|
||||
}
|
||||
|
||||
g.setColor(Color.RED); // Set Player 2 Color
|
||||
|
||||
if (Player.isAlive2)
|
||||
{
|
||||
g.fillOval(Player.x2, Player.y2, Player.width2, Player.height2);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue