You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesi贸n a prueba de IA

Antes: $249

Currency
$209
Suscr铆bete

Termina en:

0 D铆as
19 Hrs
21 Min
17 Seg

Creando proyectiles

10/14
Resources

How to create a bullet sprite in Game Maker?

Creating a bullet sprite in Game Maker is an essential step to bring our game to life. By following these steps, you will be able to design a visually stunning projectile:

  1. Create a new sprite: Within the Sprites folder, it is advisable to create a specific sprite for enemy bullets, naming it SPR Enemy Bullets.

  2. Design the sprite: Select a simple white circle for the first frame image and, for the second one, use the bucket tool to paint the circle red. This gives a flickering effect, which you can optimize by setting the speed to 10 for better visualization.

  3. Trim the sprite: Use Game Maker's Image Auto Trim All Frames feature to trim excess space in the sprite, which helps keep the project organized.

  4. Centralize the object: Make sure to place the sprite in the center of the canvas for proper animation in the game.

How to incorporate physics and collisions into bullets?

Implementing physics and collisions in the bullets ensures that they interact properly with other objects in the game:

  1. Create the bullet object: From the sprite, create the EnemyBullets object and assign the corresponding sprite to it.

  2. Define physical properties: Add properties such as speed(SPD), which you can initially set to 3, and the direction that will control the trajectory of the bullet.

  3. Implement movement: In the Step event of the bullet object, use functions like LengthDirX to move the bullet in the defined direction and speed. Here is a shorthand way to define the movement:

    x += lengthdir_x(spd, direction);y += lengthdir_y(spd, direction);
  4. Manage the collision: When the bullet collides with the player, decrease the life points with HP -= 10 and destroy the bullet using instance destroy. It is essential to do it outside the keys to avoid eliminating the player wrongly.

  5. Eliminate bullets outside the screen: Use the OutsideRoom event to automatically destroy the bullet if it goes out of sight, preventing it from consuming memory unnecessarily.

How to make the enemy shoot automatically?

Making the enemy shoot automatically makes the game more dynamic and challenging. Here's how to do it:

  1. Add trigger logic in Animation End: Right after the enemy attack animation ends, create the bullet with the instance create layer function in the corresponding layer, as shown here:

    bullet = instance_create_layer(x, y, "Instances", obj_enemy_bullet);
  2. Adjust the exit of the shot: To make the bullet not exit from the center of the enemy, but from a more natural place like its finger, adjust the position using lengthdir.

    x += lengthdir_x(10, dir_x);
  3. Define the direction of the shot: Transfer the direction of the enemy to the shot so that it correctly targets the player with:

    bullet.dir = point_direction(x, y, obj_player.x, obj_player.y);
  4. Test and adjust: Test the game to verify the movement and direction of the bullets, adjusting the distance and direction as needed.

By following these steps, you will enrich the game experience by allowing the enemy to fire automatically, adding an additional level of challenge for players.

Contributions 6

Questions 4

Sort by:

Want to see more contributions, questions and answers from the community?

La funcion instance_create_depth ya no recibe un texto con el nombre de la capa.
Ahora recibe un numero de profundidad.
Asi lo dej茅:
var bullet = instance_create_depth(x + lengthdir_x(10, dir_x), y, depth, obj_enemy_bullet);

En la 煤ltima clase pregunto algo importante sobre el scope de bullet y por qu茅 s铆 es v谩lido usar .dir ac谩 en este caso
Pregunta ultima clase - https://platzi.com/comentario/3569704/
.
Espero les sirva

Al principio intente ir a mi propio ritmo para ver si corr铆a el bullet y me equivoque en lo mismo de Instances Jajaja, le hab铆a colocado Itances, Muy buena clase esta de proyectiles

Mi bala se crea siempre, cada 3 segundos.

Al aplicar la funci贸n image_angle al objeto bullet que se crea, pude hacer que mi proyerctil apunte hacia el personaje.

Dej茅 el animation end de esta manera:


if(state == scr_enemy_neo_state_attack){
	var bullet = instance_create_layer(x + lengthdir_x(5,dir_x),y,"Instances",obj_enemy_neo_bullets);
	
	bullet.dir = point_direction(x,y,obj_Player.x,obj_Player.y);
	
	
	bullet.image_angle = point_direction(x, y, obj_Player.x, obj_Player.y);
	
	state = scr_enemy_neo_state_idle;

}


excelente clase de interacci贸n y ataque