I'm trying to make basically just the game snake. I'm using the Allegro graphics library. I'm trying to use sin and cos to find the direction the snake should go, but I keep getting the error 'sin': ambiguous call to overloaded function. I don't know what that means or what the problem is. But here's my code:
Code:
//Includes
#include <allegro.h>
#include<iostream>
#include<string>
#include <stdlib.h>
#include <stdlib.h>
#include <cstdlib>
#include <time.h>
#include <vector>
#include <complex>
#include <math.h>
//Graphics
BITMAP *snakeimg = NULL;
BITMAP *buffer = NULL;
//Sounds
//Variables
int x,y;
int dir = 0;
int dx = sin(dir);
int dy = cos(dir);
//Structs
struct snake{
int x;
int y;
};
struct fruit{
int x;
int y;
};
//Vectors
vector<snake> snakes(0);
//Functions
void UpdateSnake();
int main(int argc, char argv[1])
{
using namespace std;
allegro_init();
install_keyboard();
set_color_depth(24);
set_gfx_mode(GFX_AUTODETECT_WINDOWED,400,400,0,0);
//BITMAPS
snakeimg = load_bitmap("Snake.bmp",NULL);
buffer = create_bitmap(400,400);
while(!key[KEY_ESC])
{
UpdateSnake();
draw_sprite(screen,buffer,0,0);
}
allegro_exit();
return 0;
//Cleanup
for(int i = 0;i < snakes.size();
{
snakes.erase(snakes.begin()+i);
}
}
destroy_bitmap(snakeimg);
destroy_bitmap(buffer);
END_OF_MAIN();
void UpdateSnake()
{
dx = Sin(dir);
dy = Cos(dir);
x = x + dx;
y = y + dy;
draw_sprite(buffer,snakeimg,x,y);
}
Please help if you have any idea what the problem is. I'm pretty sure I have the right include file.