Hi.
I've been programming with hugo for a few years (starting in 2010). I'm wondering how to implement combat in hugo games. Nothing tactical; just something other than "Attack x" or "attack x with y". I'm also wondering how to implement multiple weapons, for example: The player has a shotgun and a switchblade. An NPC breaks into his home and fires a shot with is 22. The player has the option to either shoot him with his shotgun or stab him with his switchblade. Any advice and/or information is appreciated.
Combat in Hugo Games: how to do it?
Moderators: Ice Cream Jonsey, joltcountry
-
- Posts: 2256
- Joined: Mon Apr 29, 2002 6:23 pm
- Location: Milwaukee
Welcome to the forum, Frobozz.
There are several aspects to doing the type of combat you describe. I'll go over some of them.
First things first, you'll need to declare some grammar for your code. For instance, your "shoot" verb definition might look like this:
Then, you might want to come up with some object classes (and maybe make up some new properties while you're at it), like:
(See also HbE's type entry)
Then you can make all of the guns in your game using that object class. Lastly, you'll want to make a verb routine:
Now, you could code your robber like such:
Now, that doesn't cover everything and I'm sure there are some bugs there, and there are other ways you could do it. You can also do a system where you character has weapons equipped which are automatically used when the player attacks.
Still, I hope that gives you some ideas about how you'd like to handle it for your game.
There are several aspects to doing the type of combat you describe. I'll go over some of them.
First things first, you'll need to declare some grammar for your code. For instance, your "shoot" verb definition might look like this:
Code: Select all
verb "shoot"
* DoVague
* object DoShoot
* object "with" held DoShoot
Code: Select all
property ammo
class gun
{
type gun
ammo 0
}
Then you can make all of the guns in your game using that object class. Lastly, you'll want to make a verb routine:
Code: Select all
routine DoShoot
{
! first, check that the player has a gun
local i , n
if not xobject ! if the player didn't specify WHICH gun
{
for i in player
{
if i.type = gun
{
xobject = i
n++ ! count how many guns we've found
}
}
if n > 1 ! more than one gun
{
"You'll have to specify which gun to use."
return false ! don't use up a turn
}
elseif not n
{
"You don't have a gun."
return false
}
}
elseif xobject.type ~= gun
{
"That doesn't make any sense."
return false
}
if not object.after
{
"Why would you shoot that?"
return false
}
return true ! take up a turn
}
Code: Select all
property hit_points
character ruffian "ruffian"
{
article "the"
adjective 0
noun "ruffian"
is unfriendly
hit_points 100
after
{
object DoShoot
{
if self is not living
{
"The ruffian is already dead."
return true
}
elseif random(2) = 2 ! hit the robber half of the time
{
"You hit!"
self.hit_points -= 50
if self.hit_points < 1
{
"The ruffian dies!"
self is not living
self.name is "dead ruffian"
self.adjective is "dead"
}
}
else
"You miss!"
return true
}
}
Still, I hope that gives you some ideas about how you'd like to handle it for your game.
- Tdarcos
- Posts: 9556
- Joined: Fri May 16, 2008 9:25 am
- Location: Arlington, Virginia
- Contact:
I'd go a bit further than Roody. In the routine DoShoot I'd add a check to make sure you have ammo and that you shot at a person. I'd also do the check for living there to reduce having to include it in every character that can be shot. These three tests would be inserted right before the object.after test, like this:
Doing it this way means you do not need to put the "self is not living" test in each character you could shoot at.
Or where I have the line that "you can only shoot at people." you could have the following:
Code: Select all
if i.ammo < 1
{
"You're out of ammo."
return false
}
if ((object.type ~= character) and
(object.type ~= female_character))
{
"You can only shoot at people."
return false
}
if object is not living
{
"The ruffian is already dead."
return false
}
if not object.after
{
"Why would you shoot that?"
return false
}
Or where I have the line that "you can only shoot at people." you could have the following:
Code: Select all
if ((object.type ~= character) and
(object.type ~= female_character))
{
i.ammo --
"The weapon makes a loud noise as the gun discharges, but it has no effect on the target other than to use up one round."
return true
}
"When I die, I want it easy and peaceful in my sleep, like my uncle.
Not screaming and crying like his passengers."
Not screaming and crying like his passengers."