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

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
GungnirDev
Party member
Posts: 119
Joined: Thu Jun 28, 2012 10:31 pm

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

Post 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)
Attachments
Invictus.love
(5.75 MiB) Downloaded 150 times
Last edited by GungnirDev on Mon Aug 13, 2012 12:31 am, edited 3 times in total.
Bullets are the beauty of the blistering sky
Bullets are the beauty and I don't know why
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Firing delay and the Dr. Device

Post 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.
Help us help you: attach a .love.
User avatar
GungnirDev
Party member
Posts: 119
Joined: Thu Jun 28, 2012 10:31 pm

Re: Firing delay and the Dr. Device

Post by GungnirDev »

I used the second option and it works beautifully, as I expected. Thanks!
Bullets are the beauty of the blistering sky
Bullets are the beauty and I don't know why
User avatar
flashkot
Prole
Posts: 27
Joined: Sun Jul 29, 2012 4:56 pm
Location: ru

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

Post 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)
User avatar
GungnirDev
Party member
Posts: 119
Joined: Thu Jun 28, 2012 10:31 pm

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

Post 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.
Attachments
Invictus.love
(6.5 MiB) Downloaded 128 times
Bullets are the beauty of the blistering sky
Bullets are the beauty and I don't know why
Post Reply

Who is online

Users browsing this forum: steVeRoll and 225 guests