World States [several questions]?


#1

Hi, this is my second thread since I’ve been infatuated in creating a JRPG using FlashPunk. Still a beginner but I’ve been fiddling with various tutorials thus learning few terminologies. So here are my questions:

(1) Can I code multiple entities inside a single “Enemy.as” class?

      public class Enemy extends Entity
    {
	public function Dragon
	{
		...
	}

public function Demon
{
	...
}
...}

(2) Does a World.as equivalent to one map/state (e.g. house1, house2, battle, party menu, world map, local map, main menu)?

(3) Can I cycle each state (above examples) in FP during the game? What library of codes do you use when I press a key to main menu? to party menu?

(4) How do you put a simple background?

(5) How can I set a town bigger than the Flash’s window size while the Player entity ventures in it? I think it has something to do with the Camera function.


(Bora Kasap) #2

Oh, you have so many questions, i think it’s better you work on existing tutorials for now, and some practice, it looks like you’re asking these questions so early… If staff try to answer your questions here, it’ll look like almost a big flashpunk tutorial…


#3

Big thanks for the fast reply :smiley: I guess I could limit my priorities on question 1 or 2.


(David Williams) #4

I’m by no means an expert, but let me see if I can help.

1.) Entities only have one update function, so no. However, what you can do is make a Base Class. Say you want all enemies to have a health variable, attack damage variable, movement logic, etc… Well, you could make a class called ‘Enemy’ that has all of these variables (preferably public var’s), and then for your specific enemies, such as Dragon and Demon, extend the ‘Enemy’ class rather than the ‘Entity’ class.

2.) Yes and no. If you would like to set it up that way you can, or you can only have one world with all of your game’s logic. I recommend what you suggested, multiple worlds for multiple levels.

3.) Well, say if you had it set up so that level 1 was class Level1 and level 2 was class Level2. After you beat level 1, you could call FP.world = new Level2();. I usually have my main menu as its own world. For the party menu, I think I would have that as it’s own entity inside of the current level world that would update only under certain circumstances (such as a key being pressed).

4.) For this, in your world’s added function, you can use the addGraphic(...) function to easily add a background. Another approach would to create an entity class that’s graphic was the background, and just add that to your world at (0, 0).

5.) Check out this forum post: Best way to have the camera follow my hero . It talks about getting the camera to follow the player. Then you can just set it up to where your player can’t go outside of however big your world’s boundaries are.

Hopefully this will help you if even a little bit. Good luck and welcome to Flashpunk.


(Abel Toy) #5

I’d like to add to Deamonr’s answer that maybe you could have a GameWorld for all your levels which loads the data for each level.


#6

Thanks guys. I now have a rough sketch in my brain on how I’m going to code it. Thanks again.


(Zachary Lewis) #7

Think of the World class as a state definition.

Looking at your plan, you’ll probably have some of the following worlds:

  • MapWorld — Displays the map, player and NPCs to interact with. This is where most of the adventuring logic will be handled and can load in any map for the user to explore.
  • BattleWorld — Displays the heroes and the enemies as they fight. This is where battle logic is handled.
  • MenuWorld — Displays the main menus, allowing the player to equip the party and use items. This is where the menu logic is handled.

#8

Thank you zachwlewis! I will keep this in mind. I decided to separate the worlds.as from the specific states, that is MapWorld, BattleWorld, MenuWorld, etc.