slot machine images

Started by
12 comments, last by phil67rpg 12 years, 11 months ago
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"][font="Consolas"]

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

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

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

{

RECT rect;

rect.left=95;

rect.right=280;

rect.top=60+i;

rect.bottom=110+i;

i+=1;

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

{

i=0;

}

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

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

}

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

{

RECT rect;

rect.left=95;

rect.right=280;

rect.top=60+i;

rect.bottom=110+i;

i+=1;

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

{

i=0;

}

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

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

}

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

{

RECT rect;

rect.left=95;

rect.right=280;

rect.top=60+i;

rect.bottom=110+i;

i+=1;

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

{

i=0;

}

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

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

}

please let me know if more code is needed.

[/font][/font]
Advertisement
i THINK your asking how to make a random image yeah?

in the[color=#008000][font=Consolas][size=2]//draw surface to the backbuffer[/font]
[font="Consolas"][color="#008000"]
[/font]
[font="Consolas"][color="#008000"]replace [/font][font=Consolas][size=2]d3ddev->StretchRect(FRUITSYMBOL, NULL, backbuffer, &rect, D3DTEXF_NONE);[/font]
[font=Consolas][size=2]([/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:[/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);[/font]
break;
case 2:
[font=Consolas][size=2]d3ddev->StretchRect(GOLDBARS, NULL, backbuffer, &rect, D3DTEXF_NONE);[/font]
break;
case 3:
[font=Consolas][size=2]d3ddev->StretchRect(LUCKY7S, NULL, backbuffer, &rect, D3DTEXF_NONE);[/font]
break;
}
well I have tried everything I can think of but no success.
what do you mean? can you try explaining more clearly?
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.
did you try what i posted earlier?


if so what happened?
I used the code you gave me.

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"] [/font][font="Consolas"][color="#008000"][font="Consolas"][color="#008000"][font="Consolas"][color="#008000"]//draw surface to the backbuffer

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

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

{

RECT rect;

rect.left=95;

rect.right=280;

rect.top=60+i;

rect.bottom=110+i;

i+=1;

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

{

i=0;

}

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

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

}

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

{

RECT rect;

rect.left=95;

rect.right=280;

rect.top=60+i;

rect.bottom=110+i;

i+=1;

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

{

i=0;

}

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

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

}

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

{

RECT rect;

rect.left=95;

rect.right=280;

rect.top=60+i;

rect.bottom=110+i;

i+=1;

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

{

i=0;

}

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

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

}

please let me know if more code is needed.

[/font][/font]


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?
well tnanks for the input. I will try to be a better coder.
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.

This topic is closed to new replies.

Advertisement