dMZX Forums: Enemy/Boss Tips? - dMZX Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Enemy/Boss Tips? Warning: LONG post with Coding

#1 User is offline   Zachski 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 41
  • Joined: 23-May 03

Posted 12 March 2007 - 08:54 PM

Okay, now... I've made an enemy, and I've made a boss. Now, they both work fine... I just want to see if there's anything more I can do.

Specifically, this is the basic enemy template, a grunt-type that's hopefully easy enough to defeat and simple enough.

I also have a rudimentary melee system that consists of touching the enemy, meant to translate into a "punch", or in a planned future case, a slash of an unsprited sword (although that's MUCH later.)

My comments from outside the game are done in \\

Robot's Name: Enemy
(real imaginative, huh?)
:start
rel to self
if c01 Normal p?? west then "start"

\\This is basically Enemy Genome Code.  Since I never plan to use that color Normal, 
\\I used it to keep the Genome still so it doesn't start attacking walls or something.
\\This code would really only be included where the number of this particular enemy 
\\isn't predetermined, for, let's say, a boss that can summon these.
\\This won't be actually included in enemies that are set in specific places on the map.

:start2
set local1 to 50 \\Enemy's HP, so I don't have to worry about multiple enemies getting their global counters confused.\\ 
go anydir for 1
if aligned then battlemodecheck
if c?? solid p?? is at -1 0 then goeast \\ 
if c?? solid p?? is at 1 0 then gowest \\ Wall protection.
if c?? solid p?? is at 0 1 then gosouth \\ Self-explanatory.
if c?? solid p?? is at 0 -1 then gonorth \\
goto start2
:battlemodecheck
if playerdist <= 30 then battlemode \\ If the player's close, it'll go into Battle Mode, which it can never actually leave.
goto start2
:goeast/west/north/south
go east/west/north/south 3
goto start2

\\They're not actually done like that, but I grouped it together so I have to type less and you have to read less.

:battlemode \\finally
if local1 <= 0 then gobye \\0 health means goodbye enemy
go randp seek for 1
wait 5 \\doesn't make the bot move so fast, so that it isn't that difficult
go seek 1
shoot seek
if c?? bullet p?? at -2 0 dodgenw
if c?? bullet p?? at 2 0 dodgenw
if c?? bullet p?? at 0 -2 dodgeew
if c?? bullet p?? at 0 2 dodgeew
if touching anydir fightback \\Yes, the robot can "punch" back.
goto battlemode
:dodgenw
go randns for 3
wait 15 \\when it dodges, it'll have a brief period where it's vulnerable.  I may consider removing the dodge equation entirely, though.
goto battlemode
dodgeew
go randew for 3
wait 15
goto battlemode
:fightback
wait 10
if touching nodir battlemode \\the player has a chance to get away
play sfx "4b3c2d" \\the default "hurt" noise is annoying, and doesn't really fit.
take (10 - 'playerdefense') healths
* "~COuch!  That hurt!" \\Player character complaining from the pain.
goto battlemode
:shot
play "4bxbxbx"
dec local1 by "((10 x 'havegun') - ('havegun - 1')" \\\Gun will be upgraded over time, and feature a bit of a sharper diminishing return
goto battlemode
:touch \\Punch!
play "dxxdxxd"
go opp seek 3
dec local1 by "((5 x 'playerstrength') - ('playerstrength' / 5)) \\Punches are weaker, but suffer less of a diminishing return. 
goto battlemode
:gobye \\It's time for the bot to die.
lockself \\prevents further player action from affecting it, of course
* "~8 3"
wait 15
* "~8 2"
wait 15
* "~8 1"
wait 15
inc enemydead by 1 \\For cases where you have to kill a certain amount of enemies for something to happen.  Will be disabled for cases that don't involve that.
* "~8 Explode!"
explode 3 \\I like explosions, what can I say?

More genome stuff that includes duplicate self stuff.


Alright then, that's the rudimentary enemy, and also the basic shell for any other enemies in the future.

Now for the Boss (and its helping bot)
BotName: TrainingGroundBoss
become a nonlavawalker \\I don't want the boss wandering into the lava that's around the stage...
end
:go \\A bot sends this to the boss when the player is in the arena.
lockplayer \\cinematic
(Skipping cinematic stuff)
unlockplayer
set local1 to 400
:battle
loopstart \\look!  I discovered loops 9_9
if local1 <= 0 die \\gotta have this.
go randpseek for 5
shoot seek
go seek 3
shoot seek
if touching anydir then #hurt \\Look!  A subroutine O_o
if local1 <=0 die \\secondary check
loop 20
loop start \\secondary attack start
lockself \\I do not want him interrupted here.
color c0f
wait 5
color c01
wait 5
loop 3 \\basically, he's announcing his attack.  I don't want him to be perfect, ya know.
unlockself
send "lazermine" to attack \\look at other code for info.
goto battle
:shot
play sfx "i5b"
* "~C Damn, he's immune!"
goto battle \\Can't defeat this boss by shooting him, but I want it made CLEAR to the player :P
:touch
* "~C Agh!  My Fist!"
take 5 healths
goto #hurt
goto battle
:#hurt
* "~C Argh!"
play sfx "ddxxddxxdd"
take 6 healths
go opp seek for 4
goto #return
:bombed
* "~1 Agh!  Damage!"
dec local1 by 30 \\He has a weakness!
goto battle
:die
lockplayer \\cinematic, skip!
(Snip)
:creatorcheat \\kill command starts here
send shield to shield \\Boss has a fancy exit involving explosions, I don't want it to hurt the player :P I'll eventually add an overlay to make the shield not so... ugly, though.
send fancy to fancy \\perpetrator of the fancy exit.
explode 15
(Insert kill command here for testing purposes, will DEFINATELY be removed in the final version.)


RobotName: LazerMine
Quantity: 2 (Somehow, I couldn't get a Lazermine to duplicate itself twice in a row... despite the fact that I had no problems with the Enemy up above)
:loop
if cf4 solid p?? north then loop \\Genome coding
wait 20
loop start
lazerwall to seek for 5
wait for 10
loop 10
explode 3
:attack \\sent from the Boss above, remember?
rel to player \\I think I love rel to commands now...
duplicate self at 1 0 \\First LazerMine has this......
(OR)
duplicate self at -1 0 \\and the Second LazerMine has this.
goto loop
:shot
color c0f
lockself
wait for 20
* "~F 5"
wait for 20
* "~F 4"
wait for 20
* "~F 3"
wait for 20
* "~F 2"
wait for 20
* "~F 1"
wait for 20
explode 10


Basically, the player doesn't have any bombs by the time he reaches the Training Ground Boss, so the trick is to use the boss's own attack against him.

Is there anyway I can make the coding better? The boss is supposed to be something of a challenge, but not very difficult because he's the very first boss.

Also, any suggestions?

Edit: *SNIP!*

Nevermind, Expressions, yada.

This post has been edited by Zachski: 12 March 2007 - 09:53 PM

0

#2 User is offline   hob nado 

  • Ancient Member
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 4,718
  • Joined: 23-September 00
  • Gender:Male

Posted 13 March 2007 - 01:32 AM

Without really reading these in-depth or anything, good use of subroutines there. =)

One pattern you might want to exploit in your enemy coding is a finite state machine - look it up on Google or some such for the details. Basically, you can think of the enemy being in different "states" of behavior (resting, attacking, running away, searching...) each represented by a labeled point in the code where that behavior happens. Then, different events such as getting shot, or reaching a certain health level, or the player being at a certain distance can cause a transition from one state into another. (If I'm attacking, and I get shot, go to the running away state!) It's a very clean and useful way to organize your code, and it'll allow you to keep track of everything better so that you can build more functionality on top of it without getting lost.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

3 User(s) are reading this topic
0 members, 3 guests, 0 anonymous users