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

Author Topic: A few Questions..  (Read 18429 times)

0 Members and 1 Guest are viewing this topic.

Father_Sloth

  • Newbie
  • *
  • Posts: 48
    • View Profile
A few Questions..
« on: October 24, 2010, 09:10:40 pm »
Hey

I'm making a top down zombie shooter, similar to uzf (i love that game btw). Now straight to the point:

1) How can I get the player sprite to face the mouse?

2) how can I get the Zombies to go towards the player?

3) How should I do the maps? Are their any editors that would work best for my needs (medium sized maps with collision and as the player moves, it scrolls.)

Sorry I'm nooby but i'd love to have some help. Thanks in advance.

- Simon

priomsrb

  • Newbie
  • *
  • Posts: 38
    • View Profile
A few Questions..
« Reply #1 on: October 25, 2010, 02:06:29 am »
Quote
1) How can I get the player sprite to face the mouse?

You need to first get the difference in position for the mouse and player. Then you arctan (tan inverse) the x/y of the position difference. Finally use sf::Sprite::SetRotation() to set the angle. Here is the code I use in uzf:

Code: [Select]
void Player::onUpdate() {
    Input *input = Input::getInstance();

    sf::Vector2f mouseToPlayer = input->getMousePosition() - getPosition();

    float facingAngle = atan(mouseToPlayer.x/mouseToPlayer.y);

    if(mouseToPlayer.x == 0 && mouseToPlayer.y == 0)
        facingAngle = 0;

    facingAngle *= 180/3.14159; // Convert to degrees

    // atan() returns an angle between 0-180 therefore it needs an offset of 180
    // when it is in the negative-Y quadrants
    if(mouseToPlayer.y >= 0) {
        facingAngle += 180;
    }

    setAngle(facingAngle);
    ...



Quote
2) how can I get the Zombies to go towards the player?


This is more trickier.

If you don't have any walls and obstacles, then you can make the zombies head straight for the player. Again using some simple maths you can figure out what the x and y speed of the zombie needs to be.

If you have walls however then you will need to do some pathfinding. Try looking up A* (a star) path finding. I used the micropather library instead of writing my own A* code. It does most of the work for you but it isn't fully straightforward.

This was probably the trickiest part of the game for me to code. There were issues like unit and wall sizes not having the same grid size that took me a while to find a workaround for.

Quote
3) How should I do the maps? Are their any editors that would work best for my needs (medium sized maps with collision and as the player moves, it scrolls.)


For this you have 2 choices: Tile-based map editors, and vector based map editors.

Tile-based map editors are the easiest to use but also the most inflexible as everything is based on the grid size. Most of them export to easy to parse files and so the code to load maps is simpler.

For UZF I used Inkscape, a vector based editor. Inkscape is actually a generic vector editing program but you can still use it to make game maps. It is the most flexible option as it has things like polygons, layers and more advanced functionality. You can also use the description fields of shapes to add game related object information. However the .svg file format is in xml and is quite complicated. So I only implemented a very basic implementation that only handles rectangles with no rotation.

Both types of map editors support medium sized maps and collision. Scrolling is something that you have to code yourself. Thankfully SFML's View classes make scrolling quite simple.


Some parts of the game can be tricky but the more you code the better you get :). Good luck with your project.

Father_Sloth

  • Newbie
  • *
  • Posts: 48
    • View Profile
A few Questions..
« Reply #2 on: October 28, 2010, 03:57:26 pm »
Thanks loads. having you reply has been awesome.

Are their any places you specifically learnt best from I am new to game programming but alright with c++ so are their any places that teach sfml (except the website because i don't find them too helpful) that I should try out?

Thanks loads.

Simon

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
A few Questions..
« Reply #3 on: October 28, 2010, 04:24:11 pm »
If you don't find the website and the docs useful, I guess you're not looking for how to learn SFML, but how to learn (game) programming in general. The questions you asked in the initial post have less to do with SFML at all, by the way.

Father_Sloth

  • Newbie
  • *
  • Posts: 48
    • View Profile
A few Questions..
« Reply #4 on: October 28, 2010, 06:16:14 pm »
it's just I know what I want to do, and what concepts will be used now but I don't know the actual commands for them. Could you help?

For example one thing I couldn't find was the structure of classes. How should I go about this? Before I was getting compile failures.

Sorry Tank I didn't mean to be so nooby.

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
A few Questions..
« Reply #5 on: October 28, 2010, 07:54:06 pm »
Classes documentation can be found here for SFML 1.6: http://sfml-dev.org/documentation/1.6/

It's no problem to be new, but it's sometimes a problem to answer a question when it's similar to "How do I write a strategy game?" ;) This is no offense, don't get me wrong.

Especially question 4 is a bit like that. SFML isn't a game maker but a library to get access to your multimedia hardware (with some utility and helper classes that make things easier). So a question like "How do I create a map?" is just to general to be answered in a forum. What kind of game do you create? How shall the map look like? What have you done so far?

The trick is to be as precise as possible. :)

Father_Sloth

  • Newbie
  • *
  • Posts: 48
    • View Profile
A few Questions..
« Reply #6 on: October 28, 2010, 11:15:33 pm »
ok thanks tank. So is there a trick or fast way to add collision to walls on a map with out drawing each wall as a sprite? I want to make map's indoors but with an outside view as well (just to give it a tad more realism). Also I'm all of a sudden struggling to compile. I'm following all the details of the tutorial precisely (btw I'm using xcode on a mac). But every time I build and run, even the just the code that it provides in the template it says loads of errors and doesn't start.

heres a screenshot:


priomsrb

  • Newbie
  • *
  • Posts: 38
    • View Profile
A few Questions..
« Reply #7 on: October 29, 2010, 05:57:32 am »
Hey Father_Sloth

It seems like you are new to game programming. My suggestion is to first make a very simple game.

Whenever I learn a new framework or library I try to make a pong game. Pong games are good because they are simple to code and teach you how to deal with sprites, collisions, controls, sounds, etc. After you finish that you'll get a good understanding of the basics and can move on to your next project.

I learnt SFML from the offical tutorials. In fact I think the tutorials are one of big strengths of SFML because they are so simple yet so comprehensive.

As for your errors, it seems that you have not specified the SFML include/ directory in your include path.

Father_Sloth

  • Newbie
  • *
  • Posts: 48
    • View Profile
A few Questions..
« Reply #8 on: October 29, 2010, 10:59:54 am »
Thank you very much Priomsrb for that. I will do that today and post my results later. Also I included al the headers but am I missing one? I did this



are there any extra's I should include?

Simon

priomsrb

  • Newbie
  • *
  • Posts: 38
    • View Profile
A few Questions..
« Reply #9 on: October 29, 2010, 02:56:37 pm »
You have included the right headers but the compiler can't find them. So you'll need to add SFML's include/ directory to your search path. I haven't used xpath before but this page gives some information on how to add directories to your search path: http://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/XcodeProjectManagement/210-Building_Products/building.html#//apple_ref/doc/uid/TP40002693-SW23

Father_Sloth

  • Newbie
  • *
  • Posts: 48
    • View Profile
A few Questions..
« Reply #10 on: October 29, 2010, 03:45:45 pm »
So do I need to add it to my Header Search Path, Library Path or Framework Path?

Simon

p.s. also just a little question about sfml. I am reading the tutorials and I keep on seeing this " .f " - what does it mean?

priomsrb

  • Newbie
  • *
  • Posts: 38
    • View Profile
A few Questions..
« Reply #11 on: October 29, 2010, 07:27:41 pm »
You'll need to add it to your header search path.

Quote
p.s. also just a little question about sfml. I am reading the tutorials and I keep on seeing this " .f " - what does it mean?


I didn't notice anything like that last time I checked. Can you give an example?

darekg11

  • Full Member
  • ***
  • Posts: 127
    • View Profile
A few Questions..
« Reply #12 on: October 29, 2010, 09:09:32 pm »
Maybe he means float mark or whatever is called like:
303.f ?

Father_Sloth

  • Newbie
  • *
  • Posts: 48
    • View Profile
A few Questions..
« Reply #13 on: October 29, 2010, 09:46:47 pm »
Well in the example source code this keeps popping up

Code: [Select]
const float Speed = 50.f;
float Left = 0.f;
float Top  = 0.f;


and I'm just stumped on what ' .f ' is. It's probably something obvious and I'm just being an idiot :roll: .

Simon

p.s. I haven't figured out the Xcode compile error but I think I'm getting to bottom of it on this new thread I started : http://www.sfml-dev.org/forum/viewtopic.php?t=3447

priomsrb

  • Newbie
  • *
  • Posts: 38
    • View Profile
A few Questions..
« Reply #14 on: October 30, 2010, 12:31:40 am »
Code: [Select]
float Left = 0.f;

The ".f" explicitly marks a value as a float instead of a double. For more info see here: http://stackoverflow.com/questions/2391818/f-after-number-float-in-objective-c-c

 

anything