Is This Termination Method Acceptable?

For questions about using Classic.

Post » Fri Oct 14, 2011 6:15 pm

In my space shooter, I so far have a single powerup weapon.

(event 66)
+ Hero: On collision between Hero and poweruplevel2
-> Hero: Set 'Weapons' to 1
-> poweruplevel2: Destroy

When the item is grabbed, and the weapon enabled, this was the only way I figured to stop it from continuing to drop.

(event 67)
+ Hero: Value 'Weapons' Equal to 1
-> poweruplevel2: Destroy

Then I would allow other powerups to fall and the already enabled ones to not fall. This acceptable or there is a cleaner way?

These are the weapon events for the ship when the above value changes from 0 to 1:

(events 7, 8, 9)
+ MouseKeyboard: On key Space pressed
+ Hero: Value 'Weapons' Equal to 0
+ System: Bullet.Count Lower than 20
-> XAudio2: Autoplay resource "imphenzia_soundtrack_laser36.wav" (No loop)
-> System: Create object Bullet on layer 1 at (0, 0) from Hero 's image point 1

(events 10, 11)
+ Hero: Value 'Weapons' Equal to 1
+ System: Bullet2.Count Lower than 10
-> XAudio2: Autoplay resource "imphenzia_soundtrack_laser36.wav" (No loop)
-> System: Create object Bullet2 on layer 1 at (0, 0) from Hero 's image point 2
-> System: Create object Bullet2 on layer 1 at (0, 0) from Hero 's image point 3
B
5
S
1
G
1
Posts: 157
Reputation: 1,219

Post » Fri Oct 14, 2011 6:43 pm

Seems ok to me...

I would have most likely done the same thing, but why do you repeat the "destroy" action in each event? Does it not trigger "on collide"?

I often use collisions (or other events) to adjust a variable, then perform the actual action based on the variable change. This is probably a more common practice than most people realise.

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
45
S
17
G
37
Posts: 2,853
Reputation: 25,966

Post » Fri Oct 14, 2011 7:24 pm

I only found stopping the powerup from coming back on the screen was by constantly destroying it when the global variable was set. This is so I figure other powerups will fall except the active one to keep clutter off. As the variable changes with other powerups, it could start coming back on screen. It probably does not have to be destroyed on event 66. Just makes it look a pinch nicer than going through the ship.
B
5
S
1
G
1
Posts: 157
Reputation: 1,219

Post » Fri Oct 14, 2011 7:36 pm

Ah right, of course I guess I failed to process that correctly the first time.

Yes I think that your method is acceptable, however you can have the condition of spawning based on the variable 'weapons'.

[pseudo code]
<Condition> =/= (negate) Global('Weapons') equal 1
<Condition> Every X seconds (or whatever)
<ACTION---> Do stuff
[/pseudo code]

Rather than deleting it when the conditions are met, make it so it doesn't even spawn if the conditions are met instead.

Either way, it will be unnoticeably different in my opinion anyway, unless you are dealing with hundreds or thousands of powerups per second... so either method would be fine, I would say.

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
45
S
17
G
37
Posts: 2,853
Reputation: 25,966

Post » Fri Oct 14, 2011 8:25 pm

I see what you mean, SoldjahBoy. Thank you. Your method might be more efficient so I will give that a try and see how well it works for me. Thank you.


EDITED to fix spelling errors.GSPforChrist2011-11-02 05:28:48
B
5
S
1
G
1
Posts: 157
Reputation: 1,219


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest