particle.java
per admin
—
darrera modificació
2020-03-25T16:34:36+02:00
/*
Gasteroids v0.1 aplicación didáctica para dispositivos MIDP2.0
Copyright (C) 2006 Victor Carceler
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package gpl.gasteroids;
/**
* Modela una partícula, es decir, un Gasteroide.
* * Una partícula cuenta con las siguiente propiedades: *
-
*
- Color (R,G,B) *
- Posición (x,y) *
- Límites para la posición. Área definida por el rectángulo: (x_min,y_min) (x_max,y_max) *
- Masa (m) para calcular la fuerza de gravedad entre diferentes partículas *
- Carga (q) para calcular la fuerza de atracción/repulsión entre diferentes partículas ACTUALMENTE NO SE UTILIZA *
- Velocidad (speed_x, speed_y) *
- Fuerza a la que está sometida por la influencia de otras partículas (force_x, force_y) *
* La partícula no podrá moverse fuera del área especificada por sus propiedades (x_min, y_min) y (x_max, y_max). * Si la partícula choca con un borde, su posición no variará y la componente velocidad que la empuja * a traspasar el límite será puesta a 0.
* Si se quisiese hacer que las partículas rebotasen al chochar con un borde, este es el método adecuado. * @param t Tiempo en segundos */ public void updatePosition(double t) { x += speed_x * t; y += speed_y * t; if(x<=x_min) {x=x_min; speed_x = 0;} if(x>=x_max) {x=x_max; speed_x = 0;} if(y<=y_min) {y=y_min; speed_y = 0;} if(y>=y_max) {y=y_max; speed_y = 0;} //System.out.println(this); } }