I am currently writing my first game (Snake) in c++ using visual Studio, I am attempting to set the blocks you eat at random areas on the screen however when I use the rand() function it says it is undefined, does anyone know why I have this error?
#include <iostream>
using namespace std;
bool gameOver;
const int WIDTH = 20;
const int HEIGHT = 20;
int x, y, foodX, foodY, score;
enum eDirection { STOP = 0, LEFT, RIGHT, UP, DOWN};
eDirection dir;
void Setup(){
gameOver = false;
dir = STOP;
x = WIDTH /2;
y = HEIGHT /2;
//rand function below is not defined??
//I thought the function was built in
foodX = rand() % WIDTH;
foodY = rand() % HEIGHT;
}
void Draw() {
}
void Input() {
}
void Logic() {
}
int main()
{
Setup();
while (!gameOver)
{
Draw();
Input();
Logic();
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire