So I added snowflakes and fixed a lot of bugs except for a few.
As you can see I have problems with snow when I increase blizzard. Also for some reason, the snowflakes move faster in the y direction.
Here's my code if you have any suggestions.
draw.c
Code: /* Keep these headers */
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <tice.h>
/* Standard headers - it's recommended to leave them included */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//libraries
#include "graphx.h"
#include <fileioc.h>
#include <keypadc.h>
//includes
#include "gfx/snowflake_gfx.h"
#include "appvar.h"
#include "draw.h"
#include "game.h"
#include "main.h"
//variables
uint8_t snowCount, flakeCount, cursory = 100;
int count = 0;
struct snow snowMain[200], snowGame[200], snowflakeXY[20];
void draw_Snow(int snowX, int flakex, uint8_t file) {
unsigned int i = 0;
if (count%(21 - (blizzard * ((bool)blizzard)) - (2 * (!blizzard)))) {
if (!(count%2) || (!(count%(10 - abs(windVelocity))) && wind)) {
if (file == MAIN) {
i = 0;
while (i <= snowCount) {
snowMain[i].y += (blizzard / 5) + 1;
if (wind) {
snowMain[i].x += windVelocity;
if (snowMain[i].x < 0)
snowMain[i].x = 320;
else if (snowMain[i].x > 320)
snowMain[i].x = 0;
}
if (snowMain[i].y > 240) {
snowMain[i].x = 0;
snowMain[i].y = 0;
if (i != snowCount)
snowMain[i] = snowMain[snowCount];
snowCount--;
}
i++;
}
i = 0;
}else {
i = 0;
while (i <= snowCount) {
snowGame[i].y += (blizzard / 5) + 1;
if (wind) {
snowGame[i].x += windVelocity;
if (snowGame[i].x < 0)
snowGame[i].x = 320;
else if (snowGame[i].x > 320)
snowGame[i].x = 0;
}
if (snowGame[i].y > 240) {
snowGame[i].x = 0;
snowGame[i].y = 0;
if (i != snowCount)
snowGame[i] = snowGame[snowCount];
snowCount--;
}
i++;
}
i = 0;
}
}
}else {
snowCount++;
if (file == MAIN) {
i = 0;
while (i <= snowCount) {
if (i == snowCount) {
snowMain[i].x = snowX;
snowMain[i].y = 0;
}
snowMain[i].y += (blizzard / 5) + 1;
if (wind) {
snowMain[i].x += windVelocity;
if (snowMain[i].x < 0)
snowMain[i].x = 320;
else if (snowMain[i].x > 320)
snowMain[i].x = 0;
}
if (snowMain[i].y > 240) {
snowMain[i].x = 0;
snowMain[i].y = 0;
if (i != snowCount - 1)
snowMain[i] = snowMain[snowCount - 1];
snowCount--;
}
i++;
}
}else {
i = 0;
while (i <= snowCount) {
if (i == snowCount) {
snowGame[i].x = snowX;
snowGame[i].y = 0;
}
snowGame[i].y += (blizzard / 5) + 1;
if (wind) {
snowGame[i].x += windVelocity;
if (snowGame[i].x < 0)
snowGame[i].x = 320;
else if (snowGame[i].x > 320)
snowGame[i].x = 0;
}
if (snowGame[i].y > 240) {
snowGame[i].x = 0;
snowGame[i].y = 0;
if (i != snowCount - 1)
snowGame[i] = snowGame[snowCount - 1];
snowCount--;
}
i++;
}
}
}
i = 0;
if (count && count%(50 - (2 * (blizzard / 2)))) {
if (file == MAIN) {
while (i <= flakeCount) {
snowflakeXY[i].y += ((int)(blizzard / 10)) + 1;
if (wind) {
snowflakeXY[i].x += (windVelocity != 1)?windVelocity / 2:windVelocity;
if (snowflakeXY[i].x < 0)
snowflakeXY[i].x = 320;
else if (snowflakeXY[i].x > 320)
snowflakeXY[i].x = 0;
}
if (snowflakeXY[i].y >= 200 && snowflakeXY[i].y < 210) {
snowflakeXY[i].x = 0;
snowflakeXY[i].y = 0;
if (i != flakeCount)
snowflakeXY[i] = snowflakeXY[flakeCount];
flakeCount--;
}
i++;
}
}else {
while (i <= flakeCount) {
snowflakeXY[i].y += (SPEEDINC != SPEEDMAX)?SPEEDINC:SPEEDMAX;
if (snowflakeXY[i].y + snowflake_data[1] >= SNOWLAYER) {
snowflakeXY[i].x = 0;
snowflakeXY[i].y = 0;
if (i != flakeCount)
snowflakeXY[i] = snowflakeXY[flakeCount];
flakeCount--;
missed++;
}
i++;
}
}
}else {
if (file == MAIN) {
flakeCount++;
while (i <= flakeCount) {
if (i == flakeCount) {
snowflakeXY[i].x = flakex;
snowflakeXY[i].y = 210;
}
snowflakeXY[i].y += ((int)(blizzard / 10)) + 1;
if (wind) {
snowflakeXY[i].x += windVelocity / 2;
if (snowflakeXY[i].x < 0)
snowflakeXY[i].x = 320;
else if (snowflakeXY[i].x > 320)
snowflakeXY[i].x = 0;
}
if (snowflakeXY[i].y >= 200 && snowflakeXY[i].y < 210) {
snowflakeXY[i].x = 0;
snowflakeXY[i].y = 0;
if (i != flakeCount)
snowflakeXY[i] = snowflakeXY[flakeCount - 1];
flakeCount--;
}
i++;
}
}else {
flakeCount += 2;
while (i <= flakeCount) {
if (i == flakeCount - 1) {
snowflakeXY[i].x = 80 - 15;
snowflakeXY[i].y = 0;
}else if (i == flakeCount) {
snowflakeXY[i].x = 240 - 15;
snowflakeXY[i].y = 0;
}
snowflakeXY[i].y += (SPEEDINC != SPEEDMAX)?SPEEDINC:SPEEDMAX;
if (snowflakeXY[i].y + snowflake_data[1] >= SNOWLAYER) {
snowflakeXY[i].x = 0;
snowflakeXY[i].y = 0;
if (i != flakeCount)
snowflakeXY[i] = snowflakeXY[flakeCount - 1];
flakeCount--;
missed++;
}
i++;
}
}
}
i = 0;
gfx_SetColor(0xFF);
if (file == MAIN)
while (i <= snowCount) {
gfx_FillRectangle(snowMain[i].x, snowMain[i].y, 3, 3);
i++;
}
else
while (i <= snowCount) {
gfx_FillRectangle(snowGame[i].x, snowGame[i].y, 3, 3);
i++;
}
i = 0;
while (i <= flakeCount) {
gfx_TransparentSprite_NoClip(snowflake, snowflakeXY[i].x, snowflakeXY[i].y);
i++;
}
/* if (file == MAIN) {
gfx_SetColor(0xFF);
gfx_FillRectangle(0, 200, 320, 40);
}*/
count++;
}
uint8_t draw_Menu() {
switch (key) {
case sk_Down:
if (cursory == 160)
cursory = 100;
else
cursory += 10;
break;
case sk_Up:
if (cursory == 100)
cursory = 160;
else
cursory -= 10;
break;
case sk_Left:
if (cursory == 140) {
if (level == 1)
level = levelmax;
else
level--;
}else if (cursory == 150) {
if (!wind) {
wind = true;
windVelocity = -1;
}else if (windVelocity == 1) {
wind = false;
windVelocity = 0;
}else if (windVelocity == -9) {
windVelocity = 9;
}else
windVelocity--;
}else if (cursory == 160) {
if (!blizzard)
blizzard = 20;
else
blizzard--;
}
break;
case sk_Right:
if (cursory == 140) {
if (level == levelmax)
level = 1;
else
level++;
}else if (cursory == 150) {
if (!wind) {
wind = true;
windVelocity = 1;
}else if (windVelocity == 9) {
windVelocity = -9;
}else if (windVelocity == -1) {
wind = false;
windVelocity = 0;
}else
windVelocity++;
}else if (cursory == 160) {
if (blizzard == 20)
blizzard = 0;
else
blizzard++;
}
break;
case sk_2nd:
return (cursory%100) / 10;
}
gfx_SetTextScale(3, 2);
gfx_PrintStringXY("Snow Math", 160 - (gfx_GetStringWidth("Snow Math")/2), 50);
gfx_SetTextScale(1, 1);
gfx_PrintStringXY("Addition", 130, 100);
gfx_PrintStringXY("Subtraction", 130, 110);
gfx_PrintStringXY("Multiplication", 130, 120);
gfx_PrintStringXY("Division", 130, 130);
gfx_PrintStringXY("Level:", 130, 140);
gfx_PrintStringXY("Wind:", 130, 150);
gfx_PrintStringXY("Blizzard:", 130, 160);
gfx_SetTextXY(135 + gfx_GetStringWidth("Level:"), 140);
gfx_PrintUInt(level, 1);
gfx_SetTextXY(135 + gfx_GetStringWidth("Wind:"), 150);
gfx_PrintInt(windVelocity, 2);
gfx_SetTextXY(135 + gfx_GetStringWidth("Blizzard:"), 160);
gfx_PrintUInt(blizzard, 2);
gfx_PrintStringXY(">", 120, cursory);
gfx_SwapDraw();
return 255;
}
draw.h
Code: #ifndef DRAW_H
#define DRAW_H
#define MAIN 0
#define GAME 1
void draw_Snow(int snowX, int flakex, uint8_t file);
uint8_t draw_Menu();
extern uint8_t snowCount, flakeCount;
extern int count;
extern struct snow {
int x;
int y;
}snowMain[200], snowGame[200], snowflakeXY[20];
#endif // DRAW_H