XNA Creators Club Online
Page 1 of 1 (15 items)
Sort Posts: Previous Next

Slot Machine

Last post 05-16-2008 6:20 PM by paranomos. 14 replies.
  • 05-16-2008 7:21 AM

    Slot Machine

    Hello everyone.I am trying to develop a slot machine using XNA and C#.If anyone could give me some guidelines or help on how  to achive this i would appreciate

    My regards
  • 05-16-2008 9:01 AM In reply to

    Re: Slot Machine

    You need to give a bit more detail :-)
    1. Are you trying to develop an actual standalone slotmachine? if so, the machine (which you probably won't get any help with here) would have to run windows.
    2. Are you just trying to develop a slot machine game?  if so, where are you stuck?

    Joel Martinez - XNA MVP  
    Blog: http://codecube.net
    Play Videos on an XNA Texture: Scurvy Media
    XNA Unit Testing: Scurvy Test
  • 05-16-2008 9:09 AM In reply to

    Re: Slot Machine

    I am not trying o build a machine just a program.I am stuck where i have to load to show the texture again when it runs off the screen

  • 05-16-2008 9:12 AM In reply to

    Re: Slot Machine

    once you've loaded a texture, you don't need to reload it again ... even if it runs off the screen.  the code you write determines "where" the sprite is ... thus, if it runs off the screen, simply move it back to the screen if that's what you need :-)

    Joel Martinez - XNA MVP  
    Blog: http://codecube.net
    Play Videos on an XNA Texture: Scurvy Media
    XNA Unit Testing: Scurvy Test
  • 05-16-2008 9:14 AM In reply to

    Re: Slot Machine

    Yes but that will not create a smooth scrolling like the one we see in real casinos but the screen will flicker when is going back again
  • 05-16-2008 10:28 AM In reply to

    Re: Slot Machine

    You shouldn't have any flicker. You're basically trying to do a scrolling background and there are several tutorials out there on that with no flickering. You can check out the one on my site or many of the other sites that demonstrate how to keep images continually scrolling.

  • 05-16-2008 11:13 AM In reply to

    Re: Slot Machine

    Dear George
    Thank you for your fast reply.I followed your tutorials and i managed to create a scrolling background.But how can i dispplay just a portion of the image.For a reel example lets say 3 rows.If if use the rectangle on draw method it will showup but when the image changes to the second one then there is a problem.Any idea?

    My regards
    Dimitris Zenios
  • 05-16-2008 11:18 AM In reply to

    Re: Slot Machine

    The logic behind scrolling a background or image in an rectangular area works like this. How big is your image  or images and how big is the rectangular area you're trying to scroll them through. Then you calculate how many images it takes to fill the rectangular are you are trying to display the scrolling images in.  So you pre-position them in a congo line of images. Next, you begin moving the images through that rectangular area and when one of the images in your congo line moves out of the viewable area, you  move it to the end of the line again.

    So it really doesn't matter if you're trying to fill the screen or just a small area, the logic used to scroll them is the same.
  • 05-16-2008 11:26 AM In reply to

    Re: Slot Machine

    Dear George

    I got the point from your post and i know how to proceed.Now i want to ask something else now.How can i stop the scrolling of the image sprite to one image i want.Since in a texture ther are 7 images one above the other.

    Thx a lot for the help

    My regards
    Dimitris Zenios
  • 05-16-2008 11:36 AM In reply to

    Re: Slot Machine

    Well, since you're emulating a slot machine, there's going to be a rectangular area that the selected image stops in. You just have to keep a timer going and when it reaches 0, stop scrolling and make the images adjust up or down so that the current image in the "selected" area is centered.

    So basically stop scrolling by no longer adjusting the positions of the images in the chain, then adjust your currently selected image (and the chain) so it's displayed where it should be.
  • 05-16-2008 11:44 AM In reply to

    Re: Slot Machine

    By having a rectangualar area where the image stops,and the timer is constant for lets say in 10 seconds then that mean that the results will always be the same.The real solution is to give the syste m3 number for example 1-3-6 so the first reel will stop in the first image,the second in the thirf image and the third in the sixth image
  • 05-16-2008 5:09 PM In reply to

    Re: Slot Machine

    You're very hard to follow, but here is some code for you.

    public class SlotReel
    {
      private Texture2D ReelTexture;
      public int ReelScroll = 0;
      public Rectangle Dimensions;
      private Viewport reelView;
      public SlotReel(Texture2D ReelTex, Rectangle ReelDeminsions)
      {
        ReelTexture = ReelTex;
        Dimensions = ReelDimensions;
        reelView = new Viewport(Dimensions.X, Dimensions.Y,
          Dimensions.Width, Dimensions.Height);
      }
      public void Draw(SpriteBatch spriteBatch, GraphicsDevice graphics)
      {
        Viewport currentViewport = graphics.Viewport;
        graphics.Viewport = reelView;
        for (int y = ReelScroll; y < Dimensions.Height; y += ReelTexture)
          spriteBatch.Draw(ReelTexture, new Rectangle(Dimensions.X,
            y, Dimensions.Width, ReelTexture.Height), Color.White);
        graphics.Viewport = currentViewport;
      }
    }
    Keep in mind: This code is untested and was done just now in notepad.  Please excuse any errors.
     
    You would implement the class like so:
     
    ...
    Texture2D reelTexture;
    public SlotReel reelOne;
    ...
    public void LoadContent()
    {
      ...
      reelTexture = Content.Load<Texture2D>("...");
      reelOne = new SlotReel(reelTexture, new Rectangle(20,20,30,300));
      ...
    }
    ...
    public void Draw(GameTime gameTime)
    {
      ...
      spriteBatch.Begin();
      //Draw your background here
      ...
      reelOne.Draw(spriteBatch, GraphicsDevice);
      reelOne.reelScroll += (gameTime.ElapsedRealTime.Millisecs / 1000) * 20; //Exchange any value for 20
      spriteBatch.End();
      ...
      ...
    }
    ...

    The [...]s signify where you would insert more code.  Note: This was also in notepad, untested.

     

    Hope this helps!

    ============================== Don't sweat the petty stuff and don't pet the sweaty stuff. ==============================
  • 05-16-2008 5:12 PM In reply to