As requested in the Facebook group, here is a quick tutorial on how to spawn (near) unlimited monsters, and why that is not a good idea.
In my example, which will appear in my "Turtle Rescue" game, I will use a beehive that spawns bees. You may use this for other purposes. For my tutorial, I will use "beehive" to identify the monster that spawns, and "bees" to identify the spawned monster.
Before we begin, create your beehive and bee monsters. They should be in the same monster tileset. Bees will be set up to behave as any normal monster. They are fully capable to function on their own. Your beehive is a placeholder for right now. We'll apply additional functionality to it later. Remember bounding boxes, health settings and to make them monster types!
Assign the beehive to a monster group. It is actually not required to assign the bees to the same monster group as the beehive, but for testing purposes, you should add them as well.
Create a test screen, assign your new monster group to the screen's Day Monsters. Place a bee and a beehive on the screen. For testing purposes, you should place your player on the same screen as well.
Export and test your game. Nothing special should be happening at this point, You just want to confirm your bee is behaving as expected, and your beehive just appears. It's not supposed to do anything yet.
Now we need to get down and dirty with code... well, not really. There's not all that much, really.
First, create two user defined constants in Project Settings:
MON_SPAWN_MAX -- Value: 5 -- The number of monsters that will appear on the screen when the beehive stops generating bees. You can change this later.
MON_SPAWN_ID -- Value: ## -- The unique ID number of your bee monster. To determine this, go to your Monster Graphic Banks, Monsters list, and starting with 16, count the number of monsters down your list that your bee appears. For example, if your bee is the 5th monster, the ID value will be 20.
Now for the code itself!
Create a new SpawnMonsters.asm file in your AiScripts folder
Insert the following code:
Code:
;; JTS Spawn Monsters
;; In this case, spawn bees from beehive monster
LDA monsterCounter
CMP #MON_SPAWN_MAX
BCS labDoNotSpawn
labSpawnBees:
TXA
STA tempx
;; get offset
LDA Object_x_hi,x
CLC
ADC #$04 ;; arbitrário... colocaria um projeto 8x8 no centro de um objeto 16x16
STA temp1
CLC
ADC #$04 ;; arbitrário... colocaria um projeto 8x8 no centro de um objeto 16x16
Objeto LDA_y_hi,x
STA temp2
;; Use um dos dois comandos abaixo com base na sua versão
;; CreateObject temp1, temp2, #MON_SPAWN_ID, #$00 ;Use esta linha para 4.0.X
CreateObject temp1, temp2, #MON_SPAWN_ID, #$00, currentNametable ;Use esta linha para 4.1.X
labDoNotSpawn:
Temperatura LDX
[/código]
Salve seu arquivo ASM.
Abra as configurações do projeto / configurações de script e atribua seu SpawnMonsters.asm a um script de ação de IA aberto.
Você também pode renomear esse script de IA na guia Rótulos do projeto e, em seguida, Tipos de ação
Agora que o script está pronto, é uma boa ideia exportar e testar seu jogo novamente. Nada terá mudado, mas como adicionamos um novo código, é um excelente momento para ter certeza de que não quebrou nosso jogo.
Agora vamos começar a fazer dessa colméia uma máquina de desova de monstros!!!
Reabra seu monstro colméia. Deve ter dois estados de ação.
O estado de ação 0 terá um temporizador. No meu caso, usei 6. Você pode usar o que quiser e mudar depois. Isso controla o ritmo em que as abelhas aparecerão. Nenhuma ação é colocada neste estado. Selecione "Avançar" para a configuração EndAction.
Em Action State 1, selecione a nova ação para refletir o novo comportamento do SpawnMonsters AI. Altere a EndAction para GoToFirst.
Isto é o que dirá à colmeia para criar uma abelha e depois repetir novamente. A abelha não aparecerá se a tela já tiver MON_SPAWN_MAX número de monstros na tela. Mate uma abelha e outra aparecerá. A única maneira de o jogador parar as abelhas é destruir a colméia.
Construa seu jogo, e tudo deve funcionar como você espera. No meu GIF abaixo, mostro que você poderia gerar muito mais do que cinco abelhas, mas seria imprudente. O NES acabará por desacelerar, e também o jogador ficará sobrecarregado. Portanto, coloque um máximo razoável para deixar todos felizes.
Boa sorte!
ATUALIZAÇÃO: Obrigado a vanderblade por ajudar a testar isso. Eu criei isso em um módulo diferente do que muitos estão usando, então sua experiência pode variar.
[/QUOTE]
amazing