Log In  

Cart [#19156#] | Code | 2016-03-10 | License: CC4-BY-NC-SA | Embed

What is it?

It's not a game, but rather a framework for a specific genre of games ala Pac-Man and Burgertime. It's a complete skeleton framework with all of the basic functionality to create these types of games.


  • A sample map with collision detection
  • Outside of map bounds = collision; nothing can move out of bounds
  • A player control system with automated assisted controls (it's difficult to line up exactly with a new corridor, so the controls will auto-correct to anticipate and compensate for this when a collision is detected)
  • Enemy AI and movement in "oldschool" style; it does not use A* or other complex pathfinding algorithms, but instead evaluates the closest next direction to move in when it detects an intersection, which is what the oldschool games did.
  • Enemy AI cannot reverse directions (classic Pac-Man Ai rule)
  • You can change the speed of the AI or player (as low as 0.1, and up to a speed of 2) without negatively affecting the collisions or AI.
  • Can easily support multiple AI-controlled units. Just call another eupd() for each of your AI characters.
  • It's currently 691 tokens

Planned features for future revisions:

  • Random map generation would be pretty cool as long as it doesn't make the engine much more token heavy than it already is.
  • I'd like to get it down to 500 tokens or less, if possible, which would definitely allow me to add more features comfortably.
  • Support for chase, scatter and scared (flee) modes?

I don't want to add too much more than that to it. It's intended to be small and then built upon on a case-by-case basis.

Known issues (updated Mar 8, 2016):

  • I don't think the AI will handle hitting a dead-end, so in its current form, I'm pretty sure any dead ends in your maps will break the AI (actually it might just start ignoring collisions and plow its way through the dead end). I just need to code in an exception to the rule that it can never reverse directions (and actually in Pac-Man for example, the AI could reverse direction during certain cases anyway, such as when you eat a power pellet, or on a timer where the AI enters 'scatter' mode).
  • A speed of 2 seems to be about the fastest that the collision system will support before it starts getting a bit wonky. 2 feels like a very fast speed though, so maybe I can let this bug slide for this use case. Let me know your thoughts.
  • A speed of less than 0.5 on the player seems to cause the assisted controls system to become unreliable. I'm not sure why anyone would want to make the player move around that slowly (seems it would be quite boring), but the issue is there nonetheless.
  • I'd like to improve the comments in the code. There isn't much there in the way of comments, and my naming conventions for variables and functions was mostly abbreviations or shortened versions of words, so it's not the most readable code in the world.

Can it easily support 8-direction movement, or is it just for mazes/corridors?

Yes, it can easily support 8-direction movement. Go to line 50, and change:

if(btn(0)) then p.x-=p.s
elseif(btn(1)) then p.x+=p.s
elseif(btn(2)) then p.y-=p.s
elseif(btn(3)) then p.y+=p.s


if(btn(0)) p.x-=p.s
if(btn(1)) p.x+=p.s
if(btn(2)) p.y-=p.s
if(btn(3)) p.y+=p.s

This will allow 8-direction movement for the player, and the AI supports it out of the box already. Be aware that enabling 8-direction movement in a corridor-based maze map such as the example provided, will sometimes cause players to move diagonally at intersections if they are holding down multiple directional buttons. The behavior feels weird in these types of games, so I have it set for 4-directions by default, but 8-direction would work well for roguelikes or Zelda-inspired adventure games.

What do I put for the CC-BY attribution if I use this in my game?

Just credit @clowerweb (my Twitter handle) as a programmer or something similar.

If you like the engine, or find any bugs or can help to reduce the token count or optimize performance, I'd love any and all input. I just started this project today and have no prior experience with Lua, so please forgive any herpyderpies. I hope to see some people make some great games with this!

Update March 9th: Reduced the token count from ~730 to ~690. No other major changes.

P#19115 2016-03-07 23:38 ( Edited 2016-03-15 12:01)

Found a simple case where the AI fails :P

But it's interesting anyways! Will take a look at the source.

P#19230 2016-03-14 22:27 ( Edited 2016-03-15 02:27)
:: Scathe

Yeah, it doesn't use A* or anything like that. If you Google "Pacman hiding spots", it shows the same "bug" in action there as well (pro players exploit it all the time as part of their strategy). Basically at the point where your character is standing in that gif, the AI has to evaluate whether moving up would be closer to the player, or moving down. It's looking at the tiles all around its current position and measuring their distance from the target, and taking the one with the shortest distance. Obviously the tile closer to the target isn't always going to lead it down the optimal path (or even a valid one, lol).

P#19235 2016-03-15 08:01 ( Edited 2016-03-15 12:10)

[Please log in to post a comment]

About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2019-09-23 09:26 | 0.031s | 4194k | Q:23