Skip to main content
gamedev.net
🔒 Locked

Please help with sprite generating problem

Started by Renegader_bj 6 replies 1.1k views
Original Post
Renegader_bj
Renegader_bj
Hi all GameDev pros, I desperatly need need your help. I am programming a match 3 puzzle game in c++ and DirectX, and I have hit a stumbling block, one of those problems you know you can do, but it just isn't working. I have 5 different colored sprites that need to be randomly loaded and drawn in columns and rows. I tried loading them randomly, the problem there is that I can't then keep track of their seperate colors and properties. I can't randomize them in the render function, because obviously it redraws them at a new random location each frame. I am probably not explaining this well, but try and help me please.
Shakedown
Shakedown
Quote:
Original post by Renegader_bj

I have 5 different colored sprites that need to be randomly loaded and drawn in columns and rows. I tried loading them randomly, the problem there is that I can't then keep track of their seperate colors and properties.

I can't randomize them in the render function, because obviously it redraws them at a new random location each frame.


First, you should have a class that represents your game pieces. These pieces should contain a sprite that represents their physical appearance. These pieces should also contain their (x,y) position.

Then, you have a function that is called when your game/level is initialized. This function will create a bunch of these game pieces and assign them a random position.

After that, you no longer will be randomizing their position. Once they're placed, you then play your game by selecting a game piece and moving it. This "moving it" part will adjust the game piece's position by some amount dependent on the direction the user is moving it.

Renegader_bj
Renegader_bj
Quote:
Original post by Shakedown

Then, you have a function that is called when your game/level is initialized. This function will create a bunch of these game pieces and assign them a random position.


Right, but I don't want them assigned at random positions. The colors need to be randomized, but they need to be drawn in rows and columns, not just all over the screen. Maybe I'm not interpreting your whole answer right though. I'm going to try to do what you said.



Shakedown
Shakedown
Quote:
Original post by Renegader_bj
Quote:
Original post by Shakedown

Then, you have a function that is called when your game/level is initialized. This function will create a bunch of these game pieces and assign them a random position.


Right, but I don't want them assigned at random positions. The colors need to be randomized, but they need to be drawn in rows and columns, not just all over the screen. Maybe I'm not interpreting your whole answer right though. I'm going to try to do what you said.


If you wanted random colors, you could just define all the lighting to achieve all your colors, store those resources in an array, and then grab a random index.

So then are you defining the position of every game piece?

Renegader_bj
Renegader_bj
Prhaps I can explain a bit better. I have 5 sprites, purple,white,yellow,orange,blue. I load them in the gameload function, then draw them in the render function. Thats what I want to happen, but I want the sprites to line up randomly, so there is not a solid row of orange, nor a solid row of blue, etc., but I do want rows and columns.

If this is not plausable, perhaps there is a better way?
Shakedown
Shakedown
Quote:
Original post by Renegader_bj
Prhaps I can explain a bit better. I have 5 sprites, purple,white,yellow,orange,blue. I load them in the gameload function, then draw them in the render function. Thats what I want to happen, but I want the sprites to line up randomly, so there is not a solid row of orange, nor a solid row of blue, etc., but I do want rows and columns.

If this is not plausable, perhaps there is a better way?


Yes, this is easily done. First of all, you're going to have to randomize the colors of your sprites. Because you only have 5 sprites, you're going to have a few of the same colors that are in the same row/column.

Now, there are 2 ways to do what you want:

1. Create all your pieces and place them in the screen, then run through all of them and randomly assign them a color, or

2. Create all your pieces and give them a color, and then randomly place those pieces in the screen.

If you're doing a match-3 game, you're probably going to have the entire screen full of pieces. Therefore, I recommend using the first way of setting up your game board/screen/map/level.

If you're having trouble understanding how you create the pieces so they're in rows and columns, then that's another topic. Another thing that is a bit ambiguous in your explanations is whether or not "sprite" is referring to the literal image (.bmp, .jpg, etc) or some user-created class. Since you say you're using DirectX, it's probably assumed you're doing 3D, which also may screw up the interpretation of "sprite." If you are doing a simple match-3 game, you'd probably be better off doing this in 2D.

So, if you still have further questions, then describe what a "sprite" is and what your game pieces are, and if you're hung up on a particular function or piece of code, then post a snippet of your relevant source code. Good luck!
Renegader_bj
Renegader_bj
Thank you for your help,Shakedown. I may post later with another question of this subject.
BigBlueShit
BigBlueShit
'I want the sprites to line up randomly, so there is not a solid row of orange, nor a solid row of blue, etc.'
if you use randomizing that will never happen unless you forget to set a new seed.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.