vashicool777
Creating an event!
- 17
- Posts
- 9
- Years
- He, Him
- Alamogordo, NM
- Seen Apr 21, 2025
So I spent quite a while writing this code for the pokeemerald decomp. I never got to fully finish it because I just don't have the time anymore. If anyone wants to use this code and implement it into there game and or modify it, then be my guest.
I have added deferent states for the time, different weather, seasons, the games own time system which allows for 1 hour in game time to equal about 20 minutes give or take. You are asked when played a new game to choose which seasons your in and what day of the seasons. I made each season (Spring, Summer, Autumn, and winter) 30 in game days long. Each season also has some implemented weather for each type. Also depending on storm strength it makes your character movement speed slower. I coded as much as I knew how to, to make it as dynamic as I possibly could at this current time.
I have added deferent states for the time, different weather, seasons, the games own time system which allows for 1 hour in game time to equal about 20 minutes give or take. You are asked when played a new game to choose which seasons your in and what day of the seasons. I made each season (Spring, Summer, Autumn, and winter) 30 in game days long. Each season also has some implemented weather for each type. Also depending on storm strength it makes your character movement speed slower. I coded as much as I knew how to, to make it as dynamic as I possibly could at this current time.
Spoiler:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <unistd.h> // Included for usleep
// Weather conditions
enum Weather {
CLEAR,
RAIN_LIGHT,
RAIN_HEAVY,
THUNDERSTORM,
SNOW_LIGHT,
SNOW_HEAVY,
BLIZZARD,
SUNNY,
NUM_WEATHER_TYPES
};
// Seasons
enum Season {
SPRING,
SUMMER,
AUTUMN,
WINTER,
NUM_SEASONS
};
// Day and night states
enum DayNight {
DAY,
NIGHT,
NUM_DAYNIGHT_STATES
};
// Function to change the seasons dynamically
void changeSeason(int* currentSeason, int* daysInSeason) {
// Check if the season has lasted for 30 days
if (*daysInSeason >= 20) {
*currentSeason = (*currentSeason + 1) % NUM_SEASONS // Switch to the next season
*daysInSeason = 0; // Reset the days counter
} else {
*daysInSeason += 1; // Increment the days counter
}
}
// Function to change the weather based on the current season
void changeWeather(int* currentWeather, int currentSeason) {
// Implement logic to determine weather based on season
// Adjust probabilities and strengths for different seasons
switch (currentSeason) {
case SPRING:
// Weather rules for spring
*currentWeather = (rand() % 10 == 0) ? THUNDERSTORM : (rand() % 3) + 1; // 10% change of thunderstorm
break;
case SUMMER:
// Weather rules for summer
*currentWeather = (rand() % 5 == 0) ? THUNDERSTORM : (rand() % 3) + 1; // 20% chance of thunderstorm
break;
case AUTUMN:
// Weather rules for autumn
if (*daysInSeason >= 25) {
*currentSeason = SNOW_LIGHT; // Snow at the end of autumn
} else {
*currentWeather = (rand() % 3) + 1; // No snow during most of autumn
}
break;
case WINTER:
// Weather rules for winter
if (*daysInSeason >= 25) {
*currentWeather = (rand() % 3 == 0) ? BLIZZARD : (rand() % 2) + 4; // 1 in 3 chance of blizzard
} else {
*currentWeather = (rand() % 3) + 4; // Random snow conditions
}
break;
default:
// Default rules for unknown seasons
*currentWeather = CLEAR;
break;
}
}
// Function to update the game's graphics and effects based on weather, seasons, and time of day
void updatedGraphics(int currentWeather, int currentSeason, int dayNightState) {
// Update graphics and animations based on the current weather, season and the time of day
switch (currentWeather) {
case CLEAR:
printf("The weather is clear.\n");
break;
case RAIN_LIGHT:
printf("It's raining lightly.\n");
break;
case RAIN_HEAVY:
printf("It's raining heavily.\n");
break;
case THUNDERSTORM:
printf("There's a thunderstorm!\n");
break;
case SNOW_LIGHT:
printf("It's snowing lightly.\n");
break;
case SNOW_HEAVY:
printf("It's snowing heavily.\n");
break;
case BLIZZARD:
printf("There's a blizzard!\n");
break;
case SUNNY:
printf("It's sunny outside.\n");
break;
default:
printf("Unknown weather condition.\n");
}
// Simulate seasonal changes in graphics (e.g., differerent backgrounds, character outfits).
switch (currentSeason) {
case SPRING:
printf("Spring-themed graphics and animations.\n");
break;
case SUMMER:
printf("Summer-themed graphics and animations.\n");
break;
case AUTUMN:
printf("Autumn-themed graphics and animations.\n");
break;
case WINTER:
printf("Winter-themed graphics and animations.\n");
break;
default:
printf("Unknown season.\n");
break;
}
// Determine the time of day (AM or PM) and update graphics accordingly
switch (dayNightState) {
case DAY:
printf("It's daytime.\n");
// Update graphics for daytime
break;
case NIGHT:
printf("It's nighttime.\n");
// Update graphics for nighttime
break;
default:
// Handle unknown time of day
break;
}
}
int main() {
int currentWeather = CLEAR;
int currentSeason = SPRING;
int startingSeason, startingDay;
int daysInSeason = 0; // Counter for tracking days in the current season
int inGameHour = 0;
int inGameMinute = 0;
time_t realTime = time(NULL); // Get the current real-time
int dayNightState = DAY; // Initially set to day
int timeChanged = 0; // Flag to track if time has been changed
double movementSpeedModifier = 1.0; // Initial movement speed modifier (no effect)
srand(time(NULL)); // Initialize random number generator
// ... (Add any other necessary variable declarations and game setup code)
// Game loop
while (1) {
// Check for triggers or events that should change the season, weather, or time of day
// (e.g., time of day transition)
// Update the in-game time
realTime = time(NULL); // Get the current real-time
inGameMinute = (realTime % (60 * 12)) / 20; // Convert real-time to in-game minutes
inGameHour = inGameMinute / 60;
// Simulate a trigger (change the season every 30 in-game minutes for demonstration)
if (inGameMinute % 30 == 0) {
changeSeason(¤tSeason, &daysInSeason);
}
// Simulate a trigger (change time of day every 60 in-game minutes for demonstration)
if (inGameMinute % 60 == 0) {
dayNightState = (dayNightState + 1) % NUM_DAYNIGHT_STATES;
}
// Update the weather based on the current season
changeWeather(¤tWeather, currentSeason);
// Update the game's graphics and effects
updateGraphics(currentWeather, currentSeason, dayNightState);
// Determine the time of day (AM or PM) and update graphics accordingly
char timeOfDay[3];
if (inGameHour < 12) {
strcpy(timeOfDay, "AM");
} else {
strcpy(timeOfDay, "PM");
}
// Apply movement speed modifier based on weather
switch (currentWeather) {
case RAIN_LIGHT:
movementSpeedModifier = 0.8; // Reduce movement speed by 20% in light rain
break;
case RAIN_HEAVY:
movementSpeedModifier = 0.6; // Reduce movement speed by 40% in heavy rain
break;
case SNOW_LIGHT:
movementSpeedModifier = 0.7; // Reduce movement speed by 30% in light snow
break;
case SNOW_HEAVY:
movementSpeedModifier = 0.5; // Reduce movement speed by 50% in heavy snow
break;
case BLIZZARD:
movementSpeedModifier = 0.4; // Reduce movement speed by 60% in a blizzard
break;
default:
movementSpeedModifier = 1.0; // No weather effect on movement speed
break;
}
// Print the current season, weather, in-game time, and starting choices (for demonstration)
printf("\nStarting season: %d, Starting day: %d\n", startingSeason, startingDay);
printf("Current season: %d, Days in season: %d\n", currentSeason + 1, daysInSeason + 1);
printf("In-game time: %02d:%02d %s\n", (inGameHour % 12) == 0 ? 12 : (inGameHour % 12), inGameMinute % 60, timeOfDay);
// Allow the player to change the in-game time in the character's room (only once)
if (inGameHour >= 8 && inGameHour <= 20 && !timeChanged) {
int choice;
printf("\nYou are in your room. What would you like to do?\n");
printf("1. Check the clock.\n");
printf("2. Change the time.\n");
printf("3. Continue your adventure.\n");
scanf("%d", &choice);
switch (choice) {
case 1:
// Display the current time on the clock in the room
printf("The clock shows the time: %02d:%02d %s\n", (inGameHour % 12) == 0 ? 12 : (inGameHour % 12), inGameMinute % 60, timeOfDay);
break;
case 2:
// Allow the player to set the in-game time
int newHour, newMinute;
printf("Enter the new hour (0-23): ");
scanf("%d", &newHour);
printf("Enter the new minute (0-59): ");
scanf("%d", &newMinute);
// Validate the entered time
if (newHour >= 0 && newHour <= 23 && newMinute >= 0 && newMinute <= 59) {
inGameHour = newHour;
inGameMinute = newMinute;
printf("You set the in-game time to %02d:%02d %s.\n", (inGameHour % 12) == 0 ? 12 : (inGameHour % 12), inGameMinute % 60, timeOfDay);
timeChanged = 1; // Mark that the time has been changed
} else {
printf("Invalid time. Please enter a valid time.\n");
}
break;
case 3:
// Continue the adventure
break;
default:
printf("Invalid choice.\n");
break;
}
}
// Apply movement speed modifier based on weather
double adjustedMovementSpeed = movementSpeedModifier * baseMovementSpeed;
// Update character movement based on adjusted movement speed
updateCharacterMovement(adjustedMovementSpeed);
// Other game logic and rendering here
// Simulate the game running at a normal speed (e.g., 60 frames per second)
usleep(1000000 / 60); // Sleep for 1/60th of a second (microseconds)
}
return 0;
}