![]() |
Visual Baisc RPG attack combat system script Tutorial
As pointed out by bpd some code snippets are taken from Visual Basic Game Programming For Teens book.
Hello guys im going to show you all a script that most begginer game VB programmers use for a combat system this is one of my scripts i ever used in the line of combat systems. Step 1. Engaging in CombatThere are two basic things you need to do to allow the player to fight with NPCS: 1.Make sure the player is close enough to an enemy to hit him. 2.Make sure the player is facing an enemy while attacking. If you can take care of these two problems, then you can create a combat system for the game. Tackle these two key problems in order. Step 2. The first thingThe first thing you need to check on before you can handle a combat strike is whether the player is close enough to an enemy character to actually hit him. That is accomplished with a simple call to the Collision function. If there is no collision between the two sprites, then there definitely can't be an attack, and the swing misses! After determining if the two sprites are close enough for an attack, see if the attacker is at least facing the enemy. I wrote a function called IsFacing that returns True or False depending on whether one sprite is facing another sprite. This is also useful for pitting NPCs against each other, not just for the player. ===================================== CODE ===================================== Code:
Public Function IsFacing( _Step 3. Managing the Player's StateAfter you have the combat code ready to go, There's just one little problem: The source code writing in the game so far just draws the walking version of the player. With combat, the player has to swing his weapon too. The main game loop has to be modified so that you can check the player's state and then draw either the walking or the attacking animations based on what the player is doing I modified the game loop so that all the player update code is replaced with a single call to UpdateHero, Which is listed here: ===================================== CODE ===================================== Code:
Public Sub UpdateHero()Step 4. Managing the Npc StatesAs you can see for yourself, there is a lot more to drawing the hero's sprite now that combat is involved.Now though, two different states have to be monitored and the correct sprite has to be animated. State engines are very helpful when you need to keep track of a uncomplicated series of conditions in a game, Because each condition is isolated from the rest, allowing you to write code for each condition separately. Here is the new List of states being use for each NPC: ===================================== CODE ===================================== Code:
===================================== CODE ===================================== Code:
Public Sonst NUMCHARS As Long =2Step 5. Checking for Attack Hits on NPCsThe section of code under the HERO_ATTACKING state includes a call to a subroutine called CheckForHits: ===================================== CODE ===================================== Code:
Public Sub CheckForHits()Step 6. Doing Damage to an NPCNow take a look at the AttackNPC subroutine that is called from the preceding routine you just looked at. This new routine is actually only called when the player has definitely hit an NPC. When this happens, the NPCS health needs to be cut down by an appropiate amount, and he dies if health is 0! aAttack NPC has some test code that prints a message above the player, and message above the target NPC during an attack, To tell you that hte game registered the hit. When the NPCS's Health reaches 0 the state of the character is set to NPC_DYING. ===================================== CODE ===================================== Code:
Step 7. Death SequenceThere is a death sequence where the NPC is frozen and fades into nothingness (a simple way to show that the NPC has died). If this happens, then h the NPCs state takes over the death allowing your players code to continue without worrying about dealing with the NPC's resting place. The state engine in characters.bas manages the state of the NPCs. When the dying state has played out (using a simple counter to keep the faded boyd visible for a short time), then the state of the bad guy is set to NPC_KILLED. This state triggers the calling of KILLNPC, Which Respawns the character. ===================================== CODE ===================================== Code:
Step 8. Moving the state-based NPCWith all theses different states to handle walking attacking and dying the code that moves and draws the NPCs has to modified to take them into account. Here is the current MoveNPCs subroutine, which is called by the main game loop" ===================================== CODE ===================================== Code:
Public Sub MoveNPCs()Step 9. Drawing the state-based NPCIn addition to moving the NPCs differently based on state, the drawing code also has to take into account that characters state. Different sequences for the walking and attacking animations have to be accounted for in the draw routine. This is where the dying sequence takes place as well. When the state is NPC_DYING the sprite is drawn using a gray color that renders the sprite with about 50% translucently. (the color is &H99FFFFFF, which has an RGB for white, but a 50% alpha or thereabouts.) ===================================== CODE ===================================== Code:
Public Sub DrawnNPCs()As long as your attacking them, the NPCS fight back. The alpha channel support is utilized by drawing the NPC in ired when the NPCS are engaging the player in combat. I wanted to clearly show when an NPC is attacking your player because the attack animations are so similar to the walking animations; its hard to tell exactly which NPC is fighting back. The red coloration of the sprite is a fantastic effect in fact i like it so much that i think it should be a part of the game and left in place it would be cool to use this coloring effect for other states and you can use it with some great results for things like spells and so on. As you know the NPCs need to be drawn even when they arent just walking or attacking, Because the other states ( such as NPC_TALKING) must habve the sprite being updated on the screen. DRAWNPC checks for new states and then assumes NPC_WALKING for any state that is not explicitly programmed to handle everything else that the NPC might be doing. If you add animations to the NPCs you need to add the state condition here to account for it ===================================== CODE ===================================== Code:
NOTE:NO ONE IS ALLOWED TO COPY ANY OF THIS MATERIAL WITHOUT MY CONSENT PLEASE BE NICE AND LISTEN TO WHAT I HAD TO SAY I WROTE THIS TUTORIAL TODAY AND IT TOOK ME A LONG TIME PLEASE JUST DO NOT COPY IT IF YOU DO WITHOUT MY CONSENT PLEASE JUST GIVE ME CREDIDATION FOR MY WORK THANKYOU VERY MUCH |
Re: Visual Baisc RPG attack combat system script Tutorial
Did you use VB IDE to write codes because I see you End Sub casing does not match in many of the sub routines.
|
Re: Visual Baisc RPG attack combat system script Tutorial
No i just actually just typed all the craped in went over it once for grammer issues and just posted it if there is any errors in it feel free to edit it i as well will be looking over it now and be fixing more issues within the scripts
|
Re: Visual Baisc RPG attack combat system script Tutorial
Thanks to you :)
VB seems to be more complicated but the structure is clear so i can grasp it and adapt it in actionscript easily ...many thanks again |
Re: Visual Baisc RPG attack combat system script Tutorial
lol np mate i just go so bored today lol so i felt like making one of theses you dont see lots of articles out there that give you a article on a acttack script combat system lol also i sent you a message saying get on windows live messenger and add me as a contact scyther777@live.com i also have yahoo messenger so you pick lol
|
Re: Visual Baisc RPG attack combat system script Tutorial
I've added you as contact on messenger, and i try to send you the software i use for my game, but i have some problem to send it lol
|
Re: Visual Baisc RPG attack combat system script Tutorial
OPPS lol i forgot messenger my e-mail is scyther777@live.com LOL
|
Re: Visual Baisc RPG attack combat system script Tutorial
lol ok send you the software, and added your new adress in my messenger :)
|
Re: Visual Baisc RPG attack combat system script Tutorial
Quote:
For example:
You, sir, are, to put it kindly, a fraud. :disappoin |
Re: Visual Baisc RPG attack combat system script Tutorial
Hello im sry it took me to long to reply im on a vaction.
First i would like to say im very very VERY sry for all of this. I had no idea this book came from a book i had read it off a forum on another vb site.And i had ask the user if i could post it on go4expert.com. He replyed back and gave all information to me (as in i can state thats its mine) as well as i did add some text of my own in there. I would like to apologize for all of this. I know you might hate me now and probably wont forgive me but i feel as if i need to apologize for this im very very VERY sry as well i taking the initiative to tell the user of his copyright infringmant. Thankyou so much for telling me this im very very very sry |
| All times are GMT +5.5. The time now is 06:20. |