Advertisement
Guest User

Clases

a guest
Jan 21st, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.78 KB | None | 0 0
  1. class Animacion {
  2. PImage[] images;
  3. int imageCount;
  4. int frame;
  5.  
  6. Animacion(String imagePrefix, int count) {
  7. imageCount = count;
  8. images = new PImage[imageCount];
  9.  
  10. for (int i = 0; i < imageCount; i++) {
  11. // Use nf() to number format 'i' into four digits
  12. String filename = imagePrefix + nf(i, 4) + ".png";
  13. images[i] = loadImage(filename);
  14. }
  15. }
  16.  
  17. void display(float xpos, float ypos) {
  18. frame = (frame+1) % imageCount;
  19. images[frame].resize(width,height);
  20. image(images[frame], xpos, ypos);
  21. }
  22.  
  23. int getWidth() {
  24. return images[0].width;
  25. }
  26. }// La mami de los objetos
  27. class Objeto
  28. {
  29. int ancho, alto;
  30. float posx, posy;
  31. PImage imgObjeto;
  32. PVector vel; // tienes un valor para la x y un valor en y, tiene sun objeto y le dices la posicion (se va a mover en los ejes tal)
  33.  
  34. Objeto(float posx, float posy, int ancho, int alto, String imgObjeto, PVector vel) {
  35. this.posx = posx;
  36. this.posy = posy;
  37. this.ancho = ancho;
  38. this.alto = alto;
  39. this.vel = vel;
  40. this.imgObjeto = loadImage(imgObjeto);
  41. }
  42.  
  43. void dibujar()
  44. {
  45. imgObjeto.resize(ancho, alto);
  46. image(imgObjeto, posx, posy);
  47. }
  48.  
  49. void mover() {
  50. posx = posx + int(vel.x);
  51. }
  52. void mover2() {
  53. posy = posy + int(vel.y);
  54. }
  55.  
  56. void zoomout() {
  57. ancho = ancho -100;
  58. alto = alto -100;
  59. }
  60. }class Pagina
  61. {
  62. int PaginaApli;
  63. Tiempo tiempoPagina;
  64. Pagina (int p)
  65. {
  66. PaginaApli=p;
  67. tiempoPagina= new Tiempo();
  68. }
  69. int getPagina()
  70. {
  71. return PaginaApli;
  72. }
  73.  
  74. Tiempo getCronoPagina()
  75. {
  76. return tiempoPagina;
  77. }
  78.  
  79. void setPagina(int nuevaPagina)
  80. {
  81. PaginaApli=nuevaPagina;
  82. if ((nuevaPagina==0)||(nuevaPagina==1)) tiempoPagina.restart();
  83. PaginaApli=nuevaPagina;
  84. }
  85. }class Personaje extends Objeto
  86.  
  87. { PImage aspecto1, aspecto2, aspecto3, aspecto4, aspecto5;
  88.  
  89. Personaje(float posx, float posy, int ancho, int alto, String aspecto1, String aspecto2, String aspecto3, String aspecto4, String aspecto5, PVector vel)
  90. { super(posx, posy, ancho, alto, aspecto1, vel);
  91. this.aspecto1 = loadImage(aspecto1);
  92. this.aspecto2 = loadImage(aspecto2);
  93. this.aspecto3 = loadImage(aspecto3);
  94. this.aspecto4 = loadImage(aspecto4);
  95. this.aspecto5 = loadImage(aspecto5);
  96. }
  97.  
  98. Personaje(float posx, float posy, int ancho, int alto, String aspecto1, String aspecto2, String aspecto3, PVector vel)
  99. { super(posx, posy, ancho, alto, aspecto1, vel);
  100. this.aspecto1 = loadImage(aspecto1);
  101. this.aspecto2 = loadImage(aspecto2);
  102. this.aspecto3 = loadImage(aspecto3);
  103. }
  104.  
  105. Personaje(float posx, float posy, int ancho, int alto, String aspecto1, String aspecto2, String aspecto3, String aspecto4, PVector vel)
  106. { super(posx, posy, ancho, alto, aspecto1, vel);
  107. this.aspecto1 = loadImage(aspecto1);
  108. this.aspecto2 = loadImage(aspecto2);
  109. this.aspecto3 = loadImage(aspecto3);
  110. this.aspecto4 = loadImage(aspecto3);
  111. }
  112. Personaje(float posx, float posy, int ancho, int alto, String aspecto1, String aspecto2, PVector vel)
  113. { super(posx, posy, ancho, alto, aspecto1, vel);
  114. this.aspecto1 = loadImage(aspecto1);
  115. this.aspecto2 = loadImage(aspecto2);
  116. }
  117.  
  118.  
  119. void dibujarAspecto1(){
  120. aspecto1.resize(ancho,alto);
  121. image(aspecto1, posx, posy);
  122. }
  123. void dibujarAspecto2(){
  124. aspecto2.resize(ancho,alto);
  125. image(aspecto2, posx, posy);
  126. }
  127. void dibujarAspecto3(){
  128. aspecto1.resize(ancho,alto);
  129. image(aspecto1, posx, posy);
  130. }
  131. void dibujarAspecto4(){
  132. aspecto2.resize(ancho,alto);
  133. image(aspecto2, posx, posy);
  134. }
  135. void dibujarAspecto5(){
  136. aspecto2.resize(ancho,alto);
  137. image(aspecto2, posx, posy);
  138. }
  139.  
  140.  
  141. }
  142. class MsgBox {
  143.  
  144. // the text and a holder
  145. String text, displayText;
  146.  
  147. //positioning
  148. PVector bgPos, textPos;
  149. float w, h;
  150.  
  151. //font and color
  152. color textColor =#CCCEBD, bgColor = color(20,200);
  153. PFont font;
  154.  
  155. //timimng
  156. int timer, wait;
  157. //it takes the text, positioning stuff and init everything
  158. MsgBox(String _tx, PVector _bg, PFont _f) {
  159. bgPos = _bg;
  160. font = _f;
  161. w = 600;
  162. h = 150;
  163. text = _tx;
  164.  
  165. displayText = text;
  166. textFont(font, 20);
  167.  
  168. //calc text pos relative to bg pos
  169. textPos = new PVector(bgPos.x + 105, (bgPos.y + 390));
  170.  
  171. // the speed of "typing"
  172. wait = 40;
  173. }
  174.  
  175. void run() {
  176. update();
  177. display();
  178. }//run
  179.  
  180. void display() {
  181. drawBg();
  182. drawText();
  183. }//display
  184.  
  185. void setText(String s) {
  186. if (!text.equals(s)) {
  187. text = s;
  188. displayText = text;
  189. }
  190. }//setText
  191.  
  192. void animateText() {
  193. displayText = "";
  194. timer = millis();
  195. }//animateText
  196.  
  197. void update() {
  198. if (!isFinished() && (millis() - timer) > wait) {
  199. displayText = text.substring(0, displayText.length()+1);
  200. timer = millis();
  201. }
  202. }//update()
  203.  
  204. boolean isFinished() {
  205. return displayText.length() == text.length();
  206. }//isFinished
  207.  
  208. void drawBg() {
  209. rectMode(CORNER);
  210. noStroke();
  211. fill(bgColor);
  212. rect(bgPos.x+70, bgPos.y+350, w, h);
  213. }//drawBg
  214.  
  215.  
  216. void drawText() {
  217. fill(textColor);
  218. text(displayText, textPos.x, textPos.y);
  219. }//drawText
  220.  
  221. //drawBullet*/
  222. }//MsgBoxclass Tiempo
  223. {
  224. long initialTiempo;
  225. long currentTiempo;
  226. Tiempo()
  227. {
  228. initialTiempo=System.currentTimeMillis();
  229. }
  230. void restart()
  231. {
  232. initialTiempo=System.currentTimeMillis();
  233. }
  234.  
  235. long timingT()
  236. {
  237. currentTiempo= System.currentTimeMillis()- initialTiempo;
  238. return currentTiempo;
  239. }
  240. void represent()
  241. {
  242. currentTiempo= (System.currentTimeMillis()- initialTiempo)/1000;
  243. fill(255, 0, 0);
  244. text(currentTiempo, 620, 60);
  245. }
  246. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement