Minilop Retroware

Tutoriais de shoot 'em up · Parte 11 de 12

Shmup vertical - Parte 11 - Melhorar o sprite do alienígena

2 de agosto de 2022

Neste momento, o nosso sprite de alienígena só tem uma frame e, por isso, aponta sempre na mesma direção, independentemente do sentido em que se desloca.

Isto deve ser bastante fácil de resolver: só temos de criar uma frame para cada direção e garantir que a frame 0 aponta na Direção 0 (Norte), a frame 1 aponta na Direção 1 (Norte-Nordeste) e assim por diante.

Foi assim que alterei o Sprite 2, que será o meu sprite de alienígena por defeito:

Captura de ecrã do tutorialCaptura de ecrã do tutorialCaptura de ecrã do tutorialCaptura de ecrã do tutorialCaptura de ecrã do tutorial

Ok, estas primeiras cinco frames representam um quarto de volta, por isso não precisas de desenhar cada uma das restantes: podes usar estas e M para copiar, I para inserir uma nova frame e K para colar, e depois V para inverter na vertical e H para inverter na horizontal.

Por exemplo, a frame 5 é igual à frame 3, mas invertida na vertical.

Quando tiveres as 16 frames, abre o teu evento Alien (Sprite Type 5) e atualiza-o assim:

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 o teu jogo e agora os alienígenas devem apontar na sua direção de deslocamento.

A seguir, há algumas coisas que quero arrumar e depois estaremos prontos para lançar o MPAGD SHMUPKIT v1, para que possas começar rapidamente a construir os teus próprios shmups!

Todos os tutoriais de shoot 'em up