As I understand it is to do this using particle, but does Osei how to do it, someone could put a simple example with rain (and thunder).
Extra info: my screen is 800x600, the camera goes with the character.
Thanks for any help
As I understand it is to do this using particle, but does Osei how to do it, someone could put a simple example with rain (and thunder).
Extra info: my screen is 800x600, the camera goes with the character.
Thanks for any help
It’s not so much about the rain particles, but about creating a believable atmosphere.
A good rain technique will use some combination of the following elements:
The particles themselves would be easy in slick. Define yourself a “rain” particle, and to start use a simple 1x4 gray line as your sprite. Spawn new rain particles randomly along the top of the screen, and have each one move down at a semi-random speed per frae. When rendering, rotate the GL context so they all fall at a given angle.
g.rotate(0, 0, rainAngle);
rainSprite.startUse();
for (RainEntity e : rain) {
rainSprite.drawEmbedded(e.x, e.y, e.width, e.height);
}
rainSprite.endUse();
g.rotate(0, 0, -rainAngle);
[quote](and thunder)
[/quote]
I suppose you mean lightning?
See this thread:
http://slick.javaunlimited.net/viewtopic.php?p=25044
(Note: the code I posted there isn’t terribly efficient so please take it with a grain of salt…)
For rain, one example would be the main method, this type here?
I am remembering that crude about it, so please kindly give me an example with a main method that I poss test and leave evolving.
Do not even know where or how to create particle rain to get an idea.
That gemserk’s tutorial is in lwjgl. To make lighting just draw a fast fading white over screen along with sound played.
I understand about the thunder, but I found the example of rain where you spoke.
I’m not on my own computer at the moment, so you’ll have to make do with pseudocode.
int spawnDelay = 250; //interval between each new dropplet
int spawnTime = 0;
ArrayList<Rain> rain = new ArrayList<Rain>(100);
void update(.. int delta ..)
//check to see if we should spawn a new rain entity
spawnTime += delta;
if (spawnTime > spawnDelay) {
spawnTime = 0;
spawn();
}
//update position of all rain entities by moving them down
for (Rain r : rain)
r.y += delta * RAIN_MOVE_SPEED;
void spawn()
Rain r = new Rain();
r.x = Math.random() * SCREEN_WIDTH;
r.y = 0;
rain.add(r);
void render(... Graphics g ...)
// render code I posted earlier...
class Rain
int x, y;
Then check to see if the droplet is out of screen bounds (removing it if so), maybe add a double-buffered type of list, randomizing the interval between a given range, randomizing the speed between a given range, etc.
Off topic edit: I just looked at my code and it looks so damn CLEAN… why I am I programming games in Java not Python?
I have it even harder… I a windfactor which is basically the angle BUT it only slowly affects a rain drop. Drops have different lengths and widths, I even manged to make a small “Storm”-effect, which pushes the drops to an certain angle and back. Every drop can also collide with the map, and splash on the ground ( velocity.y * -0.7 + changing the render style):
(colliding is not implemented here)
Edit:
Oh it also uses pooling but I guess that’s what everybody does.
I tried to make the example, using what you have spoken in the 2nd post, but not ta Dand right, that entity can not be a simple rectangle with a white background?
This is looking pretty complex :-\
my class responsible for drawing everything that is above the User (eg. fog, sandstorm, etc.).
public class RenderMapCloudSystem extends EntityProcessingSystem implements ManagerAllSystem{
private GameContainer container;
private Graphics graphics;
private CameraCharacterSystem cameraSystem;
private int value;
private Timer turnForMapEffect;
private Timer turn;
private int currentTurn;
private Image imgNight;
@SuppressWarnings("unused")
private boolean day;
private Image img;
private int directionStartEffect;
@SuppressWarnings("unchecked")
public RenderMapCloudSystem(GameContainer container) {
super(CharacterComponent.class);
this.container = container;
this.graphics = container.getGraphics();
}
@Override
public void initialize() {
cameraSystem = world.getSystemManager().getSystem(CameraCharacterSystem.class);
turnForMapEffect = new Timer(1000); //1000ms=1.0seg
turn = new Timer(1000); //1000ms=1.0seg | //600000ms=10 minutos
img = null;
imgNight = ResourceManager.getFog("Night");
imgNight.setAlpha(0.0f);
day = true;
currentTurn = 0;
restartSystem();
}
@Override
public void restartSystem() {
value=0;
String effectMap = ManagerMap.getInstance().getCurrentMap().getEffectMap();
if (effectMap==null || effectMap.isEmpty()){
img =null;
} else if (effectMap.equals("sandStorm")){
img = ResourceManager.getFog("Sandstorm02");
img.setAlpha(0.7f);
turnForMapEffect.resetTime(50, 50); //1000ms=1.0seg
directionStartEffect = EnumPosition.FACE_DOWN.getIndex();
} else if (effectMap.equals("mist")){
img = ResourceManager.getFog("Fog01");
img.setAlpha(0.4f);
turnForMapEffect.resetTime(50, 50); //1000ms=1.0seg
directionStartEffect = EnumPosition.FACE_RIGHT.getIndex();
} else if (effectMap.equals("cloud")){
img = ResourceManager.getFog("Clouds01");
img.setAlpha(0.2f);
turnForMapEffect.resetTime(50, 50); //1000ms=1.0seg
directionStartEffect = EnumPosition.FACE_LEFT.getIndex();
}
}
@Override
protected void process(Entity player) {
cameraSystem = world.getSystemManager().getSystem(CameraCharacterSystem.class);
int cameraOffSetPixelX = (int) -cameraSystem.getOffsetX();
int cameraOffSetPixelY = (int) -cameraSystem.getOffsetY();
cameraOffSetPixelX = cameraOffSetPixelX - cameraOffSetPixelX
% Util.getInstance().getTileSize();
cameraOffSetPixelY = cameraOffSetPixelY - cameraOffSetPixelY
% Util.getInstance().getTileSize();
int cameraOffSetTileX = (cameraOffSetPixelX) / Util.getInstance().getTileSize();
int cameraOffSetTileY = (cameraOffSetPixelY) / Util.getInstance().getTileSize();
int visionX = ((this.container.getWidth() / Util.getInstance().getTileSize()) + 2)-9;
int visionY = ((this.container.getHeight() / Util.getInstance().getTileSize()) + 2)-6;
ManagerMap.getInstance().getTmap().render(cameraOffSetPixelX,
cameraOffSetPixelY, cameraOffSetTileX, cameraOffSetTileY,
visionX, visionY, EnumTiledLayer.HEAD_UP.getIndex(), true);
ManagerMap.getInstance().getTmap().render(cameraOffSetPixelX,
cameraOffSetPixelY, cameraOffSetTileX, cameraOffSetTileY,
visionX, visionY, EnumTiledLayer.HEAD_UP_2.getIndex(), true);
ManagerMap.getInstance().getTmap().render(cameraOffSetPixelX,
cameraOffSetPixelY, cameraOffSetTileX, cameraOffSetTileY,
visionX, visionY, EnumTiledLayer.SKY.getIndex(), true);
ManagerMap.getInstance().getTmap().render(cameraOffSetPixelX,
cameraOffSetPixelY, cameraOffSetTileX, cameraOffSetTileY,
visionX, visionY, EnumTiledLayer.SKY_2.getIndex(), true);
if (img !=null){
if (directionStartEffect == EnumPosition.FACE_LEFT.getIndex()) {
img.draw(0-value, 0, 2000, 2000);
} else if (directionStartEffect == EnumPosition.FACE_RIGHT.getIndex()) {
img.draw((0-FacadeFactory.getConfiguration().get(1, false).getGameFrameWidth())+value, 0, 2000, 2000);
} else if (directionStartEffect == EnumPosition.FACE_DOWN.getIndex()) {
img.draw(0, (0-FacadeFactory.getConfiguration().get(1, false).getGameFrameHeight())+value, 2000, 2000);
} else if (directionStartEffect == EnumPosition.FACE_UP.getIndex()) {
img.draw(0, (0-value), 2000, 2000);
}
}
if (ManagerMap.getInstance().getCurrentMap().isEnableDayNight()==true){
imgNight.draw(0,0,ManagerMap.getInstance().getCurrentMap().getMapWidthInPixel(), ManagerMap.getInstance().getCurrentMap().getMapHeightInPixel());
}
}
public void checkTurnDayNight(){
//Controla o dia e noite
turn.update(this.world.getDelta());
if (turn.isTimeComplete() == true) {
currentTurn++;
if (currentTurn == 1){ //0 minuto
imgNight.setAlpha(0.0f);
day = true;
} else if (currentTurn == 600){ //10minutos
imgNight.setAlpha(0.1f);
day = true;
} else if (currentTurn == 1200){ //20 minutos
imgNight.setAlpha(0.2f);
day = true;
} else if (currentTurn == 1800){ //30 minutos
imgNight.setAlpha(0.3f);
day = true;
} else if (currentTurn == 2400){ //40 minutos
imgNight.setAlpha(0.4f);
day = false;
} else if (currentTurn == 3000){ //50 minutos
imgNight.setAlpha(0.5f);
day = false;
} else if (currentTurn == 3600){ //60 minutos
imgNight.setAlpha(0.6f);
day = false;
} else if (currentTurn == 4200){ //80 minutos
imgNight.setAlpha(0.5f);
day = false;
} else if (currentTurn == 4800){ //90 minutos
imgNight.setAlpha(0.4f);
day = false;
} else if (currentTurn == 5400){ //100 minutos
imgNight.setAlpha(0.3f);
day = true;
} else if (currentTurn == 6000){ //110 minutos
imgNight.setAlpha(0.2f);
day = true;
} else if (currentTurn == 6600){ //120 minutos
imgNight.setAlpha(0.1f);
} else if (currentTurn == 7200){ //130 minutos
currentTurn=0;
}
turn.resetTime();
}
}
public void mapEffect(){
//Controla o clima do mapa
turnForMapEffect.update(this.world.getDelta());
if (turnForMapEffect.isTimeComplete() == true) {
value++;
if (img !=null){
if (directionStartEffect == EnumPosition.FACE_RIGHT.getIndex() ||
directionStartEffect == EnumPosition.FACE_LEFT.getIndex()) {
if (value == (FacadeFactory.getConfiguration().get(1, false).getGameFrameWidth()-50)){
value=0;
}
} else if (directionStartEffect == EnumPosition.FACE_UP.getIndex() ||
directionStartEffect == EnumPosition.FACE_DOWN.getIndex()){
if (value == (FacadeFactory.getConfiguration().get(1, false).getGameFrameHeight()-50)){
value=0;
}
}
}
turnForMapEffect.resetTime();
}
}
@Override
protected void begin() {
graphics.translate(cameraSystem.getOffsetX(), cameraSystem.getOffsetY());
super.begin();
}
@Override
protected void end() {
graphics.translate(-cameraSystem.getOffsetX(),
-cameraSystem.getOffsetY());
super.end();
}
}
R.D.
how to have a main method just to make this effect of rain?
Not working, I tested the codes above and nothing, even managed to appear fixed rectangles that were flashing on the screen, but nothing more.
What is the purpose of using a complex and heavily abstracted object-oriented entity system (Artemis) if the rest of your code is hacked together without any object-oriented thought at all? Of course it’s going to look “complex” if you have hundreds of if-else chains that all do things that really should be in their own classes in the first place… ???
Please tell me you didn’t just try to compile my pseudo code?
Sorry to say, but if you can’t get this working based on the code I posted, and can’t be bothered to explain to us what part of my suggestion doesn’t work / doesn’t make sense, maybe you are in over your head trying to program a game?
I tried to adapt your code, but it did not work has something in his logic that is not right.
As you said is a pseudo code, I tried to adapt, but what happened was that flash images on the screen images and not falling as it should be.
Ok, how about explaining the problem…
:cranky:
EDIT: Ok, after your edit…
[quote]As you said is a pseudo code, I tried to adapt, but what happened was that flash images on the screen images and not falling as it should be.
[/quote]
I don’t know how I can help you with this small amount of information. I’m not near a compiler but unless I’m missing the obvious, my code looks like it should at least get you something falling.
I’ll redo the problem and will post here after you’re done.
Get it to work thanks, I really did not understand (What’s doing things early in the morning), I rested a little and got the project again and it worked (of course adapted to my reality.) My only question is how do I get the rain on the diagonal?
For example when I put “graphics.rotate (0, 0, 30.0f),” it does not come out of the screen, but starts from the inside, almost in the middle of the screen.
private Timer spawnRain;
private ArrayList<RainDrops> rain;
public void initialize() {
spawnRain = new Timer(200);
rain = new ArrayList<RainDrops>();
spawnRain(5,10);
}
/**
* <b> This method shall be called the update method, passing the delta
* As parameter. </ B> <p>
*
* It performs two tasks:
* 1. Updates the timer when the timer is complete it recreates new objects (raindrops) by calling the {@ link # spawnRain (int, int) spawnRain (int, int)}.
* 2. Keep moving objects (Moving X pixes per second).
*
* @ Param delta
*/
public void updateRain(int delta){
//Checa se pode fazer o spawn das gostas de chuva
spawnRain.update(delta);
if (spawnRain.isTimeComplete() == true) {
//Cria de 5 a 10 gotas de chuva e depois reseta o timer
spawnRain(5,10);
spawnRain.resetTime();
}
//Move 96 pixel in 1 seg
float speed = Util.getInstance().calcSpeed(delta, 1000f, 96f);
//RainDrops que serão removidos
ArrayList<RainDrops> rainRemove = new ArrayList<RainDrops>();
//Atualiza a posição das entidade "chuva" movendo elas para baixo
for (RainDrops rainDrops : rain){
rainDrops.addY(speed);
//Se chegar ao fim da tela marca para remoção
if ( rainDrops.getY() > (Util.getInstance().getCameraOffsetXY().y + FacadeFactory.getConfiguration().get(1, false).getGameFrameHeight())){
rainRemove.add(rainDrops);
}
}
//Remove efetivamente as gotas de chuva que chegaram ao fim da tela
//Efetivamente parando de desenhar e atualizar seus movimentos (Pondo os RainDrops para o coletor de lixo)
rain.removeAll(rainRemove);
}
/**
* Draw the rain effectively
*/
private void renderRain(){
graphics.rotate(0, 0, 0f);
for (RainDrops rainDrops : rain) {
graphics.fillRect(rainDrops.getX(), rainDrops.getY(), 1, 2);
}
graphics.rotate(0, 0, -0f);
}
/**
* This method creates the near objects (raindrops) that will be created. <P>
*/
private void spawnRain(int min, int max){
RainDrops rainDrops = null;
int value = Util.getInstance().randomIntervalValue(min,max);
for (int x=0; x<value;x++){
rainDrops = new RainDrops();
rainDrops.setX(Util.getInstance().getCameraOffsetXY().x + (int) (Math.random() * FacadeFactory.getConfiguration().get(1, false).getGameFrameWidth()));
rainDrops.setY((float) Util.getInstance().getCameraOffsetXY().y);
rain.add(rainDrops);
}
}
Because you rotate on 0,0 not the center of screen. Better not using rotate which is expensive. Just use dx and dy simultaneously when updating the rain.
People really appreciate the help, I know that patience is complicated, but breaking that branch, ta almost ready.
Can someone post the full rain and raindrops code?