// Weather.cpp : Weather class // // 26.11.1998 / DH - Genesis // 30.11.1998 / DH - RainyWeather: collision detection against center tiles // // Copyright (c) 1998 Daniel Hartmeier. All rights reserved. #include "Weather.hpp" #include // ------------------------------------------------------------------- #define SPRITE_RAINDROP_1 144, 48 #define SPRITE_RAINDROP_2 144, 50 #define SPRITE_RAINDROP_3 144, 52 #define SPRITE_RAINDROP_4 144, 54 // ------------------------------------------------------------------- inline int abs(int i) { return (i < 0 ? -i : i); } // ------------------------------------------------------------------- void SunnyWeather::act(unsigned long pad) { //step++; if (step > 64) step = 0; //backgroundColor_b = 128+step; return; } void SunnyWeather::draw(GsOT *ot) { return; } // ------------------------------------------------------------------- RainyWeather::RainyWeather(Image *image, Level &level) : Weather(), image(image), level(level), intensity(0), count(0), wind(0) { backgroundColor_r = 16; backgroundColor_g = 16; backgroundColor_b = 40; baseIntensity = 32; } void RainyWeather::act(unsigned long pad) { wind += (rand()%129)-64; const int windmax = 1750; if (wind < -windmax) wind = -windmax; else if (wind > windmax) wind = windmax; intensity += (rand()%3)-1; if (intensity < 1) intensity = 1; else if (intensity > 100) intensity = 100; Raindrop *raindrop = raindrops.First(); while (raindrop) { if (raindrop->isGone()) { delete raindrop; raindrop = raindrops.Remove(); count--; } else { if (!raindrop->isSplash()) { raindrop->act(pad); int cx, cy; unsigned char attr; level.checkCollision(raindrop->x(), raindrop->y(), cx, cy, attr); if (attr & 1) { raindrop->move(raindrop->x(), cy-9); raindrop->setSplash(true); } else { if (raindrop->x() < 0) raindrop->move(320+raindrop->x(), raindrop->y()); else if (raindrop->x() >= 320) raindrop->move(raindrop->x()-320, raindrop->y()); if (raindrop->y() < 0) raindrop->move(raindrop->x(), 256+raindrop->y()); else if (raindrop->y() >= 256) raindrop->move(raindrop->x(), raindrop->y()-256); //raindrop->setSpeedX((raindrop->speedX()+3*wind)/4); // Snow } } raindrop = raindrops.Next(); } } while (count < intensity) { Raindrop *raindrop = new Raindrop(image); raindrop->move(rand()%320, 0); raindrop->setSpeedX(wind); //raindrop->setSpeedY(1800+(rand()%513)-256-abs(wind)); // Snow raindrop->setSpeedY(2400+(rand()%257)-128); raindrops.Append(raindrop); count++; } return; } void RainyWeather::draw(GsOT *ot) { for (Raindrop *raindrop = raindrops.First(); raindrop; raindrop = raindrops.Next()) raindrop->draw(ot); return; } void RainyWeather::scroll(int x, int y) { for (Raindrop *raindrop = raindrops.First(); raindrop; raindrop = raindrops.Next()) raindrop->move(raindrop->x()+x, raindrop->y()+y); return; } // ------------------------------------------------------------------- Raindrop::Raindrop(Image *image) : ActiveSprite(image, 4, 2), splash(false), gone(false), step(0) { } void Raindrop::draw(GsOT *ot) { if (splash) { step++; if (step > 6) gone = true; else if (step > 4) change(SPRITE_RAINDROP_4); else if (step > 2) change(SPRITE_RAINDROP_3); else change(SPRITE_RAINDROP_2); } else change(SPRITE_RAINDROP_1); if (!gone) ActiveSprite::draw(ot); return; } // -------------------------------------------------------------------