Sunday, April 11, 2021

Procedural Buildings: Object Interaction

I'm continuing to work on my game where the player steals valuable items from houses and office buildings while avoiding zombies. My goal is to make almost every object inside the building both something the player can steal, and something the player can interact with either before or after stealing it. I also want to make this as silly as possible rather than a horror game. I started with the basic set of player object interactions required for gameplay, and some other easy ones, which were implemented earlier:

  • Picking up objects
  • Opening room, closet, and bathroom stall doors (which may be locked)
  • Opening and closing dresser, desk, and nightstand drawers
  • Turning on and off ceiling room lights and lamps
  • Throwing and kicking basketballs and soccer balls
  • Drinking beverages (wine, beer, Coke, water, and newly added poison)
  • Riding elevators up and down
  • Spinning office chairs

This time I've added many more object interactions to increase the fun level. Why stop at stealing when you can trash someone's house in the process? Add graffiti, make a mess, and run up their utility bills. The zombies won't care, but when those people return to their houses after the invasion, won't they be in for a surprise!

  • Basketballs and soccer balls can now be thrown at zombies to make them temporarily retreat 
  • Spray paint cans that can be used to add graffiti to walls, ceilings, floors, and other flat surfaces
  • Markers that will draw on walls, ceilings, floors, whiteboards, pictures, rugs, mirrors, etc.
  • Turn sinks on and off (to waste water)
  • Flush toilets (to waste water)
  • Pull toilet paper off the roll (future work: wrap toilet paper around objects)
  • Tilt pictures hanging on the wall
  • Various other objects make sounds and/or animate
  • Player can use elevator buttons (fully functioning elevators are in the planning stage)

None of these really affect gameplay, except for the first bullet point where hitting a zombie above the legs with a ball will cause it to retreat for a few seconds. This gives the player some time to get away. I might add other throwable items, such as books, at a later time. None of these interactions affect the value of items the player has or the player's survivability.

Spray paint and markers are my favorite so far. My daughter Kate also loves to make her artwork in the office buildings. Too bad I haven't implemented a save system for this yet! The player must first find a can of spray paint or a marker on a storage room shelf or in a desk drawer. These will be a color randomly chosen from a set of common colors for those items. Picking up this object will allow the player to carry it around and use it with the action key.

Each key press (or each frame if the key is held down) will generate a circular spot of color as long as it's not too close to the previous spot (optimization). Spray paint and markers have a max range and will only write on certain types of large, flat, static objects. This includes walls, ceilings, floors, windows, mirrors, bathroom stalls, cubicles, stairs, elevators, rugs, pictures, and whiteboards. Each spot is an alpha blended point sprite quad drawn with a circular blur texture. Multiple points placed near each other will merge into solid lines of color that look like real brush strokes. These are oriented in the direction of the surface and shifted a bit in front so that they're drawn on top as decals. The draw order is preserved for blending, so the player can paint over existing spots with new colors. Spray paint that's sprayed from far away creates a larger but lighter circle, while close up sprays produce smaller and stronger color spots.

These quads are stored in a dynamic buffer and sent to the GPU each frame. I could probably break them up into blocks and store them on the GPU in VBOs as an optimization. For now it seems to be fast enough that this isn't needed, unless I really expect players to spend tens of minutes painting the walls. The graffiti will remain in the building until the player starts drawing in some other building. I only allow graffiti in one building at once for now, as an optimization. Paint and marker can be seen through the windows and open doors of a building. Here is an example of my artwork:

Inspecting my artwork in this office building hallway. All it took was three cans of spray paint and a dry erase marker.

Markers will write on whiteboards, but they write just fine on the walls as well. If you take your time it's possible to create very accurate and detailed drawings. The capacity of a spray paint can or marker is large enough to create quite a bit of color. At this point there's no way to erase them, so you need to be careful not to make a mistake.

I left a surprise for someone to find when they get back to the office after this zombie invasion.

Toilet paper rolls can also be taken off the holder and used. (The holder can be stolen as well.) I haven't quite figured out how to use toilet paper, other than pulling it off the roll down to the floor. I was thinking that I would have the action key wrap toilet paper around objects. Or maybe the roll can be thrown and will trail toilet paper behind it. I guess we'll see what I end up doing.

Here's some graffiti to point out that the roll of toilet paper can be taken for some extra fun.

[Yes, the toilet paper roll is attached to the block window. The house near the player starting position is the only house I've seen that's like this. This looks bad for normal transparent windows, so I remove the toilet paper in those cases. But a roll on a glass block window isn't as bad. Maybe it's glued on? So I allow it.]

The player can turn bathroom/kitchen sinks and tubs on and off. The sound of running water is played for a few seconds when these are turned on. I've considered letting the sound play in a loop while the water is running, but I'm not sure how practical it is when the player can turn on every sink in a building. Maybe it should only play when the player is in the bathroom? I don't know, it still seems like the sound would be annoying. I've also added an animated stream of water coming from bathroom sinks when they're on. Here's a screenshot, though you can't really see the animation in the water.

I turned on the water in this sink. You can see the reflection of the previous screenshot in the mirror.

It's silly to tilt the pictures in someone's house after you've stolen all of their valuables and drawn all over their walls. However, this was fun and easy to add.

Does that picture look crooked to you? I swear it was like that when I got here!

The next item on my list is working elevators. I currently have elevators that will move up and down based on the direction the player is looking. I want to add real elevators with call buttons on each floor and a button for each floor inside the elevator. These will control the vertical position of the elevator and the opening and closing of its doors. I've added the call buttons, and they do light up when pressed, but they have no effect on elevators at this time. This is intended for use by the player and not building AI people. Implementing all of this could be time consuming, but sounds like another fun and interesting mini-project.

I really should record another video of all these building interactions. I wish I could figure out how to make audio recording work so that I can show off all the sound effects I've added. Maybe I'll put a video up on YouTube once I get elevator buttons working.


  1. I wonder how hard it would be to add a "vandalism" tally, which counts up how much money it would cost to repair the damage you did. What about a "ransack" count, for moving items from where you find them to other hidden locations (drawers, closets, etc) so the owners can't find them when they get back?

    1. I think I just might add that. Maybe something like "damage", that includes both the value of items the player stole or destroyed, and the cost of repairs to other damage. I don't see how that would be used in gameplay, but it's a fun stat.

      The owners will never get back though. Everyone but the player has turned into zombies. That makes the game even more silly: You're the only person left alive and your goal is to steal things you don't need, from people who will never need them, so that you can make money you can't spend! Now maybe if the player's goal is to find the cure, as in your other comment, then this would make more sense.

    2. I added a damage counter. It doesn't affect gameplay, it's just some info shown on the bottom of the screen (which is getting pretty crowded). This includes the value of items stolen, used/consumed, or broken. It also includes cleaning cost for spray paint and markers, and a $100 cost for cleaning up the blood the player leaves when they die. Though the damage does reset on player death, so that's kind of pointless, but the blood is never reset.