mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 11:39:45 +02:00
Ficken ist!
This commit is contained in:
@@ -95,7 +95,7 @@ public class GameLoopD extends JFrame implements Runnable {
|
|||||||
|
|
||||||
gamePanel.setFocusable(true);
|
gamePanel.setFocusable(true);
|
||||||
|
|
||||||
kb = new KeyBindings();
|
kb = new KeyBindings(player01);
|
||||||
gamePanel.addKeyListener(kb);
|
gamePanel.addKeyListener(kb);
|
||||||
|
|
||||||
//dynO3.setRescale(1.5,3.5);
|
//dynO3.setRescale(1.5,3.5);
|
||||||
@@ -158,7 +158,7 @@ public class GameLoopD extends JFrame implements Runnable {
|
|||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
long lastTime = System.nanoTime();
|
long lastTime = System.nanoTime();
|
||||||
final double fps = 60.0;
|
final double fps = 30.0;
|
||||||
double ns = 1000000000 / fps;
|
double ns = 1000000000 / fps;
|
||||||
double delta = 0;
|
double delta = 0;
|
||||||
int updates = 0;
|
int updates = 0;
|
||||||
@@ -166,6 +166,7 @@ public class GameLoopD extends JFrame implements Runnable {
|
|||||||
long timer = System.currentTimeMillis();
|
long timer = System.currentTimeMillis();
|
||||||
|
|
||||||
while (running) {
|
while (running) {
|
||||||
|
kb.foo();
|
||||||
long now = System.nanoTime();
|
long now = System.nanoTime();
|
||||||
delta += (now-lastTime) / ns;
|
delta += (now-lastTime) / ns;
|
||||||
lastTime = now;
|
lastTime = now;
|
||||||
@@ -189,15 +190,7 @@ public class GameLoopD extends JFrame implements Runnable {
|
|||||||
}
|
}
|
||||||
// alles was geupdatet werden muss hier rein
|
// alles was geupdatet werden muss hier rein
|
||||||
private void tick() {
|
private void tick() {
|
||||||
if (kb.isRight()) {
|
player01.tick();
|
||||||
player01.step('x', 1);
|
|
||||||
} else if (kb.isLeft()) {
|
|
||||||
player01.step('x', -1);
|
|
||||||
} else if (kb.isUp()) {
|
|
||||||
player01.step('y', -1);
|
|
||||||
} else if (kb.isDown()) {
|
|
||||||
player01.step('y', 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// alles was animiert wird hier rein (paints)
|
// alles was animiert wird hier rein (paints)
|
||||||
|
|||||||
@@ -26,14 +26,31 @@ public class Player extends JComponent {
|
|||||||
private double rescaleFactorX = 0.0;
|
private double rescaleFactorX = 0.0;
|
||||||
private double rescaleFactorY = 0.0;
|
private double rescaleFactorY = 0.0;
|
||||||
|
|
||||||
|
public boolean startMove = false;
|
||||||
|
public boolean animate = false;
|
||||||
|
|
||||||
|
private char d;
|
||||||
|
private int i;
|
||||||
|
|
||||||
|
final int stepx = 25;
|
||||||
|
final int stepy = 25;
|
||||||
|
|
||||||
|
int startX;
|
||||||
|
int startY;
|
||||||
|
|
||||||
|
int currentCountX = 25;
|
||||||
|
int currentCountY = 0;
|
||||||
|
|
||||||
public void paintComponent(Graphics g) {
|
public void paintComponent(Graphics g) {
|
||||||
g2d = (Graphics2D) g;
|
g2d = (Graphics2D) g;
|
||||||
//this.image = Toolkit.getDefaultToolkit().getImage("src/de/heatup/resources/images/little_green_guy.png");
|
// this.image =
|
||||||
|
// Toolkit.getDefaultToolkit().getImage("src/de/heatup/resources/images/little_green_guy.png");
|
||||||
if (bf1 == null) {
|
if (bf1 == null) {
|
||||||
loadBufferedImage();
|
loadBufferedImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||||
|
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
g2d.drawImage(bf1, 0, 0, this);
|
g2d.drawImage(bf1, 0, 0, this);
|
||||||
g2d.setStroke(new BasicStroke(8.0f));
|
g2d.setStroke(new BasicStroke(8.0f));
|
||||||
g2d.finalize();
|
g2d.finalize();
|
||||||
@@ -41,7 +58,9 @@ public class Player extends JComponent {
|
|||||||
|
|
||||||
private void loadBufferedImage() {
|
private void loadBufferedImage() {
|
||||||
try {
|
try {
|
||||||
this.bf1 = ImageIO.read(new File("src/de/heatup/resources/images/little_blue_guy_verysmall.png"));
|
this.bf1 = ImageIO
|
||||||
|
.read(new File(
|
||||||
|
"src/de/heatup/resources/images/little_blue_guy_verysmall.png"));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -55,32 +74,86 @@ public class Player extends JComponent {
|
|||||||
this.setBounds(x, y, this.bf1.getWidth(), this.bf1.getHeight());
|
this.setBounds(x, y, this.bf1.getWidth(), this.bf1.getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void step(final char d, final int i) {
|
public void step(char d, int i) {
|
||||||
final int stepx = 25;
|
this.d = d;
|
||||||
final int stepy = 25;
|
this.i = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tick() {
|
||||||
|
|
||||||
|
if ( startMove || animate ) {
|
||||||
|
|
||||||
int newx = this.getX();
|
int newx = this.getX();
|
||||||
int newy = this.getY();
|
int newy = this.getY();
|
||||||
int countx = stepx;
|
|
||||||
int county = stepy;
|
|
||||||
|
|
||||||
while (true) {
|
for (int s = 0; s<4; s++) { // speed multiplikator
|
||||||
if (d == 'x' && i == -1 && countx != 0) {
|
|
||||||
countx=countx-1;
|
|
||||||
|
if (d == 'x' && i == -1) {
|
||||||
newx = newx - 1;
|
newx = newx - 1;
|
||||||
} else if ( d == 'x' && i == 1 && countx != 0 ) {
|
} else if (d == 'x' && i == 1) {
|
||||||
countx=countx-1;
|
|
||||||
newx = newx + 1;
|
newx = newx + 1;
|
||||||
} else if ( d == 'y' && i == -1 && county != 0 ) {
|
} else if (d == 'y' && i == -1) {
|
||||||
county=county-1;
|
|
||||||
newy = newy - 1;
|
newy = newy - 1;
|
||||||
} else if ( d == 'y' && i == 1 && county != 0 ) {
|
} else if (d == 'y' && i == 1) {
|
||||||
county=county-1;
|
|
||||||
newy = newy + 1;
|
newy = newy + 1;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
this.setAutoBounds(newx, newy);
|
||||||
|
|
||||||
|
System.out.println("X: " + newx + " Y: " + newy);
|
||||||
|
currentCountX--;
|
||||||
|
|
||||||
|
if ( currentCountX <= 0 ) {
|
||||||
|
animate = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
this.setAutoBounds(newx, newy);
|
}
|
||||||
}
|
if (currentCountX <= 0) {
|
||||||
|
currentCountX = 25;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (foo) {
|
||||||
|
//
|
||||||
|
// int newx = this.getX();
|
||||||
|
// int newy = this.getY();
|
||||||
|
//
|
||||||
|
// int countx = 0;
|
||||||
|
// int county = 0;
|
||||||
|
//
|
||||||
|
// if (currentCountX == 0 && currentCountY == 0) {
|
||||||
|
// currentCountX = stepx;
|
||||||
|
// currentCountY = stepy;
|
||||||
|
// } else {
|
||||||
|
// countx = currentCountX;
|
||||||
|
// county = currentCountY;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // while (true) {
|
||||||
|
// if (countx != 0) {
|
||||||
|
// if (d == 'x' && i == -1 && countx != 0) {
|
||||||
|
// countx = countx - 1;
|
||||||
|
// newx = newx - 1;
|
||||||
|
// } else if (d == 'x' && i == 1 && countx != 0) {
|
||||||
|
// countx = countx - 1;
|
||||||
|
// newx = newx + 1;
|
||||||
|
// } else if (d == 'y' && i == -1 && county != 0) {
|
||||||
|
// county = county - 1;
|
||||||
|
// newy = newy - 1;
|
||||||
|
// } else if (d == 'y' && i == 1 && county != 0) {
|
||||||
|
// county = county - 1;
|
||||||
|
// newy = newy + 1;
|
||||||
|
// }
|
||||||
|
// this.setAutoBounds(newx, newy);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// currentCountX = countx;
|
||||||
|
// currentCountY = county;
|
||||||
|
//
|
||||||
|
// // }
|
||||||
|
startMove = false;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,30 +3,87 @@ package de.heatup.ui;
|
|||||||
import java.awt.event.KeyAdapter;
|
import java.awt.event.KeyAdapter;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
|
|
||||||
|
import de.heatup.testing.Player;
|
||||||
|
|
||||||
public class KeyBindings extends KeyAdapter {
|
public class KeyBindings extends KeyAdapter {
|
||||||
|
|
||||||
private boolean left = false;
|
private boolean left = false;
|
||||||
private boolean right = false;
|
private boolean right = false;
|
||||||
private boolean up = false;
|
private boolean up = false;
|
||||||
private boolean down = false;
|
private boolean down = false;
|
||||||
|
private Player player;
|
||||||
|
|
||||||
@Override public void keyReleased(KeyEvent evt) {
|
public KeyBindings(Player player) {
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyReleased(KeyEvent evt) {
|
||||||
int keyCode = evt.getKeyCode();
|
int keyCode = evt.getKeyCode();
|
||||||
switch (keyCode) {
|
switch (keyCode) {
|
||||||
case KeyEvent.VK_LEFT: left=false; break;
|
case KeyEvent.VK_LEFT:
|
||||||
case KeyEvent.VK_RIGHT: right=false; break;
|
left = false;
|
||||||
case KeyEvent.VK_UP: up=false; break;
|
break;
|
||||||
case KeyEvent.VK_DOWN: down=false; break;
|
case KeyEvent.VK_RIGHT:
|
||||||
|
right = false;
|
||||||
|
break;
|
||||||
|
case KeyEvent.VK_UP:
|
||||||
|
up = false;
|
||||||
|
break;
|
||||||
|
case KeyEvent.VK_DOWN:
|
||||||
|
down = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void keyPressed(KeyEvent evt) {
|
@Override
|
||||||
|
public void keyPressed(KeyEvent evt) {
|
||||||
int keyCode = evt.getKeyCode();
|
int keyCode = evt.getKeyCode();
|
||||||
switch (keyCode) {
|
switch (keyCode) {
|
||||||
case KeyEvent.VK_LEFT: left=true; break;
|
case KeyEvent.VK_LEFT:
|
||||||
case KeyEvent.VK_RIGHT: right=true; break;
|
left = true;
|
||||||
case KeyEvent.VK_UP: up=true; break;
|
break;
|
||||||
case KeyEvent.VK_DOWN: down=true; break;
|
case KeyEvent.VK_RIGHT:
|
||||||
|
right = true;
|
||||||
|
break;
|
||||||
|
case KeyEvent.VK_UP:
|
||||||
|
up = true;
|
||||||
|
break;
|
||||||
|
case KeyEvent.VK_DOWN:
|
||||||
|
down = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void foo() {
|
||||||
|
|
||||||
|
if (isLeft()) {
|
||||||
|
if (!player.animate) {
|
||||||
|
player.step('x', -1);
|
||||||
|
player.startMove = true;
|
||||||
|
}
|
||||||
|
player.animate = true;
|
||||||
|
}
|
||||||
|
if (isRight()) {
|
||||||
|
if (!player.animate) {
|
||||||
|
player.step('x', 1);
|
||||||
|
player.startMove = true;
|
||||||
|
}
|
||||||
|
player.animate = true;
|
||||||
|
}
|
||||||
|
if (isUp()) {
|
||||||
|
if (!player.animate) {
|
||||||
|
player.step('y', -1);
|
||||||
|
player.startMove = true;
|
||||||
|
}
|
||||||
|
player.animate = true;
|
||||||
|
}
|
||||||
|
if (isDown()) {
|
||||||
|
if (!player.animate) {
|
||||||
|
player.step('y', 1);
|
||||||
|
player.startMove = true;
|
||||||
|
}
|
||||||
|
player.animate = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user