Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. import env3d.EnvObject;
  2. import java.util.ArrayList;
  3.  
  4. public class Tux extends Creature
  5. {
  6. private int frame = 0;
  7. private double rand = 0;
  8.  
  9. public Tux(double x, double y, double z)
  10. {
  11. super(x, y, z);
  12.  
  13. // Must use the mutator as the fields have private access
  14. // in the parent class
  15. setTexture("models/tux/tux.png");
  16. setModel("models/tux/tux.obj");
  17. }
  18.  
  19. private void randomGenerator()
  20. {
  21. rand = Math.random();
  22. }
  23.  
  24. public void move(ArrayList<Creature> creatures, ArrayList<Creature> dead_creatures, ArrayList<Creature> new_creatures)
  25. {
  26. frame++;
  27. if (frame > 15) {
  28. randomGenerator();
  29. frame = 0;
  30. }
  31.  
  32. if (rand < 0.5) {
  33. setRotateY(getRotateY()-5);
  34. } else if (rand < 1) {
  35. setRotateY(getRotateY()+5);
  36. }
  37.  
  38. setX(getX()+Math.sin(Math.toRadians(getRotateY()))*0.1);
  39. setZ(getZ()+Math.cos(Math.toRadians(getRotateY()))*0.1);
  40.  
  41. if (getX() < getScale()) setX(getScale());
  42. if (getX() > 10-getScale()) setX(10 - getScale());
  43. if (getZ() < getScale()) setZ(getScale());
  44. if (getZ() > 30-getScale()) setZ(10 - getScale());
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement