Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Blaster-type game

Tindy

Sponsor

Hello all,

I've jumped ship from RMXP and decided to try my hand at Construct. Unfortunately I'm extraordinarily behind the curve...

The game I'm trying to make at present is a Math Blasters-esque game, wherein one uses the keyboard to key in the correct sequence before the symbols crash into your base.

I've got the symbols to move across the screen (well, that's easy!), but...that's about it. I've already looked up how to randomly generate objects, but the tutorial I got isn't quite what I need. I have around 50 individual sprites that I'm working with, and I need them to be randomly generated and come across the screen at an (eventually) accelerated speed. The acceleration I'm pretty sure I can handle, it's just the generation that I need help with.

Can anybody help me? Thanks in advance <3
 
Wow 50 sprites is quite a lot. Well, you could save a random number from a Round(Random(1,50)) statement in to a local variable, and then have an If statement for each of the results.
ie
Every 5 seconds, number = Round(Random(1,50))
If(number=1), Spawn object1
object1.X = [some number]
object1.Y = [some number]
If(number=2), Spawn object2
object2.X = [some number]
object2.Y = [some number]
...
If(number=50), Spawn object50
object50.X = [some number]
object50.Y = [some number]

There may be a way to simplify it with families but I'm not sure because I've only been using the free version so far.

As a side note, acceleration can be easily handled by setting the acceleration value after giving an object the Bullet behaviour.

Hope that helps!
 

onzephyr

Awesome Bro

I'm thinking there are a couple ways you could go about this. The first one that comes to mind is to turn all 50 individual sprites into one sprite, with either a 50 frame animation. Or if each sprite currently has it's own animations. then turn them into a single sprite with 50 animations.
That way you could have a single event, create the object and set the frame/animation based on either a variable or at random.
Giving you the ability use the sprites frame or animation name in other events to help with keying in the correct answer.

something like.

Every X seconds.
-------------------------> system create object "sprite" layer 0   x=0 y=0
-------------------------> sprite set frame =round(random(49))
------or by animation---->sprite set animation = str(round(random(49)))  play from beginning.
"if the animations were named 0-49
 
------or by animation---->sprite set animation = choose(Value, Value,Value,Value)
"if you have non sequential names for the animations".

and as an over simplified example of using the frame or animation with another event, say a key press
|keyboard on Num 1 pressed.| -------->Do Actions.
|sprite is onscreen |
|sprite frame =1] |
 
Oh actually that's a great idea onzephyr. I didn't even think of that. That's certainly a creative way of using animations! Wow, this would actually have been quite handy for the beats in Music Fighter. Another strategy under the belt. Cheers! :D
 

Tindy

Sponsor

Ooh, I didn't think about that. Thanks!

I actually did manage to get them to generate randomly - sort of - by simply putting in:

every random(1000) seconds create sprite

That's a lot of coding, though, since each sprite needs its own, individual line (or else they all parade through at once).
 

onzephyr

Awesome Bro

One way to control the number of "sprites" that get created
you could create a event condition compairing the number of "sprite" objects and as long as it's smaller than whatever number you would like to be the max. Move on and create the sprite.

Something like this will work if all your "sprites" are a single object, like my first post. or if you are using families and all sprites belong to that family "family.count"
system sprite.count < 5
Every random(X) seconds
----------------------------------->system create sprite. x,y
----------------------------------->other actions to perform on sprite.


If all your sprites are independent I would suggest using a global variable in place of count to do the same thing. Then just have each sprite add to the variable on creation and subtract on being destoyed. you will also need a local variable to make sure that only one of the subevent sets fires Something like
[global number Variable1=0]
system variable1 < 5
Every random(X) seconds
other conditions for picking if needed
-------sub events
------[local number Variable2=0]
-------> other condition----->create sprite#1
---------------------------->system add 1 to Variable1
---------------------------->system set Variable2=1

------->Variable2=0, other conditions->create sprite#2
------------------------------------->system add 1 to Variable1
------------------------------------->system set Variable2=1


sprite#1 on destoryed---->system subtract 1 from Variable1
sprite#2 on destoryed---->system subtract 1 from Variable1

The second way needs more events, but does the same thing. The local variable will reset back to 0 with each tick , or loop
 

Tindy

Sponsor

hey Onzephyr, new question

I tried both

sprite set frame =round(random(49)) and
sprite set animation = str(round(random(49))) play from beginning ,

but all they do is cycle through to the last frame of the animation. I can't figure out what I'm doing wrong. Any ideas?
 

onzephyr

Awesome Bro

OOPS! Sorry I forgot to mention you will need to stop the animation for the example to work.

if you have a single sprite with a single 50 frame animation. and the goal is to set a frame and hold it. you can do it two ways. The easy way is to change the speed of the animation to 0 in the Animation dialog properties. "Left hand side menu while editing a sprites animations".
animationspeed.png







The other way is to add and action after you create and set the frame number. I would suggest using this way , only if you have a reason to sometimes play the animation and sometimes not. Because this way you will have to use Sprite start Animation in some other event when you wish it to play.
Every X seconds.
-------------------------> system create object "sprite" layer 0 x=0 y=0
-------------------------> sprite set frame =round(random(49))
-------------------------> sprite stop animation



The above is also the answer if you are using 50 animations instead of frames. in that case i would suggest just using an action to turn off the animation. Mostly because my mind would go numb if I had to open and edit 50 animations just to change a speed variable. :wink:
 

Tindy

Sponsor

Hello, I hate asking for more help, but I have a feeling this won't be the last question... :(

The movement system works great (thanks, onzephyr!), but now I've run into another problem.

A few of my sprites only require one key to destroy them, for example, pressing the "A" button destroys one of them. However, most of them require two keys to destroy them - for example, "K" + "A".

I thought I could do it just by adding more than one condition, but it only allows for "Key pressed" and "Key Down," which...is workable, but not quite what I'm looking for.

Do I need to use a variable? ....how would I use a variable? >_>
One day I'll understand this engine...
 

onzephyr

Awesome Bro

Yup you're going to have to give the sprites an instance variable.
Then set it at the same time you create it.
Set animation frame to --> 45 set sprite.variable-->45
something like that.

Then you're going to have to check it against some other object,
or variable to see if the player has the correct answer.
Here is a very basic example of what I mean.
For a full game it will need to be a bit more robust but it does
show the basic idea. Hope it helps.

Download example Textbox_input_sprite_destory.capx
Textbox_input_sprite_destory.png
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top