The game is finished.
Download:https://www.cemetech.net/downloads/files/2184/x2425
Source Code: https://github.com/ZebraVogel94349/RoulCE
Looks really good and it works pretty fast too for such a big sprite!

Are you going to be fledging this out to a full game?
That was the biggest sprite that didn't cause it to crash. It's 128x128 pixels.
I want to add a roulette board, soon. Maybe I'll add chips later.
tr1p1ea wrote:
Looks really good and it works pretty fast too for such a big sprite!

lol you're the one who wrote the rotation routine what did you expect Razz

Looking good so far! It would be cool to have a full-fledge game Smile
I forgot about this project for a while, but I want to add new features, soon. I cleaned the code a bit and added the ability to spin the wheel another time without restarting the program. Here's a screenshot:
Huh I forgot to make a joke about gambling at school when you first posted this; let's pretend I did and move on to all that optimization stuff.

You use a for() loops for a regular loop, just use do{}while(), and you can add multiple conditions to a for() loop, so you can add a kb_clear one really easily. You have this hoogormus number checking bit that's way more complicated then it needs to be. Generally, something like that where you need to check numbers that are in multiple different ranges can be simplified to this:
Code:
      if(n < 7){e = 26; c = 249;}
      elseif(n < 14){e = 3;  c = 1;}
      else if(n < 20){e = 35; c = 249;}

                //and so on...

      else if(n < 242){e = 15; c = 249;}
      else if(n < 249){e = 32; c = 1;}
      else if(n <= 255){e = 0; c = 12;}

This moves through each conditional checking if the number is under a certain threshold and raises said threshold until it evaluates to true. However, since each if is checking if the number is between a multiple of seven, an even better way would be to have arrays of your e and c values (which need proper names, along with all the other single-character variables) and use those with n divided by 7:

Code:
c = colors[i / 7];
e = pockets[i / 7];

And that's 37 lines of code all the way down to 2, although you have to define the arrays somewhere else too but those aren't really functional lines. gfx_RotateSprite() takes a uint8_t for the rotation, so 0-255, meaning that you should define n as one as well. Your reset bit doesn't do anything since greater than 255 just overflows back to 0, it will never count all the way to 256; which means all you need to do is increment it. And finally, the sprite you use for the roulette has some extra space on the edges, so you can cut off some bytes by making it as small as possible. You also don't need to refill the whole screen with green each frame since the only thing that changes is the wheel, and it gets replaced every time. You can just use a gfx_RectNoClip() to erase the pocket announcement when needed. And use convimg too, convpng isn't supported anymore. Huh you actually read all this, kudos for having the patience! There's probably other things but I got all the big stuff, although there're some small things with the type definitions that

Will there be a slot machine update soon? Razz
Thanks for the help. I optimized the code and made the program about 25% smaller. I couldn't remove gfx_FillScreen. When I tried, the background began to blink white and green. It's possible to leave the program everytime, now, without waiting for the spin to end. When roulette is completed, I'll think about adding more games.
I've added a tableau. It doesn't do anything, yet, but I'll that soon.

[Cemetech's janky double-post combined with Chrome doing whatever it does to create a delayed-double-post that was a copy of what I last said, ignore this.]
Why did you post that again? Very Happy
Does anybody know, how I can fix this problem:

Here is the code:

Code:
while (kb_Data[1] != kb_Clear && kb_Data[1] != kb_2nd)//Controls
      {
         gfx_SetDrawBuffer();
         gfx_RotateSprite(ro, rotate_sprite, a + s);//Rotate the sprite
         gfx_SetColor(7);
         gfx_FillRectangle_NoClip(210,10,105,220);//Green background
         gfx_SetTextFGColor(231);//Black text color
         gfx_SetTextBGColor(255);//Transparent text background
         gfx_SetTextScale(1,1);//Text size for title
         gfx_SetTextXY(110,10);//Title position
         gfx_PrintString("Roulette v0.2.0");//Print title
         gfx_TransparentSprite_NoClip(rotate_sprite, 17, 69);//Show rotated sprite
         gfx_TransparentSprite_NoClip(pfeil, 59, 36);//Show arrow
   
         /*Create table*/
         gfx_SetColor(231);
         for(y = 0; y<15; ++y)
         {
            gfx_Line(215, (y + 1) * 14, 310, (y + 1) * 14);
         }
         for(z = 0; z<6; ++z)
         {
            if (z != 1 && z != 0)
            {
               gfx_Line(220 + (z * 18), 14, 220 + (z * 18), 210);
            }
         }
         if (kb_Data[1] == kb_Clear || kb_Data[1] == kb_2nd) {break;}//Exit
         /*Create table*/
         /*Print numbers in table*/
         gfx_SetTextScale(1,1);//Text size for numbers
         gfx_SetTextFGColor(231);//Black text color
         gfx_SetTextXY(280, 17);
         gfx_PrintString("0");
         gfx_SetTextXY(262, 199);
         gfx_PrintString("^");
         gfx_SetTextXY(280, 199);
         gfx_PrintString("^");
         gfx_SetTextXY(298, 199);
         gfx_PrintString("^");
         gfx_SetColor(7);
         gfx_FillRectangle_NoClip(215,14,41,14);
         gfx_FillRectangle_NoClip(215,84,41,15);
         gfx_FillRectangle_NoClip(215,126,41,15);
         gfx_SetColor(8);
         gfx_FillTriangle(235,75,225,90,245,90);
         gfx_FillTriangle(235,105,225,90,245,90);
         gfx_SetColor(231);
         gfx_FillTriangle(235,117,225,132,245,132);
         gfx_FillTriangle(235,147,225,132,245,132);
         gfx_Line(215,29,215,210);
         gfx_SetTextXY(222, 31);
         gfx_PrintString("1-12");
         gfx_SetTextXY(217, 45);
         gfx_PrintString("13-24");
         gfx_SetTextXY(217, 59);
         gfx_PrintString("25-36");
         gfx_SetTextXY(222, 157);
         gfx_PrintString("1-18");
         gfx_SetTextXY(217, 171);
         gfx_PrintString("19-36");
         gfx_SetTextXY(225, 185);
         gfx_PrintString("ODD");
         gfx_SetTextXY(222, 199);
         gfx_PrintString("EVEN");
         g = 1;
         if (kb_Data[1] == kb_Clear || kb_Data[1] == kb_2nd) {break;}//Exit
         for(y = 0; y < 12; ++y)
         {
            for(z = 0; z<3; ++z)
            {
               gfx_SetTextXY(258 + z * 18, 31 + y * 14);
               gfx_PrintInt(g, 2);
               g++;
            }
         }
         if (kb_Data[1] == kb_Clear || kb_Data[1] == kb_2nd) {break;}//Exit
         /*Print numbers in table*/
         gfx_SetTextFGColor(231);//Black text color
         gfx_SetTextBGColor(255);//Transparent text background
         gfx_SetTextScale(1,1);//Text size for Title
         gfx_SetTextXY(110,10);//Title position
         gfx_PrintString("Roulette v0.2.0");//Print title
         gfx_SetTextScale(3,3);//Text size for number
         gfx_SetTextXY(56,200);//number position
         gfx_SetTextFGColor(c);//Text color of number
         gfx_PrintInt(e,2);//Print number
   
         gfx_RotateSprite(ro, rotate_sprite, n);//Rotate the sprite
         gfx_TransparentSprite_NoClip(rotate_sprite, 17, 69);//Show rotated sprite
         gfx_TransparentSprite_NoClip(pfeil, 59, 36);//Show arrow
         
         gfx_SwapDraw();
         if (kb_Data[1] == kb_Clear || kb_Data[1] == kb_2nd) {break;}//Exit
         if(kb_Data[1] == kb_Up)//Up
         {
            if(posy > 1){posy = posy - 1;}
         }
         if(kb_Data[1] == kb_Down)//Down
         {
            if(posy < 15){posy = posy + 1;}
         }
         if(kb_Data[1] == kb_Up)//Left
         {
            if(posy > 1){posx = posx - 1;}
         }
         if(kb_Data[1] == kb_Up)//Right
         {
            if(posy < 6){posx = posx + 1;}
         }
      }         
You have two buffers and call gfx_SwapDraw. One of those buffers is not green. You should really read up in the documentation how to use gfx_SwapDraw correctly, because the style of your program does not gain you any benefit the way you are using it.
ZebraVogel wrote:
Why did you post that again? Very Happy

Because Cemetech do be dat way sometimes. I left my laptop running, came back to see it hadn't posted, reloaded, still nothing. Went back and re-submitted and it worked. Odd that none of your other posts showed up. To answer though, SwapDraw does what it says: swaps the screen and the buffer back and forth. Once you blit to the blank screen, you get that blank screen as your canvas, which needs to be greenified once, then it's nice and clean. That table sprite would make a really good RLET sprite, would be much faster than having to draw all the text sprites.

EDIT: It did it again, and this time Cemetech threw up a wonderfully cryptic "Post mode not specified" error. However, I posted just fine and didn't need a resubmission, so that's neat, I guess you just need to be careful when writing posts and putting your machine to sleep.
The game is now playable. Betting works now. I have to improve the controls but it's usable.
Here is a screenshot:
That's really cool!
Do you plan on adding a celebration animations if you win big? (falling coins etc?)

Also what are you using to generate randomness?
Maybe I'll make celebration animations, after everything works fine, but I don't have specific plans, yet. I'm generating the randomness by using rand() to generate a number between 0 and 1000 each frame and subtracting the rotation speed (which is 50000 at the beginning) by this number.
I improved the controls and added a history, which shows the last 5 numbers.
Screenshot:
I've just released version 1.0.0. I've made a few small changes and deleted some unnecessary things. It can be downloaded from github. I've also uploaded it to the cemetech archives.
Heya, what are the controls?
xlibman wrote:
Heya, what are the controls?

Arrow keys - Move the cursor
2nd - Click on selected thing (betting, choosing chips, spin)
Y= - Add Coins
Y=, Window, Zoom, Trace, Graph - choose how many coins to add
Clear - exit the game
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement