projectiles | gml
Add a new object objProjectile:

objPlayer Step
if (keyboard_check(vk_right)){ horiz = move_speed; };if (keyboard_check(vk_left)){ horiz = -move_speed; };if (keyboard_check(vk_nokey)){ horiz = horiz * frict; };vert = vert + grav;if (place_meeting(x, y+1, objBlock)) and (keyboard_check(vk_up)) { vert = jump_speed; }if (place_meeting(x+horiz, y, objBlock)) {while (!place_meeting(x+sign(horiz), y, objBlock)) {x = x + sign(horiz);}horiz = 0;}x = x + horiz;if (place_meeting(x, y+vert, objBlock)) {while (!place_meeting(x, y+sign(vert), objBlock)) {y = y + sign(vert);}vert = 0;}y = y + vert;//---------------------------- PROECTILES:if mouse_check_button(mb_left){var inst = instance_create_layer(x,y,"Instances",objProjectile);with(inst){inst.direction = point_direction(x,y,mouse_x,mouse_y);inst.image_angle = direction;inst.speed = 10;}}
Challenges
1. Implement the above code.2. Find and replace the current key configuration to work with left hand for movement:
//Find and replace the keys to bind to ordinal characters:ord("D") //instead of vk_right in player step eventord("A") //instead of vk_left in player step eventord("W") //instead of vk_up in player step event//for example, instead of vk_left in player step event:if (keyboard_check(ord("A"))){ horiz = -move_speed; };
3. CHALLENGE this code aims at the mouse position - can you make it so that the projectile fires in the direction the player is facing - left or right?
4. CHALLENGE what if the player is holding up or down - can the projectile go 4 ways? (up down left right)
5. Find a projectile sprite from the internet to use here - perhaps something animated NOT A BULLET AND NOTHING VIOLENT