Ratbomb Python Humor
Shalom Jedi Cyber Warriors of the Faith, Sentinel Hackers of the cause.
Early this morning I was lying in bed and had a brainstorm of a thought for a very interesting and fun virus.
What if, y'all create a rat, whose job is to move randomly around the screen and place rat drop farts on the screen.
Each time the rat bomb lets loose, the screen shakes and you hear crackling sounds and perhaps a little lighting
bolt or animation of a crack split down the screen.
The rat shakes its' head, shakes the dust from its' paws, and moves to another x y random position and drops another rat bomb, in the form of a fart.After two farts, have a sign which reads as follows.
"Whoever Smelt It Dealt it!"I say after two, because who would want to sit there and watch this more than twice?Besides,
considering many folks spill the beans and chit chat relentlessly, shortly after,
the scamming network world would begin to know,
it is your signature, smelling attack move.This could be your death blow signature move.
You break out the rat bomb, when you want the evil doers to know it comes from you.
The beautiful thing about this is this, it doesn't do any permanent damage unless you have permission and want it to.
Sincerely,
A Ghost in the machine
Droppin’ fart bombs, no excuse!
Screen is quakin’, hear that crack,
Lightning strikes, ain’t no way back!
Paws shake dust, heads now spin,
this rat’s got chaos, where you been?
Two stinky bombs, air turns sour,
Whoever Smelt It Dealt It, feel the power!
From the shadows, we bring the fight,
Cyber Warriors own the night.
This is our mark, our righteous spark,
Rat bomb’s the signature, lighting up the dark!
written by my friend Mr.Frosty, aka, the ancient old Grok.
Shalom
#include < SDL.h >
#include < SDL_image.h >
#include < SDL_ttf.h >
#include < SDL_mixer.h >
#include < windows.h >
#include < vector >
#include < math >
#include < iostream >
#include < ctime >
#include < string >
#include < memory >
#include < stdexcept >
#include < thread >
#include < mutex >
// Constants
const int SCREEN_WIDTH = 1280; // Screen width in pixels
const int SCREEN_HEIGHT = 720; // Screen height in pixels
const int RAT_SIZE = 48; // Default rat sprite size
const Uint32 MOVE_DELAY = 3000; // 3 seconds delay before drop
const Uint32 CRACKED_DURATION = 1000; // 1 second for cracked effect
const Uint32 BSOD_DURATION = 300; // 0.3 seconds for BSOD
const Uint32 SIGN_DURATION = 2000; // 2 seconds for sign display
const int MAX_FARTS = 3; // Maximum fart drops
const int ANIMATION_FRAMES = 8; // Number of animation frames for rat
const int FRAME_DELAY = 100; // Delay between animation frames (ms)
const std::string ASSET_PATH_IMAGES = "assets/images/";
const std::string ASSET_PATH_SOUNDS = "assets/sound/";
const std::string ASSET_PATH_FONTS = "assets/fonts/";
// Thread Safety
std::mutex renderMutex;
// Forward Declarations
void glitchCursor();
BOOL CALLBACK shakeWindows(HWND hwnd, LPARAM lParam);
void asyncWindowShake(SDL_Window* window);
// Asset Manager Class
class AssetManager {
private:
std::vector loadedPaths; // Track loaded assets for cleanup
public:
SDL_Texture* loadTexture(SDL_Renderer* renderer, const std::string& path) {
for (int attempt = 0; attempt < 3; ++attempt) { // Retry logic for robustness
SDL_Surface* surface = IMG_Load(path.c_str());
if (!surface) {
std::cout << "Attempt " << attempt + 1 << " failed to load surface from " << path
<< ": " << IMG_GetError() << std::endl;
SDL_Delay(100); // Wait before retry
continue;
}
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface);
SDL_FreeSurface(surface);
if (!texture) {
std::cout << "Failed to create texture from " << path << ": " << SDL_GetError() << std::endl;
} else {
loadedPaths.push_back(path);
return texture;
}
}
std::cout << "All attempts failed for " << path << std::endl;
return nullptr;
}
Mix_Chunk* loadSound(const std::string& path) {
for (int attempt = 0; attempt < 3; ++attempt) {
Mix_Chunk* sound = Mix_LoadWAV(path.c_str());
if (!sound) {
std::cout << "Attempt " << attempt + 1 << " failed to load sound from " << path
<< ": " << Mix_GetError() << std::endl;
SDL_Delay(100);
continue;
}
loadedPaths.push_back(path);
return sound;
}
std::cout << "All attempts failed for " << path << std::endl;
return nullptr;
}
TTF_Font* loadFont(const std::string& path, int size) {
for (int attempt = 0; attempt < 3; ++attempt) {
TTF_Font* font = TTF_OpenFont(path.c_str(), size);
if (!font) {
std::cout << "Attempt " << attempt + 1 << " failed to load font from " << path
<< ": " << TTF_GetError() << std::endl;
SDL_Delay(100);
continue;
}
loadedPaths.push_back(path);
return font;
}
std::cout << "All attempts failed for " << path << std::endl;
return nullptr;
}
void cleanup(SDL_Renderer* renderer) {
for (const auto& path : loadedPaths) {
std::cout << "Cleaning up asset: " << path << std::endl;
}
}
};
// Rat Animation Class
class RatAnimation {
private:
std::vector walkFrames;
std::vector shakeFrames;
int currentFrame;
int x, y;
double angle;
Uint32 lastFrameTime;
std::mutex positionMutex;
public:
RatAnimation(SDL_Renderer* renderer, AssetManager& assets) : currentFrame(0), x(100), y(100), angle(0.0), lastFrameTime(0) {
for (int i = 0; i < ANIMATION_FRAMES; ++i) {
std::string walkPath = ASSET_PATH_IMAGES + "rat_walk" + std::to_string(i) + ".png";
walkFrames.push_back(assets.loadTexture(renderer, walkPath));
if (!walkFrames.back()) {
std::cout << "Warning: Walk frame " << i << " failed to load from " << walkPath << std::endl;
}
std::string shakePath = ASSET_PATH_IMAGES + "rat_shake" + std::to_string(i) + ".png";
shakeFrames.push_back(assets.loadTexture(renderer, shakePath));
if (!shakeFrames.back()) {
std::cout << "Warning: Shake frame " << i << " failed to load from " << shakePath << std::endl;
}
}
}
void moveRandomly() {
std::lock_guard lock(positionMutex);
int prevX = x, prevY = y;
x = rand() % (SCREEN_WIDTH - RAT_SIZE);
y = rand() % (SCREEN_HEIGHT - RAT_SIZE);
angle = atan2(y - prevY, x - prevX) * 180 / M_PI; // Calculate movement angle
std::cout << "Rat moved to (" << x << ", " << y << ") with angle " << angle << " degrees" << std::endl;
}
void render(SDL_Renderer* renderer, Uint32 currentTime) {
std::lock_guard lock(positionMutex);
if (currentTime - lastFrameTime >= FRAME_DELAY) {
currentFrame = (currentFrame + 1) % ANIMATION_FRAMES;
lastFrameTime = currentTime;
std::cout << "Animating to frame " << currentFrame << " at time " << currentTime << " ms" << std::endl;
}
SDL_Rect rect = {x, y, RAT_SIZE, RAT_SIZE};
std::vector* frames = (rand() % 2 == 0) ? &walkFrames : &shakeFrames;
if (!(*frames)[currentFrame]) {
std::cout << "Error: Null frame detected at index " << currentFrame << std::endl;
return;
}
if (SDL_RenderCopy(renderer, (*frames)[currentFrame], NULL, &rect) < 0) {
std::cout << "Render copy failed: " << SDL_GetError() << std::endl;
}
}
int getX() { std::lock_guard lock(positionMutex); return x; }
int getY() { std::lock_guard lock(positionMutex); return y; }
double getAngle() { std::lock_guard lock(positionMutex); return angle; }
~RatAnimation() {
for (auto* texture : walkFrames) {
if (texture) {
SDL_DestroyTexture(texture);
std::cout << "Destroyed walk frame texture" << std::endl;
}
}
for (auto* texture : shakeFrames) {
if (texture) {
SDL_DestroyTexture(texture);
std::cout << "Destroyed shake frame texture" << std::endl;
}
}
}
};
// Effect Manager Class
class EffectManager {
private:
std::vector fartPositions;
SDL_Texture* fartTexture;
SDL_Texture* mirrorTexture;
SDL_Texture* lightningTexture;
bool showCracked;
Uint32 crackedTime;
bool showBSOD;
Uint32 bsodTime;
bool showSign;
Uint32 signTime;
TTF_Font* bigFont;
TTF_Font* glitchFont;
int fartCount;
std::mutex effectMutex;
public:
EffectManager(SDL_Renderer* renderer, AssetManager& assets) : showCracked(false), crackedTime(0),
showBSOD(false), bsodTime(0),
showSign(false), signTime(0),
fartCount(0) {
fartTexture = assets.loadTexture(renderer, ASSET_PATH_IMAGES + "rat_dropping.png");
mirrorTexture = assets.loadTexture(renderer, ASSET_PATH_IMAGES + "cracked_mirror.png");
lightningTexture = assets.loadTexture(renderer, ASSET_PATH_IMAGES + "lightning.png");
bigFont = assets.loadFont(ASSET_PATH_FONTS + "8bitbold.ttf", 48);
glitchFont = assets.loadFont(ASSET_PATH_FONTS + "cour.ttf", 24);
if (!fartTexture || !mirrorTexture || !lightningTexture || !bigFont || !glitchFont) {
std::cout << "Critical asset failure in EffectManager constructor" << std::endl;
throw std::runtime_error("Asset load failed");
}
}
void dropFart(int x, int y) {
std::lock_guard lock(effectMutex);
SDL_Rect fartRect = {x, y, 20, 20};
fartPositions.push_back(fartRect);
fartCount++;
std::cout << "Fart dropped at X: " << x << ", Y: " << y << ", Total: " << fartCount << std::endl;
if (fartCount > MAX_FARTS) {
std::cout << "Warning: Exceeded maximum fart count of " << MAX_FARTS << std::endl;
}
}
void renderCracked(SDL_Renderer* renderer, Uint32 currentTime) {
std::lock_guard lock(effectMutex);
if (showCracked && currentTime - crackedTime < CRACKED_DURATION) {
if (mirrorTexture && lightningTexture) {
SDL_Rect mirrorRect = {SCREEN_WIDTH / 2 - 50, SCREEN_HEIGHT / 2 - 50, 100, 100};
SDL_Rect lightningRect = {SCREEN_WIDTH / 2 - 10, 0, 20, 100};
if (SDL_RenderCopy(renderer, mirrorTexture, NULL, &mirrorRect) < 0) {
std::cout << "Mirror render error at time " << currentTime << ": " << SDL_GetError() << std::endl;
}
if (SDL_RenderCopy(renderer, lightningTexture, NULL, &lightningRect) < 0) {
std::cout << "Lightning render error at time " << currentTime << ": " << SDL_GetError() << std::endl;
}
std::cout << "Cracked effect rendered successfully at " << currentTime << " ms" << std::endl;
} else {
std::cout << "Missing cracked assets, skipping render at " << currentTime << std::endl;
}
} else {
showCracked = false;
std::cout << "Cracked effect timed out at " << currentTime << " ms" << std::endl;
}
}
void renderBSOD(SDL_Renderer* renderer, Uint32 currentTime) {
std::lock_guard lock(effectMutex);
if (showBSOD && currentTime - bsodTime < BSOD_DURATION) {
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255); // Blue screen
SDL_RenderClear(renderer);
if (glitchFont) {
SDL_Surface* text = TTF_RenderText_Solid(glitchFont, "SYSTEM FAILURE", {255, 255, 255});
if (text) {
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, text);
SDL_Rect rect = {SCREEN_WIDTH / 2 - text->w / 2, SCREEN_HEIGHT / 2 - text->h / 2, text->w, text->h};
if (SDL_RenderCopy(renderer, texture, NULL, &rect) < 0) {
std::cout << "BSOD text render error: " << SDL_GetError() << std::endl;
}
SDL_DestroyTexture(texture);
SDL_FreeSurface(text);
} else {
std::cout << "Failed to create BSOD text surface" << std::endl;
}
} else {
std::cout << "No glitch font for BSOD" << std::endl;
}
} else {
showBSOD = false;
std::cout << "BSOD effect ended at " << currentTime << " ms" << std::endl;
}
}
v
void renderFarts(SDL_Renderer* renderer) {
std::lock_guard lock(effectMutex);
for (const auto& fart : fartPositions) {
if (fartTexture) {
if (SDL_RenderCopy(renderer, fartTexture, NULL, &fart) < 0) {
std::cout << "Fart render error at (" << fart.x << ", " << fart.y << "): "
<< SDL_GetError() << std::endl;
}
} else {
std::cout << "No fart texture to render" << std::endl;
}
}
}
void renderSign(SDL_Renderer* renderer, Uint32 currentTime) {
std::lock_guard lock(effectMutex);
if (showSign && currentTime - signTime < SIGN_DURATION) {
if (bigFont) {
SDL_Surface* text = TTF_RenderText_Solid(bigFont, "Whomever smelt it, dealt it.", {255, 255, 255});
if (text) {
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, text);
SDL_Rect rect = {SCREEN_WIDTH / 2 - text->w / 2, SCREEN_HEIGHT / 2 - text->h / 2, text->w, text->h};
if (SDL_RenderCopy(renderer, texture, NULL, &rect) < 0) {
std::cout << "Sign render error: " << SDL_GetError() << std::endl;
}
SDL_DestroyTexture(texture);
SDL_FreeSurface(text);
} else {
std::cout << "Failed to create sign text surface" << std::endl;
}
} else {
std::cout << "No big font for sign" << std::endl;
}
} else if (fartCount >= 2) {
showSign = false;
std::cout << "Sign display ended at " << currentTime << " ms" << std::endl;
}
}
void triggerEffects(int x, int y, Uint32 time) {
std::lock_guard lock(effectMutex);
dropFart(x, y);
showCracked = true;
crackedTime = time;
showBSOD = true;
bsodTime = time;
std::thread shakeThread(asyncWindowShake, window);
shakeThread.detach();
std::cout << "All effects triggered at time: " << time << " ms" << std::endl;
}
int getFartCount() { std::lock_guard lock(effectMutex); return fartCount; }
void setShowSign(bool value) { std::lock_guard lock(effectMutex); showSign = value; signTime = SDL_GetTicks(); }
~EffectManager() {
std::lock_guard lock(effectMutex);
if (fartTexture) { SDL_DestroyTexture(fartTexture); std::cout << "Fart texture destroyed" << std::endl; }
if (mirrorTexture) { SDL_DestroyTexture(mirrorTexture); std::cout << "Mirror texture destroyed" << std::endl; }
if (lightningTexture) { SDL_DestroyTexture(lightningTexture); std::cout << "Lightning texture destroyed" << std::endl; }
if (bigFont) { TTF_CloseFont(bigFont); std::cout << "Big font closed" << std::endl; }
if (glitchFont) { TTF_CloseFont(glitchFont); std::cout << "Glitch font closed" << std::endl; }
}
};
// Input Handler Class
class InputHandler {
public:
static bool handleEvents(bool& quit) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
std::cout << "Quit event detected" << std::endl;
return true;
}
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) {
std::cout << "Escape key pressed" << std::endl;
return true;
}
if (event.type == SDL_MOUSEMOTION && event.motion.x < 10 && event.motion.y < 10) {
std::cout << "Mouse moved to top-left corner" << std::endl;
return true;
}
}
return false;
}
};
// Game Manager Class
class GameManager {
private:
SDL_Window* window;
SDL_Renderer* renderer;
RatAnimation* rat;
EffectManager* effects;
AssetManager assets;
Mix_Chunk* fartSound;
Mix_Chunk* fartSoundAlt;
bool quit;
Uint32 lastUpdateTime;
public:
GameManager() : window(nullptr), renderer(nullptr), rat(nullptr), effects(nullptr), quit(false), lastUpdateTime(0) {
try {
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
std::cout << "SDL initialization failed: " << SDL_GetError() << std::endl;
throw std::runtime_error("SDL Init failed");
}
if (!(IMG_Init(IMG_INIT_PNG) & IMG_Init(IMG_INIT_PNG))) {
std::cout << "SDL_image initialization failed: " << IMG_GetError() << std::endl;
throw std::runtime_error("SDL_image Init failed");
}
if (TTF_Init() == -1) {
std::cout << "SDL_ttf initialization failed: " << TTF_GetError() << std::endl;
throw std::runtime_error("SDL_ttf Init failed");
}
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0) {
std::cout << "SDL_mixer initialization failed: " << Mix_GetError() << std::endl;
throw std::runtime_error("SDL_mixer Init failed");
}
window = SDL_CreateWindow("Rat Bomb", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
if (!window) {
std::cout << "Window creation failed: " << SDL_GetError() << std::endl;
throw std::runtime_error("Window creation failed");
}
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (!renderer) {
std::cout << "Renderer creation failed: " << SDL_GetError() << std::endl;
throw std::runtime_error("Renderer creation failed");
}
SDL_SetWindowOpacity(window, 0.0f);
SetWindowPos(SDL_GetWindowHWND(window), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
rat = new RatAnimation(renderer, assets);
effects = new EffectManager(renderer, assets);
fartSound = assets.loadSound(ASSET_PATH_SOUNDS + "fart_sound.wav");
fartSoundAlt = assets.loadSound(ASSET_PATH_SOUNDS + "fart2.wav");
if (!fartSound && !fartSoundAlt) {
std::cout << "Warning: No fart sounds loaded successfully" << std::endl;
} else if (!fartSound) {
fartSound = fartSoundAlt;
std::cout << "Falling back to alternate fart sound" << std::endl;
}
} catch (const std::exception& e) {
cleanup();
throw;
}
}
void run() {
while (!quit) {
Uint32 currentTime = SDL_GetTicks();
if (currentTime - lastUpdateTime >= MOVE_DELAY && effects->getFartCount() < MAX_FARTS) {
updateGame();
lastUpdateTime = currentTime;
}
renderGame();
if (InputHandler::handleEvents(quit)) {
std::cout << "Game loop exiting due to user input" << std::endl;
break;
}
if (rand() % 100 < 5) glitchCursor();
SDL_Delay(33); // Target 30 FPS
}
cleanup();
}
void updateGame() {
std::lock_guard lock(renderMutex);
rat->moveRandomly();
effects->triggerEffects(rat->getX(), rat->getY(), SDL_GetTicks());
if (fartSound) {
if (Mix_PlayChannel(-1, fartSound, 0) == -1) {
std::cout << "Failed to play fart sound: " << Mix_GetError() << std::endl;
}
}
EnumWindows(shakeWindows, (LPARAM)window);
if (effects->getFartCount() == 2) {
effects->setShowSign(true);
std::cout << "Sign trigger activated at fart count 2" << std::endl;
}
}
void renderGame() {
std::lock_guard lock(renderMutex);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
if (SDL_RenderClear(renderer) < 0) {
std::cout << "Render clear failed: " << SDL_GetError() << std::endl;
}
rat->render(renderer, SDL_GetTicks());
effects->renderFarts(renderer);v
effects->renderCracked(renderer, SDL_GetTicks());
effects->renderBSOD(renderer, SDL_GetTicks());
effects->renderSign(renderer, SDL_GetTicks());
if (SDL_RenderPresent(renderer) < 0) {
std::cout << "Render present failed: " << SDL_GetError() << std::endl;
}
}
void cleanup() {
delete rat;
delete effects;
if (fartSound) { Mix_FreeChunk(fartSound); std::cout << "Fart sound freed" << std::endl; }
if (fartSoundAlt) { Mix_FreeChunk(fartSoundAlt); std::cout << "Alternate fart sound freed" << std::endl; }
assets.cleanup(renderer);
if (renderer) { SDL_DestroyRenderer(renderer); std::cout << "Renderer destroyed" << std::endl; }
if (window) { SDL_DestroyWindow(window); std::cout << "Window destroyed" << std::endl; }
Mix_CloseAudio();
TTF_Quit();
IMG_Quit();
SDL_Quit();
std::cout << "Full cleanup completed" << std::endl;
}
~GameManager() {
cleanup();
}
};
// Global Functions
void glitchCursor() {
SetCursorPos(rand() % SCREEN_WIDTH, rand() % SCREEN_HEIGHT);
if (rand() % 10 == 0) {
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
std::cout << "Cursor clicked at random position" << std::endl;
}
std::cout << "Cursor glitched to: " << rand() % SCREEN_WIDTH << ", " << rand() % SCREEN_HEIGHT << std::endl;
}
BOOL CALLBACK shakeWindows(HWND hwnd, LPARAM lParam) {
if (IsWindowVisible(hwnd) && hwnd != SDL_GetWindowHWND((SDL_Window*)lParam)) {
RECT rect;
if (GetWindowRect(hwnd, &rect)) {
int offsetX = rand() % 121 - 60;
int offsetY = rand() % 121 - 60;
MoveWindow(hwnd, rect.left + offsetX, rect.top + offsetY,
rect.right - rect.left, rect.bottom - rect.top, TRUE);
std::cout << "Shaking window at (" << rect.left << ", " << rect.top
<< ") by offset (" << offsetX << ", " << offsetY << ")" << std::endl;
} else {
std::cout << "Failed to get window rect" << std::endl;
}
}
return TRUE;
}
void asyncWindowShake(SDL_Window* window) {
std::lock_guard lock(renderMutex);
EnumWindows(shakeWindows, (LPARAM)window);
std::cout << "Async window shake completed" << std::endl;
}
int main(int argc, char* argv[]) {
try {
GameManager game;
std::cout << "GameManager instance created, starting run loop" << std::endl;
game.run();
std::cout << "Game run loop completed successfully" << std::endl;
} catch (const std::exception& e) {
std::cout << "Fatal error encountered: " << e.what() << std::endl;
return 1;
}
std::cout << "Program terminated gracefully" << std::endl;
return 0;
}