Jump to content


Photo

Weapons Toggling?


  • Please log in to reply
2 replies to this topic

#1 Trogador

Trogador

    GMC Member

  • New Member
  • 17 posts

Posted 29 May 2007 - 03:55 AM

In my game I'm making a system that lets you toggle between weapons you pick up during a level. I'm not sure whether to use data structures or to just use a variable caled global.toggle and write a plain script. I plan for the character to start each level with two weapons and get more during the course of that level, so I'm thinking that a script may not be the best thing. :D
  • 0

#2 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14395 posts
  • Version:GM:Studio

Posted 29 May 2007 - 05:03 AM

In my game I'm making a system that lets you toggle between weapons you pick up during a level. I'm not sure whether to use data structures or to just use a variable caled global.toggle and write a plain script. I plan for the character to start each level with two weapons and get more during the course of that level, so I'm thinking that a script may not be the best thing. :D

<{POST_SNAPBACK}>


I use object instances and stuff them in a list. That way, weapon shooting and ammo handling is left to the actual weapon object.

To toggle between weapons, you remove the item at the top of the list (the active weapon) and place it at the end... To add weapon you add them at the end, to add ammo, you loop through the list and add ammo to the appropriate weapon instance id...

For slotted weapons (1) for gun, (2) machine gun, I'd use a map or an array to keep the instance IDs the same way...

http://gmc.yoyogames...opic=295097&hl=

Actually, here is my post for a single weapon switching system
http://gmc.yoyogames...dpost&p=2065690

Edited by icuurd12b42, 29 May 2007 - 05:08 AM.

  • 0

#3 purple_pixie

purple_pixie

    GMC Member

  • New Member
  • 2647 posts

Posted 29 May 2007 - 09:45 AM

I just use a simple array for guns.
You have a variable for your current weapon, and this is the first level in the array.

Then the ,0 level can be if you have it ,1 for its sprite and ,2 for ammo.
You can add ,3 for time to reload if you want to make things easier too.
And you could replace the classic can_shoot variable with another array level, but then you would need lots of alarms :-D

So when you press say 3:
if guns[3,0] gun=3 // if you own the gun, equip it.

To fire:
if guns[gun,2] // if ammo
if can_shoot
{
 shoot()
}

And you can draw the sprite with draw_sprite(guns[gun,1],0,x,y)

Edited by purple_pixie, 29 May 2007 - 09:46 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users