Rougelike Help

I’ve thought of making a turn-based roguelike similar to PokeRogue but with characters from another game (not thought out yet). I think things like the menu and all are manageable, but I need help coming up with battle code, such as swapping in and out characters, storing items during a run, and most importantly the “ai” to control the enemy. I want the “ai” to know which move is the best to use in certain situations, like choosing a move that would defeat a character over a move that wouldn’t. If there’s any extensions, or if you’ve done something like this before, please give some suggestions :smiley:

1 Like

This is interesting. I would suggest pining admins/game jam winners or well known makecoders for this

I don’t know most of them so uhh help if you can lol

Can I help?

Ok uh. I’d suggest @Brohann @randomuser or @richard for this

1 Like

Hmm well if it were me, I’d think about how I want to store all this information, first off. What stats will a creature/character have? What abilities? How are those things recalculated when they level up? Etc. You’ll want some sort of data structure to hold all that information.

You could pick between a dictionary and a class I think, but if I were you, classes are the best thing to learn as a transferrable skill (useful in other coding languages). You may need to be in javascript mode to program them - I haven’t tried in blocks.

Here’s a w3schools tutorial on typescript (the kind of javascript Makecode uses) classes

Once you learn about them, you’ll start thinking of so many things in terms of classes. What if you stored information for different attacks in a class called Move?

class Move {
    constructor(name:string, type:string, damage:number, accuracy:number, effect:string, effectChance:number) {
        this.name = name;
        this.type = type;
        //and so on
    }
}

And maybe a creature/character class that was something like

class Character{
    constructor(species:string, nickname:string, type:string, level:number, hp:number, attack:number, defense:number, speed:number) {
        this.species = species;
        this.nickname = nickname;
        //and so on
    }
}

And so far all these are doing is storing information - but your AI needs information to figure out which move is best, right? Let’s make a pretend function for using a move

function UseMove (move:Move, attacker:Character, defender:Character): number {
    if (move.damage > 0) {
        let damage = (attacker.atk * move.damage) - defender.defense;
        return damage;
    }
}

This is a super basic version of a damage calculation that you could run wherever you want in your code. It doesn’t include an accuracy check or crit chance or damage variance or anything that the actual Pokémon games do - you’d have to look up those formulas if you want to copy them, but I’ll warn you - they’re not simple.

Basically your AI can call this function for each of its 4 moves and then pick the one that returns the highest damage to actually perform.

That’s just scratching the surface, but I hope it gives you an idea of where to go from here. Maybe try looking up typescript class tutorials on youtube?

4 Likes

By any chance, are you a teacher

@ChimbroDaPro could help he is very smart

I taught middle school comp sci last year and used Makecode Arcade for our game dev unit. This year I teach 9th and 12th grade comp sci :slight_smile:

I have a degree in game dev, and love sharing my knowledge with people.

2 Likes

I can help if you need, although it seems @MrJones jones has done an amazing job getting started! :laughing:

1 Like

BRO MY TEACHER IS NAMED MR JONES. AND HIS A COMP SCIENCE 9TH GRADE! (Sentence)

5 Likes

after spring break ask him if he’s @MrJones that would be crazy

3 Likes

I will lol

1 Like

Oh, uh, hi

2 Likes

hi too yo too

either use unsigned arduino’s https://github.com/UnsignedArduino/Inventory extension, or you could try coding yr own with arrays (might be better for flexibility)

for the enemy ai, lots of games have certain “weights” which go up or down depending on certain variables. These weights then influence what decisions the algorithm makes - makes it both kinda smart and also a bit random!
for example, you could have 4 different weights

  • attack
  • defend
  • heal
  • special

and a bunch of variables that influence it like

  • enemy/player health
  • type advantages
  • status effects
  • enemy features (offensive or defensive, weak or strong etc)

Each move could have a different combination of weight values which the enemy algorithm compares it’s own weights to pick the right move

at the start, the enemy’s weights might look like 5, 5, 0, 0
this means it’s move will be a random choice between it’s attacking and defending

but if it detects a type advantage it’s weights might change to 15, 5, 0, 10 (increase in defense, increase in special)
will be more likely to choose an offensive move or a special move (since it has an advantage)

if it takes damage maybe it changes to 1, 15, 15, 0 (increase in defense and heal, decrease in special and attack)
more likely to choose a defensive move to heal, or to block or maybe a move that does both

1 Like

Great explanation!! ^^

1 Like

*increase in attack btw

Ill consider this thx!

1 Like

Asked he said he owns one