Author Topic: Programming RPG's...  (Read 5380 times)

0 Members and 1 Guest are viewing this topic.

Alex

  • Guest
Programming RPG's...
« on: May 19, 2006, 05:39:00 am »
Someday (far far away) I might start working on an RPG game for the 68k's. I know how a tilemap works, but specific events triggered by certain locations have me stumped. Let's say you walk over a tile that has a door drawn on it - how do you go to another room by passing through the door? I have the idea of having a tilemap of events over the graphics tilemap, and have each number on the event tilemap assigned to a sub-program/function that would handle that event. Not very flexible, but should work.

What methods do you use?

- Alex

Offline tifreak

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2708
  • Rating: +82/-3
  • My Kung Fu IS strong...
    • View Profile
    • TI-Freakware
Programming RPG's...
« Reply #1 on: May 19, 2006, 06:18:00 am »
Well, I program Z80 basic, though the principle should work just the same for 68k basic (and the asm and C languages as well).

Inside the walking engine, I have the calculator do a check to see if the tile that the character is currently sitting on is a tile that would take it to a different area, or for that matter, have it do something else entirely. It just depends on the situation.

Anyways, it checks to see if it equals that particular tile, either by numerical value, or by a character representing it, depending on hit detection methods. If the boolean is true, then it calls another program, to do the redirect from there, allowing the engine to stay fairly small, and not become bloated with that other code.

Do you understand, or would you like me to provide sample code (it would be in z80 basic)??
Projects: AOD Series: 75% | FFME: 80% | Pokemon: 18% | RPGSK: 60% | Star Trek: 70% | Star Trek 83+: 40% | TI-City: 5%

Alex

  • Guest
Programming RPG's...
« Reply #2 on: May 19, 2006, 08:13:00 am »
Let's see if I get this right:

Tilemap:

000000000
008000000
000000900
000000000
000000000


Pseudo-code:

if(tile_player_is_on == 8) subprogram()
else if(tile_player_is_on == 9) subprogram2()


subprogram and subprogram2 contain the redirect or specific data that I want to happen when the player is on that tile.

- Alex

Offline tifreak

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2708
  • Rating: +82/-3
  • My Kung Fu IS strong...
    • View Profile
    • TI-Freakware
Programming RPG's...
« Reply #3 on: May 19, 2006, 08:43:00 am »
Sort of...

to make it easier, and the engine more compact, I have it do this:

If (Char Position) != 0: prgmEvent

This works wonderfully, as long as inside the movement, you restirct where the character can go.

Inside prgmEvent:

If (Char Position) = 8: Deal with Event
If (Char Position) = 9: Deal with Event
etc...

prgmEvent also redirects to another program, if neccessary. I have found this increases the speed of things on the z80, though I have only made a couple progs on the 68k basic, so I don't know a whole lot about it...
Projects: AOD Series: 75% | FFME: 80% | Pokemon: 18% | RPGSK: 60% | Star Trek: 70% | Star Trek 83+: 40% | TI-City: 5%

Liazon

  • Guest
Programming RPG's...
« Reply #4 on: May 19, 2006, 09:25:00 am »
It looks like a switch/case structure would be a tempting idea.

hey, btw Alex, can you use run a function if you know the pointer to the function, or can that only be done in 68k ASM?

Alex

  • Guest
Programming RPG's...
« Reply #5 on: May 19, 2006, 09:37:00 am »
Pointers to functions seems like the way to go. I sure that it can be done in C, but I'll have to look it up.

Let's say tiles with number greater than 0 are event triggers on the event tile map:

void function(void) {
 //do something
}

void function2(void) {
 //do something else
}

void* functions[2] = { function, function2 };

...

if(tile > 0) functions[tile];


Of course, this code is wrong, but that's the structure I'm going for.

Keep the ideas coming, and thank you everyone!

- Alex

Alex

  • Guest
Programming RPG's...
« Reply #6 on: May 19, 2006, 10:36:00 am »
I just found something: http://www.newty.de/fpt/fpt.html

In C it would be:


void function(void);
void function2(void);

void (*functions[2])(void) = { NULL };

functions[0] = &function;
functions[1] = &function2;

...

if(tile > 0) (*functions[tile])();


It should work in TIGCC, perhaps with a little tweaking of the pointer casts.

- Alex

saubue

  • Guest
Programming RPG's...
« Reply #7 on: May 19, 2006, 11:58:00 am »
Good idea! It seems like I can also implement this into Shadow Falls for some optimization :)smile.gif

Offline Fryedsoft

  • LV3 Member (Next: 100)
  • ***
  • Posts: 90
  • Rating: +2/-0
    • View Profile
Programming RPG's...
« Reply #8 on: May 19, 2006, 12:04:00 pm »
# (Indirection) and Expr( are your best friends on the 89, but in this case Expr( is.

basicially...
c1-->
CODE
ec1
If (tilenumber) != 0
expr("run"&string(tilenumber)&"()")
c2
ec2
if tilenumber = 5, the expr command will execute run5. 6 will execute run6, ETC. if you put a variable between the "()" (say Tilenumber for example) it will send that variable to the program, so if tilenumber was 6, it would be execute run6(6).

Liazon

  • Guest
Programming RPG's...
« Reply #9 on: May 19, 2006, 02:10:00 pm »
QuoteBegin-Alex+May 19 2006, 04:36 PM-->
QUOTE (Alex @ May 19 2006, 04:36 PM)
I just found something: http://www.newty.de/fpt/fpt.html

In C it would be:


void function(void);
void function2(void);

void (*functions[2])(void) = { NULL };

functions[0] = &function;
functions[1] = &function2;

...

if(tile > 0) (*functions[tile])();


It should work in TIGCC, perhaps with a little tweaking of the pointer casts.

- Alex  

 Awesome!! no idea how this code works, but I'll figure it out.  I made the suggestion only because in z80 ASM, you could probably store the location of a function/label into a variable, and then jump to that function.

So, the ASM would look like a switch case block where each option stored a different function location/address to the address variable that the main funtion will jump to.

Probably could be simplified more though in ASM.  I guess it's this freedom that I enjoy about ASM.  It's the huge amount of code in ASM that makes me prefer the niceness of C.  :)smile.gif:)smile.gif:)smile.gif

Alex

  • Guest
Programming RPG's...
« Reply #10 on: May 19, 2006, 02:37:00 pm »
Yea, there's something about nicely structured, tabbed C code that screams "pure logic!". :)smile.gif

- Alex

Dragon__lance

  • Guest
Programming RPG's...
« Reply #11 on: May 19, 2006, 03:38:00 pm »
hey guys, correct me if i'm wrong:
In z80 ASM, wouldn't you use vector tables to do the jumping for doors and such in a tilemap routine?

Liazon

  • Guest
Programming RPG's...
« Reply #12 on: May 20, 2006, 05:32:00 am »
Maybe that's what it's called.  I haven't looked at z80 ASM in ages XDsmiley.gif.  

Either way, it's the idea that labels are address/pointers to functions, which in ASM can be used as a jump location.  I just wasn't sure if it could still be done in C. otherwise a most likely bloated C if else structure would probably be needed.

saubue

  • Guest
Programming RPG's...
« Reply #13 on: May 20, 2006, 09:32:00 am »
QuoteBegin-Alex+May 20 2006, 03:37 AM-->
QUOTE (Alex @ May 20 2006, 03:37 AM)
Yea, there's something about nicely structured, tabbed C code that screams "pure logic!". :)smile.gif

- Alex  

 Right, but I like C++ more, because classes make it even more logical to me. That might by a reason why I like using typedef structs in my C projects... :Ptongue.gif

Alex

  • Guest
Programming RPG's...
« Reply #14 on: May 20, 2006, 10:20:00 am »
Yea, structures are great. I just recently started using them for File I/O, but I'm sure that gradually I'll use them more and more.

- Alex