News: 11 March 2016 - Forum Rules

Author Topic: Battle System created by me.  (Read 5251 times)

InfamousKnight

  • Sr. Member
  • ****
  • Posts: 321
    • View Profile
Battle System created by me.
« on: July 28, 2012, 06:12:34 pm »
I made this without any help. You have 3 allies and 2 enemies. The enemies are fairly easy since the battle I provided doesn't take much strategy.

http://pastebin.com/Dcs8dARC

Make sure you have negative strenght values for damage then positive values for healing. Yeah, I plan on combining this with my other projects. It'll be a huge source file!

I updated the code:

http://pastebin.com/eU3mK2Pj
« Last Edit: August 23, 2012, 01:07:53 pm by InfamousKnight »

Klarth

  • Sr. Member
  • ****
  • Posts: 498
    • View Profile
Re: Battle System created by me.
« Reply #1 on: July 28, 2012, 07:42:16 pm »
May I suggest creating an array of structs that contains all ability names, function pointers to a damage calculation function, so you can clean up your battle loop?  Also, you don't need to seed your random number generator before every time you use it, just once at the start.  Looks like you have a good start, but if you want to make the game more complex, you really need to refactor your code to be more organized.

Rhys

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • CN
Re: Battle System created by me.
« Reply #2 on: July 29, 2012, 09:34:34 am »
Seeding all depends on how random you want your numbers, if the random function is good then it usually ends up using crypto routines to take care of ensuring your numbers are random, a lot of the simpler functions however just base it off of some math done with the current timestamp, and in those cases you'll definitely want to generate a new seed after each use, .NET's Random class is one example of this.

LostTemplar

  • Hero Member
  • *****
  • Posts: 910
    • View Profile
    • au-ro-ra.net
Re: Battle System created by me.
« Reply #3 on: July 29, 2012, 09:39:57 am »
May I suggest creating an array of structs that contains all ability names, function pointers to a damage calculation function, so you can clean up your battle loop?

Or just polymorphic classes, as he is using C++ anyway.

Rhys

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • CN
Re: Battle System created by me.
« Reply #4 on: July 29, 2012, 02:08:42 pm »
C++ Polymorphism gives me nightmares :(

Ryusui

  • Hero Member
  • *****
  • Posts: 4989
  • It's the greatest day.
    • View Profile
    • Tumblr
Re: Battle System created by me.
« Reply #5 on: July 29, 2012, 03:38:19 pm »
It's simple enough, really.

In game development, you might have a "Game Object" class with a function called "Update" which handles everything a given object needs to do on a given frame. The game's main loop calls "Update" on every single Game Object (or, if we're clever, just the ones on screen), but the twist is that we don't actually use the base Game Object class - we use derived classes, like "Player" or "Bullet" or "Powerup" or "Enemy," which override "Update" in their own specific ways. When you tell a Player to Update, it might read the controller/keyboard input and move accordingly; when you tell an Enemy to Update, it might follow its AI instead. The point, however, is that each of these objects can be treated as a "Game Object" by the rest of the program; they feature the same functions, even if what those functions actually do is different.
« Last Edit: July 29, 2012, 05:38:02 pm by Ryusui »
In the event of a firestorm, the salad bar will remain open.

Rhys

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • CN
Re: Battle System created by me.
« Reply #6 on: July 29, 2012, 05:17:18 pm »
The problem with C++ Polymorphism is STL containers become completely useless, if you want to store derived types you're in for a world of hurt

Trax

  • RHDN Patreon Supporter!
  • Hero Member
  • *****
  • Posts: 609
    • View Profile
    • Trax ROM Hacking
Re: Battle System created by me.
« Reply #7 on: July 29, 2012, 08:26:36 pm »
Polymorphism is a lot easier (and intuitive) with Objective-C...

InfamousKnight

  • Sr. Member
  • ****
  • Posts: 321
    • View Profile
Re: Battle System created by me.
« Reply #8 on: July 29, 2012, 10:46:36 pm »
It's simple enough, really.

In game development, you might have a "Game Object" class with a function called "Update" which handles everything a given object needs to do on a given frame. The game's main loop calls "Update" on every single Game Object (or, if we're clever, just the ones on screen), but the twist is that we don't actually use the base Game Object class - we use derived classes, like "Player" or "Bullet" or "Powerup" or "Enemy," which override "Update" in their own specific ways. When you tell a Player to Update, it might read the controller/keyboard input and move accordingly; when you tell an Enemy to Update, it might follow its AI instead. The point, however, is that each of these objects can be treated as a "Game Object" by the rest of the program; they feature the same functions, even if what those functions actually do is different.

With controller/keyboard input, it would be hard to wait for input when its the allies turn. I tried it in VB and no luck. I don't have much experience with SDL but I should learn it. In-fact, I can't do anything interesting with SDL with my little knowledge on it. I could use windows.h but I'm running lubuntu at the moment and I don't feel like going back to windows. I would like some graphics in this game.

Would anyone like to add graphics to this game? Its your choice. I would highly appreciate it though. You don't have to draw the sprites either. use videogamesprites.net for that.

InfamousKnight

  • Sr. Member
  • ****
  • Posts: 321
    • View Profile
Re: Battle System created by me.
« Reply #9 on: August 22, 2012, 05:29:28 pm »
Sorry about the double post: OP updated.