////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <fstream>
#include <stdio.h>
#include <string.h>
#include <sstream>
#include <iostream> // I/O
#include <iomanip> // format manipulation
using namespace std;
////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
////////////////////////////////////////////////////////////
int create_bullet(int bullet_count, int x, int y, int speed, int direction, int color_r, int color_g, int color_b)
{
int create_id = bullet_count + 1;
int bullet_x[3], bullet_y[3], bullet_speed[3], bullet_direction[3], bullet_color_r[3], bullet_color_g[3], bullet_color_b[3];
// Position of the bullet
bullet_x[create_id] = x;
bullet_y[create_id] = y;
// Speed of the bullet
bullet_speed[create_id] = speed;
// Direction of the bullet
bullet_direction[create_id] = direction;
// Color of the bullet
bullet_color_r[create_id] = color_r;
bullet_color_g[create_id] = color_g;
bullet_color_b[create_id] = color_b;
// We've got one extra bullet now,
// don't forget to add 1 extra after creation!
// Create successful!
return 1;
}
int main()
{
// Create the main rendering window
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Bullet Fusion C++ Version");
// Initialize the player :3
int player_hspeed = 0;
int player_vspeed = 0;
int bullet_count = 0;
int level_number = 1;
const double pi = 3.1415;
const int player_hspeed_max = 125;
const int player_vspeed_max = 125;
// Load the sprite image from a file
sf::Image PlayerImage;
sf::Image BulletImage;
if (!PlayerImage.LoadFromFile("data/gfx/player1.png"))
return EXIT_FAILURE;
if (!BulletImage.LoadFromFile("data/gfx/bullet1.png"))
return EXIT_FAILURE;
[...]
// Create a sprite for the player image.
sf::Sprite PlayerSpr(PlayerImage);
sf::Sprite BulletSpr(BulletImage);
// Set up some properties for it.
PlayerSpr.SetCenter(27.f, 4.f);
BulletSpr.SetCenter(14.f, 14.f);
PlayerSpr.SetPosition(400.f, 520.f);
// Start game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
}
// Get elapsed time
float ElapsedTime = App.GetFrameTime();
[...]
// Clear screen
App.Clear();
// Display sprite in our window
// Initialize a variable for our personal uses
create_bullet(bullet_count, 26, 26, 1, 45, 255, 0, 0);
int i = 0;
// Enter the bullet update loop
while (i < bullet_count)
{
// Update every bullet's position
bullet_x[i] = bullet_x[i] - sin(bullet_direction[i]*pi/180);
bullet_y[i] = bullet_x[i] - cos(bullet_direction[i]*pi/180);
BulletSpr.SetPosition(bullet_x[i], bullet_y[i]);
BulletSpr.SetColor(sf::Color(0, bullet_color_r[i], bullet_color_g[i], bullet_color_b[i]));
App.Draw(BulletSpr);
}
[...]
}
1>.\SFML_Test.cpp(212) : error C2065: 'bullet_x' : undeclared identifier 1>.\SFML_Test.cpp(212) : error C2065: 'bullet_x' : undeclared identifier 1>.\SFML_Test.cpp(212) : error C2065: 'bullet_direction' : undeclared identifier 1>.\SFML_Test.cpp(213) : error C2065: 'bullet_y' : undeclared identifier 1>.\SFML_Test.cpp(213) : error C2065: 'bullet_x' : undeclared identifier 1>.\SFML_Test.cpp(213) : error C2065: 'bullet_direction' : undeclared identifier 1>.\SFML_Test.cpp(215) : error C2065: 'bullet_x' : undeclared identifier 1>.\SFML_Test.cpp(215) : error C2065: 'bullet_y' : undeclared identifier 1>.\SFML_Test.cpp(216) : error C2065: 'bullet_color_r' : undeclared identifier 1>.\SFML_Test.cpp(216) : error C2065: 'bullet_color_g' : undeclared identifier 1>.\SFML_Test.cpp(216) : error C2065: 'bullet_color_b' : undeclared identifier
Title + above should be enough for you to understand my problem. I declare all those arrays in the function bullet_create, but int main() doesn't know that. Also, am I declaring this stuff right? It seems like there is something major-ly wrong with my code and I don't know what.
Edited by Samuka97, 02 November 2010 - 05:23 AM.
Telling people in the title that this is already solved.


Sign In
Create Account


Back to top










