Jump to content
  • Advertisement
Sign in to follow this  
NoahBangs

help with creating a Sims-like code

This topic is 2495 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,


I am trying to create a code for the pre-alpha version of my Sims-like game.

I currently want to know how to code a pie menu and how to make an object go to the location i clicked on.




I don't wan't to feel selfish so can someone please explain how its done rather that write a code?

I know some C++, but not too much.

Share this post


Link to post
Share on other sites
Advertisement

how to code a pie menu

The specifics will depend on what APIs and libraries you are using -- which language (C++?) and graphics API are you working with, and are you using any library for user interface or writing your own? These are also called "radial menus" if that helps you to find other resources.

The basic logic involves:

  1. Detecting where the mouse is clicked (so you know where to open the menu). You'll probably also want to ensure the menu will fit there and move the centre to accommodate if part of the menu would end up off screen.
  2. Drawing the menu elements around the centre coordinate.
  3. Handling further input as appropriate.

Being more specific than that is difficult without knowing a little more context about your project.

how to make an object go to the location i clicked on[/quote]

  1. Detect the location of the click.
  2. Determine a path from the current location of the object in question to the location of the click -- search "path finding" to research ways of doing this. "A*" or "A star" is a commonly used algorithm, but may or may not be the best fit for your particular situation.
  3. Animate the object moving along the path. If there are other objects moving around you may need to recalculate the path when/if it becomes blocked.



We can probably give you some more specific hints and perhaps some links on the subjects if you let us know a bit more about what APIs and libraries you're using. If you're still a beginner programmer some of these might be pretty difficult to get your head around -- have you written any smaller games such as a Pong clone yet?


Hope that's helpful! cool.png

Share this post


Link to post
Share on other sites
In the simplest terms possible:

Pie Menu: With a given amount of objects, place the possible selections in some circular order. Given a completed circle = 2pi, we can say that the placement of the objects can be the amount of objects per placement on the circle. i.e. (2pi)/N = displacement. Since you have the radians per selection object, we can place each one i*((2pi)/N) on the unit circle. Then we can expand given the scale of the menu.

Yuck. Kinda mathy. Less mathy: Per radians one the unit circle, divide that up by how many objects can fit. Then multiply by the index of the objects. Move that result to the screen coordinates. Bam.

Clicked location: When your mouse clicks, it has a location on your screen it was on when it clicked. Your engine will know where your game is being drawn (i.e. camera displacement). From that, you send the mouse coordinates and it gets converted into "world coordinates". You send that to your Sim object who can move to that location from its local position. Ta-da!

Share this post


Link to post
Share on other sites

[quote name='Mastermind89' timestamp='1329333596' post='4913435']
how to code a pie menu

The specifics will depend on what APIs and libraries you are using -- which language (C++?) and graphics API are you working with, and are you using any library for user interface or writing your own? These are also called "radial menus" if that helps you to find other resources.

The basic logic involves:

  1. Detecting where the mouse is clicked (so you know where to open the menu). You'll probably also want to ensure the menu will fit there and move the centre to accommodate if part of the menu would end up off screen.
  2. Drawing the menu elements around the centre coordinate.
  3. Handling further input as appropriate.

Being more specific than that is difficult without knowing a little more context about your project.

how to make an object go to the location i clicked on[/quote]

  1. Detect the location of the click.
  2. Determine a path from the current location of the object in question to the location of the click -- search "path finding" to research ways of doing this. "A*" or "A star" is a commonly used algorithm, but may or may not be the best fit for your particular situation.
  3. Animate the object moving along the path. If there are other objects moving around you may need to recalculate the path when/if it becomes blocked.



We can probably give you some more specific hints and perhaps some links on the subjects if you let us know a bit more about what APIs and libraries you're using. If you're still a beginner programmer some of these might be pretty difficult to get your head around -- have you written any smaller games such as a Pong clone yet?


Hope that's helpful! cool.png
[/quote]

I'm kinda lost on the API part. When I said some c++, that meant I know real basic stuff. Also I don't really know what libraries to use.

Share this post


Link to post
Share on other sites
An API is an Application Programming Interface. It's basically a LOT of code that specifically works together to achieve some overal goal. Some work on the operating system level. i.e. Win32 API allows you to make Windows games and software. smile.png

There are a lot of libraries to use. (not always single-API dependent! Typically a mixture of many.) Gosu Library is my favorite so far. There's also SFML, SDL, Allegro 5, and many many more.

Share this post


Link to post
Share on other sites

We can probably give you some more specific hints and perhaps some links on the subjects if you let us know a bit more about what APIs and libraries you're using. If you're still a beginner programmer some of these might be pretty difficult to get your head around -- have you written any smaller games such as a Pong clone yet?


I've tried, but my disability won't let me focus. I need more perseverance.

Share this post


Link to post
Share on other sites
Honestly, you're not ready to be coding these particular features yet -- you need to start on the basics -- how are you going to code an object moving to a point you've clicked on if there isn't an object in some game world yet?


Since you're working with C++ and SDL I'd suggest working through Lazy Foo's Tutorials, which will walk you through the basics of setting up and using SDL, showing you all kinds of useful things like how to load and display graphics, basic collision detection, etc. They walk you through with some pretty good explanations and plenty of code samples to examine and try out. You'll also get to practice your C++ basics some more along the way, and you can post here to get help if you get stuck with any of the lessons.


Once you can create a basic game with graphics and objects which move around based on player input with some basic collision detection then you will be ready to think about more advanced features like pie menus, and path-finding for your characters.


If you have a disability that makes it difficult for you to focus then you'll need to learn to work around that. Perhaps it would help if you set some reasonable and achievable goals to achieve along the way, and concentrate on small parts of the project one at a time rather than aiming for a large game. A good first few goals might be:

  1. Learn to load and display a single image in a window.
  2. Learn to move your image around based on player input.
  3. Learn to add additional images, and detect and react to collisions between them and your moving object.

If you can do those 3 basic steps you'll have almost everything you need to create a basic Pong game, and will be well on the way towards being able to make something more complex like a sims-style game.


Does that help? smile.png

Share this post


Link to post
Share on other sites

Honestly, you're not ready to be coding these particular features yet -- you need to start on the basics -- how are you going to code an object moving to a point you've clicked on if there isn't an object in some game world yet?


Since you're working with C++ and SDL I'd suggest working through Lazy Foo's Tutorials, which will walk you through the basics of setting up and using SDL, showing you all kinds of useful things like how to load and display graphics, basic collision detection, etc. They walk you through with some pretty good explanations and plenty of code samples to examine and try out. You'll also get to practice your C++ basics some more along the way, and you can post here to get help if you get stuck with any of the lessons.


Once you can create a basic game with graphics and objects which move around based on player input with some basic collision detection then you will be ready to think about more advanced features like pie menus, and path-finding for your characters.


If you have a disability that makes it difficult for you to focus then you'll need to learn to work around that. Perhaps it would help if you set some reasonable and achievable goals to achieve along the way, and concentrate on small parts of the project one at a time rather than aiming for a large game. A good first few goals might be:

  1. Learn to load and display a single image in a window.
  2. Learn to move your image around based on player input.
  3. Learn to add additional images, and detect and react to collisions between them and your moving object.

If you can do those 3 basic steps you'll have almost everything you need to create a basic Pong game, and will be well on the way towards being able to make something more complex like a sims-style game.


Does that help? smile.png


thank you for the advice. I will do my best.biggrin.png

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!