mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 08:49:44 +02:00
Ficken ist!
This commit is contained in:
@@ -95,7 +95,7 @@ public class GameLoopD extends JFrame implements Runnable {
|
||||
|
||||
gamePanel.setFocusable(true);
|
||||
|
||||
kb = new KeyBindings();
|
||||
kb = new KeyBindings(player01);
|
||||
gamePanel.addKeyListener(kb);
|
||||
|
||||
//dynO3.setRescale(1.5,3.5);
|
||||
@@ -158,14 +158,15 @@ public class GameLoopD extends JFrame implements Runnable {
|
||||
public void run() {
|
||||
|
||||
long lastTime = System.nanoTime();
|
||||
final double fps = 60.0;
|
||||
final double fps = 30.0;
|
||||
double ns = 1000000000 / fps;
|
||||
double delta = 0;
|
||||
int updates = 0;
|
||||
int frames = 0;
|
||||
long timer = System.currentTimeMillis();
|
||||
|
||||
while (running) {
|
||||
while (running) {
|
||||
kb.foo();
|
||||
long now = System.nanoTime();
|
||||
delta += (now-lastTime) / ns;
|
||||
lastTime = now;
|
||||
@@ -189,15 +190,7 @@ public class GameLoopD extends JFrame implements Runnable {
|
||||
}
|
||||
// alles was geupdatet werden muss hier rein
|
||||
private void tick() {
|
||||
if (kb.isRight()) {
|
||||
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);
|
||||
}
|
||||
player01.tick();
|
||||
|
||||
}
|
||||
// alles was animiert wird hier rein (paints)
|
||||
|
||||
@@ -19,68 +19,141 @@ import de.heatup.objects.ImageLoader;
|
||||
|
||||
public class Player extends JComponent {
|
||||
private static final long serialVersionUID = 1L;
|
||||
//private Image image;
|
||||
// private Image image;
|
||||
private BufferedImage bf1;
|
||||
private Graphics2D g2d;
|
||||
|
||||
|
||||
private double rescaleFactorX = 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) {
|
||||
g2d = (Graphics2D)g;
|
||||
//this.image = Toolkit.getDefaultToolkit().getImage("src/de/heatup/resources/images/little_green_guy.png");
|
||||
if ( bf1 == null ) {
|
||||
g2d = (Graphics2D) g;
|
||||
// this.image =
|
||||
// Toolkit.getDefaultToolkit().getImage("src/de/heatup/resources/images/little_green_guy.png");
|
||||
if (bf1 == null) {
|
||||
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.setStroke(new BasicStroke(8.0f));
|
||||
g2d.finalize();
|
||||
}
|
||||
|
||||
|
||||
private void loadBufferedImage() {
|
||||
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) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setImage(BufferedImage image) {
|
||||
this.bf1 = image;
|
||||
}
|
||||
|
||||
|
||||
public void setAutoBounds(int x, int y) {
|
||||
this.setBounds(x, y, this.bf1.getWidth(), this.bf1.getHeight());
|
||||
}
|
||||
|
||||
public void step(final char d, final int i) {
|
||||
final int stepx = 25;
|
||||
final int stepy = 25;
|
||||
|
||||
|
||||
public void step(char d, int i) {
|
||||
this.d = d;
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
|
||||
if ( startMove || animate ) {
|
||||
|
||||
int newx = this.getX();
|
||||
int newy = this.getY();
|
||||
int countx = stepx;
|
||||
int county = stepy;
|
||||
|
||||
while (true) {
|
||||
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;
|
||||
} else {
|
||||
|
||||
for (int s = 0; s<4; s++) { // speed multiplikator
|
||||
|
||||
|
||||
if (d == 'x' && i == -1) {
|
||||
newx = newx - 1;
|
||||
} else if (d == 'x' && i == 1) {
|
||||
newx = newx + 1;
|
||||
} else if (d == 'y' && i == -1) {
|
||||
newy = newy - 1;
|
||||
} else if (d == 'y' && i == 1) {
|
||||
newy = newy + 1;
|
||||
}
|
||||
|
||||
this.setAutoBounds(newx, newy);
|
||||
|
||||
System.out.println("X: " + newx + " Y: " + newy);
|
||||
currentCountX--;
|
||||
|
||||
if ( currentCountX <= 0 ) {
|
||||
animate = false;
|
||||
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.KeyEvent;
|
||||
|
||||
public class KeyBindings extends KeyAdapter {
|
||||
|
||||
private boolean left=false;
|
||||
private boolean right=false;
|
||||
private boolean up=false;
|
||||
private boolean down=false;
|
||||
import de.heatup.testing.Player;
|
||||
|
||||
@Override public void keyReleased(KeyEvent evt) {
|
||||
int keyCode = evt.getKeyCode();
|
||||
switch (keyCode) {
|
||||
case KeyEvent.VK_LEFT: left=false; break;
|
||||
case KeyEvent.VK_RIGHT: right=false; break;
|
||||
case KeyEvent.VK_UP: up=false; break;
|
||||
case KeyEvent.VK_DOWN: down=false; break;
|
||||
}
|
||||
public class KeyBindings extends KeyAdapter {
|
||||
|
||||
private boolean left = false;
|
||||
private boolean right = false;
|
||||
private boolean up = false;
|
||||
private boolean down = false;
|
||||
private Player player;
|
||||
|
||||
public KeyBindings(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override public void keyPressed(KeyEvent evt) {
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent evt) {
|
||||
int keyCode = evt.getKeyCode();
|
||||
switch (keyCode) {
|
||||
case KeyEvent.VK_LEFT: left=true; break;
|
||||
case KeyEvent.VK_RIGHT: right=true; break;
|
||||
case KeyEvent.VK_UP: up=true; break;
|
||||
case KeyEvent.VK_DOWN: down=true; break;
|
||||
case KeyEvent.VK_LEFT:
|
||||
left = 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) {
|
||||
int keyCode = evt.getKeyCode();
|
||||
switch (keyCode) {
|
||||
case KeyEvent.VK_LEFT:
|
||||
left = 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