mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 10:19:46 +02:00
Aufgeräumt. Rendering. Erste Kollisionserkennung.
This commit is contained in:
@@ -3,6 +3,7 @@ package de.heatup.testing;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
@@ -11,6 +12,7 @@ import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import de.heatup.mapengine.MapEngine;
|
||||
import de.heatup.mapengine.SpawnAssistant;
|
||||
import de.heatup.objects.DynamicObject;
|
||||
import de.heatup.objects.StaticObject;
|
||||
import de.heatup.objects.logic;
|
||||
@@ -79,6 +81,8 @@ public class GameLoopD extends JFrame implements Runnable {
|
||||
/*
|
||||
* zeug aus dem alten gameloop
|
||||
*/
|
||||
|
||||
|
||||
DynamicObject dynO1 = new DynamicObject();
|
||||
gamePanel.add(dynO1);
|
||||
DynamicObject dynO2 = new DynamicObject();
|
||||
@@ -88,35 +92,31 @@ public class GameLoopD extends JFrame implements Runnable {
|
||||
DynamicObject dynO4 = new DynamicObject();
|
||||
gamePanel.add(dynO4);
|
||||
|
||||
|
||||
|
||||
player01 = new Player();
|
||||
Query.setPlayer(player01);
|
||||
// Query.setPlayer(player01);
|
||||
gamePanel.add(player01);
|
||||
player01.setBounds(25, 25, 200, 200);
|
||||
player01.setBounds(25, 25, 200, 200); // !!! MUSS DRIN BLEIBEN TROTZ NACHTRÄGLICHES SPAWN UMSETZEN !!!
|
||||
|
||||
gamePanel.setFocusable(true);
|
||||
|
||||
kb = new KeyBindings(player01);
|
||||
gamePanel.addKeyListener(kb);
|
||||
|
||||
//dynO3.setRescale(1.5,3.5);
|
||||
|
||||
// Config.setGamePanelWidth(900);
|
||||
MapEngine me = new MapEngine(1);
|
||||
for (StaticObject currentStaticObject : me.getAllMapObjects()) {
|
||||
gamePanel.add(currentStaticObject);
|
||||
}
|
||||
|
||||
Point spawnPoint = SpawnAssistant.getPathLocationOnGrid();
|
||||
player01.spawnAt(spawnPoint);
|
||||
|
||||
gamePanel.setVisible(true);
|
||||
|
||||
//GameInterface.getGamePanel().repaint();
|
||||
//GameInterface.getGamePanel().setComponentZOrder(dynO1, 1);
|
||||
//GameInterface.getGamePanel().add(dynO1);
|
||||
//logic.startMovement(dynO1);
|
||||
//logic.startMovement(dynO2);
|
||||
|
||||
logic.startMovement(dynO3);
|
||||
|
||||
//logic.startMovement(dynO4);
|
||||
|
||||
|
||||
/*
|
||||
@@ -158,7 +158,7 @@ public class GameLoopD extends JFrame implements Runnable {
|
||||
public void run() {
|
||||
|
||||
long lastTime = System.nanoTime();
|
||||
final double fps = 30.0;
|
||||
final double fps = 60.0;
|
||||
double ns = 1000000000 / fps;
|
||||
double delta = 0;
|
||||
int updates = 0;
|
||||
@@ -195,7 +195,7 @@ public class GameLoopD extends JFrame implements Runnable {
|
||||
}
|
||||
// alles was animiert wird hier rein (paints)
|
||||
private void render() {
|
||||
|
||||
player01.repaint();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package de.heatup.testing;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
@@ -39,7 +40,16 @@ public class Player extends JComponent {
|
||||
int startY;
|
||||
|
||||
int currentCountX = 25;
|
||||
int currentCountY = 0;
|
||||
|
||||
private Point currentGridPosition;
|
||||
|
||||
public void setGridLocation(int x, int y) {
|
||||
currentGridPosition.setLocation(x, y);
|
||||
}
|
||||
|
||||
public Point getGridLocation() {
|
||||
return currentGridPosition;
|
||||
}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
g2d = (Graphics2D) g;
|
||||
@@ -56,6 +66,11 @@ public class Player extends JComponent {
|
||||
g2d.finalize();
|
||||
}
|
||||
|
||||
public void spawnAt(Point spawnPoint) {
|
||||
this.currentGridPosition = spawnPoint;
|
||||
this.setAutoBounds(spawnPoint.x*25, spawnPoint.y*25);
|
||||
this.repaint();
|
||||
}
|
||||
private void loadBufferedImage() {
|
||||
try {
|
||||
this.bf1 = ImageIO
|
||||
@@ -86,7 +101,7 @@ public class Player extends JComponent {
|
||||
int newx = this.getX();
|
||||
int newy = this.getY();
|
||||
|
||||
for (int s = 0; s<4; s++) { // speed multiplikator
|
||||
for (int s = 0; s<2; s++) { // speed multiplikator
|
||||
|
||||
|
||||
if (d == 'x' && i == -1) {
|
||||
@@ -101,7 +116,9 @@ public class Player extends JComponent {
|
||||
|
||||
this.setAutoBounds(newx, newy);
|
||||
|
||||
System.out.println("X: " + newx + " Y: " + newy);
|
||||
//debug
|
||||
System.out.println("on grid - x: "+getGridLocation().x + " y: "+getGridLocation().y);
|
||||
|
||||
currentCountX--;
|
||||
|
||||
if ( currentCountX <= 0 ) {
|
||||
@@ -114,46 +131,6 @@ public class Player extends JComponent {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 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,6 +3,7 @@ package de.heatup.ui;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import de.heatup.mapengine.MapGrid;
|
||||
import de.heatup.testing.Player;
|
||||
|
||||
public class KeyBindings extends KeyAdapter {
|
||||
@@ -57,29 +58,36 @@ public class KeyBindings extends KeyAdapter {
|
||||
|
||||
public void foo() {
|
||||
|
||||
if (isLeft()) {
|
||||
if (!player.animate) {
|
||||
/*
|
||||
* rudimentäre kollisionserkennung, exportiere ich gerade in eigenes modul :)
|
||||
*/
|
||||
if (isLeft() && MapGrid.getGridCell(player.getGridLocation().x-1, player.getGridLocation().y).isPath()) {
|
||||
if (!player.animate ) {
|
||||
player.setGridLocation(player.getGridLocation().x-1, player.getGridLocation().y);
|
||||
player.step('x', -1);
|
||||
player.startMove = true;
|
||||
}
|
||||
player.animate = true;
|
||||
}
|
||||
if (isRight()) {
|
||||
if (!player.animate) {
|
||||
if (isRight() && MapGrid.getGridCell(player.getGridLocation().x+1, player.getGridLocation().y).isPath()) {
|
||||
if (!player.animate ) {
|
||||
player.setGridLocation(player.getGridLocation().x+1, player.getGridLocation().y);
|
||||
player.step('x', 1);
|
||||
player.startMove = true;
|
||||
}
|
||||
player.animate = true;
|
||||
}
|
||||
if (isUp()) {
|
||||
if (!player.animate) {
|
||||
if (isUp() && MapGrid.getGridCell(player.getGridLocation().x, player.getGridLocation().y-1).isPath()) {
|
||||
if (!player.animate ) {
|
||||
player.setGridLocation(player.getGridLocation().x, player.getGridLocation().y-1);
|
||||
player.step('y', -1);
|
||||
player.startMove = true;
|
||||
}
|
||||
player.animate = true;
|
||||
}
|
||||
if (isDown()) {
|
||||
if (!player.animate) {
|
||||
if (isDown() && MapGrid.getGridCell(player.getGridLocation().x, player.getGridLocation().y+1).isPath()) {
|
||||
if (!player.animate ) {
|
||||
player.setGridLocation(player.getGridLocation().x, player.getGridLocation().y+1);
|
||||
player.step('y', 1);
|
||||
player.startMove = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user