public void update(float time) { super.update(time); int xi = (int) x, yi = (int) y; int r2 = iradius * iradius; for (int x0 = -iradius; x0 <= iradius; x0++) for (int y0 = -iradius; y0 <= iradius; y0++) { if (x0 * x0 + y0 * y0 < r2) world.setPixel(xi + x0, yi + y0, color); } life -= time; if (life <= 0) remove(); }
@Override public void update(float deltaTime) { // Compute player input direction if (cmds.isEmpty() == false) { dir.x = 0; dir.y = 0; if (cmds.contains(Command.MoveUp)) { dir.y += 1; } if (cmds.contains(Command.MoveDown)) { dir.y -= 1; } if (cmds.contains(Command.MoveLeft)) { dir.x -= 1; } if (cmds.contains(Command.MoveRight)) { dir.x += 1; } dir.nor(); // Set the velocity of the player object to the direction * speed // This enables immediate turns super.setVelocity(dir.scl(speed)); super.position.x += velocity.x * deltaTime; super.position.y += velocity.y * deltaTime; bounds.setCenter(super.position); System.out.println(position.toString()); } if (timeLeftOnEmpowered > 0.0f) { timeLeftOnEmpowered -= deltaTime; if (timeLeftOnEmpowered < 0.0f) { timeLeftOnEmpowered = 0.0f; } } }
@Override public void setPosition(Vector2 value) { super.setPosition(value); bounds.setCenter(value); }
/** * The action that happens when the Add Button is pressed. We save all the values and create a new * object, giving it those values. The object is then passed to NetLogo for displaying. * * @param evt */ private void addButtonActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_addButtonActionPerformed // "preprocessor" int MY_OFFSET = 5; int BUS_STREET_CONTACT = -33; int BUS_LENGTH = 286; int BOX_OFFSET = 10; int TOP_OF_BUS = 50; System.out.println("add object"); double weight = weightValue.getValue(); double radius = radiusValue.getValue(); double width = widthValue.getValue(); int x = 0, y = 0; // get the bus object for the x, y coordinates PhysicsObject bus = ObjectManager.getInstance().getObject("bus"); double busX = bus.getXCoord(); double busY = bus.getYCoord(); System.out.println("busX = " + busX + "\tbusY = " + busY); // If we are creating a box... if (boxButton.isSelected()) { System.out.println("making box"); if (topButton.isSelected()) { x = (int) busX; y = (int) (busY + width + TOP_OF_BUS); RelationshipManager.getInstance() .setRelationship("object", "bus", RelationshipTypes.ABOVE_UNRESTRAINED); if (RelationshipManager.getInstance().getRelationship("object", "bus") == RelationshipTypes.ABOVE_UNRESTRAINED) System.out.println("On top works"); } else if (insideRButton.isSelected()) { x = (int) busX; y = (int) (width * (double) MY_OFFSET); RelationshipManager.getInstance() .setRelationship("object", "bus", RelationshipTypes.INSIDE_RESTRAINED); } else if (insideUButton.isSelected()) { x = (int) busX; y = (int) (width * (double) MY_OFFSET); RelationshipManager.getInstance() .setRelationship("object", "bus", RelationshipTypes.INSIDE_UNRESTRAINED); } else if (behindButton.isSelected()) { x = (int) (-0.5 * (double) BUS_LENGTH); y = BUS_STREET_CONTACT; RelationshipManager.getInstance() .setRelationship("object", "bus", RelationshipTypes.BEHIND_ATTACHED); } else if (inFrontButton.isSelected()) { x = (int) (0.5 * (double) BUS_LENGTH); y = BUS_STREET_CONTACT; RelationshipManager.getInstance().setRelationship("object", "bus", RelationshipTypes.FRONT); } PhysicsObject boxOb = ObjectManager.getInstance().createSquare(x, y, (width * BOX_OFFSET), weight); ObjectManager.getInstance().addObject("object", boxOb); ObjectManager.getInstance().getObject("object").setAcceleration(0); ObjectManager.getInstance().getObject("object").setDecleration(0); System.out.println("width = " + ((SquareObject) boxOb).getWidth()); System.out.println("weight = " + boxOb.getMass()); System.out.println("x = " + x); System.out.println("y = " + y); } // else if we are creating a ball... else if (ballButton.isSelected()) { System.out.println("making ball"); if (topButton.isSelected()) { x = (int) busX; y = (int) (busY + radius + TOP_OF_BUS); RelationshipManager.getInstance() .setRelationship("object", "bus", RelationshipTypes.ABOVE_UNRESTRAINED); } else if (insideRButton.isSelected()) { x = (int) busX; y = (int) (radius * (double) MY_OFFSET); RelationshipManager.getInstance() .setRelationship("object", "bus", RelationshipTypes.INSIDE_RESTRAINED); } else if (insideUButton.isSelected()) { x = (int) busX; y = (int) (radius * (double) MY_OFFSET); RelationshipManager.getInstance() .setRelationship("object", "bus", RelationshipTypes.INSIDE_UNRESTRAINED); } else if (behindButton.isSelected()) { x = (int) (-0.5 * BUS_LENGTH); y = (int) (BUS_STREET_CONTACT); RelationshipManager.getInstance() .setRelationship("object", "bus", RelationshipTypes.BEHIND_ATTACHED); } else if (inFrontButton.isSelected()) { x = (int) (0.5 * BUS_LENGTH); y = (int) (BUS_STREET_CONTACT); RelationshipManager.getInstance().setRelationship("object", "bus", RelationshipTypes.FRONT); } PhysicsObject ballOb = ObjectManager.getInstance().createCircle(x, y, (radius * MY_OFFSET), weight); ObjectManager.getInstance().addObject("object", ballOb); ObjectManager.getInstance().getObject("object").setAcceleration(0); ObjectManager.getInstance().getObject("object").setDecleration(0); System.out.println("weight = " + ballOb.getMass()); System.out.println("radius = " + ((RoundObject) ballOb).getRadius()); System.out.println("x = " + x); System.out.println("y = " + y); } // if the world crashed and died... else { System.out.println("failboat"); } this.dispose(); } // GEN-LAST:event_addButtonActionPerformed