Sign in to follow this  
phil67rpg

slot machine images

Recommended Posts

phil67rpg    443
Well I am still working on my slot machine video game. In the game loop I am able to get an image to scroll down the screen and redraw the image and start it at the top again.What I want to accomplish is that the images is selected randomly and is different every time it jumps to the top of the screen.Here is some game loop code.
[font="Consolas"][size="2"][font="Consolas"][size="2"]

[/size][/font][/size][/font][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"]//draw surface to the backbuffer

[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]d3ddev->StretchRect(surface4, NULL, backbuffer, NULL, D3DTEXF_NONE);

[/size][/font][/size][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]if[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"](r==1)

{

RECT rect;

rect.left=95;

rect.right=280;

rect.top=60+i;

rect.bottom=110+i;

i+=1;

[/size][/font][/size][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]if[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"](i>=280)

{

i=0;

}

[/size][/font][/size][/font][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"]//draw surface to the backbuffer

[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]d3ddev->StretchRect(surface2, NULL, backbuffer, &rect, D3DTEXF_NONE);

}

[/size][/font][/size][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]if[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"](r==2)

{

RECT rect;

rect.left=95;

rect.right=280;

rect.top=60+i;

rect.bottom=110+i;

i+=1;

[/size][/font][/size][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]if[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"](i>=280)

{

i=0;

}

[/size][/font][/size][/font][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"]//draw surface to the backbuffer

[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]d3ddev->StretchRect(surface, NULL, backbuffer, &rect, D3DTEXF_NONE);

}

[/size][/font][/size][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]if[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"](r==3)

{

RECT rect;

rect.left=95;

rect.right=280;

rect.top=60+i;

rect.bottom=110+i;

i+=1;

[/size][/font][/size][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]if[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"](i>=280)

{

i=0;

}

[/size][/font][/size][/font][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"]//draw surface to the backbuffer

[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]d3ddev->StretchRect(surface3, NULL, backbuffer, &rect, D3DTEXF_NONE);

}

please let me know if more code is needed.

[/size][/font][/size][/font]

Share this post


Link to post
Share on other sites
fuedone    128
i THINK your asking how to make a random image yeah?

in the[color=#008000][font=Consolas][size=2]//draw surface to the backbuffer[/size][/font][/color]
[font="Consolas"][size="2"][color="#008000"]
[/color][/size][/font]
[font="Consolas"][size="2"][color="#008000"]replace [/color][/size][/font][font=Consolas][size=2]d3ddev->StretchRect(FRUITSYMBOL, NULL, backbuffer, &rect, D3DTEXF_NONE);[/size][/font]
[font=Consolas][size=2]([/size][/font]this is off the top of my head and may need fixing, but you want something like(this is for c#, similar concept in c++ tho)
[font=Consolas][size=2]with the following:[/size][/font]


//sets the random field
random rand = new random();
//gets a number 1,2 or 3
rand.next(1,3)

//display a certain image depending on what is used
select(rand){
case 1:
[font=Consolas][size=2]d3ddev->StretchRect(FRUITSYMBOL, NULL, backbuffer, &rect, D3DTEXF_NONE);[/size][/font]
break;
case 2:
[font=Consolas][size=2]d3ddev->StretchRect(GOLDBARS, NULL, backbuffer, &rect, D3DTEXF_NONE);[/size][/font]
break;
case 3:
[font=Consolas][size=2]d3ddev->StretchRect(LUCKY7S, NULL, backbuffer, &rect, D3DTEXF_NONE);[/size][/font]
break;
}

Share this post


Link to post
Share on other sites
phil67rpg    443
well I am able to draw an image to the screen and scroll it down the screen.however when I redraw the image at the top of the screen it is the same image.I want to change the image randomly during the redraw time so that it is a different image and then scrolls down the screen.let me know if you need any more code.

Share this post


Link to post
Share on other sites
shadowisadog    3217
[quote name='phil67rpg' timestamp='1305516157' post='4811310']
Well I am still working on my slot machine video game. In the game loop I am able to get an image to scroll down the screen and redraw the image and start it at the top again.What I want to accomplish is that the images is selected randomly and is different every time it jumps to the top of the screen.Here is some game loop code.
[font="Consolas"][size="2"] [/size][/font][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"]//draw surface to the backbuffer

[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]d3ddev->StretchRect(surface4, NULL, backbuffer, NULL, D3DTEXF_NONE);

[/size][/font][/size][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]if[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"](r==1)

{

RECT rect;

rect.left=95;

rect.right=280;

rect.top=60+i;

rect.bottom=110+i;

i+=1;

[/size][/font][/size][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]if[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"](i>=280)

{

i=0;

}

[/size][/font][/size][/font][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"]//draw surface to the backbuffer

[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]d3ddev->StretchRect(surface2, NULL, backbuffer, &rect, D3DTEXF_NONE);

}

[/size][/font][/size][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]if[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"](r==2)

{

RECT rect;

rect.left=95;

rect.right=280;

rect.top=60+i;

rect.bottom=110+i;

i+=1;

[/size][/font][/size][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]if[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"](i>=280)

{

i=0;

}

[/size][/font][/size][/font][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"]//draw surface to the backbuffer

[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]d3ddev->StretchRect(surface, NULL, backbuffer, &rect, D3DTEXF_NONE);

}

[/size][/font][/size][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]if[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"](r==3)

{

RECT rect;

rect.left=95;

rect.right=280;

rect.top=60+i;

rect.bottom=110+i;

i+=1;

[/size][/font][/size][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]if[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"](i>=280)

{

i=0;

}

[/size][/font][/size][/font][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"]//draw surface to the backbuffer

[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]d3ddev->StretchRect(surface3, NULL, backbuffer, &rect, D3DTEXF_NONE);

}

please let me know if more code is needed.

[/size][/font][/size][/font]
[/quote]

You REALLY (like I have told you many many times already) need to do a number of things. The first is return the money that you are being paid to do this because you don't know what you are doing and it isn't fair to charge for something you don't know how to do. The second is to learn C++ structure and OOP programming techniques. It is obvious from your code that you do not know how to use OOP (or even switch case statements). There is absolutely no reason you couldn't have say a SlotMachine class that has some Reel objects (maybe a data structure of reel objects)... You could then have the reels inherit from a renderable base class (maybe a sprite or something).

Beyond that your approach is off. It would be easier to animate the reel spin animation instead of doing it through code (it will allow you to actually make it look like a reel). Either that or you could use a few UV textured cylinders. Also you should not use magic numbers in your code... it makes your code hard to maintain and change.

I really recommend against using these DirectX calls directly in your main code... It is a much better idea to abstract these away in your own "rendering engine" that you then call through your code (or better yet use an existing one... there are THOUSANDS out there!). If the DirectX API changes (and it does!) through a new version, you are headed for a miserable time of updating your code in the future...

Also your comments are completely pointless. Actually comment what your routine is doing, not what one obvious call is doing... obviously you are drawing "the surface" to the "back buffer" but what about all of the other stuff? how about a comment like "draw reel 1" or "make reel spin"... Beyond that your use of variable names is terrible... Why use "i" and "r"... when you can use "reelYPos" or something like that?

Share this post


Link to post
Share on other sites
frob    44971
[quote name='phil67rpg' timestamp='1305946223' post='4813736']
honestly maybe I should pick a different and easier line of work.Is there anything I can do to improve my coding skills. any good books that would help.
[/quote]

The most solid and direct path is a university/college computer science program.

Working through a single book without a good teacher will not take you very far down the path.

Share this post


Link to post
Share on other sites
phil67rpg    443
[quote name='frob' timestamp='1305999046' post='4813907']
[quote name='phil67rpg' timestamp='1305946223' post='4813736']
honestly maybe I should pick a different and easier line of work.Is there anything I can do to improve my coding skills. any good books that would help.
[/quote]

The most solid and direct path is a university/college computer science program.

Working through a single book without a good teacher will not take you very far down the path.
[/quote]

well I already have my B.S. in computer science, but honestly I dont remember much,

Share this post


Link to post
Share on other sites
shadowisadog    3217
[quote name='phil67rpg' timestamp='1306007623' post='4813942']
[quote name='frob' timestamp='1305999046' post='4813907']
[quote name='phil67rpg' timestamp='1305946223' post='4813736']
honestly maybe I should pick a different and easier line of work.Is there anything I can do to improve my coding skills. any good books that would help.
[/quote]

The most solid and direct path is a university/college computer science program.

Working through a single book without a good teacher will not take you very far down the path.
[/quote]

well I already have my B.S. in computer science, but honestly I dont remember much,
[/quote]

I am not sure I fully believe that (having just received comp sci, physics, and math degrees myself) but ok...

The best path to learn programming is experience. You just need to keep trying and attempting to solve problems... but you need to spend considerable time actually figuring things out on your own! You seem to be posting every single time you run into a snag... Don't just take people's code, try to understand what makes it tick... Maybe stop and go make some console applications and practice various aspects of the C++ language before you continue...

If you have received a degree in comp sci then you should at least know that books and experience are important.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this