Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: mario 1 style advice  (Read 3640 times)

0 Members and 1 Guest are viewing this topic.

paulhaggo

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Email
mario 1 style advice
« on: November 02, 2014, 04:03:12 am »
hello

i am trying to make a mario clone for fun

i have the sprite running, and a png as a large background image and the screen moving, if i run to which ever end of screen

ofcouse, he runs thur everything at the min

if i wanted mario to jump on to a box(like in the normal game)

should i be going down the route of

map tiles.. (to load the whole background image)
and then map tile collision

which i guess works on the system of

so................

you load the background image (mario level background), you load and display as tiles (chopping your image in to boxes on the fly)

and also you have a collision text file, with 0 and 1

and a loop, which checks if that tile, related to a 0 or 1

is that right.. or am i doing this the hardway ?

thank you

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: mario 1 style advice
« Reply #1 on: November 02, 2014, 05:22:24 am »
This has nothing to do with SFML or sfml-graphics. Ask this on a game programming forum such as www.gamedev.net or www.dreamincode.net and hope somebody understands what you just said.

Somebody close this thread please, otherwise this is just going to lead to another useless discussion.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

paulhaggo

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Email
Re: mario 1 style advice
« Reply #2 on: November 02, 2014, 07:00:52 pm »
this is sfml as far as i know

i am only using sfml, i only know sfml ~(slightly)

i admit, the same methods may be used in other frameworks, lib, engines etc

but why can i not just have a tiny bit of advice from an expert

it will save me a great deal of time, and i do not want to know how to do it

i'm not asking you to code it.. just point in me in the right direction

i'm sorry if its not in the wrong part of the forum, i'm sorry your clearly god

and a mere mortal as myself should not even speak to you

why don't you get a life, or better yet, be the big man and point out my bad grammar or spelling

thanks for your help anyways




Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: mario 1 style advice
« Reply #3 on: November 02, 2014, 07:13:34 pm »
He's right that this has nothing to do with SFML itself since the question is about collision detection.  SFML has no features specifically for doing collision detection, and dealing with collision is a common issue in a very large number of video games no matter what language or libraries they're based on.  Collision in particular is such a common problem that you can easily find very detailed guides and resources on the internet already written up for you about the typical ways of handling it (though of course they'll describe generic algorithms rather than give you SFML code examples).

But I'm in a good mood so I'll answer your question directly: What you're proposing is perfectly fine for a first game.  It's a very limited system, so once you're done with your Mario clone and working on some other project you'll probably want to explore some more complicated solutions, but it's perfectly functional and by far the easiest approach.

paulhaggo

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Email
Re: mario 1 style advice
« Reply #4 on: November 02, 2014, 07:28:40 pm »
thank you , onwards with the game

paulhaggo

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Email
Re: mario 1 style advice
« Reply #5 on: November 04, 2014, 03:47:58 pm »
just incase anyone wants to try this themselves

i have decided, tile mapping is right for my mini game and also tile map collision

if you take pacman as a sample

anyways

i have made some very basic code.. which will read a image, of 800 by 800 pixcels, cut it in to 32 by 32 squares and display all the squares in orders

which is below, from this i hope to make 1 screen per level games, whereby i used a txt file, which states which tiles can be passed over

the code is below

#include <SFML/Graphics.hpp>
#include <iostream>
#include <cmath>



int main()
{
    sf::Texture texture;
    if (!texture.loadFromFile("hag.png"))
    {
       return 0;
    }

    sf::Sprite box1;
    box1.setTexture(texture);

    sf::RenderWindow window(sf::VideoMode(800, 800), "Particles");

    // run the main loop
    while (window.isOpen())
    {
        // handle events
        sf::Event event;
        while (window.pollEvent(event))
        {
            if(event.type == sf::Event::Closed)
                window.close();
        }


        sf::Time elapsed = clock.restart();
      //  std::cout << (elapsed.asSeconds()*97680) << std::endl;


        window.clear();

        int lngRow = 0;
        int lngCol = 0;

        while(lngCol < 800)
        {
            lngRow = 0;
            while(lngRow < 800)
            {
                box1.setPosition(lngRow,lngCol);
                box1.setTextureRect(sf::IntRect(lngRow, lngCol, 32, 32));
                window.draw(box1);
                lngRow = lngRow + 32;
            }
            lngCol = lngCol + 32;

        }
        window.display();

    }

    return 0;
}






Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: mario 1 style advice
« Reply #6 on: November 04, 2014, 04:26:30 pm »
Might as well do a mini code review.

- First, when posting code here, put it in code tags so it gets properly formatted and highlighted.  When you post there's a "Code" dropdown that lets you select the language, so you can get tags that do this:
    sf::Texture texture;
    if (!texture.loadFromFile("hag.png"))
    {
       return 0;
    }
Makes it much easier for people to read your code.

- Make sure you've read *all* of the official SFML tutorials (even ones you don't think you'll need, they're not long), and check out what's available in the SFML wiki (https://github.com/SFML/SFML/wiki/Sources) and in Thor (http://www.bromeon.ch/libraries/thor/) since there's a good chance you can save yourself some time by using existing SFML code.

- When an error happens, always print something to cout or cerr so you're not completely lost if the error ever starts happening.

- lngRow/lngCol might not be the best variable names.  You appear to be using them to represent x/y coordinates rather than row/column indices, and I have no idea what "lng" means.  If it's meant to be an abbreviation, don't be afraid of writing out long variable names.

- Though it's not an issue yet, it would be a good idea even at this early stage to take some of that code out of the main() loop and into a separate function or class.  The obvious candidate is a Level class that initializes the texture and sprite in its constructor, and has an draw() method (taking a window as an argument) which contains the while(lngCol < 800) {} loop.  This will make it easier to change how you handle the tile-based levels in the future (try using multiple sprites, experiment with vertex arrays, etc) without the risk of messing up unrelated logic.  And yes, it's worth getting into these refactoring habits even on tiny projects like this.

- Speaking of while(lngCol < 800), that 800 is a magic number.  It's best to define it at the top (or in your Level class) as const int LEVEL_HEIGHT = 800; and then say while(lngCol < LEVEL_HEIGHT).

paulhaggo

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Email
Re: mario 1 style advice
« Reply #7 on: November 08, 2014, 07:50:48 pm »
thank to your help i managed to make these bad bad game, but still learning, all good thanks



and



cheers

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: mario 1 style advice
« Reply #8 on: November 08, 2014, 09:58:12 pm »
That's good progress for your first week of using SFML.  Keep it up!

 

anything