Increasining power by holding down mouse button
#1
Posted 20 October 2011 - 05:28 PM
I am working on a game which feature a cannon that fires a ball ever time the right mouse button is released.
The next thing I would like is to have the speed in which the ball travels out the cannon to change depending on how long the button is pressed down for.
much like a power button.
I was kindly given some advice on this and so I have
In the cannon's create event:
global.bulletpower=0
Iin the 'Right Released' event:
global.bulletpower=0
In the cannon's step event:
if mouse_check_button(mb_right) = true and global.bulletpower<30
global.bulletpower += 0.5
But I can see no difference, any suggestions on amendments or change to code?
Thanks
Sound Design
#2
Posted 20 October 2011 - 05:47 PM
The variable global.bulletpower increases as you have the right mouse button pressed, and resets to 0 when you release it.
My guess is that it gets reset before firing the ball. I will need the code you use to fire the ball to tell you how to change it.
#3
Posted 20 October 2011 - 05:54 PM
The code is correct. Did you use the variable global.bulletpower in your cannon mechanics?
The variable global.bulletpower increases as you have the right mouse button pressed, and resets to 0 when you release it.
My guess is that it gets reset before firing the ball. I will need the code you use to fire the ball to tell you how to change it.
Ah yeah that makes sense, anyway here is what I am using in the right release event
if global.ammo>0
{
instance_create(x,y,bullet);
global.ammo-=1
}
with(instance_find(obj_interface,0))instance_destroy();
global.bulletpower=0
This is currently in the cannon create event
global.ammo= 4
global.bulletpower=0
In step event for cannon
image_index = point_direction (x, y, mouse_x,mouse_y)/6
if mouse_check_button(mb_right) = true and global.bulletpower<30
global.bulletpower += 0.5
#4
Posted 20 October 2011 - 06:45 PM
The speed of the bullet should be relative with global.bulletpower. Something like:
bullet.speed = 5 + global.bulletpower/1.5;
#5
Posted 20 October 2011 - 07:13 PM
Where do you set the speed of the bullet?
The speed of the bullet should be relative with global.bulletpower. Something like:bullet.speed = 5 + global.bulletpower/1.5;
I currently have not got speed anywhere, should I put the code in the create event for the cannon?
Do I need to add speed anywhere?
#6
Posted 20 October 2011 - 07:54 PM
I am working on a game which feature a cannon that fires a ball ever time the right mouse button is released.
I thought you had already made the ball get fired...
How do you fire the ball without speed?
#7
Posted 20 October 2011 - 08:57 PM
something along the lines of bullet = instance_create(x,y,obj_bullet) bullet.speed = 5+global.bulletpower global.bulletpower = 0
Edited by GoldenDragon14, 20 October 2011 - 08:59 PM.
#8
Posted 21 October 2011 - 09:58 AM
make sure you set the speed of the ball before you set the global.bulletpower back to 0.
something along the lines of bullet = instance_create(x,y,obj_bullet) bullet.speed = 5+global.bulletpower global.bulletpower = 0
Thank you very much, works perfect,
Cheers
SD
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











