/android/Android(LGame-0.3.2&LAE-1.1)/LGame-0.3.2(OpenGLES)/src/core/org/loon/framework/android/game/action/sprite/effect/SnowKernel.java

http://loon-simple.googlecode.com/ · Java · 101 lines · 68 code · 13 blank · 20 comment · 9 complexity · c9ddc8241049d2a60e193cf7d0dbb41c MD5 · raw file

  1. package org.loon.framework.android.game.action.sprite.effect;
  2. import org.loon.framework.android.game.core.LSystem;
  3. import org.loon.framework.android.game.core.graphics.opengl.GLEx;
  4. import org.loon.framework.android.game.core.graphics.opengl.LTexture;
  5. /**
  6. * Copyright 2008 - 2009
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  9. * use this file except in compliance with the License. You may obtain a copy of
  10. * the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  16. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  17. * License for the specific language governing permissions and limitations under
  18. * the License.
  19. *
  20. * @project loonframework
  21. * @author chenpeng
  22. * @email??šceponline@yahoo.com.cn
  23. * @version 0.1
  24. */
  25. public class SnowKernel implements IKernel {
  26. private boolean exist;
  27. private LTexture snow;
  28. private double offsetX, offsetY, speed, x, y, width, height, snowWidth,
  29. snowHeight;
  30. public SnowKernel(int n, int w, int h) {
  31. snow = new LTexture((LSystem.FRAMEWORK_IMG_NAME + "snow_" + n + ".png")
  32. .intern());
  33. snowWidth = snow.getWidth();
  34. snowHeight = snow.getHeight();
  35. width = w;
  36. height = h;
  37. offsetX = 0;
  38. offsetY = n * 0.6 + 1.9 + Math.random() * 0.2;
  39. speed = Math.random();
  40. }
  41. public void make() {
  42. exist = true;
  43. x = Math.random() * width;
  44. y = -snowHeight;
  45. }
  46. public void move() {
  47. if (!exist) {
  48. if (Math.random() < 0.002) {
  49. make();
  50. }
  51. } else {
  52. x += offsetX;
  53. y += offsetY;
  54. offsetX += speed;
  55. speed += (Math.random() - 0.5) * 0.3;
  56. if (offsetX >= 1.5) {
  57. offsetX = 1.5;
  58. }
  59. if (offsetX <= -1.5) {
  60. offsetX = -1.5;
  61. }
  62. if (speed >= 0.2) {
  63. speed = 0.2;
  64. }
  65. if (speed <= -0.2) {
  66. speed = -0.2;
  67. }
  68. if (y >= height) {
  69. y = -snowHeight;
  70. x = Math.random() * width;
  71. }
  72. }
  73. }
  74. public void draw(GLEx g) {
  75. if (exist) {
  76. g.drawTexture(snow, (int) x, (int) y);
  77. }
  78. }
  79. public LTexture getSnow() {
  80. return snow;
  81. }
  82. public double getSnowHeight() {
  83. return snowHeight;
  84. }
  85. public double getSnowWidth() {
  86. return snowWidth;
  87. }
  88. }