Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. I'm trying to do a simple gun system to be as generic as possible, where the player can have one gun equipped at a time and you switch between guns using the number keys (1, 2, etc) using an array. I'm still quite new to programming, so obviously this isn't working for me. But I believe this is very basic and I've done something very stupid. The game supposed to be a classic spaceship top-down shooter and is basically empty right now so there's nearly no code apart from basic movement and some objects.
  2.  
  3. I have an object named objSystem that initializes the gunArray and global.gunCurrent that is created in a room called "rmInit" (it simply goes to the next room after creating objSystem):
  4.  
  5. global.gunCurrent = 0;
  6.  
  7. gunArray[0] = objGun1;
  8. gunArray[1] = objGun2;
  9. Following this, I have an objPlayer as well that changes global.gunCurrent depending the number key you press. This works fine and dandy, as I have a Draw GUI event on objSystem that displays what global.gunCurrent is set to. However, what doesn't work, is the fact that the gun object doesn't appear at all. Step event of objPlayer:
  10.  
  11. //UPDATE PLAYER INPUT
  12. input_gun1 = keyboard_check(ord("1"));
  13. input_gun2 = keyboard_check(ord("2"));
  14.  
  15. if (input_gun1){
  16. global.gunCurrent = 0;
  17. }
  18.  
  19. else if (input_gun2){
  20. global.gunCurrent = 1;
  21. }
  22.  
  23. if (!instance_exists(global.gunCurrent)){
  24. instance_create_layer(x,y,layer,objSystem.gunArray[global.gunCurrent])
  25. }
  26.  
  27. I don't have much code for the gun apart from a parent that makes the gun object follow the player around (any direction or rotation isn't needed, just need the gun to stay on top of the player object):
  28.  
  29. //Movement
  30. x = objPlayer.x;
  31. y = objPlayer.y;
  32.  
  33. The guns themselves have basically no code yet apart from the inheritance it gets from its parent object. I'm not sure why it won't appear from the instance_create_layer function? I've made the guns sprites super big in size as well to troubleshoot the possibility that the players sprite was blocking the gun. I'd like to draw the actual object instead of just drawing a sprite as well, but maybe this is not achievable?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement