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

Author Topic: [Question/Request(?)] Modular Spaceship  (Read 2518 times)

0 Members and 1 Guest are viewing this topic.

UchihaKite

  • Newbie
  • *
  • Posts: 33
    • View Profile
    • Email
[Question/Request(?)] Modular Spaceship
« on: September 06, 2016, 03:00:52 pm »
Good morning SFML community! As I approach the end of my third C++ class and it is about time to customize my game to make it stand out from the rest! Since the game is asteroids, the idea came up to get a sprite sheet of a modular space ship, and allow the user to customize the space ship they are going to use in the game. Now, I've never done anything like this before, so I am used to having a single sprite, a single origin point, and thus allowing for easy manipulation of the "player". Does anyone have any ideas on how I should approach creating a modular space ship?

Thank you to anyone who takes the time to read this and to reply, I hope you all have a nice day!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: [Question/Request(?)] Modular Spaceship
« Reply #1 on: September 06, 2016, 04:31:11 pm »
You could go with predefined origin or calculate a center point at ship creation. Additionally you'll want to write a function that either returns the bounds of the ship or checks collision with the ship's shape.

As for modules, you could just provide base ships with various slots that can be filled with different modules and once that works maybe allow slots on modules themselves. Just make sure that modules have actually some meaning otherwise it becomes a bit pointless. Additionally you could add module requirements for a ship, e.g. you need to have an engine module and a controll module or something like that.

Last but not least don't forget that suvh a module system can get very complex. So it's best to pick the smallest thing you could think of first and try to implement that. Don't try to get "the" system done. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: [Question/Request(?)] Modular Spaceship
« Reply #2 on: September 06, 2016, 11:33:40 pm »
A draw a ship "with added modules", you can simply use multiple sprites (one for each "part" - the ship and each module), each with different origins to "push" them to their position on the ship. Then, if you apply the same transformations to all the "parts", they will move and rotate together. To simplify this, you can create a class that stores all of these sprites and provide transformation functions that just "pass through" and duplicate onto all of those sprites. That way, you only need to transform the one class.

Taking this further, you may consider using a vertex array, which allows multiple primitives (triangles or more likely quads in this case) to be drawn to the screen buffer at one time. If you have very many sprites (hundreds) on screen at once, this may be necessary but for an Asteroids-style game, using a few extra sprites - as mentioned in the paragraph above - should be just fine. Plus, it is the simplest way!
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

UchihaKite

  • Newbie
  • *
  • Posts: 33
    • View Profile
    • Email
Re: AW: [Question/Request(?)] Modular Spaceship
« Reply #3 on: September 14, 2016, 04:05:20 am »
You could go with predefined origin or calculate a center point at ship creation. Additionally you'll want to write a function that either returns the bounds of the ship or checks collision with the ship's shape.

As for modules, you could just provide base ships with various slots that can be filled with different modules and once that works maybe allow slots on modules themselves. Just make sure that modules have actually some meaning otherwise it becomes a bit pointless. Additionally you could add module requirements for a ship, e.g. you need to have an engine module and a controll module or something like that.

Last but not least don't forget that suvh a module system can get very complex. So it's best to pick the smallest thing you could think of first and try to implement that. Don't try to get "the" system done. ;)

A draw a ship "with added modules", you can simply use multiple sprites (one for each "part" - the ship and each module), each with different origins to "push" them to their position on the ship. Then, if you apply the same transformations to all the "parts", they will move and rotate together. To simplify this, you can create a class that stores all of these sprites and provide transformation functions that just "pass through" and duplicate onto all of those sprites. That way, you only need to transform the one class.

Taking this further, you may consider using a vertex array, which allows multiple primitives (triangles or more likely quads in this case) to be drawn to the screen buffer at one time. If you have very many sprites (hundreds) on screen at once, this may be necessary but for an Asteroids-style game, using a few extra sprites - as mentioned in the paragraph above - should be just fine. Plus, it is the simplest way!

Thank you both so much for replying to my topic, I know I sometimes ask the most random things, but it truly means a lot that you both take the time to reply to my questions. Because it seems whenever I have a question you two are one of the first to reply lol

After my class on Saturday and I get the AI worked in, I am going to work on this. I will be sure to let you guys know how it goes and if I have more questions.

I was hoping to create some type of menu for the selection of parts, like IMGUI or something, but I'm not entirely sure which GUI would be the simplest to use @_@