Mystic Software Forums

Mystic Software => General Discussion => Topic started by: Tosoto on November 30, 2005, 12:33:11 PM

Title: (no subject)
Post by: Tosoto on November 30, 2005, 12:33:11 PM
Alright listen up, and don't laugh or I will strike you.

Despite all this time I've spent on this forum and playing around with the toolkit I still pretty much know nothing about making custom systems. Which is what I want to do.

What I'm basically asking is for someone to teach(tutor) me.

Any takers? I'd really appreciate help with learning more about RPG coding.
Title: (no subject)
Post by: Xorlak on December 01, 2005, 01:05:52 PM
I can usually be tricked into helping if the questions are small and evenly spaced out.  (Heh...)

Let's start with a simplified battle system shell.  The basic idea is to organize everything into smaller, easier to deal with methods (which in turn can be broken down further, and so on).  This is sort of how DAX's battle system is set up:

Code: [Select]
initialize()
battleover! = 0

while(battleover! = 0)
{
  playerturn()
  enemyturn()
}

endbattle()

That's it!  Well, not really.  (Heh...)  But the problem has been broken down into smaller parts.  Were to you want to go from here?  We could do the basics of a one-on-one battle system, just to get you used to things.  Or, we could do multiple players and enemies, which people tend to have trouble with.
Title: (no subject)
Post by: Tosoto on December 01, 2005, 02:18:42 PM
Well, if I learned how to make a 1vs1 battle system would it be difficult to expand it to bring in more characters and/or enemies?
Title: (no subject)
Post by: Number Eight on December 01, 2005, 10:08:06 PM
I beleive I made a one on one battle system a very long time ago, and the big X can correct me if I'm wrong, but I think it's fairly easy to add stuff once you've got the shell.
Title: (no subject)
Post by: AlienDude on December 02, 2005, 08:56:09 AM
Tosoto you can develop the framework to be as general as possible, maybe if you are lucky you can eventually have it so that it can be 30 vs 30! If you make the 1x1 work well you are a lot farther than you think, becuase you have a good foundation to pull from. Basically yeah work your way up.
Title: (no subject)
Post by: Xorlak on December 02, 2005, 01:07:37 PM
Making the jump from 1x1 shouldn't be too hard if you code it right in the first place.  You will have to add lots of #for loops, make some variables into arrays, add arguments to methods, etc. though.

Let's do 1 on 1 for now.  It'll save a lot of explanation and typing.  (Heh...)

First, let's sketch out what we need to do in initialize().

Code: [Select]
method initialize()
{
  getplayerstats()
  getenemystats()

  drawbackground()

  drawplayer()
  drawenemy()

  drawplayerstats()
  drawenemystats()
}

Now, we're getting to some stuff you should know how to do if you have some basic RPG Code knowledge.  Here's the methods we need to write:

getplayerstats() -- Might not be necessary, you could just have the player's stats in a series of global variables that you can access from anywhere, but I would recommend copying the variables at the beginning of each battle so that if you do status effects, you can easily reset them to normal at the end.

getenenemystats() -- Should take the literal variable 'enemy$' (probably passed to our battle system method or set before battle) and put its stats into variables.  There's a lot of ways to do this.

drawbackground() -- Take 'background$' (could be an image file, perhaps), and draw it to the screen.

drawplayer(), drawenemy() -- Draw the player's sprite and the enemy to the screen ( I would consider the enemy's graphic information to be part of it's stats, above)

drawplayerstats(), drawenemystats() -- Draw player/enemy stats in a box or something (if you want to show the enemy stats, that is)

You might need to use some canvases or savescreens in the draw functions.

Do you think you could write these functions, or do you want to go into some of them  in detail?  (Other people are free to help as well.  Heh...)
Title: (no subject)
Post by: Tosoto on December 03, 2005, 10:25:46 AM
Some details would be nice, maybe an example or two on some of them.

Yep. (I'm learning, yay)
Title: (no subject)
Post by: Dude Man on December 03, 2005, 11:29:03 AM
I'm interested in learning to. Judgeing it's been months since I've touched RPG Code.

Damn buggy TK3... <_<
Title: (no subject)
Post by: Xorlak on December 03, 2005, 02:01:49 PM
Okay, easy one first.

Just because you have one player, doesn't mean you don't have more than one character to play as.  First, let's set up the all characters' stat variables.  This would proably be in your start program.

I'm not going to get into classes right now, so let's just use global variables with maps (we can alway redo it with classes later, if you want.)

Code: [Select]
player_HP["Vance"]! = 100
player_MP["Vance"]! = 10
player_Attack["Vance"]! = 7
...
etc.

player_HP["Darius"]! = 110
player_MP["Darius"]! = 5
player_Attack["Darius"]! = 9
...
etc.

Now comes the getplayerstats() function in the battle system.  This will retrieve the stats for one particular character and put it into temporary variables the battle stystem will use.

Code: [Select]
method getplayerstats()
{
  name$ = playerhandle[0]$ // "playerhandle[0]$" is automatically the handle of the first player in your party (we'll only have one anyway since this is 1 on 1)

  player_HP! = player_HP[name$]!
  player_MP! = player_MP[name$]!
  player_Attack! = player_Attack[name$]!
  ...
  etc.
}

Now player_HP!, player_MP!, etc. are loaded with the correct player's stats.

Questions?  I'll do more later.
Title: (no subject)
Post by: Xorlak on December 05, 2005, 02:09:55 PM
This time let's draw the player's stats to the screen.  We'll draw a box on a canvas, write the player's stats on it, then draw the canvas to the screen.

Code: [Select]
method drawplayerstats()
{
  fontsize(16)

  // Our stat box is going to be 200 x 100 pixels
  // 'playerstats_cnv!' will be the ID for our canvas
  playerstats_cnv! = createCanvas(200, 100)

  bitmap("box.jpg", playerstats_cnv!) // 'box.jpg' will be our stat box background image
  text(2,1.2, name$, playerstats_cnv!)
  text(2,3, "HP: " + castlit(player_HP!) + " / " + castlit(player_MaxHP!), playerstats_cnv!)
  text(2,4, "MP: " + castlit(player_MP!) + " / " + castlit(player_MaxMP!), playerstats_cnv!)

  drawCanvas(playerstats_cnv!, 0, 0) // Draw the stat box in the upper left hand corner.

  killCanvas(playerstats_cnv!)
}

The text() commands will output the info in the form:

Brash
HP: 95/100
MP: 8/10

What's nice about canvases is that if you don't want the stat box in the upper left hand corner of the screen (0,0),  all you need to do is change the (0,0) in drawCanvas().  In TK2, you'd have to change all the text coordinates, etc.  You could get fancy and pass the (x!,y!) position to the function itself, if you want.

Actually, we're creating and destroying a new canvas every time we call this function (which will be a lot: we need to update the stats every time the player takes a hit or casts a spell).  It would be more efficient if we created the canvas once at the very start in our initialize() function and didn't destroy it until the battle is over.  So, we'll take that one out and stick it in initialize():

Code: [Select]
method initialize()
{
  getplayerstats()
  getenemystats()

  drawbackground()

  drawplayer()
  drawenemy()

  // Player stat canvas
  playerstats_cnv! = createCanvas(200, 100)

  drawplayerstats()
  drawenemystats()
}

And our shortened drawplayerstats() will be:

Code: [Select]
method drawplayerstats()
{
  fontsize(16)

  bitmap("box.jpg", playerstats_cnv!) // 'box.jpg' will be our stat box background image
  text(2,1.2, name$, playerstats_cnv!)
  text(2,3, "HP: " + castlit(player_HP!) + " / " + castlit(player_MaxHP!), playerstats_cnv!)
  text(2,4, "MP: " + castlit(player_MP!) + " / " + castlit(player_MaxMP!), playerstats_cnv!)

  drawCanvas(playerstats_cnv!, 0, 0) // Draw the stat box in the upper left hand corner.
}

And we know one thing needs to go in endbattle() (we'll need to add a lot more later)

Code: [Select]
method endbattle()
{
  killCanvas(playerstats_cnv!)
}
Title: (no subject)
Post by: Tosoto on December 06, 2005, 06:42:54 PM
Very interesting, I'll have to read it over a couple times, though.
Title: (no subject)
Post by: AlienDude on December 07, 2005, 10:39:07 AM
I believe it is also necessary to either savescreen() after all static elements are applied to the canvas, or clear(cnv!) at the start of the drawing command (drawplayerstats()). Unless there is a way that does not require it, then i am all ears. My cursor stuff will be a lot more manageable.
Title: (no subject)
Post by: TK Game Boy on December 08, 2005, 11:14:13 PM
I am making a BS tutorial right now. Heres a preview (not all images available):

<a href='http://jupiter.walagata.com/w/tkgameboy/tut_01.htm' target='_blank'>http://jupiter.walagata.com/w/tkgameboy/tut_01.htm</a>

When I finish it, you'll be the first to know.