Page 1 of 1

Dr. Device :: (bullets shoot more bullets, but lag & freeze)

Posted: Thu Aug 09, 2012 5:02 am
by GungnirDev
I've been very busy...I'm making weapons!

I currently have three weapons (well, two and a half finished ones.) You can cycle through them with the "x" key because this is the "alpha version," although there will be a somewhat more interesting way of switching weapons when I get around to programming it. "z" key shoots. The first two, the triangle lasers and the spastic dark hole ball, work exactly as designed and I am very proud of them. :ultraglee:

The third is a bit of a challenge. Anyone here read "Ender's Game?" The third weapon, the one with the little yellow ball, is going to be like the "Dr. Device," the kinetic energy weapon that [[IMPORTANT PLOT STUFF; GO READ THE BOOK IF YOU HAVEN'T YET]] and then goes to live with some pig aliens.

Question One:

Basically I want it to be where when I shoot enemies with the third weapon, the enemy explodes into three more yellow balls that fire in different directions, and then when those balls hit enemies, they explode into three more yellow balls that fire in different directions, and you see where this is going, mmyes? I tried calling a shoot-like function but I get basically no response, and one set of variables that I tried glitched my game so bad I was afraid the computer would start smoking.

Anyway. The weapon should be potentially devastating to your foes if it works, which brings me to my next point

Question Two:

(fix'd, thx Robin)

Re: Firing delay and the Dr. Device

Posted: Thu Aug 09, 2012 9:09 am
by Robin
Here's the idea for question two: add a variable, set it to 0 initially.

When you're holding the fire button and you're using a non-rapidfire weapon, instead of shooting, increase that variable by dt. Once that variable is larger than say one or two (for one or two seconds delay respectively), all the actual "shoot" function and reset the variable to 0.

Note that this way, you have to keep holding the shoot button to get any result. A better method might be this:

Add a variable, set it to 0 initially.

On every update, add dt to it.

When you're holding the fire button and you're using a non-rapidfire weapon, do the following:if the variable is less than one or two (again, the actual value should depend on how long you want the wait), do nothing. Otherwise, do the shooting and reset the variable to 0.

This means you can usually shoot with a single button press, but if you try to be too rapid, it does nothing.

Re: Firing delay and the Dr. Device

Posted: Fri Aug 10, 2012 8:52 pm
by GungnirDev
I used the second option and it works beautifully, as I expected. Thanks!

Re: Dr. Device :: (need help w/bullets that shoot more bulle

Posted: Fri Aug 10, 2012 9:25 pm
by flashkot
thesmeagle wrote:Basically I want it to be where when I shoot enemies with the third weapon, the enemy explodes into three more yellow balls that fire in different directions, and then when those balls hit enemies, they explode into three more yellow balls that fire in different directions, and you see where this is going, mmyes? I tried calling a shoot-like function but I get basically no response, and one set of variables that I tried glitched my game so bad I was afraid the computer would start smoking.
This is hard to implement with your current bullets logic.

All your bullets moving straight from bottom to top. Because you coded it like this

Code: Select all

v.y = v.y - dt * 700
You just decrease y coordinate by 700px each second.

I suggest to add speed parameters (.u for horizontal and .v for vertical) to bullet and change all this code to this

Code: Select all

v.x = v.x + dt * v.u
v.y = v.y + dt * v.v
So, for all your bullets initial values for "u" and "v" will be 0 and -700

then in ship.lua, at line 177 you add something like

Code: Select all

	shot = {}
	shot.img = drdoom
	shot.x = v.x
	shot.y = v.x
	shot.u = math.random(-700,700)
	shot.v = math.random(-700,700)
	table.insert(player.shots, shot)

	laser:rewind()
	love.audio.play(laser)
	table.insert(player.shots, shot)
Repeat as many times as you need (use for loop around bullet creation)

Re: Dr. Device :: (need help w/bullets that shoot more bulle

Posted: Mon Aug 13, 2012 12:29 am
by GungnirDev
Ok, it appears to be mostly doing what I want it to, but there's an error where it'll freeze up occasionally and I'm not entirely sure why. It's not giving an error message, same as before, it just locks up. I think it's because it's trying to handle a bunch of collisions at once maybe, but sometimes it'll screw up and sometimes it won't so it's hard to pinpoint the error.

Also, the explosion is sometimes off centre.