id
stringlengths 36
36
| text
stringlengths 1
1.25M
|
---|---|
9b9f09fc-c253-48cb-9662-786b555ab6b2 | public static Product getProduct2(String name) {
//definimos el producto y la clase vacia
Product p = null;
Class c = null;
try {
// la clase objet tiene metodos por defecto y atributos y son
// heredados por todos
// El metodo Class.forName tu le metes el nombre de la clase y el te
// devuelte la clase que es
// El metodo c.newInstance( permite intanciasn como new Objet());
c = Class.forName(name);
p = (Product) c.newInstance();
} catch (Exception e) {
}
return p;
} |
a84afb50-29a3-4eca-9184-3a8b22af9241 | public int getId() {
return id;
} |
7f0a3391-c07a-45af-ad53-404be2147dd7 | public void setId(int id) {
this.id = id;
} |
f22bffc9-877c-4ec8-a03e-c2becf847b09 | public void manipulated()
{
} |
cce5e895-9d57-4e4e-998b-fc143a52c1e6 | @Override
public void manipulate() {
// TODO Auto-generated method stub
} |
7191a491-ce4b-4955-a2ce-0d67f23dc69e | @Override
public void vender() {
// TODO Auto-generated method stub
} |
cd427d7c-de44-4e91-95f9-cd4908f515e7 | public void manipulate(); |
ef59acde-3397-4495-8f5e-cd1eb5343829 | public void vender(); |
40bf1360-a339-45ec-8031-4aeeee151d0d | public static void main(String[] args)
{
MainWindow myMainWindow = new MainWindow(); //Create the window
JMenuBar bar = new JMenuBar(); //Menu bar
JMenu fileMenu = new JMenu("File");
JMenu levelMenu = new JMenu("Level");
JMenu levelSelectionMenu = new JMenu("Choose level");
JMenu helpMenu = new JMenu("Help");
JMenuItem exit = new JMenuItem("Exit");
exit.addActionListener(myMainWindow);
fileMenu.add(exit);
JMenuItem reset = new JMenuItem("Reset level");
reset.addActionListener(myMainWindow);
levelMenu.add(reset);
levelMenu.add(levelSelectionMenu);
JMenuItem level1 = new JMenuItem("Level 1");
level1.addActionListener(myMainWindow);
levelSelectionMenu.add(level1);
JMenuItem level2 = new JMenuItem("Level 2");
level2.addActionListener(myMainWindow);
levelSelectionMenu.add(level2);
JMenuItem level3 = new JMenuItem("Level 3");
level3.addActionListener(myMainWindow);
levelSelectionMenu.add(level3);
JMenuItem level4 = new JMenuItem("Level 4");
level4.addActionListener(myMainWindow);
levelSelectionMenu.add(level4);
JMenuItem level5 = new JMenuItem("Level 5");
level5.addActionListener(myMainWindow);
levelSelectionMenu.add(level5);
JMenuItem level6 = new JMenuItem("Level 6");
level6.addActionListener(myMainWindow);
levelSelectionMenu.add(level6);
JMenuItem level7 = new JMenuItem("Level 7");
level7.addActionListener(myMainWindow);
levelSelectionMenu.add(level7);
JMenuItem level8 = new JMenuItem("Level 8");
level8.addActionListener(myMainWindow);
levelSelectionMenu.add(level8);
JMenuItem level9 = new JMenuItem("Level 9");
level9.addActionListener(myMainWindow);
levelSelectionMenu.add(level9);
JMenuItem level10 = new JMenuItem("Level 10");
level10.addActionListener(myMainWindow);
levelSelectionMenu.add(level10);
JMenuItem howToPlay = new JMenuItem("How to Play");
howToPlay.addActionListener(myMainWindow);
helpMenu.add(howToPlay);
JMenuItem hint = new JMenuItem("Display hint");
hint.addActionListener(myMainWindow);
helpMenu.add(hint);
bar.add(fileMenu);
bar.add(levelMenu);
bar.add(helpMenu);
myMainWindow.setJMenuBar(bar);
myMainWindow.setVisible(true); //Make the window visible
} |
0db3fa62-8fe1-41df-98e3-d66129ebb9b5 | public Vec2()
{
this.x = 0.0;
this.y = 0.0;
} |
4cf5592e-c418-4fcf-9714-9cfb45f448fc | public Vec2(double theX, double theY)
{
this.x = theX;
this.y = theY;
} |
f7b01e14-de88-457f-be14-875985326bee | public double[] getValues()
{
double[] values = {x, y};
return values;
} |
1a5ea5b3-3c4e-4280-98c7-bfbc97c31757 | public double getX()
{
return this.x;
} |
b0ad7c96-df21-4276-8f78-560d15039d89 | public double getY()
{
return this.y;
} |
fe233bee-652d-4620-97c7-143b26acc768 | public double magnitude()
{
magnitude = Math.sqrt(Math.pow(x, 2.0) + Math.pow(y, 2.0));
return magnitude;
} |
bc3c7c35-e59c-454e-ba9a-1a8c6d03e637 | public Vec2 normalize()
{
double newX, newY, magnitude;
magnitude = this.magnitude();
if(magnitude != 0.0)
{
newX = (this.x / magnitude);
newY = (this.y / magnitude);
}
else
{
newX = this.x;
newY = this.y;
}
Vec2 newVec2 = new Vec2(newX, newY);
return newVec2;
} |
efc5478d-99a5-4074-8e6c-3342f56a3905 | public void set(Vec2 otherVec2)
{
this.x = otherVec2.getX();
this.y = otherVec2.getY();
} |
841e86c7-13a0-4a4f-a59c-a9fc4efbe7b6 | public void set(double theX, double theY)
{
this.x = theX;
this.y = theY;
} |
3851b31f-6945-4387-88ca-68c706404c50 | public Vec2 add(Vec2 otherVec2)
{
double[] newValues = new double[2];
for(int i = 0; i < 2; i++)
{
newValues[i] = (this.getValues()[i] + otherVec2.getValues()[i]);
}
Vec2 newVec2 = new Vec2(newValues[0], newValues[1]);
return newVec2;
} |
25d945a1-4745-4ffc-a134-227619811d03 | public Vec2 add(double theX, double theY)
{
Vec2 newVec2 = new Vec2(this.x + theX, this.y + theY);
return newVec2;
} |
ae9fa95d-3c32-48f9-ae6f-5d1fcd53097a | public Vec2 subtract(Vec2 otherVec2)
{
double[] newValues = new double[2];
for(int i = 0; i < 2; i++)
{
newValues[i] = (this.getValues()[i] - otherVec2.getValues()[i]);
}
Vec2 newVec2 = new Vec2(newValues[0], newValues[1]);
return newVec2;
} |
cf95723c-6fb8-4c83-a142-8b2785184e87 | public Vec2 subtract(double theX, double theY)
{
Vec2 newVec2 = new Vec2(this.x - theX, this.y - theY);
return newVec2;
} |
f320d390-fa0b-4091-91f3-3a34ee49d9ea | public Vec2 multiply(double scalar)
{
double newX, newY;
newX = (this.x * scalar);
newY = (this.y * scalar);
Vec2 newVec2 = new Vec2(newX, newY);
return newVec2;
} |
aa49fae8-8530-4c4b-a54c-e3df9d3393e9 | public double dot(Vec2 otherVec2)
{
double[] newValues = new double[3];
double dotProduct = 0.0;
for(int i = 0; i < 2; i++)
{
newValues[i] = (this.getValues()[i] * otherVec2.getValues()[i]);
}
for(int i = 0; i < 2; i++)
{
dotProduct += newValues[i];
}
return dotProduct;
} |
5b2ea05b-40a2-4794-be10-02d25afb7924 | public HowToPlayWindow()
{
super();
this.setSize(WIDTH, HEIGHT);
this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
this.setResizable(false);
this.setTitle("How to Play");
this.setLocationRelativeTo(null);
ImagePanel theImagePanel = new ImagePanel();
this.add(theImagePanel);
} |
f27970e5-ffc8-4f8d-a997-96a0150a077d | public ImagePanel()
{
super();
try
{
howToPlayTexture = ImageIO.read(new File("textures/howtoplay.jpg"));
}
catch(IOException e)
{
}
} |
9cca472c-0fb9-45cf-95c7-6ec1b322cb95 | public void paint(Graphics canvas)
{
super.paint(canvas);
canvas.drawImage(howToPlayTexture, 0, 0, null);
} |
7b5870c2-af72-4698-96f2-ee59b5b07633 | public MainWindow()
{
super();
this.setSize(WIDTH, HEIGHT);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.setTitle("Vortex");
this.getContentPane().setBackground(Color.BLACK);
this.add(theGamePanel);
this.setLocationRelativeTo(null);
} |
ec072784-109a-45ec-933e-1315bd1b5d03 | public void actionPerformed(ActionEvent e) //Handles the JMenuItems
{
String buttonString = e.getActionCommand();
if(buttonString.equals("Exit"))
{
System.exit(0);
} else if(buttonString.equals("Reset level"))
{
theGamePanel.loadLevel(theGamePanel.getCurrentLevelNumber());
} else if(buttonString.equals("Level 1"))
{
theGamePanel.loadLevel(1);
} else if(buttonString.equals("Level 2"))
{
theGamePanel.loadLevel(2);
} else if(buttonString.equals("Level 3"))
{
theGamePanel.loadLevel(3);
} else if(buttonString.equals("Level 4"))
{
theGamePanel.loadLevel(4);
} else if(buttonString.equals("Level 5"))
{
theGamePanel.loadLevel(5);
} else if(buttonString.equals("Level 6"))
{
theGamePanel.loadLevel(6);
} else if(buttonString.equals("Level 7"))
{
theGamePanel.loadLevel(7);
} else if(buttonString.equals("Level 8"))
{
theGamePanel.loadLevel(8);
} else if(buttonString.equals("Level 9"))
{
theGamePanel.loadLevel(9);
} else if(buttonString.equals("Level 10"))
{
theGamePanel.loadLevel(10);
} else if(buttonString.equals("How to Play"))
{
myHowToPlayWindow.setVisible(true);
} else if(buttonString.equals("Display hint"))
{
theCurrentLevelNumber = theGamePanel.getCurrentLevelNumber();
switch(theCurrentLevelNumber)
{
case 1:
hintPane.showMessageDialog(this, "You can't fit through the hole in the wall, but you CAN see through it...", "Hint", JOptionPane.INFORMATION_MESSAGE);
break;
case 2:
hintPane.showMessageDialog(this, "The gap is too far to jump, if only there was some way for you to gain more momentum...", "Hint", JOptionPane.INFORMATION_MESSAGE);
break;
case 3:
hintPane.showMessageDialog(this, "You can't go through the door unless it's open, but in order for it to be open the button has to be pressed down.\nYou can't be in two places at once...", "Hint", JOptionPane.INFORMATION_MESSAGE);
break;
case 4:
hintPane.showMessageDialog(this, "Did you know that the box can go through vortexes?", "Hint", JOptionPane.INFORMATION_MESSAGE);
break;
case 5:
hintPane.showMessageDialog(this, "How could you get enough speed to make it to the door?", "Hint", JOptionPane.INFORMATION_MESSAGE);
break;
case 6:
hintPane.showMessageDialog(this, "I wonder what would happen if you placed one vortex directly above the other...", "Hint", JOptionPane.INFORMATION_MESSAGE);
break;
case 7:
hintPane.showMessageDialog(this, "Success is only a hop, skip, and a fling away!", "Hint", JOptionPane.INFORMATION_MESSAGE);
break;
case 8:
hintPane.showMessageDialog(this, "Each pillar is taller than the last, how could you use this to your advantage?\nAlso, the S key is your friend!", "Hint", JOptionPane.INFORMATION_MESSAGE);
break;
case 9:
hintPane.showMessageDialog(this, "Momentum is conserved when moving through vortexes; I wonder what would happen if both were placed on the ground?", "Hint", JOptionPane.INFORMATION_MESSAGE);
break;
case 10:
hintPane.showMessageDialog(this, "Did you know that the box can move through vortexes without you having to hold it?", "Hint", JOptionPane.INFORMATION_MESSAGE);
break;
default:
hintPane.showMessageDialog(this, "What level are you on anyways?", "Hint", JOptionPane.INFORMATION_MESSAGE);
break;
}
}
} |
1f222d66-6c74-4590-9ebb-6b5edd48126e | public GamePanel()
{
super();
this.setFocusable(true); //Allows for keyboard listener
this.setBackground(Color.BLACK);
this.setDoubleBuffered(true);
firstPaint = true;
playerX = 100.0;
playerY = 500.0;
boxX = -200.0;
boxY = -50.0;
playerPos = new Vec2(playerX, playerY);
playerVel = new Vec2(0.0, 0.0);
playerAcc = new Vec2(0.0, 0.2);
boxPos = new Vec2(boxX, boxY);
boxVel = new Vec2(0.0, 0.0);
boxAcc = new Vec2(0.0, 0.2);
ray = new Vec2(0.0, 0.0);
testRay = new Vec2(0.0, 0.0);
drawnRay = new Vec2(0.0, 0.0);
theKeyboardHandler = new KeyboardHandler();
addKeyListener(theKeyboardHandler);
myMouseInput = new MouseInput();
addMouseListener(myMouseInput);
addMouseMotionListener(myMouseInput);
outputPane = new JOptionPane();
} |
c56b9cca-4dc9-420f-aeda-121c453f5a14 | private void initialize()
{
firstPaint = false;
thePainter = new Painter();
thePainter.setName("Painter Thread");
theAnimator = new Animator();
theAnimator.setName("Animator Thread");
theRenderingHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
theRenderingHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
//The locations of the shapes
floor = new Rectangle2D.Double(0, 657, 1008, 50);
ceiling = new Rectangle2D.Double(0, 0, 1008, 50);
leftWall = new Rectangle2D.Double(0, 0, 50, 657);
rightWall = new Rectangle2D.Double(958, 0, 50, 657);
outsidePlatform = new Rectangle2D.Double(-300, 0, 200, 50);
button = new Rectangle2D.Double(buttonX, buttonY, 25, 25);
portal1 = new Ellipse2D.Double(0, -50, portalWidth, portalHeight);
portal2 = new Ellipse2D.Double(100, -50, portalWidth, portalHeight);
player = new Rectangle2D.Double(playerX, playerY, 20, 40);
box = new Rectangle2D.Double(boxX, boxY, 25, 25);
entranceDoor = new Rectangle2D.Double(entranceDoorX, entranceDoorY, 29, 60);
exitDoor = new Rectangle2D.Double(exitDoorX, exitDoorY, 29, 60);
panel1 = new Rectangle2D.Double(-100, -100, 50, 50);
panel2 = new Rectangle2D.Double(-100, -100, 50, 50);
panel3 = new Rectangle2D.Double(-100, -100, 50, 50);
panel4 = new Rectangle2D.Double(-100, -100, 50, 50);
panel5 = new Rectangle2D.Double(-100, -100, 50, 50);
panel6 = new Rectangle2D.Double(-100, -100, 50, 50);
panel7 = new Rectangle2D.Double(-100, -100, 50, 50);
panel8 = new Rectangle2D.Double(-100, -100, 50, 50);
drawnRaylineIntersections = new ArrayList();
allCollidableSurfaces = new ArrayList();
portalableSurfaces = new ArrayList(); //Any surface not in this ArrayList will NOT be portalable
nonPortalableSurfaces = new ArrayList();
rayline = new Line2D.Double();
drawnRayline = new Line2D.Double();
testPoint = new Point2D.Double();
try
{
playerTexture = ImageIO.read(new File("textures/character.png"));
playerTextureFlip = ImageIO.read(new File("textures/character_flip.png"));
buttonTexture = ImageIO.read(new File("textures/button.png"));
buttonPressedTexture = ImageIO.read(new File("textures/button_pressed.png"));
boxTexture = ImageIO.read(new File("textures/box_pink.jpg"));
doorTexture = ImageIO.read(new File("textures/door.png"));
doorOpenTexture = ImageIO.read(new File("textures/door_open.png"));
backgroundTexture = ImageIO.read(new File("textures/metal_background.jpg"));
bluePortalTextureVert = ImageIO.read(new File("textures/portal_blue_vert.png"));
orangePortalTextureVert = ImageIO.read(new File("textures/portal_orange_vert.png"));
bluePortalTextureHoriz = ImageIO.read(new File("textures/portal_blue_horiz.png"));
orangePortalTextureHoriz = ImageIO.read(new File("textures/portal_orange_horiz.png"));
metalFloorLightTexture = ImageIO.read(new File("textures/metal_floor.jpg"));
metalFloorDarkTexture = ImageIO.read(new File("textures/metal_floor_dark.jpg"));
metalVertLightTexture = ImageIO.read(new File("textures/metal_vert_light.jpg"));
metalVertDarkTexture = ImageIO.read(new File("textures/metal_vert_dark.jpg"));
metalHorizLightTexture = ImageIO.read(new File("textures/metal_horiz_light.jpg"));
metalHorizDarkTexture = ImageIO.read(new File("textures/metal_horiz_dark.jpg"));
marbleTileTexture = ImageIO.read(new File("textures/metal_tile_light.jpg"));
darkMarbleTexture = ImageIO.read(new File("textures/metal_tile_dark.jpg"));
}
catch(IOException e)
{
}
currentLevelNumber = 1;
loadLevel(currentLevelNumber);
theAnimator.start(); //Starts the animation/painting threads
thePainter.start();
} |
749d3d91-bcf5-4b8c-b943-77b16fcbbf99 | public void loadLevel(int theLevelNumber)
{
currentLevelNumber = theLevelNumber;
resetVariables();
if(theLevelNumber == 1)
{
//Button code
levelHasButton = false;
//Player code
playerPos.set(100, 617);
//Level structure code
panel1.setFrame(50, 400, 400, 50);
panel2.setFrame(400, 400, 50, 400);
panel3.setFrame(200, 425, 50, 200);
panel4.setFrame(200, 650, 50, 100);
//Door code
entranceDoorX = 100.0;
entranceDoorY = 597.0;
exitDoorX = 300.0;
exitDoorY = 597.0;
exitDoor.setFrame(exitDoorX, exitDoorY, DOOR_WIDTH, DOOR_HEIGHT);
//Collision code
nonPortalableSurfaces.add(panel1);
portalableSurfaces.add(panel2);
nonPortalableSurfaces.add(panel3);
nonPortalableSurfaces.add(panel4);
nonPortalableSurfaces.add(floor);
portalableSurfaces.add(leftWall);
nonPortalableSurfaces.add(ceiling);
nonPortalableSurfaces.add(rightWall);
allCollidableSurfaces.addAll(portalableSurfaces);
allCollidableSurfaces.addAll(nonPortalableSurfaces);
}
if(theLevelNumber == 2)
{
levelHasButton = false;
playerPos.set(100, 467);
panel1.setFrame(50, 100, 400, 50);
panel2.setFrame(450, 100, 50, 600);
panel3.setFrame(350, 500,100, 200);
panel4.setFrame(50, 500, 100, 200);
entranceDoorX = 100.0;
entranceDoorY = 447.0;
exitDoorX = 400.0;
exitDoorY = 440.0;
exitDoor.setFrame(exitDoorX, exitDoorY, DOOR_WIDTH, DOOR_HEIGHT);
nonPortalableSurfaces.add(panel1);
nonPortalableSurfaces.add(panel2);
nonPortalableSurfaces.add(panel3);
nonPortalableSurfaces.add(panel4);
portalableSurfaces.add(floor);
portalableSurfaces.add(leftWall);
nonPortalableSurfaces.add(ceiling);
nonPortalableSurfaces.add(rightWall);
allCollidableSurfaces.addAll(portalableSurfaces);
allCollidableSurfaces.addAll(nonPortalableSurfaces);
}
if(theLevelNumber == 3)
{
levelHasButton = true;
buttonX = 100.0;
buttonY = 632.0;
button.setFrame(buttonX, buttonY, 25, 25);
boxX = 500.0;
boxY = 450.0;
boxPos.set(boxX, boxY);
playerPos.set(100, 400);
panel1.setFrame(50, 450, 150, 50);
panel2.setFrame(400, 500, 150, 50);
panel3.setFrame(50, 300, 500, 50);
panel4.setFrame(550, 300, 50, 400);
entranceDoorX = 100.0;
entranceDoorY = 390.0;
exitDoorX = 500.0;
exitDoorY = 597.0;
exitDoor.setFrame(exitDoorX, exitDoorY, DOOR_WIDTH, DOOR_HEIGHT);
nonPortalableSurfaces.add(panel1);
nonPortalableSurfaces.add(panel2);
nonPortalableSurfaces.add(panel3);
portalableSurfaces.add(panel4);
nonPortalableSurfaces.add(floor);
portalableSurfaces.add(leftWall);
nonPortalableSurfaces.add(ceiling);
nonPortalableSurfaces.add(rightWall);
allCollidableSurfaces.addAll(portalableSurfaces);
allCollidableSurfaces.addAll(nonPortalableSurfaces);
}
if(theLevelNumber == 4)
{
levelHasButton = true;
buttonX = 400.0;
buttonY = 632.0;
button.setFrame(buttonX, buttonY, 25, 25);
boxX = 250.0;
boxY = 350.0;
boxPos.set(boxX, boxY);
playerPos.set(100, 617);
panel1.setFrame(50, 400, 50, 50);
panel2.setFrame(200, 400, 300, 50);
panel3.setFrame(50, 200, 600, 50);
panel4.setFrame(650, 200, 50, 500);
panel5.setFrame(300, 200, 50, 350);
panel6.setFrame(300, 580, 50, 100);
panel7.setFrame(550, 400, 150, 50);
entranceDoorX = 100.0;
entranceDoorY = 597.0;
exitDoorX = 600.0;
exitDoorY = 340.0;
exitDoor.setFrame(exitDoorX, exitDoorY, DOOR_WIDTH, DOOR_HEIGHT);
nonPortalableSurfaces.add(panel1);
nonPortalableSurfaces.add(panel2);
portalableSurfaces.add(panel3);
portalableSurfaces.add(panel4);
nonPortalableSurfaces.add(panel5);
nonPortalableSurfaces.add(panel6);
nonPortalableSurfaces.add(panel7);
nonPortalableSurfaces.add(floor);
portalableSurfaces.add(leftWall);
nonPortalableSurfaces.add(ceiling);
nonPortalableSurfaces.add(rightWall);
allCollidableSurfaces.addAll(portalableSurfaces);
allCollidableSurfaces.addAll(nonPortalableSurfaces);
}
if(theLevelNumber == 5)
{
levelHasButton = true;
buttonX = 800.0;
buttonY = 425.0;
button.setFrame(buttonX, buttonY, 25, 25);
boxX = 150.0;
boxY = 350.0;
boxPos.set(boxX, boxY);
playerPos.set(100, 617);
panel1.setFrame(50, 400, 400, 50);
panel2.setFrame(600, 450, 400, 50);
panel3.setFrame(908, 150, 50, 300);
panel4.setFrame(700, 150, 300, 50);
panel5.setFrame(500, 50, 50, 200);
entranceDoorX = 100.0;
entranceDoorY = 597.0;
exitDoorX = 850.0;
exitDoorY = 90.0;
exitDoor.setFrame(exitDoorX, exitDoorY, DOOR_WIDTH, DOOR_HEIGHT);
nonPortalableSurfaces.add(panel1);
nonPortalableSurfaces.add(panel2);
portalableSurfaces.add(panel3);
nonPortalableSurfaces.add(panel4);
portalableSurfaces.add(panel5);
portalableSurfaces.add(floor);
portalableSurfaces.add(leftWall);
nonPortalableSurfaces.add(ceiling);
nonPortalableSurfaces.add(rightWall);
allCollidableSurfaces.addAll(portalableSurfaces);
allCollidableSurfaces.addAll(nonPortalableSurfaces);
}
if(theLevelNumber == 6)
{
levelHasButton = false;
playerPos.set(100, 617);
panel1.setFrame(50, 50, 300, 50);
panel2.setFrame(600, 200, 500, 50);
panel3.setFrame(350, 50, 50, 50);
entranceDoorX = 100.0;
entranceDoorY = 597.0;
exitDoorX = 900.0;
exitDoorY = 140.0;
exitDoor.setFrame(exitDoorX, exitDoorY, DOOR_WIDTH, DOOR_HEIGHT);
portalableSurfaces.add(panel1);
nonPortalableSurfaces.add(panel2);
nonPortalableSurfaces.add(panel3);
portalableSurfaces.add(floor);
portalableSurfaces.add(leftWall);
nonPortalableSurfaces.add(ceiling);
nonPortalableSurfaces.add(rightWall);
allCollidableSurfaces.addAll(portalableSurfaces);
allCollidableSurfaces.addAll(nonPortalableSurfaces);
}
if(theLevelNumber == 7)
{
levelHasButton = true;
buttonX = 550.0;
buttonY = 425.0;
button.setFrame(buttonX, buttonY, 25, 25);
boxX = 550.0;
boxY = 275.0;
boxPos.set(boxX, boxY);
playerPos.set(100, 617);
panel1.setFrame(50, 100, 300, 50);
panel2.setFrame(350, 100, 250, 50);
panel3.setFrame(600, 100, 50, 600);
panel4.setFrame(250, 607, 350, 50);
panel5.setFrame(450, 300, 150, 50);
panel6.setFrame(400, 450, 200, 50);
panel7.setFrame(200, 300, 50, 600);
entranceDoorX = 100.0;
entranceDoorY = 597.0;
exitDoorX = 550.0;
exitDoorY = 547.0;
exitDoor.setFrame(exitDoorX, exitDoorY, DOOR_WIDTH, DOOR_HEIGHT);
portalableSurfaces.add(panel1);
nonPortalableSurfaces.add(panel2);
nonPortalableSurfaces.add(panel3);
portalableSurfaces.add(panel4);
nonPortalableSurfaces.add(panel5);
nonPortalableSurfaces.add(panel6);
nonPortalableSurfaces.add(panel7);
nonPortalableSurfaces.add(floor);
portalableSurfaces.add(leftWall);
nonPortalableSurfaces.add(ceiling);
nonPortalableSurfaces.add(rightWall);
allCollidableSurfaces.addAll(portalableSurfaces);
allCollidableSurfaces.addAll(nonPortalableSurfaces);
}
if(theLevelNumber == 8)
{
levelHasButton = false;
playerPos.set(100, 567);
panel1.setFrame(50, 50, 50, 200);
panel2.setFrame(200, 500, 100, 200);
panel3.setFrame(400, 350, 100, 350);
panel4.setFrame(650, 300, 100, 600);
panel5.setFrame(700, 130, 150, 50);
panel6.setFrame(908, 50, 50, 50);
panel7.setFrame(700, 50, 50, 200);
panel8.setFrame(50, 607, 150, 50);
entranceDoorX = 100.0;
entranceDoorY = 557.0;
exitDoorX = 800.0;
exitDoorY = 70.0;
exitDoor.setFrame(exitDoorX, exitDoorY, DOOR_WIDTH, DOOR_HEIGHT);
portalableSurfaces.add(panel1);
nonPortalableSurfaces.add(panel2);
nonPortalableSurfaces.add(panel3);
nonPortalableSurfaces.add(panel4);
nonPortalableSurfaces.add(panel5);
portalableSurfaces.add(panel6);
nonPortalableSurfaces.add(panel7);
nonPortalableSurfaces.add(panel8);
portalableSurfaces.add(floor);
portalableSurfaces.add(leftWall);
nonPortalableSurfaces.add(ceiling);
nonPortalableSurfaces.add(rightWall);
allCollidableSurfaces.addAll(portalableSurfaces);
allCollidableSurfaces.addAll(nonPortalableSurfaces);
}
if(theLevelNumber == 9)
{
levelHasButton = true;
buttonX = 525.0;
buttonY = 632.0;
button.setFrame(buttonX, buttonY, 25, 25);
boxX = 125.0;
boxY = 200.0;
boxPos.set(boxX, boxY);
playerPos.set(100, 617);
panel1.setFrame(50, 250, 100, 50);
panel2.setFrame(500, 250, 100, 50);
panel3.setFrame(500, 50, 100, 50);
panel4.setFrame(600, 50, 50, 650);
panel5.setFrame(450, 50, 50, 50);
entranceDoorX = 100.0;
entranceDoorY = 597.0;
exitDoorX = 550.0;
exitDoorY = 190.0;
exitDoor.setFrame(exitDoorX, exitDoorY, DOOR_WIDTH, DOOR_HEIGHT);
nonPortalableSurfaces.add(panel1);
nonPortalableSurfaces.add(panel2);
portalableSurfaces.add(panel3);
nonPortalableSurfaces.add(panel4);
nonPortalableSurfaces.add(panel5);
portalableSurfaces.add(floor);
nonPortalableSurfaces.add(leftWall);
nonPortalableSurfaces.add(ceiling);
nonPortalableSurfaces.add(rightWall);
allCollidableSurfaces.addAll(portalableSurfaces);
allCollidableSurfaces.addAll(nonPortalableSurfaces);
}
if(theLevelNumber == 10)
{
levelHasButton = true;
buttonX = 425.0;
buttonY = 275.0;
button.setFrame(buttonX, buttonY, 25, 25);
boxX = 700.0;
boxY = 550.0;
boxPos.set(boxX, boxY);
playerPos.set(100, 617);
panel1.setFrame(500, 607, 550, 50);
panel2.setFrame(500, 50, 550, 50);
panel3.setFrame(450, 50, 50, 300);
panel4.setFrame(350, 300, 100, 50);
panel5.setFrame(300, 150, 50, 300);
panel6.setFrame(800, 200, 250, 50);
entranceDoorX = 100.0;
entranceDoorY = 597.0;
exitDoorX = 900.0;
exitDoorY = 140.0;
exitDoor.setFrame(exitDoorX, exitDoorY, DOOR_WIDTH, DOOR_HEIGHT);
portalableSurfaces.add(panel1);
portalableSurfaces.add(panel2);
nonPortalableSurfaces.add(panel3);
nonPortalableSurfaces.add(panel4);
nonPortalableSurfaces.add(panel5);
nonPortalableSurfaces.add(panel6);
nonPortalableSurfaces.add(floor);
portalableSurfaces.add(leftWall);
nonPortalableSurfaces.add(ceiling);
nonPortalableSurfaces.add(rightWall);
allCollidableSurfaces.addAll(portalableSurfaces);
allCollidableSurfaces.addAll(nonPortalableSurfaces);
}
if(theLevelNumber == 11)
{
levelHasButton = false;
playerPos.set(100, 617);
nonPortalableSurfaces.add(floor);
nonPortalableSurfaces.add(leftWall);
nonPortalableSurfaces.add(ceiling);
nonPortalableSurfaces.add(rightWall);
allCollidableSurfaces.addAll(portalableSurfaces);
allCollidableSurfaces.addAll(nonPortalableSurfaces);
if(!gameOver)
{
gameOver = true;
outputPane.showMessageDialog(this, "Congratulations!", "You win!", JOptionPane.INFORMATION_MESSAGE);
this.loadLevel(1);
}
}
} |
7c334b44-bce0-4b9d-af1b-c3ec8968a8fa | private void resetVariables()
{
allCollidableSurfaces.clear();
portalableSurfaces.clear();
nonPortalableSurfaces.clear();
loadNextLevel = false;
playerX = 100.0;
playerY = 500.0;
boxX = -200.0;
boxY = -50.0;
buttonX = 0.0;
buttonY = -200;
entranceDoorX = -100;
entranceDoorY = -100;
exitDoorX = -100;
exitDoorY = -100;
portalWidth = 20.0;
portalHeight = 40.0;
mouseX = 0.0;
mouseY = 0.0;
heldBoxX = 20.0;
portal1.setFrame(0, -50, portalWidth, portalHeight);
portal2.setFrame(100, -50, portalWidth, portalHeight);
panel1.setFrame(-100, -100, 50, 50);
panel2.setFrame(-100, -100, 50, 50);
panel3.setFrame(-100, -100, 50, 50);
panel4.setFrame(-100, -100, 50, 50);
panel5.setFrame(-100, -100, 50, 50);
panel6.setFrame(-100, -100, 50, 50);
panel7.setFrame(-100, -100, 50, 50);
panel8.setFrame(-100, -100, 50, 50);
button.setFrame(buttonX, buttonY, 25, 25);
box.setFrame(boxX, boxY, 25, 25);
entranceDoor.setFrame(entranceDoorX, entranceDoorY, 29, 60);
exitDoor.setFrame(exitDoorX, exitDoorY, 29, 60);
playerPos.set(100, 617);
playerVel.set(0.0, 0.0);
playerAcc.set(0.0, 0.0);
boxPos.set(boxX, boxY);
boxVel.set(0.0, 0.0);
boxAcc.set(0.0, 0.0);
portalRelativeLocation = 0;
portal1RelativeLocation = 0;
portal2RelativeLocation = 0;
aPressed = false;
dPressed = false;
onGround = false;
playerOnGround = false;
jumping = false;
playerJustPortaled = false;
boxJustPortaled = false;
lastShotBluePortal = true;
raylineIntersection = false;
portalsActive = false;
portal1Active = false;
portal2Active = false;
portalableIntersection = false;
portalCollisionIssue = false;
raylineColorIsBlue = false;
playerMovementIssue = false;
boxHeld = false;
boxToggle = true;
buttonIntersection = false;
playerFacingRight = true;
levelResetRequired = false;
gameOver = false;
} |
fbb20c9d-a528-4fde-9b5f-d09563261a55 | public int getCurrentLevelNumber()
{
return this.currentLevelNumber;
} |
0decd391-714b-41c6-99e7-839fbaebca6a | public void paint(Graphics canvas)
{
super.paint(canvas);
canvas2D = (Graphics2D)canvas;
if(firstPaint) //Only ran once
{
this.initialize();
}
canvas2D.setRenderingHints(theRenderingHints);
canvas2D.drawImage(backgroundTexture, 0, 0, this); //Background image
canvas2D.drawImage(doorTexture, (int)entranceDoorX, (int)entranceDoorY, this);
if(buttonIntersection)
{
canvas2D.drawImage(doorOpenTexture, (int)exitDoorX, (int)exitDoorY, this);
canvas2D.drawImage(buttonPressedTexture, (int)buttonX, (int)buttonY, this);
}
else
{
canvas2D.drawImage(doorTexture, (int)exitDoorX, (int)exitDoorY, this);
canvas2D.drawImage(buttonTexture, (int)buttonX, (int)buttonY, this);
}
if(portalableIntersection && raylineColorIsBlue)
{
canvas2D.setColor(Color.BLUE);
}
else if(portalableIntersection && !raylineColorIsBlue)
{
canvas2D.setColor(Color.ORANGE);
}
else
{
canvas2D.setColor(Color.GRAY);
}
canvas2D.draw(drawnRayline); //Used to show where a portal will be placed
for(int i = 0; i < portalableSurfaces.size(); i++) //Portalable surfaces
{
double theWidth = ((Rectangle2D)portalableSurfaces.get(i)).getWidth();
double theHeight = ((Rectangle2D)portalableSurfaces.get(i)).getHeight();
int timesToDrawX = (int)(theWidth / 50);
int timesToDrawY = (int)(theHeight / 50);
for(int x = 0; x < timesToDrawX; x++)
{
for(int y = 0; y < timesToDrawY; y++)
{
canvas2D.drawImage(marbleTileTexture, (int)((Rectangle2D)portalableSurfaces.get(i)).getX() + 50 * x, (int)((Rectangle2D)portalableSurfaces.get(i)).getY() + 50 * y, this);
}
}
}
for(int i = 0; i < nonPortalableSurfaces.size(); i++) //Non-portalable surfacse
{
double theWidth = ((Rectangle2D)nonPortalableSurfaces.get(i)).getWidth();
double theHeight = ((Rectangle2D)nonPortalableSurfaces.get(i)).getHeight();
int timesToDrawX = (int)(theWidth / 50);
int timesToDrawY = (int)(theHeight / 50);
for(int x = 0; x < timesToDrawX; x++)
{
for(int y = 0; y < timesToDrawY; y++)
{
canvas2D.drawImage(darkMarbleTexture, (int)((Rectangle2D)nonPortalableSurfaces.get(i)).getX() + 50 * x, (int)((Rectangle2D)nonPortalableSurfaces.get(i)).getY() + 50 * y, this);
}
}
}
if(portalableSurfaces.contains(leftWall))
{
canvas2D.drawImage(metalVertLightTexture, (int)leftWall.getX(), (int)leftWall.getY(), this);
canvas2D.drawImage(metalVertLightTexture, (int)leftWall.getX(), (int)leftWall.getY() + 400, this);
}
else
{
canvas2D.drawImage(metalVertDarkTexture, (int)leftWall.getX(), (int)leftWall.getY(), this);
canvas2D.drawImage(metalVertDarkTexture, (int)leftWall.getX(), (int)leftWall.getY() + 400, this);
}
if(portalableSurfaces.contains(rightWall))
{
canvas2D.drawImage(metalVertLightTexture, (int)rightWall.getX(), (int)rightWall.getY(), this);
canvas2D.drawImage(metalVertLightTexture, (int)rightWall.getX(), (int)rightWall.getY() + 400, this);
}
else
{
canvas2D.drawImage(metalVertDarkTexture, (int)rightWall.getX(), (int)rightWall.getY(), this);
canvas2D.drawImage(metalVertDarkTexture, (int)rightWall.getX(), (int)rightWall.getY() + 400, this);
}
if(portalableSurfaces.contains(ceiling))
{
canvas2D.drawImage(metalHorizLightTexture, (int)ceiling.getX(), (int)ceiling.getY(), this);
canvas2D.drawImage(metalHorizLightTexture, (int)ceiling.getX() + 400, (int)ceiling.getY(), this);
canvas2D.drawImage(metalHorizLightTexture, (int)ceiling.getX() + 800, (int)ceiling.getY(), this);
}
else
{
canvas2D.drawImage(metalHorizDarkTexture, (int)ceiling.getX(), (int)ceiling.getY(), this);
canvas2D.drawImage(metalHorizDarkTexture, (int)ceiling.getX() + 400, (int)ceiling.getY(), this);
canvas2D.drawImage(metalHorizDarkTexture, (int)ceiling.getX() + 800, (int)ceiling.getY(), this);
}
if(portalableSurfaces.contains(floor))
{
canvas2D.drawImage(metalFloorLightTexture, (int)floor.getX(), (int)floor.getY(), this);
canvas2D.drawImage(metalFloorLightTexture, (int)floor.getX() + 400, (int)floor.getY(), this);
canvas2D.drawImage(metalFloorLightTexture, (int)floor.getX() + 800, (int)floor.getY(), this);
}
else
{
canvas2D.drawImage(metalFloorDarkTexture, (int)floor.getX(), (int)floor.getY(), this);
canvas2D.drawImage(metalFloorDarkTexture, (int)floor.getX() + 400, (int)floor.getY(), this);
canvas2D.drawImage(metalFloorDarkTexture, (int)floor.getX() + 800, (int)floor.getY(), this);
}
if(portal1.getWidth() > portal1.getHeight())
{
canvas2D.drawImage(bluePortalTextureHoriz, (int)portal1.getX(), (int)portal1.getY(), this);
}
else
{
canvas2D.drawImage(bluePortalTextureVert, (int)portal1.getX(), (int)portal1.getY(), this);
}
if(portal2.getWidth() > portal2.getHeight())
{
canvas2D.drawImage(orangePortalTextureHoriz, (int)portal2.getX(), (int)portal2.getY(), this);
}
else
{
canvas2D.drawImage(orangePortalTextureVert, (int)portal2.getX(), (int)portal2.getY(), this);
}
canvas2D.drawImage(boxTexture, (int)boxPos.getX(), (int)boxPos.getY(), this);
if(playerFacingRight)
{
canvas2D.drawImage(playerTexture, (int)playerPos.getX(), (int)playerPos.getY(), this);
}
else
{
canvas2D.drawImage(playerTextureFlip, (int)playerPos.getX(), (int)playerPos.getY(), this);
}
if(loadNextLevel && buttonIntersection)
{
this.loadLevel(++currentLevelNumber);
}
if(levelResetRequired)
{
this.loadLevel(currentLevelNumber);
}
} |
3e6f8c9e-1428-44dd-8843-6f2c836fbc0f | public void run()
{
while(true) //While the game is running
{
animatorInitialTime = System.currentTimeMillis();
if(!levelHasButton)
{
buttonIntersection = true;
}
this.checkMaxVelocity(playerVel); //Check against the maximum velocity
this.checkBounds(playerPos); //Makes sure the player is inside the visible area
this.checkCollisions(player, playerPos, playerVel, playerAcc); //Check to see if the player is colliding with a surface
this.addFriction(playerVel, playerAcc); //Adds friction
this.sumAccVelPos(playerPos, playerVel, playerAcc); //Add up the player's acceleration to their velocity, and their velocity to their position
if(!boxHeld)
{
this.checkMaxVelocity(boxVel);
if(levelHasButton)
{
this.checkBounds(boxPos);
}
this.checkCollisions(box, boxPos, boxVel, boxAcc);
this.addFriction(boxVel, boxAcc);
this.sumAccVelPos(boxPos, boxVel, boxAcc);
}
else
{
boxPos.set((playerPos.getX() + heldBoxX), (playerPos.getY() + 10));
boxVel.set(playerVel);
boxAcc.set(playerAcc);
this.checkCollisions(box, boxPos, boxVel, boxAcc);
playerPos.set(boxPos.getX() - heldBoxX, boxPos.getY() - 10);
}
this.setNewPosition(); //Move the player to the new location
this.setDrawnRay(); //Draw the ray indicating where a portal will go
animatorFinalTime = System.currentTimeMillis();
this.doNothing(); //Sleep for the appropriate amount of time
}
} |
abb23b63-32c5-428c-8933-9315e6e3cf21 | private void checkMaxVelocity(Vec2 thePhysicsObjectVel) //Check against the maximum velocity
{
if(thePhysicsObjectVel.getX() > MAXIMUM_VELOCITY)
{
thePhysicsObjectVel.set(MAXIMUM_VELOCITY, thePhysicsObjectVel.getY());
}
else if(thePhysicsObjectVel.getX() < -MAXIMUM_VELOCITY)
{
thePhysicsObjectVel.set(-MAXIMUM_VELOCITY, thePhysicsObjectVel.getY());
}
if(thePhysicsObjectVel.getY() > MAXIMUM_VELOCITY)
{
thePhysicsObjectVel.set(thePhysicsObjectVel.getX(), MAXIMUM_VELOCITY);
}
else if(thePhysicsObjectVel.getY() < -MAXIMUM_VELOCITY)
{
thePhysicsObjectVel.set(thePhysicsObjectVel.getX(), -MAXIMUM_VELOCITY);
}
} |
aae01d95-82bc-4966-b724-caa045699517 | private void checkBounds(Vec2 thePhysicsObjectPos) //Resets the level if the player/box exit the visible area
{
if(thePhysicsObjectPos.getX() < 0.0
|| thePhysicsObjectPos.getX() > 1008.0
|| thePhysicsObjectPos.getY() < 0.0
|| thePhysicsObjectPos.getY() > 707.0)
{
levelResetRequired = true;
}
} |
513abd2e-277b-4a0b-a87f-131c5519a82b | private void checkCollisions(Rectangle2D thePhysicsObject, Vec2 thePhysicsObjectPos, Vec2 thePhysicsObjectVel, Vec2 thePhysicsObjectAcc) //Handles collisions
{
onGround = false;
if(thePhysicsObject == player)
{
playerOnGround = false;
}
for(int i = 0; i < allCollidableSurfaces.size(); i++) //For each normal surface
{
if(thePhysicsObject.intersects((Rectangle2D)allCollidableSurfaces.get(i))) //If the player is touching a surface
{
if(portalsActive && (thePhysicsObject.intersects(portal1.getFrame()) || thePhysicsObject.intersects(portal2.getFrame()))) //If the player is touching an active portal
{
break;
}
thePhysicsObjectIntersection = thePhysicsObject.createIntersection((Rectangle2D)allCollidableSurfaces.get(i)); //Create an object representing the intersection
if(thePhysicsObjectIntersection.getHeight() > 5) //Makes sure a majority of the player is up against the wall
{
if(thePhysicsObjectIntersection.getCenterX() > thePhysicsObject.getCenterX()) //If the surface is to the right of the player
{
if(thePhysicsObjectIntersection.getWidth() > 0) //If they are not just touching the edge
{
thePhysicsObjectPos.set(thePhysicsObjectPos.getX() - thePhysicsObjectIntersection.getWidth(), thePhysicsObjectPos.getY()); //Move them out of the object
//Stop them from moving
thePhysicsObjectVel.set(0.0, thePhysicsObjectVel.getY());
thePhysicsObjectAcc.set(0.0, thePhysicsObjectVel.getY());
}
}
else if(thePhysicsObjectIntersection.getCenterX() < thePhysicsObject.getCenterX()) //If the surface is to the left of the player
{
if(thePhysicsObjectIntersection.getWidth() > 0) //If they are not just touching the edge
{
thePhysicsObjectPos.set(thePhysicsObjectPos.getX() + thePhysicsObjectIntersection.getWidth(), thePhysicsObjectPos.getY()); //Move them out of the object
thePhysicsObjectVel.set(0.0, thePhysicsObjectVel.getY());
thePhysicsObjectAcc.set(0.0, thePhysicsObjectVel.getY());
}
}
}
if(thePhysicsObjectIntersection.getWidth() > 5) //Makes sure a majority of the player is up against the floor/ceiling
{
if(thePhysicsObjectIntersection.getCenterY() < thePhysicsObject.getCenterY()) //If the surface is above the player
{
if(thePhysicsObjectIntersection.getHeight() > 0) //If they are not just touching the edge
{
thePhysicsObjectPos.set(thePhysicsObjectPos.getX(), thePhysicsObjectPos.getY() + thePhysicsObjectIntersection.getHeight()); //Move them out of the object
//Stop them from moving
thePhysicsObjectVel.set(thePhysicsObjectVel.getX(), 0.0);
thePhysicsObjectAcc.set(thePhysicsObjectAcc.getX(), 0.0);
}
}
else if(thePhysicsObjectIntersection.getCenterY() > thePhysicsObject.getCenterY()) //If the surface is below the player
{
onGround = true;
if(thePhysicsObject == player)
{
playerOnGround = true;
}
if(thePhysicsObjectIntersection.getHeight() > 0) //If they are not just touching the surface of the floor
{
thePhysicsObjectPos.set(thePhysicsObjectPos.getX(), thePhysicsObjectPos.getY() - thePhysicsObjectIntersection.getHeight() + 1); //Move them to the surface
if(!jumping && (thePhysicsObject == player))
{
//Stop them from moving
thePhysicsObjectVel.set(thePhysicsObjectVel.getX(), 0.0);
thePhysicsObjectAcc.set(thePhysicsObjectAcc.getX(), 0.0);
}
else if(thePhysicsObject != player)
{
//Stop them from moving
thePhysicsObjectVel.set(thePhysicsObjectVel.getX(), 0.0);
thePhysicsObjectAcc.set(thePhysicsObjectAcc.getX(), 0.0);
}
}
}
}
}
if(drawnRayline.intersects((Rectangle2D)allCollidableSurfaces.get(i))) //If the drawnRayline intersects a surface
{
drawnRaylineIntersections.add((Rectangle2D)allCollidableSurfaces.get(i)); //Contains all surfaces that the drawnRayline intersects
}
if(!onGround) //Apply gravity if not on the ground
{
thePhysicsObjectAcc.set(thePhysicsObjectAcc.getX(), 0.2);
}
}
if(levelHasButton)
{
if(player.intersects(button) || box.intersects(button))
{
buttonIntersection = true;
}
else
{
buttonIntersection = false;
}
}
if(drawnRaylineIntersections.size() > 0) //If the drawnRayline intersects any surfaces
{
double distance;
//Find which surface is the closest (not perfect)
minimumDistance = Math.sqrt(Math.pow(((Rectangle2D)drawnRaylineIntersections.get(0)).getCenterX() - player.getCenterX(), 2) + Math.pow(((Rectangle2D)drawnRaylineIntersections.get(0)).getCenterY() - player.getCenterY(), 2));
for(int i = 0; i < drawnRaylineIntersections.size(); i++)
{
distance = Math.sqrt(Math.pow(((Rectangle2D)drawnRaylineIntersections.get(i)).getCenterX() - player.getCenterX(), 2) + Math.pow(((Rectangle2D)drawnRaylineIntersections.get(i)).getCenterY() - player.getCenterY(), 2));
if(distance <= minimumDistance)
{
closestIntersectedObject = (Rectangle2D)drawnRaylineIntersections.get(i);
minimumDistance = Math.sqrt(Math.pow((closestIntersectedObject.getCenterX() - player.getCenterX()), 2) + Math.pow((closestIntersectedObject).getCenterY() - player.getCenterY(), 2));
}
}
if(portalableSurfaces.contains(closestIntersectedObject)) //if the closest object is portalable
{
portalableIntersection = true;
}
else
{
portalableIntersection = false;
}
}
drawnRaylineIntersections.clear();
if(thePhysicsObject == player)
{
if(!playerJustPortaled) //For portals
{
if(thePhysicsObject.intersects(portal1.getFrame()) && portalsActive)
{
thePhysicsObjectPos.set(portal2.getX(), portal2.getY());
setUpPortalPhysics(portal1RelativeLocation, portal2RelativeLocation, thePhysicsObjectPos, thePhysicsObjectVel, thePhysicsObjectAcc);
playerJustPortaled = true;
}
else if(thePhysicsObject.intersects(portal2.getFrame()) && portalsActive)
{
thePhysicsObjectPos.set(portal1.getX(), portal1.getY());
setUpPortalPhysics(portal2RelativeLocation, portal1RelativeLocation, thePhysicsObjectPos, thePhysicsObjectVel, thePhysicsObjectAcc);
playerJustPortaled = true;
}
}
else if(!thePhysicsObject.intersects(portal1.getFrame()) && !thePhysicsObject.intersects(portal2.getFrame())) //Once the player is no longer touching a portal, they are able to use a portal again
{
playerJustPortaled = false;
}
if(player.intersects(exitDoor))
{
loadNextLevel = true;
}
else
{
loadNextLevel = false;
}
}
if(thePhysicsObject == box)
{
if(!boxHeld)
{
if(!boxJustPortaled) //For portals
{
if(thePhysicsObject.intersects(portal1.getFrame()) && portalsActive)
{
thePhysicsObjectPos.set(portal2.getX(), portal2.getY());
setUpPortalPhysics(portal1RelativeLocation, portal2RelativeLocation, thePhysicsObjectPos, thePhysicsObjectVel, thePhysicsObjectAcc);
boxJustPortaled = true;
}
else if(thePhysicsObject.intersects(portal2.getFrame()) && portalsActive)
{
thePhysicsObjectPos.set(portal1.getX(), portal1.getY());
setUpPortalPhysics(portal2RelativeLocation, portal1RelativeLocation, thePhysicsObjectPos, thePhysicsObjectVel, thePhysicsObjectAcc);
boxJustPortaled = true;
}
}
else if(!thePhysicsObject.intersects(portal1.getFrame()) && !thePhysicsObject.intersects(portal2.getFrame())) //Once the player is no longer touching a portal, they are able to use a portal again
{
boxJustPortaled = false;
}
}
}
} |
b67eaea8-6dba-4918-89cf-54894bd4b11e | private void setUpPortalPhysics(int firstPortalRelativeLocation, int secondPortalRelativeLocation, Vec2 thePhysicsObjectPos, Vec2 thePhysicsObjectVel, Vec2 thePhysicsObjectAcc) //Sets up the portal physics (dependent upon the relative placement of the portals: above, below etc.)
{
switch(firstPortalRelativeLocation) //Where the portal is going to be drawn relative to the object it is being drawn on
{
case Rectangle2D.OUT_TOP:
if(thePhysicsObjectVel.getY() < 0) //If the object attempts to enter the portal the "wrong way"
{
thePhysicsObjectVel.set(thePhysicsObjectVel.getX(), 0.0); //Stop their motion
}
switch(secondPortalRelativeLocation)
{
case Rectangle2D.OUT_TOP:
thePhysicsObjectVel.set(0.0, -thePhysicsObjectVel.getY());
if(thePhysicsObjectPos == playerPos)
{
thePhysicsObjectPos.set(thePhysicsObjectPos.add(10.0, -40.0));//Has to compensate for gravity
}
if(thePhysicsObjectPos == boxPos)
{
thePhysicsObjectPos.set(thePhysicsObjectPos.add(10.0, -25.0));//Has to compensate for gravity
}
if(thePhysicsObjectVel.getY() >= -0.5) //In case the player steps sideways into a floor portal
{
thePhysicsObjectVel.set(thePhysicsObjectVel.add(0.0, -2.0));
}
break;
case Rectangle2D.OUT_BOTTOM:
thePhysicsObjectVel.set(0.0, thePhysicsObjectVel.getY());
thePhysicsObjectPos.set(thePhysicsObjectPos.add(0.0, 10.0));
break;
case Rectangle2D.OUT_LEFT:
thePhysicsObjectVel.set(-thePhysicsObjectVel.getY(), 0.0);
thePhysicsObjectPos.set(thePhysicsObjectPos.add(-10.0, 0.0));
if(thePhysicsObjectVel.getX() == 0.0)
{
thePhysicsObjectPos.set(thePhysicsObjectPos.add(-10.0, 0.0));
}
break;
case Rectangle2D.OUT_RIGHT:
thePhysicsObjectVel.set(thePhysicsObjectVel.getY(), 0.0);
thePhysicsObjectPos.set(thePhysicsObjectPos.add(10.0, 0.0));
if(thePhysicsObjectVel.getX() == 0.0)
{
thePhysicsObjectPos.set(thePhysicsObjectPos.add(10.0, 0.0));
}
break;
default:
//System.out.println("OUT_TOP Default");
break;
}
break;
case Rectangle2D.OUT_BOTTOM:
if(thePhysicsObjectVel.getY() > 0) //If the object attempts to enter the portal the "wrong way"
{
thePhysicsObjectVel.set(thePhysicsObjectVel.getX(), 0.0); //Stop their motion
}
switch(secondPortalRelativeLocation)
{
case Rectangle2D.OUT_TOP:
thePhysicsObjectVel.set(0.0, thePhysicsObjectVel.getY());
thePhysicsObjectPos.set(thePhysicsObjectPos.add(10.0, -40.0));
if(thePhysicsObjectVel.getY() >= 0.0)
{
thePhysicsObjectPos.set(thePhysicsObjectPos.add(10.0, -20.0));
}
break;
case Rectangle2D.OUT_BOTTOM:
thePhysicsObjectVel.set(0.0, -thePhysicsObjectVel.getY());
thePhysicsObjectPos.set(thePhysicsObjectPos.add(10.0, 10.0));
break;
case Rectangle2D.OUT_LEFT:
thePhysicsObjectVel.set(thePhysicsObjectVel.getY(), 0.0);
thePhysicsObjectPos.set(thePhysicsObjectPos.add(-10.0, 0.0));
break;
case Rectangle2D.OUT_RIGHT:
thePhysicsObjectVel.set(-thePhysicsObjectVel.getY(), 0.0);
thePhysicsObjectPos.set(thePhysicsObjectPos.add(10.0, 0.0));
break;
default:
//System.out.println("OUT_BOTTOM Default");
break;
}
break;
case Rectangle2D.OUT_LEFT:
if(thePhysicsObjectVel.getX() < 0) //If the object attempts to enter the portal the "wrong way"
{
thePhysicsObjectVel.set(0.0, thePhysicsObjectVel.getY()); //Stop their motion
}
switch(secondPortalRelativeLocation)
{
case Rectangle2D.OUT_TOP:
thePhysicsObjectVel.set(0.0, -thePhysicsObjectVel.getX());
thePhysicsObjectPos.set(thePhysicsObjectPos.add(10.0, -60.00)); //Takes care of collision issues
break;
case Rectangle2D.OUT_BOTTOM:
thePhysicsObjectVel.set(0.0, thePhysicsObjectVel.getX());
thePhysicsObjectPos.set(thePhysicsObjectPos.add(10.0, 10.0));
break;
case Rectangle2D.OUT_LEFT:
thePhysicsObjectVel.set(-thePhysicsObjectVel.getX(), 0.0);
thePhysicsObjectPos.set(thePhysicsObjectPos.add(-10.0, 0.0));
break;
case Rectangle2D.OUT_RIGHT:
thePhysicsObjectVel.set(thePhysicsObjectVel.getX(), 0.0);
thePhysicsObjectPos.set(thePhysicsObjectPos.add(10.0, 0.0));
if(thePhysicsObjectVel.getX() <= 0.0)
{
thePhysicsObjectPos.set(thePhysicsObjectPos.add(10.0, 0.0));
}
break;
default:
//System.out.println("OUT_LEFT Default");
break;
}
break;
case Rectangle2D.OUT_RIGHT:
if(thePhysicsObjectVel.getX() > 0) //If the object attempts to enter the portal the "wrong way"
{
thePhysicsObjectVel.set(0.0, thePhysicsObjectVel.getY()); //Stop their motion
}
switch(secondPortalRelativeLocation)
{
case Rectangle2D.OUT_TOP:
thePhysicsObjectVel.set(0.0, thePhysicsObjectVel.getX());
thePhysicsObjectPos.set(thePhysicsObjectPos.add(10.0, -60.0)); //Takes care of collision issues
break;
case Rectangle2D.OUT_BOTTOM:
thePhysicsObjectVel.set(0.0, -thePhysicsObjectVel.getX());
thePhysicsObjectPos.set(thePhysicsObjectPos.add(10.0, 10.0));
break;
case Rectangle2D.OUT_LEFT:
thePhysicsObjectVel.set(thePhysicsObjectVel.getX(), 0.0);
thePhysicsObjectPos.set(thePhysicsObjectPos.add(-10.0, 0.0));
if(thePhysicsObjectVel.getX() >= 0.0)
{
thePhysicsObjectPos.set(thePhysicsObjectPos.add(-10.0, 0.0));
}
break;
case Rectangle2D.OUT_RIGHT:
thePhysicsObjectVel.set(-thePhysicsObjectVel.getX(), 0.0);
thePhysicsObjectPos.set(thePhysicsObjectPos.add(10.0, 0.0));
break;
default:
//System.out.println("OUT_RIGHT Default");
break;
}
break;
default:
//System.out.println("portal1RelativeLocation Default");
break;
}
} |
d483d711-b14c-468f-9a7e-8fa4fef8e33d | private void addFriction(Vec2 thePhysicsObjectVel, Vec2 thePhysicsObjectAcc) //Applies friction (if on the ground)
{
if((thePhysicsObjectVel == playerVel) && (aPressed || dPressed))
{
playerMovementIssue = true;
}
else
{
playerMovementIssue = false;
}
if(onGround && !playerMovementIssue) //If on the ground, and not trying to move left, and not trying to move right
{
if(thePhysicsObjectVel.getX() > 0.0) //If the player is moving to the right
{
if(thePhysicsObjectVel.getX() < 1.0) //If they are moving very slowly
{
//Stop them from moving
thePhysicsObjectVel.set(0.0, thePhysicsObjectVel.getY());
thePhysicsObjectAcc.set(0.0, thePhysicsObjectAcc.getY());
}
else
{
thePhysicsObjectAcc.set(thePhysicsObjectAcc.add(-0.10, 0.0));
}
}
if(thePhysicsObjectVel.getX() < 0.0) //If the player is moving to the left
{
if(thePhysicsObjectVel.getX() > -1.0) //If they are moving very slowly
{
//Stop them from moving
thePhysicsObjectVel.set(0.0, thePhysicsObjectVel.getY());
thePhysicsObjectAcc.set(0.0, thePhysicsObjectAcc.getY());
}
else
{
thePhysicsObjectAcc.set(thePhysicsObjectAcc.add(0.10, 0.0));
}
}
}
else if(!onGround || dPressed || aPressed) //If in the air, or trying to move right, or trying to move left
{
thePhysicsObjectAcc.set(0.0, thePhysicsObjectAcc.getY()); //Get rid of any friction acceleration
}
} |
5671fde2-2b36-4a79-8307-dca90e8731ac | private void sumAccVelPos(Vec2 thePhysicsObjectPos, Vec2 thePhysicsObjectVel, Vec2 thePhysicsObjectAcc)
{
//Calculate the new velocity/position for the player
thePhysicsObjectVel.set(thePhysicsObjectVel.add(thePhysicsObjectAcc));
thePhysicsObjectPos.set(thePhysicsObjectPos.add(thePhysicsObjectVel));
playerX = playerPos.getX();
playerY = playerPos.getY();
boxX = boxPos.getX();
boxY = boxPos.getY();
if(playerVel.getY() >= 0.0)
{
jumping = false;
}
} |
1247838d-44ca-4066-8ca7-7eb5479af7c1 | private void setNewPosition() //Move the player to the new location
{
player.setRect(playerX, playerY, 20, 40);
box.setRect(boxX, boxY, 25, 25);
} |
f2ce2c3b-bec5-4229-a9bc-b8a249d5af3b | private void setDrawnRay()
{
drawnRay.set((mouseX - player.getCenterX()), (mouseY - player.getCenterY()));
drawnRay = drawnRay.normalize();
drawnRay = drawnRay.multiply(1200);
drawnRayline.setLine(player.getCenterX(), player.getCenterY(), drawnRay.getX() + player.getCenterX(), drawnRay.getY() + player.getCenterY());
} |
a63351af-da00-419c-be58-f7fe95bde60e | private void doNothing()
{
animatorDeltaTime = (animatorFinalTime - animatorInitialTime);
animatorSleepTime = (ANIMATOR_SLEEP_TIME - animatorDeltaTime);
if(animatorSleepTime < 0) //If the animations took longer than ANIMATOR_SLEEP_TIME to run
{
animatorSleepTime = 0;
}
try
{
Thread.sleep(animatorSleepTime);
}
catch(InterruptedException e)
{
System.exit(0);
}
} |
c774cb5b-e78f-4edd-841a-ace5a94a80b3 | public void run()
{
while(true)
{
painterInitialTime = System.currentTimeMillis();
repaint();
painterFinalTime = System.currentTimeMillis();
painterDeltaTime = (painterFinalTime - painterInitialTime);
painterSleepTime = (PAINTER_SLEEP_TIME - painterDeltaTime);
if(painterSleepTime < 0)
{
painterSleepTime = 0;
}
try
{
Thread.sleep(painterSleepTime); //Approx. 1/60th of a second
}
catch(InterruptedException e)
{
System.exit(0);
}
}
} |
f71f4e44-84fd-4894-8a1f-69e18976793e | public void keyPressed(KeyEvent e)
{
int theKey = e.getKeyCode();
double boxDistance;
if((theKey == KeyEvent.VK_A) && (!aPressed) && (!playerJustPortaled)) //!justPortaled prevents the user from going backwards, potentially through the level
{
aPressed = true;
if(playerVel.getX() > -3.0) //If not moving to the left at walking velocity
{
playerVel.set(playerVel.add(-3.0 - playerVel.getX(), 0.0));
heldBoxX = -20.0;
playerFacingRight = false;
}
}
if((theKey == KeyEvent.VK_D) && (!dPressed) && (!playerJustPortaled))
{
dPressed = true;
if(playerVel.getX() < 3.0) //If not moving to the right at walking velocity
{
playerVel.set(playerVel.add(3.0 - playerVel.getX(), 0.0));
heldBoxX = 20.0;
playerFacingRight = true;
}
}
if((theKey == KeyEvent.VK_S) && (!playerJustPortaled))
{
playerVel.set(0.0, playerVel.getY());
}
if(theKey == KeyEvent.VK_SPACE)
{
if(playerOnGround && (playerVel.getY() > -2))
{
playerVel.set(playerVel.add(0.0, -6.0)); //-6.0
jumping = true;
}
}
if(theKey == KeyEvent.VK_E)
{
boxDistance = Math.sqrt(Math.pow(player.getCenterX() - box.getCenterX(), 2) + Math.pow(player.getCenterY() - box.getCenterY(), 2));
if(boxDistance < 30)
{
if(boxToggle)
{
if(boxHeld)
{
boxHeld = false;
boxToggle = false;
}
else
{
boxHeld = true;
boxToggle = false;
}
}
}
}
} |
3cfb6cd0-077e-4e5e-bb86-60aed1a3d7b4 | public void keyReleased(KeyEvent e)
{
int theKey = e.getKeyCode();
if(theKey == KeyEvent.VK_A)
{
aPressed = false;
}
if(theKey == KeyEvent.VK_D)
{
dPressed = false;
}
if(theKey == KeyEvent.VK_E)
{
boxToggle = true;
}
} |
e5b48b22-f1f1-41ce-8b25-f7aadab3a378 | public void mouseMoved(MouseEvent e)
{
mouseX = e.getX();
mouseY = e.getY();
} |
23b1a33b-38f4-4834-83ed-b3fd2b60ff6d | public void mouseDragged(MouseEvent e)
{
mouseX = e.getX();
mouseY = e.getY();
} |
e4ba252f-eec4-491f-bf84-cde4b0636888 | public void mousePressed(MouseEvent e)
{
int surfaceNumber = 0;
double distanceBetweenPortals;
ray.set((e.getX() - player.getCenterX()), (e.getY() - player.getCenterY()));
ray = ray.normalize();
for(int i = 0; i < 1200; i++)
{
testRay = ray.multiply(i); //Each run of the for loop, the testRay gets 1 pixel longer
rayline.setLine(player.getCenterX(), player.getCenterY(), testRay.getX() + player.getCenterX(), testRay.getY() + player.getCenterY()); //Draw a line from the player to the end of the testRay
for(surfaceNumber = 0; surfaceNumber < allCollidableSurfaces.size(); surfaceNumber++) //For each normal surface
{
if(rayline.intersects((Rectangle2D)allCollidableSurfaces.get(surfaceNumber))) //If the line intersects a surface
{
//Break out of the loops
raylineIntersection = true;
testRay = ray.multiply(i - 1); //Get the ray just before the intersection
testPoint.setLocation(testRay.getX() + player.getCenterX(), testRay.getY() + player.getCenterY()); //Get the point just before the intersection (used to find the relative portal location)
break;
}
}
if(raylineIntersection) //Break out of the loop if an intersection is made
{
break;
}
}
if(portalableSurfaces.contains((Rectangle2D)allCollidableSurfaces.get(surfaceNumber))) //If the first surface hit is portalable
{
portalRelativeLocation = ((Rectangle2D)allCollidableSurfaces.get(surfaceNumber)).outcode(testPoint);
if((e.getButton() == 1) && raylineIntersection)
{
lastShotBluePortal = true;
}
else if((e.getButton() == 3) && raylineIntersection)
{
lastShotBluePortal = false;
}
if(raylineIntersection && lastShotBluePortal) //Prevents from portals being too close to eachother (70 pixels)
{
distanceBetweenPortals = Math.sqrt(Math.pow(testPoint.getX() - portal2.getCenterX(), 2) + Math.pow(testPoint.getY() - portal2.getCenterY(), 2));
if(distanceBetweenPortals < 50)
{
portalCollisionIssue = true;
}
else
{
portalCollisionIssue = false;
}
}
else if(raylineIntersection && !lastShotBluePortal)
{
distanceBetweenPortals = Math.sqrt(Math.pow(testPoint.getX() - portal1.getCenterX(), 2) + Math.pow(testPoint.getY() - portal1.getCenterY(), 2));
if(distanceBetweenPortals < 70)
{
portalCollisionIssue = true;
}
else
{
portalCollisionIssue = false;
}
}
if(!portalCollisionIssue)
{
findPortalRelativeLocations();
}
if(lastShotBluePortal && raylineIntersection && !portalCollisionIssue) //Shooting the blue portal
{
portal1.setFrame(rayline.getX2() - (portalWidth / 2), rayline.getY2() - (portalHeight / 2), portalWidth, portalHeight);
raylineColorIsBlue = true;
portal1Active = true;
}
else if(!lastShotBluePortal && raylineIntersection && !portalCollisionIssue) //Shooting the orange portal
{
portal2.setFrame(rayline.getX2() - (portalWidth / 2), rayline.getY2() - (portalHeight / 2), portalWidth, portalHeight);
raylineColorIsBlue = false;
portal2Active = true;
}
if(portal1Active && portal2Active)
{
portalsActive = true;
}
}
raylineIntersection = false;
} |
4dfd13ee-a6e7-4491-9e17-85cc4d108332 | private void findPortalRelativeLocations()
{
switch(portalRelativeLocation) //Where the portal is going to be drawn relative to the object it is being drawn on
{
case Rectangle2D.OUT_TOP:
portalWidth = 40.0;
portalHeight = 20.0;
if(lastShotBluePortal && raylineIntersection)
{
portal1RelativeLocation = Rectangle2D.OUT_TOP;
}
else if(!lastShotBluePortal && raylineIntersection)
{
portal2RelativeLocation = Rectangle2D.OUT_TOP;
}
break;
case Rectangle2D.OUT_BOTTOM:
portalWidth = 40.0;
portalHeight = 20.0;
if(lastShotBluePortal)
{
portal1RelativeLocation = Rectangle2D.OUT_BOTTOM;
}
else if(!lastShotBluePortal && raylineIntersection)
{
portal2RelativeLocation = Rectangle2D.OUT_BOTTOM;
}
break;
case Rectangle2D.OUT_LEFT:
portalWidth = 20.0;
portalHeight = 40.0;
if(lastShotBluePortal)
{
portal1RelativeLocation = Rectangle2D.OUT_LEFT;
}
else if(!lastShotBluePortal && raylineIntersection)
{
portal2RelativeLocation = Rectangle2D.OUT_LEFT;
}
break;
case Rectangle2D.OUT_RIGHT:
portalWidth = 20.0;
portalHeight = 40.0;
if(lastShotBluePortal)
{
portal1RelativeLocation = Rectangle2D.OUT_RIGHT;
}
else if(!lastShotBluePortal && raylineIntersection)
{
portal2RelativeLocation = Rectangle2D.OUT_RIGHT;
}
break;
default:
//System.out.println("portalRelativeLocation Default");
break;
}
} |
be81d255-9ce6-4b73-a16a-72c7173db72f | public void init(ServletConfig config) throws ServletException {
//Initialize the servlet
super.init(config);
message = "Hello out there";
} |
ac7d551b-db6d-49c1-9756-7604607fb2c4 | protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// catch back name from submitted form
String name = request.getParameter("name");
String pass = request.getParameter("password");
// Set refresh, auto load time as 5 seconds
response.setIntHeader("Refresh", 10);
// Set response content type
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<h1>" + message + "</h1> <h3> " + name + "</h3>");
out.println("<h3> your password is " + pass + "</h3>");
out.println("<a href=\"ServletExample\">Return to Previous Page</a>");
out.close();
} |
8465aed8-e049-400c-9afe-b9fcf5898840 | @Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// Set refresh, auto load time as 5 seconds
resp.setIntHeader("Refresh", 10);
PrintWriter pw = resp.getWriter();
pw.println("<title>Example with GET request</title>");
pw.println("<h2> You referred to this page with a get request </h2>");
pw.println("<a href=\"ServletExample\">Return to Previous Page</a>");
pw.close();
} |
4d857ac3-34a3-42ee-8d0a-2d24de49cc34 | @Override
public void destroy() {
super.destroy();
// Does nothing for now
} |
d295b2ef-88f2-4c47-b1c9-15c54860bbce | public Config() {
this.getAllConfigs();
} |
88d285bc-85fa-4ae6-bf0a-67a7bd1249fc | public String getGlobalConfig(String msg){
return config.get(msg);
} |
c8d9829a-21e1-4b2c-837d-def0cb263009 | protected HashMap<String, String> getAllConfigs() {
config.put(LOGGER_NAME, "log4jConfig");
config.put(JSP_LOCAL_FILE, "/WEB-INF/include/test.jsp");
return config;
} |
69bc7828-d75e-4cf3-a0af-9877addf913b | public void init(ServletConfig scon) throws ServletException {
super.init(scon);
ctx = scon.getServletContext();
jspFile = config.getGlobalConfig(Config.JSP_LOCAL_FILE);
} |
0e52bb65-8070-404b-a277-ca19dd013b02 | protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// set the attribute
String message = "My name is devon what's yours?";
request.setAttribute("message", message);
request.getRequestDispatcher(jspFile).forward(request, response);
} |
6bd4465c-f548-4ef6-afee-7ff1b1f47078 | protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
} |
c2337b2a-7db2-4b6f-9f37-b24b79db5adb | public void destroy() {
} |
976548e3-da40-4f56-9ecc-6da8c874b95a | public void init(FilterConfig fConfig) throws ServletException {
} |
054e36d8-5b32-4ed0-b256-091918ea57ca | public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
String client = request.getRemoteAddr();
String host = request.getLocalName();
myLog.info("Client address:" + client +" HostName:" + host);
// pass the request along the filter chain
chain.doFilter(request, response);
} |
6f83affc-301d-4551-8475-95a4b69050b8 | @Override
/**
* Handles the event when the app is initialized(starts)
*/
public void contextInitialized(ServletContextEvent sce) {
try {
ServletContext sc = sce.getServletContext();
String root = sc.getInitParameter(cf.getGlobalConfig(Config.LOGGER_NAME));
actualPath = sc.getRealPath(root);
PropertyConfigurator.configure(actualPath);
} catch (Exception e) {
e.printStackTrace();
}
message = "Life cycle event";
myLog.info(message);
} |
73158e57-6c0e-47fa-845e-0c9c9b437e1d | @Override
/**
* Handles the event when the app is destroyed(ends)
*/
public void contextDestroyed(ServletContextEvent arg0) {
myLog.info(message);
} |
76d1969b-b217-42db-841e-fdae79dd85eb | public static void generate(String reportName, ReportsTypes type,
Map<String, Object> params, OutputStream out, Connection conn) throws FileNotFoundException, JRException {
ReportFileUtil rFile = ReportFileUtil.getReport(reportName);
JasperPrint jPrint = JasperFillManager.fillReport(new FileInputStream(rFile.getRelatorio()), params, conn);
switch (type) {
case PDF:
makePdf(jPrint, out);
break;
case XLS:
makeXls(jPrint, out);
break;
case HTML:
makeHtml(jPrint, out);
break;
case XML:
makeXml(jPrint, out);
break;
default:
break;
}
} |
d315f828-970d-4753-a35f-4d756d9201bd | private static void makeXml(JasperPrint jPrint, OutputStream out) throws JRException {
JRXmlExporter exporter = new JRXmlExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out);
exporter.exportReport();
} |
27943912-2425-4934-9a2b-41f5c9daeca1 | private static void makeHtml(JasperPrint jPrint, OutputStream out) throws JRException {
JRHtmlExporter exporter = new JRHtmlExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out);
exporter.exportReport();
} |
1ced4c32-a146-46e0-ae2f-6c07c5b28d44 | private static void makeXls(JasperPrint jPrint, OutputStream out) throws JRException {
JRXlsExporter exporter = new JRXlsExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out);
exporter.exportReport();
} |
4b736d25-e434-469c-9358-63c326dc5968 | private static void makePdf(JasperPrint jPrint, OutputStream out) throws JRException {
JasperExportManager.exportReportToPdfStream(jPrint, out);
} |
acf96f6d-99da-4e50-b1fa-b5493e6d7406 | public static ReportsTypes getReportType(String type) {
for(ReportsTypes r : ReportsTypes.values()) {
if(r.toString().equalsIgnoreCase(type)) {
return r;
}
}
return null;
} |
495bb560-34ca-42b6-8e9b-86f26c14d3fd | public ReportFileUtil(File relatorio) {
this.relatorio = relatorio;
this.name = relatorio.getName();
this.cleanName = this.name.split("\\.")[0];
} |
8c2662f6-56ce-4955-b5fe-0c32d1056038 | public String getCleanName() {
return cleanName;
} |
a6e586d5-619f-493c-96e3-d1808a7abadc | public void setCleanName(String cleanName) {
this.cleanName = cleanName;
} |
a89b1b99-77cd-4347-bd45-2740f5c1d669 | public String getName() {
return name;
} |
1fe57917-0a2c-4b52-85b7-b7f6821ecdf8 | public void setName(String name) {
this.name = name;
} |
0cb9ffcb-8c89-4bba-9c30-a5382da068b0 | public File getRelatorio() {
return relatorio;
} |
9d333be3-77a9-49b6-90c7-329c173cdf6a | public void setRelatorio(File relatorio) {
this.relatorio = relatorio;
} |
64af8549-5d4e-4203-980a-b7808d0e6555 | public static List<ReportFileUtil> getRelatorios() {
return relatorios;
} |
802fe19a-af2d-4c7c-a699-5d003164423e | public static boolean exists(String reportName) {
return exists(new File(PropUtil.get("reports-path")), reportName);
} |
5edab7bf-effd-4356-b431-b4fa59cbad4f | public static boolean exists(File path, String reportName) {
try {
for(File file : path.listFiles()) {
if(file.isFile() && file.getName().equals(reportName + ".jasper")) {
return true;
}
if(file.isDirectory()) {
return exists(file, reportName);
}
}
} catch(Exception e) {
e.printStackTrace();
}
return false;
} |
20dab9e7-f3b1-4edd-8bbe-1d1f608e5114 | public static void loadReports() {
loadReports(new File(PropUtil.get("reports-path")));
} |
12185a4f-2196-4001-a94b-58a4f3ac0a94 | public static void loadReports(File path) {
try {
for(File file : path.listFiles()) {
if(file.isFile() && file.getName().endsWith(".jasper")) {
relatorios.add(new ReportFileUtil(file));
}
if(file.isDirectory()) {
loadReports(file);
}
}
} catch(Exception e) {
e.printStackTrace();
}
} |
1ef880cc-6598-4b2b-a51b-e22b3b7edefc | public static ReportFileUtil getReport(String reportName) {
if(relatorios == null || relatorios.isEmpty()) {
loadReports();
}
for(ReportFileUtil report : relatorios) {
if(report.getCleanName().equals(reportName)) {
return report;
}
}
return null;
} |
560264bf-7a5f-4884-83e3-60b727962bb0 | @Override
public String toString() {
return this.cleanName + " - " + this.name + " - " + this.relatorio.getAbsolutePath();
} |
75aa8aea-691b-436e-88f1-78f32b9dd015 | public static String get(String key) {
try {
prop.load(PropUtil.class.getClassLoader().getResourceAsStream("config.properties"));
Object value = prop.get(key);
if(value != null) {
return value.toString();
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
} |
a5b85d9c-f041-4084-a2e4-3261e4891054 | public GroupedParameter(final String name) {
super(name, null);
values = new ArrayList<Parameter>();
} |
dc46d4cf-0464-4d53-a2f9-a5157258f397 | public GroupedParameter(final String name, final ArrayList<Parameter> values) {
super(name, null);
this.values = values;
} |
8cfaebe8-8eb8-445a-bac6-70c8119b7298 | public ArrayList<Parameter> getValues() {
return values;
} |
10a3badb-4c5e-4545-9776-83c204b1dc63 | public void add(final Parameter param) {
values.add(param);
} |
a542b089-4557-47a4-bda1-92fa9f1f1d77 | public Parameter get(final String name) {
Parameter parameterToReturn = null;
for (final Parameter param : values) {
if (param.getName().equals(name)) {
parameterToReturn = param;
}
}
if (parameterToReturn == null) {
throw new IllegalArgumentException("The parameter " + name + " is not found");
}
return parameterToReturn;
} |
f4f9a7fa-9f27-46c9-9eab-ffa49266ecfa | public void setValues(Parameter[] params) {
values = new ArrayList<Parameter>();
for (int i = 0; i < params.length; i++) {
values.add(params[i]);
}
} |
bbaf35c5-ba86-4080-833a-297adaa6db2b | public Object getValue() {
Object objectToReturn = null;
try {
objectToReturn = (Object) toJSONObject(Message.EncodeMode.VERBOSE);
} catch (JSONException e) {
e.printStackTrace();
}
return objectToReturn;
} |
931179a4-3dc6-40ac-9bf8-6cd5d40b5b00 | JSONObject toJSONObject(final Message.EncodeMode encodeMode) throws JSONException {
JSONObject objectGroup = null;
if (values != null) {
objectGroup = new JSONObject();
for (int i = 0; i < values.size(); i++) {
Parameter param = values.get(i);
String paramName = param.getName();
if (encodeMode == Message.EncodeMode.VERBOSE) {
if (paramName == null || paramName.length() == 0) {
paramName = "" + i;
}
}
if (param instanceof SingleParameter) {
objectGroup.put(paramName, param.getValue());
} else if (param instanceof ArrayParameter) {
ArrayParameter arrayParam = (ArrayParameter) param;
objectGroup.put(paramName, arrayParam.toJSONArray(encodeMode));
}
}
}
return objectGroup;
} |
db17312b-c802-4864-b9ae-7eb975384011 | public Message(final Parameter... parameters) {
this.name = null;
this.parameters = parameters;
} |
bad5fbdb-4e55-44d1-b31e-c1baa2d4e7c2 | public Message(final String name, final ArrayParameter parameters) {
this.name = name;
this.parameters = new Parameter[] { parameters };
} |
ad509c18-ae42-4154-b9cb-52894033efb4 | public Message(final String msgText) throws JSONException {
new Decoder().decode(msgText, this);
} |
ca4858b8-97cb-4218-ab91-81b914b1ed15 | public String getName() {
return name;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.