6 Commits
Author SHA1 Message Date
Yorick 23020d03b6 Added some icons and implemented them 2015-03-12 23:42:06 +00:00
Yorick 7e51fe541a Scrolling works, had boundaries, only draws an object when image is drawn, woo 2015-03-12 23:00:44 +00:00
Yorick fa726f062e Scrolling added 2015-03-12 22:44:02 +00:00
aareschluchtje 33f0105337 new horrible sprites 2015-03-12 23:16:43 +01:00
Yorick be6aba1e38 Added images to Panel 2015-03-12 21:56:42 +00:00
Yorick be342a5976 added dragbar 2015-03-11 21:50:15 +00:00
32 changed files with 212 additions and 27 deletions
+111 -11
View File
@@ -3,10 +3,7 @@ import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.TexturePaint;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.awt.geom.AffineTransform;
import java.awt.geom.Ellipse2D;
import java.awt.geom.NoninvertibleTransformException;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
@@ -21,11 +18,21 @@ import javax.swing.JPanel;
import Listeners.Mouse;
import Listeners.MouseMotion;
import Listeners.MouseWheel;
import Objects.Entrance;
import Objects.Path;
import Objects.Podium;
import Objects.Toilet;
import Objects.Wall;
public class Panel extends JPanel {
BufferedImage background;
BufferedImage podiumImage, toiletImage, entranceImage, pathImage,wallImage;
private int panelInfox, panelInfoy,scrollfactor;
private ArrayList<BufferedImage> panelInfo = new ArrayList<BufferedImage>();
// private ArrayList<Object> panelTypes = new ArrayList<Object>();
ArrayList<DrawObject> objects = new ArrayList<>();
DrawObject dragObject = null;
@@ -37,17 +44,35 @@ public class Panel extends JPanel {
Point2D lastClickPosition = new Point(0,0);
Point lastMousePosition = new Point(0,0);
//how to nieuwe dingen aan het panel toe te voegen:
//maak bufferedimage global aan, voeg er een image aan toe, en voeg de image aan panelInfo toe en het object aan panelTypes.
//en maak een case statement die een new Object returnt in createNewDrawObject.
Panel()
{
try {
background = ImageIO.read(new File("images/grass.jpg"));
podiumImage = ImageIO.read(new File("images/stageIcon.png"));
toiletImage = ImageIO.read(new File("images/wcIcon.png"));
entranceImage = ImageIO.read(new File("images/entranceIcon.png"));
pathImage = ImageIO.read(new File("images/pathIcon.png"));
wallImage = ImageIO.read(new File("images/wallIcon.png"));
} catch (IOException e) {
e.printStackTrace();
}
panelInfo.add(podiumImage);
panelInfo.add(toiletImage);
panelInfo.add(entranceImage);
panelInfo.add(pathImage);
panelInfo.add(wallImage);
objects.add(new Podium(new Point2D.Double(100, 100)));
objects.add(new Podium(new Point2D.Double(500, 100)));
objects.add(new Podium(new Point2D.Double(300, 400)));
panelInfox = 0;
panelInfoy = 0;
scrollfactor = 0;
// objects.add(new Podium(new Point2D.Double(100, 100)));
// objects.add(new Podium(new Point2D.Double(500, 100)));
// objects.add(new Podium(new Point2D.Double(300, 400)));
addMouseListener(new Mouse(this));
@@ -57,6 +82,35 @@ public class Panel extends JPanel {
}
public int getPanelInfoLength()
{
int panelInfoLength = 0;
for(BufferedImage image : panelInfo)
{
panelInfoLength += image.getWidth();
}
return panelInfoLength;
}
public DrawObject createNewDrawObject(int index)
{
switch(index)
{
case 0:
return new Podium(null);
case 1:
return new Toilet(null);
case 2:
return new Entrance(null);
case 3:
return new Path(null);
case 4:
return new Wall(null);
default:
return null;
}
}
public void add(DrawObject dragObject)
{
@@ -67,21 +121,30 @@ public class Panel extends JPanel {
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setClip(new Rectangle2D.Double(0,0, 200, getHeight()));
g2.setClip(new Rectangle2D.Double(0,0, getWidth(), 300));
g2.fill(new Ellipse2D.Double(0,0,300,300));
// g2.fill(new Ellipse2D.Double(0,0,300,300));
// g2.drawImage(podiumImage, 0, 0, null);
for(BufferedImage image : panelInfo)
{
g2.drawImage(image, panelInfox + scrollfactor, panelInfoy, null);
panelInfox += image.getWidth();
}
panelInfox = 0;
g2.setClip(new Rectangle2D.Double(200,0, getWidth()-200, getHeight()));
g2.setClip(new Rectangle2D.Double(0,150, getWidth(), getHeight()));
AffineTransform oldTransform = g2.getTransform();
g2.setTransform(getCamera());
TexturePaint p = new TexturePaint(background, new Rectangle2D.Double(0, 0, 100, 100));
g2.setPaint(p);
g2.fill(new Rectangle2D.Double(0,0,1920,1080));
g2.fill(new Rectangle2D.Double(-1920,-1080,3840,2160));
for(DrawObject o : objects)
for(DrawObject o : objects){
o.draw(g2);
}
g2.setClip(null);
@@ -171,6 +234,43 @@ public class Panel extends JPanel {
public void setLastMousePosition(Point lastMousePosition) {
this.lastMousePosition = lastMousePosition;
}
public BufferedImage getPodiumImage() {
return podiumImage;
}
public void setPodiumImage(BufferedImage podiumImage) {
this.podiumImage = podiumImage;
}
public ArrayList<BufferedImage> getPanelInfo() {
return panelInfo;
}
public void setPanelInfo(ArrayList<BufferedImage> panelInfo) {
this.panelInfo = panelInfo;
}
public int getScrollfactor() {
return scrollfactor;
}
public void setScrollfactor(int scrollfactor) {
this.scrollfactor = scrollfactor;
}
public int getPanelInfox() {
return panelInfox;
}
public void setPanelInfox(int panelInfox) {
this.panelInfox = panelInfox;
}
}
+27 -10
View File
@@ -3,12 +3,13 @@ package Listeners;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import java.util.Iterator;
import java.util.Map;
import Applicatie.DrawObject;
import Applicatie.Panel;
import Objects.Podium;
import Objects.Toilet;
import Applicatie.Panel;
public class Mouse extends MouseAdapter {
@@ -23,14 +24,31 @@ public class Mouse extends MouseAdapter {
Point2D clickPoint = panel.getClickPoint(e.getPoint());
panel.setLastClickPosition(clickPoint);
panel.setLastMousePosition(e.getPoint());
if(e.getX() < 200)
if(e.getY() < 150)
{
if(e.getY() < 300)
panel.setDragObject(new Podium(clickPoint));
else
panel.setDragObject(new Toilet(clickPoint));
panel.add(panel.getDragObject());
// if(e.getX() < 51) //51 = width podium image
// panel.setDragObject(new Podium(clickPoint));
// else
// panel.setDragObject(new Toilet(clickPoint));
int i = 0;
int last = 0;
for(BufferedImage image : panel.getPanelInfo())
{
if(e.getX() >= panel.getScrollfactor() && e.getX() < last + image.getWidth() + panel.getScrollfactor())
{
DrawObject tempDrawObj = panel.createNewDrawObject(i);
tempDrawObj.setPosition(clickPoint);
panel.setDragObject(tempDrawObj);
break;
}
i++;
last += image.getWidth();
}
if(panel.getDragObject() != null)
{
panel.add(panel.getDragObject());
}
}
else
{
@@ -40,7 +58,6 @@ public class Mouse extends MouseAdapter {
}
}
public void mouseReleased(MouseEvent e) {
panel.setDragObject(null);
}
+34 -5
View File
@@ -9,12 +9,14 @@ import Applicatie.Panel;
public class MouseWheel implements MouseWheelListener {
private Panel panel;
private int scrollfactor;
public MouseWheel(Panel panel)
{
this.panel = panel;
scrollfactor = 20;
}
public void mouseWheelMoved(MouseWheelEvent e) {
Point2D clickPoint = panel.getClickPoint(e.getPoint());
for(DrawObject o : panel.getObjects())
@@ -27,10 +29,37 @@ public class MouseWheel implements MouseWheelListener {
return;
}
}
if(e.getY() < 150)
{
if(e.getPreciseWheelRotation() < 0)
{
if(panel.getScrollfactor() + scrollfactor + panel.getPanelInfoLength() < panel.getWidth())
{
panel.setScrollfactor(panel.getScrollfactor() + scrollfactor);
}
// cameraPoint
double cameraScale = panel.getCameraScale() * 1 - (e.getPreciseWheelRotation()/10);
panel.setCameraScale((float) cameraScale);
}
else
{
if(panel.getScrollfactor() - scrollfactor >= 0)
{
panel.setScrollfactor(panel.getScrollfactor() - scrollfactor);
}
}
}
else
{
// cameraPoint
double cameraScale = panel.getCameraScale() * 1 - (e.getPreciseWheelRotation()/10);
panel.setCameraScale((float) cameraScale);
}
panel.repaint();
}
}
+13
View File
@@ -0,0 +1,13 @@
package Objects;
import java.awt.geom.Point2D;
import Applicatie.DrawObject;
public class Entrance extends DrawObject {
public Entrance(Point2D position) {
super("images/entrance.png", position);
}
}
+13
View File
@@ -0,0 +1,13 @@
package Objects;
import java.awt.geom.Point2D;
import Applicatie.DrawObject;
public class Path extends DrawObject {
public Path(Point2D position) {
super("images/path.jpg", position);
}
}
+1 -1
View File
@@ -7,7 +7,7 @@ import Applicatie.DrawObject;
public class Toilet extends DrawObject {
public Toilet(Point2D position) {
super("images/toilet.png", position);
super("images/wc.png", position);
}
}
+13
View File
@@ -0,0 +1,13 @@
package Objects;
import java.awt.geom.Point2D;
import Applicatie.DrawObject;
public class Wall extends DrawObject {
public Wall(Point2D position) {
super("images/wall.png", position);
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 972 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 972 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 494 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 737 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 737 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB