145 : Adding potions

Balthazar:

Copy the potion.png image into your images/items directory.

potion.png

Copy the following files into your project:

function init_level1() { ... var item_data = [ [480, 110, 18, 20, "key", "key"], [465, 170, 16, 23, "potion", "potion"], ]; add_items(level, item_data); ... }
function check_item_collisions() { var level = _levels[_game.current_level]; var items = level.items; for (var i = 0; i < items.length; i++) { var item = items[i]; if (!item.found) { if (collide(item, _player)) { if (item.type == "key") { level.player_has_key = true; } else if (item.type == "potion") { adjust_health(30); } else if (item.type == "finish") { _game.game_over = true; _game.game_win = true; } item.found = true; } } } }

Congratulations! You've earned the Treasure III - Potion badge!

GOTO 100