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);
Scripts del personaje principal
驴Qu茅 es un producto escalable?
Scripts y las ventajas de su uso
Estados
El estado de ataque
Creando un enemigo
Seguimos creando el estado de ataque
Nuestro primer enemigo
Los primeros pasos de nuestro enemigo
Midiendo distancias
El ataque del enemigo
Creando proyectiles
Eliminando a nuestro enemigo
Persistencia de objetos
Objetos persistentes
Porting
Conceptos a considerar para porting
You don't have access to this class
Keep learning! Join and start boosting your career
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:
Create a new sprite: Within the Sprites folder, it is advisable to create a specific sprite for enemy bullets, naming it SPR Enemy Bullets
.
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.
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.
Centralize the object: Make sure to place the sprite in the center of the canvas for proper animation in the game.
Implementing physics and collisions in the bullets ensures that they interact properly with other objects in the game:
Create the bullet object: From the sprite, create the EnemyBullets
object and assign the corresponding sprite to it.
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.
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);
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.
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.
Making the enemy shoot automatically makes the game more dynamic and challenging. Here's how to do it:
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);
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);
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);
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
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
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
Want to see more contributions, questions and answers from the community?