Jump to content

Photo

Enemy script


  • Please log in to reply
3 replies to this topic

#1 Cereal Guy

Cereal Guy

    Senior

  • Members
  • Location:ConcepciĆ³n, CHL

Posted 23 July 2016 - 06:22 PM

I have an animated enemy (which moves around)

 

33dce2d23f19429381cbfc7ef5f97ca3.png

 

It's possible create a script to recreate the animation? The enemy uses 19 tiles

 

NOTE: It's only a walking enemy with no weapons/eweapons.


Edited by Cereal Guy, 23 July 2016 - 06:23 PM.


#2 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 23 July 2016 - 07:33 PM

You want to what now? You can make it a combo, and do DrawCombo, or just make an ffc with those graphics, which would do the same. I don't comprehend your goal.

You can also make a sprite of it, and use it for weapons, or items.

With a script, it'd be possible to clone the tile of an npc to another object, based on both its tile, and its direction; but it may be a frame out of sync.

You can also do raw DrawTiles() to do it, but it's the more complicated approach.

There is no raw 'DrawSprite' in zscript, but maybe there should be. I've considered adding that, but it's not something with a direct allegro instruction. Allegro has what equates to 'DrawSprite()', but that's for bitmap effects, not ZC 'sprites'. (Allegro defines a 'sprite' as a bitmap, so if you see that term in the allegro docs, it means something entirely different to what ZC means by a 'sprite'.)

Edited by ZoriaRPG, 23 July 2016 - 07:38 PM.


#3 Cereal Guy

Cereal Guy

    Senior

  • Members
  • Location:ConcepciĆ³n, CHL

Posted 23 July 2016 - 07:55 PM

You want to what now? You can make it a combo, and do DrawCombo, or just make an ffc with those graphics, which would do the same. I don't comprehend your goal.

 

 

I prefer use a combo and do the DrawCombo function for the enemy animation


Edited by Cereal Guy, 23 July 2016 - 07:56 PM.


#4 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 24 July 2016 - 05:16 AM

I prefer use a combo and do the DrawCombo function for the enemy animation


I still don;t comprehend what you want to accomplish. Please, give specific details on how you want to draw it, where, when, and why.

Do you just want to draw multiple fake enemies tot he screen? Do you want them to move? I have no clue what you want to do.

If you want to draw a combo, first make the combo, then you do:

Screen->DrawCombo(1, x_pos, y_pos, combo_id, 1, 1, cset, -1, -1, 0, 0, 0, frame, 0, true, 128)
 
In this instruction, 'frame' is the Nth frame of the combo animation.
 
If it's supposed to move around, then you use x_pos and y_pos to set its position on the screen.
 
Draws last for only one frame, so you'd put it in a loop (for, while), and set its position, and frame using timers, and movement instructions.
 
Drawn combos have no collision, but you can fake it: In fact, I made a header (DrawCollision.zh) to do exactly that. If you want engine collision, use an enemy. If you want easier scripted collision, use an lweapon, an eweapon, or an item.
 
This is completely untested, and just out of me head...
 
 
const int FFC_FAKE_ENEMY_STEP = 20; //higher = slower.
const int FFC_FAKE_ENEMY_HALT_MIN = 10;
const int FFC_FAKE_ENEMY_HALT_MAX = 40;
const int FFC_FAKE_ENEMY_FIRST_FRAME = 1;

const int FFC_FAKE_ENEMY_RANDOM = 0;
const int FFC_FAKE_ENEMY_DIR = 1;
const int FFC_FAKE_ENEMY_STEP_TIMER = 2;
const int FFC_FAKE_ENEMY_HALT = 3;
const int FFC_FAKE_ENEMY_FRAMETIMER = 4;
const int FFC_FAKE_ENEMY_CURFRAME = 5;

ffc script FakeEnemy{
	void run(int combo_id, int cset, int layer, int delay, int frames, int time_per_frame, int random){
		int a[1024];
		if ( !random ) random = 200; 
			//Do some fake movement.
		a[FFC_FAKE_ENEMY_RANDOM] = random; //a[0] = timer
		a[FFC_FAKE_ENEMY_DIR] = Rand(5); //The initial direction. 4 = halted
		a[FFC_FAKE_ENEMY_STEP_TIMER] = FFC_FAKE_ENEMY_STEP; //Step : higher = slower. 
		a[FFC_FAKE_ENEMY_HALT] = Rand(FFC_FAKE_ENEMY_HALT_MIN, FFC_FAKE_ENEMY_HALT_MAX); //Halt rate
		a[FFC_FAKE_ENEMY_FRAMETIMER] = time_per_frame; //a[FFC_FAKE_ENEMY_FRAMETIMER] == frametimer
		a[FFC_FAKE_ENEMY_CURFRAME] = FFC_FAKE_ENEMY_FIRST_FRAME; //Present frame. 
		
		while(true){ 
			if ( a[FFC_FAKE_ENEMY_RANDOM] ) a[FFC_FAKE_ENEMY_RANDOM] --;
			if ( !a[FFC_FAKE_ENEMY_RANDOM] ) {
				a[FFC_FAKE_ENEMY_DIR] = Rand(4);
				a[FFC_FAKE_ENEMY_RANDOM] = random;
			}
			if ( a[FFC_FAKE_ENEMY_STEP_TIMER] ) a[FFC_FAKE_ENEMY_STEP_TIMER]--;
			//Do some make movement.
			if ( !a[FFC_FAKE_ENEMY_STEP_TIMER] ) {
				if ( a[FFC_FAKE_ENEMY_DIR] == DIR_UP ) this->Y -= 1;
				if ( a[FFC_FAKE_ENEMY_DIR] == DIR_DOWN ) this->Y += 1;
				if ( a[FFC_FAKE_ENEMY_DIR] == DIR_RIGHT ) this->X += 1;
				if ( a[FFC_FAKE_ENEMY_DIR] == DIR_LEFT ) this->Y -= 1;
				if ( a[FFC_FAKE_ENEMY_DIR] == 4 ) { //halted
					while ( a[FFC_FAKE_ENEMY_HALT]-- ) { //Skip movement
						if ( a[FFC_FAKE_ENEMY_FRAMETIMER] ) { //frame timer isn't 0
							a[FFC_FAKE_ENEMY_FRAMETIMER]--;
						}
						if ( !a[FFC_FAKE_ENEMY_FRAMETIMER] ) { //frame timer is at 0
							a[FFC_FAKE_ENEMY_FRAMETIMER] = time_per_frame; 
							if ( a[FFC_FAKE_ENEMY_CURFRAME] < frames ) a[FFC_FAKE_ENEMY_CURFRAME]++;
							if ( a[FFC_FAKE_ENEMY_CURFRAME] == frames ) a[FFC_FAKE_ENEMY_CURFRAME] = FFC_FAKE_ENEMY_FIRST_FRAME;
						}
						Screen->DrawCombo(layer, this->X, this->Y, combo_id, 1, 1, cset, -1, -1, 0, 0, 0, a[FFC_FAKE_ENEMY_CURFRAME], 0, true, 128)
						Waitframe();
					}
					a[FFC_FAKE_ENEMY_HALT] = Rand(FFC_FAKE_ENEMY_HALT_MIN, FFC_FAKE_ENEMY_HALT_MAX);
				}
				a[FFC_FAKE_ENEMY_STEP_TIMER] = FFC_FAKE_ENEMY_STEP;
			}
			
			//Handle animation frame
			
			if ( a[FFC_FAKE_ENEMY_FRAMETIMER] ) { //frame timer isn't 0
				a[FFC_FAKE_ENEMY_FRAMETIMER]--;
			}
			if ( !a[FFC_FAKE_ENEMY_FRAMETIMER] ) { //frame timer is at 0
				a[FFC_FAKE_ENEMY_FRAMETIMER] = time_per_frame; 
				if ( a[FFC_FAKE_ENEMY_CURFRAME] < frames ) a[FFC_FAKE_ENEMY_CURFRAME]++;
				if ( a[FFC_FAKE_ENEMY_CURFRAME] == frames ) a[FFC_FAKE_ENEMY_CURFRAME] = FFC_FAKE_ENEMY_FIRST_FRAME;
			}
			
			//Draw the combo
			
			
			
			Screen->DrawCombo(layer, this->X, this->Y, combo_id, 1, 1, cset, -1, -1, 0, 0, 0, a[FFC_FAKE_ENEMY_CURFRAME], 0, true, 128)
			
			
			Waitframe();
		}
	}
}

Edited by ZoriaRPG, 24 July 2016 - 05:45 AM.



1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users