Added potion saving and stuff. forgot about that

This commit is contained in:
ElijahZAwesome 2018-01-26 07:23:27 -06:00
parent 6370ea9014
commit a20f960f35
11 changed files with 72 additions and 29 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 37 KiB

5
run in Citra.bat Normal file
View file

@ -0,0 +1,5 @@
@echo off
echo Building 3DSX/ELF/SMDH...
make
echo Running in citra
C:/Users/computer/AppData/Local/Citra/canary-mingw/citra-qt.exe result/Minicraft3DS.3dsx

View file

@ -152,11 +152,12 @@ void initRecipes(){
enchanterRecipes.recipes[6] = defineRecipe(ITEM_WALL_GEM,1,1,ITEM_GEM,10);
enchanterRecipes.recipes[7] = defineRecipe(ITEM_GOLD_APPLE,1,2,ITEM_APPLE,1,ITEM_GOLDINGOT,15);
potionMakerRecipes.size = 3;
potionMakerRecipes.size = 4;
potionMakerRecipes.recipes = (Recipe*)malloc(sizeof(Recipe) * (potionMakerRecipes.size));
potionMakerRecipes.recipes[0] = defineRecipe(ITEM_STRENGTH_POTION,1,3,ITEM_GOLD_APPLE,1,ITEM_GLASS,10,ITEM_IRONINGOT,10);
potionMakerRecipes.recipes[1] = defineRecipe(ITEM_SPEED_POTION,1,4,ITEM_GEM,2,ITEM_GLASS,10,ITEM_IRONINGOT,10, ITEM_GOLDINGOT,15);
potionMakerRecipes.recipes[2] = defineRecipe(ITEM_REGEN_POTION,1,3,ITEM_GOLD_APPLE,2,ITEM_GLASS,10,ITEM_GEM,10);
potionMakerRecipes.recipes[3] = defineRecipe(ITEM_SWIM_BREATH_POTION,1,4,ITEM_GOLD_APPLE,2,ITEM_GLASS,10,ITEM_GEM,10, ITEM_STRING,15);
}
/* Free up allocated memory */

View file

@ -47,6 +47,7 @@ typedef struct {
int swimTimer;
int regenTimer;
int strengthTimer;
int swimBreathTimer;
int speedTimer;
int score;
Inventory* inv;

View file

@ -4,9 +4,6 @@
char versionText[34] = "Version 1.4.1";
char fpsstr[34];
u8 currentMenu = 0;
bool UnderStrengthEffect = false;
bool UnderSpeedEffect = false;
bool regening = false;
void addItemsToWorld(Item item,int x, int y, int count){
int i;
@ -222,12 +219,6 @@ void tickTouchQuickSelect() {
void hurtEntity(Entity* e, int damage, int dir, u32 hurtColor){
if (shouldRenderDebug && e->type==ENTITY_PLAYER) return;
if(UnderStrengthEffect && player.p.strengthTimer <2000) {
damage = damage + 5;
} else if (player.p.strengthTimer >= 2000) {
UnderStrengthEffect = false;
player.p.strengthTimer = 0;
}
if (e->hurtTime > 0) return;
int xd = player.x - e->x;
int yd = player.y - e->y;
@ -690,14 +681,19 @@ void healPlayer(int amount){
addEntityToList(newTextParticleEntity(healText,0xFF00FF00,player.x,player.y,currentLevel), &eManager);
}
void strengthPotionEffect() {
UnderStrengthEffect = true;
}
void speedPotionEffect() {
UnderSpeedEffect = true;
}
void regenPotionEffect() {
regening = true;
void potionEffect(int type) {
if(type == 1) {
UnderStrengthEffect = true;
}
if(type == 2) {
UnderSpeedEffect = true;
}
if (type == 3) {
regening = true;
}
if (type == 4) {
UnderSwimBreathEffect = true;
}
}
s8 itemTileInteract(int tile, Item* item, int x, int y, int px, int py, int dir){
@ -723,19 +719,25 @@ s8 itemTileInteract(int tile, Item* item, int x, int y, int px, int py, int dir)
return 0;
case ITEM_STRENGTH_POTION:
if(player.p.health < 20 && playerUseEnergy(2) && player.p.strengthTimer == 0){
strengthPotionEffect();
potionEffect(1);
--item->countLevel;
}
return 0;
case ITEM_SPEED_POTION:
if(player.p.health < 20 && playerUseEnergy(2) && player.p.strengthTimer == 0){
speedPotionEffect();
potionEffect(2);
--item->countLevel;
}
return 0;
case ITEM_REGEN_POTION:
if(player.p.health < 20 && playerUseEnergy(2) && player.p.strengthTimer == 0){
regenPotionEffect();
potionEffect(3);
--item->countLevel;
}
return 0;
case ITEM_SWIM_BREATH_POTION:
if(player.p.health < 20 && playerUseEnergy(2) && player.p.strengthTimer == 0){
potionEffect(4);
--item->countLevel;
}
return 0;
@ -1674,6 +1676,10 @@ void spawnPlayer(){
}
void initPlayer(){
UnderStrengthEffect = false;
UnderSpeedEffect = false;
regening = false;
UnderSwimBreathEffect = false;
player.type = ENTITY_PLAYER;
spawnPlayer();
player.xr = 4;
@ -1703,6 +1709,7 @@ void initPlayer(){
addItemToInventory(newItem(ITEM_STRENGTH_POTION,1), player.p.inv);
addItemToInventory(newItem(ITEM_SPEED_POTION,1), player.p.inv);
addItemToInventory(newItem(ITEM_REGEN_POTION,1), player.p.inv);
addItemToInventory(newItem(ITEM_SWIM_BREATH_POTION,1), player.p.inv);
addItemToInventory(newItem(TOOL_SHOVEL,4), player.p.inv);
addItemToInventory(newItem(TOOL_HOE,4), player.p.inv);
addItemToInventory(newItem(TOOL_SWORD,4), player.p.inv);
@ -1725,12 +1732,6 @@ void initPlayer(){
void playerHurtTile(int tile, int xt, int yt, int damage, int dir){
if(shouldRenderDebug) damage = 99;
if(UnderStrengthEffect && player.p.strengthTimer <2000) {
damage = damage + 8;
} else if (player.p.strengthTimer >= 2000) {
UnderStrengthEffect = false;
player.p.strengthTimer = 0;
}
char hurtText[11];
switch(tile){
@ -1981,7 +1982,11 @@ void playerAttack(){
if (player.p.dir == 3) xt = (player.x + r) >> 4;
if (xt >= 0 && yt >= 0 && xt < 128 && 128) {
if(UnderStrengthEffect && player.p.strengthTimer <2000) {
playerHurtTile(getTile(xt,yt), xt, yt, (rand()%3 + 5) + 1, player.p.dir);
} else {
playerHurtTile(getTile(xt,yt), xt, yt, (rand()%3) + 1, player.p.dir);
}
}
}
}
@ -2251,7 +2256,7 @@ void tickPlayer(){
if (player.p.staminaRechargeDelay % 2 == 0) moveMob(&player, player.p.ax, player.p.ay);
if (swimming && player.p.swimTimer % 60 == 0) {
if (swimming && player.p.swimTimer % 60 == 0 && !UnderSwimBreathEffect) {
if (player.p.stamina > 0) {
if(!shouldRenderDebug) --player.p.stamina;
} else {
@ -2298,6 +2303,11 @@ void tickPlayer(){
player.p.regenTimer = 0;
regening = false;
}
if(UnderSwimBreathEffect) ++player.p.swimBreathTimer;
if(player.p.swimBreathTimer >= 2000) {
player.p.swimBreathTimer = 0;
UnderSwimBreathEffect = false;
}
if(player.p.attackTimer > 0) {
--player.p.attackTimer;
}

View file

@ -91,6 +91,10 @@ Entity player;
bool shouldRenderDebug;
bool shouldSpeedup;
bool shouldRenderMap;
bool UnderStrengthEffect;
bool UnderSpeedEffect;
bool regening;
bool UnderSwimBreathEffect;
u8 zoomLevel;
char mapText[32];
s16 mScrollX, mScrollY;

View file

@ -155,6 +155,7 @@ char* getItemName(int itemID, int countLevel){
case ITEM_STRENGTH_POTION: sprintf(currentName,"%d Strength Potion", countLevel); return currentName;
case ITEM_SPEED_POTION: sprintf(currentName,"%d Speed Potion", countLevel); return currentName;
case ITEM_REGEN_POTION: sprintf(currentName,"%d Regen Potion", countLevel); return currentName;
case ITEM_SWIM_BREATH_POTION: sprintf(currentName,"%d Swim Potion", countLevel); return currentName;
case ITEM_COAL: sprintf(currentName,"%d Coal", countLevel); return currentName;
case ITEM_IRONORE: sprintf(currentName,"%d Iron ore", countLevel); return currentName;
case ITEM_GOLDORE: sprintf(currentName,"%d Gold ore", countLevel); return currentName;
@ -306,6 +307,7 @@ char* getBasicItemName(int itemID, int countLevel){
case ITEM_STRENGTH_POTION: return "Strength Potion";
case ITEM_SPEED_POTION: return "Speed Potion";
case ITEM_REGEN_POTION: return "Regen Potion";
case ITEM_SWIM_BREATH_POTION: return "Water Potion";
case TOOL_BUCKET:
switch(countLevel){
case 1: return "Water Bucket";

View file

@ -76,6 +76,7 @@
#define ITEM_STRENGTH_POTION 77
#define ITEM_SPEED_POTION 78
#define ITEM_REGEN_POTION 79
#define ITEM_SWIM_BREATH_POTION 80
#define TOOL_BUCKET 101
#define TOOL_BOW 102

View file

@ -1502,6 +1502,9 @@ void renderItemIcon(int itemID, int countLevel, int x, int y) {
case ITEM_REGEN_POTION:
render(x, y, 198, 160, 0);
break;
case ITEM_SWIM_BREATH_POTION:
render(x, y, 219, 160, 0);
break;
case ITEM_SLIME:
renderb(x, y, 88, 152, 0, 0xFF4DC04D);
break;

View file

@ -37,6 +37,14 @@ void saveCurrentWorld(char * filename, EntityManager * eManager, Entity * player
// Player Data
fwrite(&player->p.score, sizeof(int), 1, file);
fwrite(&player->p.hasWonSaved, sizeof(bool), 1, file);
fwrite(&UnderStrengthEffect, sizeof(bool), 1, file);
fwrite(&UnderSpeedEffect, sizeof(bool), 1, file);
fwrite(&regening, sizeof(bool), 1, file);
fwrite(&UnderSwimBreathEffect, sizeof(bool), 1, file);
fwrite(&player->p.strengthTimer, sizeof(int), 1, file);
fwrite(&player->p.speedTimer, sizeof(int), 1, file);
fwrite(&player->p.swimBreathTimer, sizeof(int), 1, file);
fwrite(&player->p.regenTimer, sizeof(int), 1, file);
fwrite(&player->p.health, sizeof(s16), 1, file);
fwrite(&player->x, sizeof(s16), 1, file);
fwrite(&player->y, sizeof(s16), 1, file);
@ -143,6 +151,14 @@ int loadWorld(char * filename, EntityManager * eManager, Entity * player, u8 * m
fread(&player->p.score, sizeof(int), 1, file);
fread(&player->p.hasWonSaved, sizeof(bool), 1, file);
fread(&UnderStrengthEffect, sizeof(bool), 1, file);
fread(&UnderSpeedEffect, sizeof(bool), 1, file);
fread(&regening, sizeof(bool), 1, file);
fread(&UnderSwimBreathEffect, sizeof(bool), 1, file);
fread(&player->p.strengthTimer, sizeof(int), 1, file);
fread(&player->p.speedTimer, sizeof(int), 1, file);
fread(&player->p.swimBreathTimer, sizeof(int), 1, file);
fread(&player->p.regenTimer, sizeof(int), 1, file);
fread(&player->p.health, sizeof(s16), 1, file);
fread(&player->x, sizeof(s16), 1, file);
fread(&player->y, sizeof(s16), 1, file);

View file

@ -322,7 +322,7 @@ int main() {
offsetY = 0;
if(shouldRenderDebug){
sprintf(fpsstr, "FPS: %.0f X:%d Y:%d E:%d %d", sf2d_get_fps(), player.x, player.y, eManager.lastSlot[currentLevel], player.p.speedTimer);
sprintf(fpsstr, "FPS: %.0f X:%d Y:%d E:%d %d", sf2d_get_fps(), player.x, player.y, eManager.lastSlot[currentLevel], player.p.swimBreathTimer);
drawText(fpsstr, 2, 225);
}