Merge branch 'master' of github.com:jokerx3/prp

This commit is contained in:
toksikk
2014-11-04 14:17:12 +01:00
10 changed files with 210 additions and 27 deletions
@@ -27,16 +27,16 @@ public class ImageLoader {
imageFileName="src/de/heatup/resources/images/25x25_wall_orange_2.png"; imageFileName="src/de/heatup/resources/images/25x25_wall_orange_2.png";
break; break;
case 'u': case 'u':
imageFileName="src/de/heatup/resources/images/little_green_guy_up.png"; imageFileName="src/de/heatup/resources/images/little_green_guy_verysmall.png";
break; break;
case 'd': case 'd':
imageFileName="src/de/heatup/resources/images/little_green_guy.png"; imageFileName="src/de/heatup/resources/images/little_green_guy_verysmall.png";
break; break;
case 'l': case 'l':
imageFileName="src/de/heatup/resources/images/little_green_guy_left.png"; imageFileName="src/de/heatup/resources/images/little_green_guy_verysmall.png";
break; break;
case 'r': case 'r':
imageFileName="src/de/heatup/resources/images/little_green_guy_right.png"; imageFileName="src/de/heatup/resources/images/little_green_guy_verysmall.png";
break; break;
default: default:
imageFileName="src/de/heatup/resources/images/dummy_image.png"; imageFileName="src/de/heatup/resources/images/dummy_image.png";
+28 -15
View File
@@ -10,6 +10,8 @@ import java.io.IOException;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.swing.JComponent; import javax.swing.JComponent;
import de.heatup.cfg.Config;
/* /*
* Draft for static objects * Draft for static objects
*/ */
@@ -30,18 +32,21 @@ public class StaticObject extends JComponent {
private int staticObjectHeight; private int staticObjectHeight;
public StaticObject(char staticObjectType, Point location, int staticObjectWidth, int staticObjectHeight) { public StaticObject(char staticObjectType, Point location, int staticObjectWidth, int staticObjectHeight) {
// System.out.println("Object Type: " + staticObjectType + "\t" +staticObjectHeight + " h:w " + staticObjectWidth);
this.staticObjectType = staticObjectType; this.staticObjectType = staticObjectType;
this.location = location; this.location = location;
this.staticObjectWidth = staticObjectWidth; this.staticObjectWidth = staticObjectWidth;
this.staticObjectHeight = staticObjectHeight; this.staticObjectHeight = staticObjectHeight;
loadBufferedImage(); loadBufferedImage();
setAutoBounds(location.x, location.y); setAutoBounds(location.x, location.y);
// autoRescale();
// System.out.println(getDebugInfo());
} }
public StaticObject(char staticObjectType, Point location) { public StaticObject(char staticObjectType, Point location) {
this(staticObjectType, location, 25, 25); this(staticObjectType, location, Config.singleTilePixels, Config.singleTilePixels);
} }
public void paintComponent(Graphics g) { public void paintComponent(Graphics g) {
this.g2d = (Graphics2D)g; this.g2d = (Graphics2D)g;
@@ -51,9 +56,11 @@ public class StaticObject extends JComponent {
} }
//g2d.rotate(0.2, 10, 10); //g2d.rotate(0.2, 10, 10);
if ( doRescale ) { // TODO: Check if we can store a rescaled image in bf1???
g2d.scale(rescaleFactorX, rescaleFactorY); // if ( doRescale ) {
} // System.out.println("Hit: " + rescaleFactorX + " " + rescaleFactorY);
// g2d.scale(rescaleFactorX, rescaleFactorY);
// }
g2d.drawImage(bf1, 0, 0, this); g2d.drawImage(bf1, 0, 0, this);
g2d.finalize(); g2d.finalize();
@@ -67,24 +74,30 @@ public class StaticObject extends JComponent {
this.bf1 = image; this.bf1 = image;
} }
public void setRescale(double rescaleFactorX, double rescaleFactorY) { private void autoRescale() {
this.rescaleFactorX = rescaleFactorX; // TODO: get original width and hight of bf1
this.rescaleFactorY = rescaleFactorY; // Calculate factor new/original
this.doRescale = true; // Rescale image using factor
// Save new bf in bf1 ???
this.rescaleFactorX = (double)this.staticObjectWidth / (double)this.bf1.getWidth();
this.rescaleFactorY = (double)this.staticObjectHeight / (double)this.bf1.getHeight();
//System.out.println("Object: " + this.staticObjectType + "\tBuffered Image: Height: " + this.bf1.getHeight() + "\t Width: " + this.bf1.getWidth() + "\tStatic Object: Height: " + this.staticObjectHeight + "\t Width: " + this.staticObjectWidth);
if (this.rescaleFactorX != 1 || this.rescaleFactorY != 1 ) {
this.doRescale = true;
}
} }
public void unsetRescale() { // TODO: getter für höhe breite position
this.rescaleFactorX = 0.0;
this.rescaleFactorY = 0.0;
this.doRescale = false;
}
public void setAutoBounds(int x, int y) { public void setAutoBounds(int x, int y) {
this.setBounds(x, y, this.bf1.getWidth(), this.bf1.getHeight()); this.setBounds(x, y, this.bf1.getWidth(), this.bf1.getHeight());
} }
public String getDebugInfo() { public String getDebugInfo() {
String info = "Debug: " + "Rescale enabled:" + this.doRescale + "Rescale X:" + this.rescaleFactorX + "Rescale Y:" + this.rescaleFactorY + " Heigth:" + this.staticObjectHeight + " Width:" + this.staticObjectWidth + " StaticObjectType:" + this.staticObjectType + " X Position:" + this.location.x + " Y Position:" + this.location.y; String info = "Debug: " + "Rescale? " + this.doRescale + "\tScale X:" + this.rescaleFactorX + "\tScale Y: " + this.rescaleFactorY + "\tsH: " + this.staticObjectHeight + "\tsW: " + this.staticObjectWidth + "\tStaticObjectType: " + this.staticObjectType + "\tbW : " + this.bf1.getWidth() + "\tbH :" + this.bf1.getHeight();
return info; return info;
} }
} }
+1 -1
View File
@@ -84,7 +84,7 @@ public class logic {
//System.out.println("x: " + dynObj.getX() + " y: " + dynObj.getY()); //System.out.println("x: " + dynObj.getX() + " y: " + dynObj.getY());
//System.out.println("h: " + dynObj.getHeight() + " w: " + dynObj.getWidth()); //System.out.println("h: " + dynObj.getHeight() + " w: " + dynObj.getWidth());
try { try {
Thread.sleep(10); Thread.sleep(40);
} catch (InterruptedException e) { } catch (InterruptedException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

+2 -1
View File
@@ -2,6 +2,7 @@ package de.heatup.testing;
import javax.swing.JLabel; import javax.swing.JLabel;
import de.heatup.cfg.Config;
import de.heatup.mapengine.MapEngine; import de.heatup.mapengine.MapEngine;
import de.heatup.objects.DynamicObject; import de.heatup.objects.DynamicObject;
import de.heatup.objects.StaticObject; import de.heatup.objects.StaticObject;
@@ -25,7 +26,7 @@ public class GameLoop {
//dynO3.setRescale(1.5,3.5); //dynO3.setRescale(1.5,3.5);
// Config.setGamePanelWidth(900);
MapEngine me = new MapEngine(1); MapEngine me = new MapEngine(1);
for (StaticObject currentStaticObject : me.getAllMapObjects()) { for (StaticObject currentStaticObject : me.getAllMapObjects()) {
GameInterface.getGamePanel().add(currentStaticObject); GameInterface.getGamePanel().add(currentStaticObject);
+6 -6
View File
@@ -51,11 +51,11 @@ public class GameInterface extends JFrame {
final JFrame frame = new JFrame(); final JFrame frame = new JFrame();
// Fullscreen testing: Remember not to use pack() when using fullscreen mode // Fullscreen testing: Remember not to use pack() when using fullscreen mode
frame.setUndecorated(true); // frame.setUndecorated(true);
frame.setResizable(false); // frame.setResizable(false);
frame.setExtendedState(Frame.MAXIMIZED_BOTH); // frame.setExtendedState(Frame.MAXIMIZED_BOTH);
frame.validate(); // frame.validate();
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(frame); // GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(frame);
frame.setTitle("HeatUP!"); frame.setTitle("HeatUP!");
frame.setDefaultCloseOperation(EXIT_ON_CLOSE); frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
@@ -94,7 +94,7 @@ public class GameInterface extends JFrame {
frame.add(outerPanel); frame.add(outerPanel);
// Comment out for fullscreen // Comment out for fullscreen
//frame.pack(); frame.pack();
frame.setVisible(true); frame.setVisible(true);
frame.repaint(); frame.repaint();
} }
@@ -0,0 +1,65 @@
package de.heatup.ui;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;
import de.heatup.ui.statusPanel.Score;
import de.heatup.ui.statusPanel.Temperature;
import de.heatup.ui.statusPanel.Timer;
public class StatusPanelAdder{
Temperature temp;
Score score;
Timer timer;
public int getTemp(){
return temp.getTemp();
}
public int getScore(){
return score.getScore();
}
public double getTime(){
return timer.getTime();
}
public static void createPanel(){
JProgressBar tempbar= new JProgressBar(30,90);
tempbar.setValue(45);
//tempbar.setSize(new Dimension(200,50));
JLabel scoreLabel= new JLabel("new Score Label");
scoreLabel.setBorder(new LineBorder(Color.BLACK, 2));
//scoreLabel.setSize(new Dimension(100,50));
JLabel powerUpLabel = new JLabel(/*new ImageIcon("path_to_image.png")*/"powerUpLabel");
powerUpLabel.setBorder(new LineBorder(Color.BLACK, 1));
//powerUpLabel.setSize(new Dimension(200,50));
JLabel timeLabel = new JLabel();
timeLabel.setBorder(new LineBorder(Color.BLACK, 2));
timeLabel.setText("0");
//timeLabel.setSize(new Dimension(300,24)); //Groesse,
timeLabel.setHorizontalAlignment(SwingConstants.CENTER );
GameInterface.getStatusPanel().add(timeLabel);
GameInterface.getStatusPanel().add(tempbar);
GameInterface.getStatusPanel().add(scoreLabel);
GameInterface.getStatusPanel().add(powerUpLabel);
}
private static void getStatusPanel(){
GameInterface.getStatusPanel();
}
}
@@ -0,0 +1,30 @@
package de.heatup.ui.statusPanel;
public class Score {
private int score;
public Score(){
score=0;
}
//returns score
public int getScore(){
return score;
}
//resets score
public void resetScore(){
score=0;
}
//raises score
public void raiseScore(int additional){
score+=additional;
}
//reduces score; when score<0, score=0;
public void reduceScore(int reduce){
score-=reduce;
//when score less than 0
if (score<0){
score=0;
}
}
}
@@ -0,0 +1,47 @@
package de.heatup.ui.statusPanel;
public class Temperature {
private int min;
private int max;
private int valtemp;
//ggf. fr Schwierigkeitsgerade min und max zu verndern und startwert!?
public Temperature(int gmin, int gmax, int gtemp){
this.min=gmin;
this.max=gmax;
this.valtemp=gtemp;
}
//returns temp
public int getTemp(){
return valtemp;
}
/*
* raiseTemp
* return true, gameplay goes on
* return false, heatup done
*/
public boolean raiseTemp(int additional){
valtemp+=additional;
if(valtemp>max){
return false;
} else {
return true;
}
}
/* reduceTemp
* return true; gameplay goes on
* return false; game over, temperature too low
*/
public boolean reduceTemp(int reduce){
valtemp-=reduce;
if (valtemp<min){
return false;
} else {
return true;
}
}
}
@@ -0,0 +1,27 @@
package de.heatup.ui.statusPanel;
import java.util.Date;
public class Timer {
static double elapsedTime = 0L;
public static void main(String[] args){
double startTime = System.currentTimeMillis();
//1s = 1000ms
while (elapsedTime <10000) {
elapsedTime = (new Date()).getTime() - startTime;
System.out.println(elapsedTime);
}
}
public double getTime(){
return elapsedTime;
}
}