Minilop Retroware

Tutoriales de shoot 'em up · Parte 11 de 12

Shmup vertical - Parte 11 - Mejorar el sprite del alienígena

2 de agosto de 2022

Ahora mismo, nuestro sprite de alienígena solo tiene un fotograma y, por tanto, siempre apunta en la misma dirección, se desplace hacia donde se desplace.

Esto debería ser bastante fácil de arreglar: solo tenemos que crear un fotograma para cada dirección y asegurarnos de que el fotograma 0 apunta en la Dirección 0 (Norte), el fotograma 1 apunta en la Dirección 1 (Nornoreste) y así sucesivamente.

Así es como cambié el Sprite 2, que será mi sprite de alienígena por defecto:

Captura de pantalla del tutorialCaptura de pantalla del tutorialCaptura de pantalla del tutorialCaptura de pantalla del tutorialCaptura de pantalla del tutorial

Vale, estos primeros cinco fotogramas representan un cuarto de vuelta, así que no hace falta dibujar cada uno de los demás: puedes usar estos y M para copiar, I para insertar un fotograma nuevo y K para pegar, y luego V para voltear verticalmente y H para voltear horizontalmente.

Por ejemplo, el fotograma 5 es igual que el fotograma 3 pero volteado verticalmente.

Cuando tengas los 16 fotogramas, abre tu evento Alien (Sprite Type 5) y actualízalo así:

EVENT SPRITETYPE5

							; FLEXI ALIENS
							; =====================
							
SPRITEINK C					; colour the alien with C value					
							
IF SETTINGA = 0				; Alien first appears
	RESTORE					; Restore the data table
	LET RND = L				; Store the Level number in RND	
	ADD 50 TO RND				; and increase it by 500
	WHILE DIRECTION <> RND  	; While DIRECTION doesnt = RND
	READ DIRECTION			; Read value from DATA table
	READ SETTINGB				; Also read second value
	ENDWHILE				; Keep going until we find the value in RND
	LET SETTINGA = 1		; When we find it change SA to 1
ENDIF

IF SETTINGA = 1				; Ready to get direction & reptitions
	READ DIRECTION    		; Read the next movement into DIRECTION
	READ SETTINGB     		; Read the repetitions into SettingB
	LET SETTINGA = 2			; Got directions & reps		
	IF IMAGE 2				; is this image # 2?
		LET FRAME = DIRECTION ; yes, set its frame to its DIRECTION
	ENDIF
ENDIF



IF COLLISION 1            	; if hit by a torpedo
	OTHER				; switch to torpedo
	LET DIRECTION = 99	; run the explosion
	ENDSPRITE			; return to this Alien
	LET TYPE = 6			; Switch it to explosion type
	LET IMAGE = 4			; Explosion image
	LET FRAME = 0			; first frame
	LET DIRECTION = 0		; tell explosion its an alien exploding
ENDIF


IF COLLISION 0				; if enemy and player collide
	LET TYPE = 6				; switch it to the explosion type
	LET IMAGE = 4				; and the explosion image
	LET FRAME = 0				; reset it to first frame
	LET DIRECTION = 0			; this is an alen exploding
	OTHER
	LET DIRECTION = 99		; trigger the player explosion
	ENDSPRITE
ENDIF

IF DIRECTION = 0				; Move N
	SPRITEUP
	SPRITEUP
ENDIF

IF DIRECTION = 1				; Move NNE
	SPRITERIGHT
	SPRITEUP
	SPRITEUP
ENDIF

IF DIRECTION = 2				; Move NE
	SPRITERIGHT
	SPRITERIGHT
	SPRITEUP
	SPRITEUP
ENDIF

IF DIRECTION = 3				; Move ENE
	SPRITERIGHT
	SPRITERIGHT
	SPRITEUP
ENDIF

IF DIRECTION = 4				; Move E
	SPRITERIGHT
	SPRITERIGHT

ENDIF

IF DIRECTION = 5				; Move ESE
	SPRITERIGHT
	SPRITERIGHT
	SPRITEDOWN
ENDIF

IF DIRECTION = 6				; MOVE SE
	SPRITERIGHT
	SPRITERIGHT
	SPRITEDOWN
	SPRITEDOWN
ENDIF

IF DIRECTION = 7				; MOVE SSE
	SPRITEDOWN
	SPRITEDOWN
	SPRITERIGHT
ENDIF

IF DIRECTION = 8				; MOVE S
	SPRITEDOWN
	SPRITEDOWN
ENDIF

IF DIRECTION = 9				; MOVE SSW
	SPRITEDOWN
	SPRITEDOWN
	SPRITELEFT
ENDIF

IF DIRECTION = 10				; MOVE SW
	SPRITEDOWN
	SPRITEDOWN
	SPRITELEFT
	SPRITELEFT
ENDIF

IF DIRECTION = 11				; MOVE WSW
	SPRITEDOWN
	SPRITELEFT
	SPRITELEFT
ENDIF

IF DIRECTION = 12				; MOVE W
	SPRITELEFT
	SPRITELEFT
ENDIF

IF DIRECTION = 13				; MOVE WNW
	SPRITELEFT
	SPRITELEFT
	SPRITEUP
ENDIF

IF DIRECTION = 14				; MOVE NW
	SPRITELEFT
	SPRITELEFT
	SPRITEUP
	SPRITEUP
ENDIF

IF DIRECTION = 15				; MOVE NNW
	SPRITELEFT
	SPRITEUP
	SPRITEUP
ENDIF

						; BOUNDARY CHECKING
						; ===================
IF X <= LEFTEDGE			; if alien reaches the left edge
	REMOVE				; remove it
	SUBTRACT 1 FROM S		; decrement the sprite counter
	SUBTRACT 1 FROM F		; decrement the alien counter
ENDIF

IF X >= RIGHTEDGE			; if alien reaches the right edge
	REMOVE				; remove it
	SUBTRACT 1 FROM S		; decrement the sprite counter
	SUBTRACT 1 FROM F		; decrement the alien counter
ENDIF

IF Y >= BOTTOMEDGE		; if alien reaches the right edge
	REMOVE				; remove it
	SUBTRACT 1 FROM S		; decrement the alien counter
	SUBTRACT 1 FROM F
ENDIF

IF Y < Q			; is alien above minimum height for releasing missiles?				
	IF W > 0				; yes, can alien release	missiles?
		IF X < M				; yes, is Alien to the right of player?
			SUBTRACT X FROM M	; yes, how far to the right of player is alien?				
			IF M <= 8			; 8 or less pixels?
				LET AIRBORNE = 1	; run the chance of firing routine
			ENDIF
			ADD X TO M			; reset M
		ELSE
			IF M < X			; is alien to the left of player?
				SUBTRACT M FROM X ; yes, how far to the left
				IF X < = 8		; 8 pixels or less?
					LET AIRBORNE = 1; yes, run the chance of firing routine
				ENDIF
				ADD M TO X		; reset X
			ELSE				; enemy must be directly above player
				LET AIRBORNE = 1; run the chance of firing routine
			ENDIF
		ENDIF
	ENDIF
ENDIF

IF AIRBORNE = 1		; Chance of firing routine
	IF S < 9			; are there 8 or less sprites on screen?
		GETRANDOM H	; yes, get a random number from 0 to the aliens missile probability #
		IF RND = 1	; is it 1?
			LET RND = DIRECTION	; yes, store aliens direction in RND
			SPAWN 3 6 		; spawn a missile
			SPAWNED			; switch to the spawned missile
			LET DIRECTION = RND 	; set its direction to RND
			ENDSPRITE	 ; switch back to this alien
		ENDIF
	ENDIF
	LET AIRBORNE = 0 		; end the chance of firing routine
ENDIF


SUBTRACT 1 FROM SETTINGB	; decrement repetitions remaining
IF SETTINGB = 0			; has alien moved all repetitions?
	LET SETTINGA = 1		; get the next direction & # of repetitions
ENDIF


DATA 51 0 8 20 7 8 6 8 5 8 4 16
DATA 52 0 8 20 9 8 10 8 11 8 12 16
DATA 53 0 12 48 11 2 10 2 9 2 8 2 7 2 6 2 5 2 4 40 5 2 6 2 7 2 8 2 9 2 10 40 
DATA 54 0 4 48 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 40 11 2 10 2 9 2 8 2 7 2 6 40
DATA 55 0 13 26 14 4 15 4 0 4 1 4 2 4 3 4 4 4 5 4 6 4 7 4 8 4 9 4 10 40
DATA 56 0 3 26 1 4 0 4 15 4 14 4 13 4 12 4 11 4 10 4 9 4 8 4 7 4 6 40
DATA 57 0 8 16 7 4 6 4 5 4 4 4 3 4 2 4 1 4 0 4 15 4 14 4 13 4 12 4 11 4 10 4 9 4 8 4 7 4 6 4 5 4 4 60
DATA 58 0 8 16 9 4 10 4 11 4 12 4 13 4 14 4 15 4 0 4 1 4 2 4 3 4 4 4 5 4 6 4 7 4 8 4 9 4 10 4 11 2 12 60

Compila tu juego y ahora los alienígenas deberían apuntar en su dirección de desplazamiento.

A continuación, hay algunas cosas que quiero ordenar y luego estaremos listos para publicar MPAGD SHMUPKIT v1, ¡para que puedas empezar enseguida a construir tus propios shmups!

Todos los tutoriales de shoot 'em up