Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


rishan1996

Member Since 09 Sep 2012
Offline Last Active Oct 13 2012 04:35 PM

Topics I've Started

How do i make a level with tiles?

09 September 2012 - 12:43 PM

Hi, I am using C++ and SFML2.0 and c++ Visual 2010. I want to make a level out of tiles but do not know how to. So far this is what I have done. I got 1 tile type and i am putting it together in photoshop to make a map. I then separate each string of tiles and put them manually into the code. So for one map i will be making over 30 Sprites and turn them into blocks and draw them out, then i will have to make boundaries for them separately. This takes a very long time and i am sure that there is a much faster way for example using xml but i don't know how to put that into the code. If you need the code just ask and i will post. Also just to clarify i dont want to make a tile engine which automatically makes them like minecraft. I want to make a puzzle map like bloody trapland so I will have to place them myself. Please help, urgent.

Help with splitting new files.

09 September 2012 - 05:24 AM

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 eventsEvent event;//Global variables, functions, classes//C++ program entry pointint 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]

PARTNERS