• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
rishan1996

Help with splitting new files.

9 posts in this topic

Hi, I am trying to organize my coding but i keep getting errors, could someone help me? i am using one file which is the Main file and everything is in there i want to become more organized for example i want a file with logic, one with levels ect. but i keep getting errors need some help. this is the code.
[source lang="cpp"]//Libraries
#include <SFML/Graphics.hpp>
#include <iostream>
#include <string>
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
using namespace sf ;
using namespace std ;

//Object for the events
Event event;

//Global variables, functions, classes



//C++ program entry point
int main()
{
//Variables
//Variable that keeps the Game loop running
bool play = true ;

//Mouse Co-ordinates
bool mousecoordinates = false ;

//Movement Variables
bool dPressed = false ;
bool aPressed = false ;
bool wPressed = false ;
bool sPressed = false ;
int xVelocity = 0;
int yVelocity = 0;

//Action Variable
bool spacebar = false ;

//Mouse
bool leftClick = false ;
int mouseX = 0, mouseY = 0;




//Creating the window
RenderWindow window(VideoMode(1280, 720, 32), "SFML Game") ;

//Setting the framrate limit to 60 FPS
window.setFramerateLimit(60) ;

//Background
Texture background;
if (background.loadFromFile("Pictures/Background.png") == 0){
return 1;
}

//Shapes Colour
Texture Shape;
if (Shape.loadFromFile("Pictures/ShapeColour.png") == 0){
return 1;
}

//Character
Texture Character;
if (Character.loadFromFile("Pictures/Character1.png") == 0){
return 1;
}
Texture texture;
texture.create(40, 45);
Sprite sprite1;
sprite1.setColor(Color::White);
sprite1.setTexture(Character);
sprite1.setPosition(70, 635);

//Levels
//Level 1 part1
Texture Level1a;
if (Level1a.loadFromFile("Pictures/level1 part1.png") == 0){
return 1;
}
Texture leveltex;
leveltex.create(1280, 40);
Sprite level1a;
level1a.setTexture(Level1a);
level1a.setPosition(0, 680);

//Level 1 part2
Texture Level1b;
if (Level1b.loadFromFile("Pictures/Level1 part2.png") == 0){
return 1;
}
Texture leveltex1;
leveltex1.create(40, 640);
Sprite level1b;
level1b.setTexture(Level1b);
level1b.setPosition(0, 40);

//level 1 part3
Texture Level1c;
if (Level1c.loadFromFile("Pictures/Level1 part3.png") == 0) return 1;
Sprite level1c;
level1c.setTexture(Level1c);
level1c.setPosition(0,0);

//level 1 part4
Texture Level1d;
if (Level1d.loadFromFile("Pictures/Level1 part2.png") == 0) return 1;
Sprite level1d;
level1d.setTexture(Level1d);
level1d.setPosition(1240,40);



//Font
Font font;
if (font.loadFromFile("Fonts/ariali.ttf") == 0){
return 1;
}

//Sounds
SoundBuffer JumpBuffer;
if (JumpBuffer.loadFromFile("Sounds/jump.wav") == 0){
return 1;
}

Sound Jump;
Jump.setBuffer(JumpBuffer);
Jump.setVolume(20);

//Music
Music sidewalk;
if (sidewalk.openFromFile("Songs/Sidewalk.ogg") == 0){
return 1;
}

sidewalk.setVolume(50);
sidewalk.setLoop(true);
sidewalk.play();



//Render Shapes
RectangleShape background1;
background1.setSize(Vector2f(1280, 720));
background1.setPosition(0, 0);
background1.setTexture(&background);







//Text
Text title;
title.setFont(font);
title.setCharacterSize(100);
title.setString("Bearumper\n");
title.setPosition(0, 0);
title.setColor(Color::Blue);

Text credits;
credits.setFont(font);
credits.setCharacterSize(50);
credits.setString("by Rishan");
credits.setPosition(0, 150);
credits.setColor(Color::Blue);



//Game Loop
while (play == true) {

//Events

while(window.pollEvent(event)){

//When X is pressed the game closes
if (event.type == Event::Closed){
play = false ;
}

if (event.type == Event::KeyPressed){
if (event.key.code == Keyboard::A) aPressed = true;
if (event.key.code == Keyboard::D) dPressed = true;
if (event.key.code == Keyboard::Space){
window.setKeyRepeatEnabled(false) ;
Jump.play();
spacebar = true;}
}

if (event.type == Event::KeyReleased){
if (event.key.code == Keyboard::A) aPressed = false;
if (event.key.code == Keyboard::D) dPressed = false;
if (event.key.code == Keyboard::Space) spacebar = false;
}


//Mouse Position
if (event.type == Event::MouseMoved){
mouseX = event.mouseMove.x ;
mouseY = event.mouseMove.y ;
}
if (event.type == Event::KeyPressed && event.key.code == Keyboard::F1){
mousecoordinates = true ;
}

//Music Pause
if (event.type == Event::KeyPressed && event.key.code == Keyboard::F2){
sidewalk.pause();
}

//Music Play
if (event.type == Event::KeyPressed && event.key.code == Keyboard::F3){
sidewalk.play();
}



}

//Logic
//Movement

if (dPressed == true){
xVelocity = 5;
}

if (aPressed == true){
xVelocity = -5;
}

if (dPressed == true && aPressed == true){
xVelocity = 0;
}

if (dPressed == false && aPressed == false){
xVelocity = 0;
}

if (spacebar == true){
yVelocity = -5;
}

//Move
sprite1.move(xVelocity, 0);
sprite1.move(0, yVelocity);

//Collision
if (sprite1.getGlobalBounds().intersects(level1a.getGlobalBounds()) == true){

sprite1.move( -xVelocity, 0);
sprite1.move( 0, -yVelocity);

}

if (sprite1.getGlobalBounds().intersects(level1b.getGlobalBounds()) == true){

sprite1.move( -xVelocity, 0);
sprite1.move( 0, -yVelocity);

}

if (sprite1.getGlobalBounds().intersects(level1c.getGlobalBounds()) == true){

sprite1.move( -xVelocity, 0);
sprite1.move( 0, -yVelocity);

}
if (sprite1.getGlobalBounds().intersects(level1d.getGlobalBounds()) == true){

sprite1.move( -xVelocity, 0);
sprite1.move( 0, -yVelocity);

}



//Print to console
if (leftClick == true){
cout << "Shoot" << endl ;

leftClick = false ;
}

if (mousecoordinates == true){
cout << "Mouse x: " << mouseX << " Mouse y: " << mouseY << endl ;
mousecoordinates = false ;
}

//Character







//Rendering
window.clear();

window.draw(background1);
window.draw(level1a);
window.draw(level1b);
window.draw(level1c);
window.draw(level1d);
window.draw(title);
window.draw(credits);
window.draw(sprite1);



window.display();



}



//Clean Up
window.close();


}[/source]
0

Share this post


Link to post
Share on other sites
Why are you using two namespaces, there could be name collisions going on. Use sf:: for every sf namespace object you want to call, and get rid of line 7.
Why are you hiding the include names from us, if not then why are there empty includes in your code?
Do not name a texture Shape, this could be causing name collisions if you import the Graphics library from sfml.
You need to organize the game into states, state transitions are triggered by global events mapped to other states.

How did you split up the files, show us how you did it. That way we can give you more detailed information.
1

Share this post


Link to post
Share on other sites
As kd7tck, mentioned, namespaces exist to prevent two classes with the same name from clashing with each other. In std:: there is a class called 'string'. What if [url="http://www.sfml-dev.org/documentation/1.4/classsf_1_1String.php"]SFML has a class called 'string' also[/url]? Luckily, SFML's String has an uppercase 's' so in this instance it won't actually clash, but having 'string str', and 'String str' in the same code base, both serving different purposes and doing different things, makes the code more confusing.

Unless you are going multiple namespaces deep (or those namespaces have long names), you should type out the full namespace. It's really not much worse to type 'std::string' than to type 'string' once you get used to it. If you must bring something into the global namespace, specify that class, instead of dragging the entire 'std' namespace into the global namespace: "[b]using std::string[/b]" instead of "[b]using [/b]([size=2]the entire[/size]) [b]namespace std[/b]". [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

Remember that the namespace is part of the name of the class. Don't shorthand it just for the sake of typing a few characters less; it helps describe your code better, declaring your intent to people reading your code (including yourself when you revisit the code two months later forgetting what you wrote).

The name of the variable is 'std::string' (The 'string' within the namespace 'std').

[hr]

Could you repost your code? It seems alot of it is missing.

How did you break it apart into multiple files (show your separate files), and what error messages did you get?
0

Share this post


Link to post
Share on other sites
Thank you for the reply guys. Sorry but i don't know why it didn't show the includes. I am not hiding them and i thought i posted them something must have gone wrong. I have given up and have started from scratch as I thought it would make life easier as i could modify it. Would you suggest i stop using namespace std and just start putting std::... for practice. I used for the reason you posted. Bit lazy :) . I am a newbie and learn best from experience. I just started SFML right after learning c++. i learnt c++ in 2 months so I still dont understand somethings and hope to understand through practice. I am 16 so i have a lot of time left. Also could you help me with some thing else, its a small thing or should i start a new thread? the problem is this if (velocityX != 0 || velocityY != 0){sourceX += tempTexture.GetWidth() / 4; } , how would i do that in sfml 2.0 as there is only a option for .getSize() and i cant divide it by 4.
0

Share this post


Link to post
Share on other sites
Yes, I would recommend just typing out the "std::", it's only five more letters, and once you type it out a few hundred times, you can type it out pretty fast and won't even notice.

SFML getSize() functions return another struct/class, usually [url="http://www.sfml-dev.org/documentation/2.0/classsf_1_1Vector2.php"]sf::[/url][url="http://www.sfml-dev.org/documentation/2.0/classsf_1_1Rect.php"]Vector2u[/url].

You can go: [i]myRenderWindow.getSize().width;[/i] and [i]myRenderWindow.getSize().height;[/i]
In your situation: { sourceX += (tempTexture.getSize().height / 4); }

The [url="http://www.sfml-dev.org/documentation/2.0/classsf_1_1Texture.php"]documentation [/url]tells you all the different variables and functions a struct or class has.
0

Share this post


Link to post
Share on other sites
getSize(). height didn't work it wasn't a member but it allowed me x and y would x be width and y height or are they completely different?
0

Share this post


Link to post
Share on other sites
i am using this http://www.youtube.com/watch?v=X4cSJ5beVJM&feature=BFa&list=SP0249162D5D6FA5D1 but some of the code i cant do in 2.0 or atleast dont know how to. These are the tutorials i am using to make my first game.
0

Share this post


Link to post
Share on other sites
That's fine. SFML 2 is still rather new, and not alot of tutorials has come out for it yet, but it's perfectly usable. You just have to learn how to use google.

Is there some specific problem you're having?

[quote name='rishan1996' timestamp='1347399593' post='4979071']
getSize(). height didn't work it wasn't a member but it allowed me x and y would x be width and y height or are they completely different?
[/quote]
Yes, that's correct. Sorry, I was thinking of [url="http://www.sfml-dev.org/documentation/2.0/classsf_1_1Rect.php"]sf::Rect[/url] which has width and height, and is sometimes returned by SFML functions. [img]http://public.gamedev.net//public/style_emoticons/default/happy.png[/img] Edited by Servant of the Lord
0

Share this post


Link to post
Share on other sites
ok thank you, i have used google alot for sfml 2.0 because i have to but there are some thing which i cant find on google or at least dont have the time to spend looking for or i am just not a good googler :), forums are my last resort and i use google a lot for programming. Also there is one more thing which i have been searching the last half an hour. I will post tomorrow if i cant find anything for it. its 11 where i am so i have to sleep have school tomorrow. thank you fot the help so far really appreciate it. If i could i would give you +1 rep
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0