Jump to content

Spawning Enemies from an array

prolemur

So I want to spawn enemies slowly at the start and then keep increasing the spawn rate according to the score. So at the start there is 1 and it keeps increasing until it reaches the maximum number of enemies.

 

At a score of 30, kbcur should equal 3 and only kb(1), kb(2) and kb(3) should be true and only these should be rendered and given a random coordinate to spawn.

/* Kamikaze Bombers' Variables */const kbmin : int := 1 % Minimum Kamikaze Bombersconst kbmax : int := 20 % Maximum Kamikaze Bombersvar kbcur : int := kbmax % Current Kamikaze Bombers Alivevar kb : array 1 .. kbmax of boolean % Alivevar kbx, kby : array 1 .. kbmax of int % X-location & Y-Locationconst kbsize : int := 10 % Sizevar kbspeed : int := 1 % Speedconst kbc : int := 42 % Colourvar kbnum : array 1 .. kbmax of int % Random Number Determining Spawn/* Spawn Kamikaze Bombers */procedure kbspawn    if kbcur < kbmax then        kbcur := score div 10        /*elsif kbcur < kbmin then         kbcur := kbmin*/    end if    % for every kb that is alive    % set a spawn pointend kbspawn/* Renders Kamikaze Bombers */procedure drawkb    for i : 1 .. kbcur        if kb (i) then            Draw.FillOval (kbx (i), kby (i), kbsize, kbsize, kbc)        end if    end forend drawkb

This is what I have so far, I wrote some comments to help people understand, but ask me if you need any more info to understand what I'm trying to do.

Link to comment
Share on other sites

Link to post
Share on other sites

I am going to guess that you're using Turing? I'm not too familiar, so I can't provide concrete examples but the basic idea would be to:

 

Maintain an acceleration variable. Then create a routine that gets called periodically and applies the acceleration to the # of bombers. Have your spawn routine update information about spawned bombers whenever the # changes.

 

Can you provide more information about how you're using kbspawn and drawkb?

 

-robodude666

Link to comment
Share on other sites

Link to post
Share on other sites

I am going to guess that you're using Turing? I'm not too familiar, so I can't provide concrete examples but the basic idea would be to:

 

Maintain an acceleration variable. Then create a routine that gets called periodically and applies the acceleration to the # of bombers. Have your spawn routine update information about spawned bombers whenever the # changes.

 

Can you provide more information about how you're using kbspawn and drawkb?

 

-robodude666

Yes I'm using Turing.

 

Right now I am not working on moving the bombers just spawning them in at a coordinate on the border of the screen. I will work on the ai later, one step at a time :)

 

kbspawn - this procedure should set all bombers from 1 to kbcur (the current number of bombers on-screen at a time) to true as well as set them up with individual random coordinates (kbx is the x-coordinate and kby is the y-coordinate) using the variable kbnum which is a random number from 0 to maxx * 2 + maxy * 2 which is the total amount of pixels on the edge of the screen. It makes sure the bomber is always on the edge of the screen.

 

drawkb - this procedure should draw all of the bombers that are alive to the screen, right now they are simply an oval as a placeholder. I wouldn't want it to check every varible in the kb array because chances are they will not all be true so I'd rather it be more efficient and only draw the ones that are already know to be true (every bomber from 1 to kbcur should be true [only false for an instant when they are killed.])

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×