123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|679|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Handheld Coding -> Fruit Machine game

Mon, 10 Mar 2008, 12:58
spanner
Hi all,i am new to making games on the ds so i need some help..

I making a fruit machine game for the DS with Palib and I have got the reels turning....BUT....

1.To be able to start them turning with the start button on the image and button A on the DS..(Edit Codes been edited..Got it working with the A button but not the start buton on the image.)

2.How do you get the reels ainimation to stop once you pressed the A button with PA_SpriteAnimPause..

3.To make them turn randomly so they don't land on the same fruit..

4.Any help with this is welcome..

I put up the source code for you all the have a look and play with it..


Picture..







-=-=-
Spanner
Mon, 10 Mar 2008, 14:01
spanner
I was trying that to get the A button to make the reels turn..can you help..?

Got it working with the A button but not the start button on the image.

Anyone..?


-=-=-
Spanner
Mon, 10 Mar 2008, 15:06
Jayenkai
I'll have a look once I get home from work.


Welcome to Socoder, btw.

-=-=-
''Load, Next List!''
Mon, 10 Mar 2008, 16:42
Jayenkai
ok, I'll give you rough pointers, and you should be able to figure things out.

For each reel, create a "Ticker". This is a simple int number that starts high, then winds back down to 0.


When the player hits A, set ticker for the first reel to a random number.. Set the second reel's ticker to another random number, but one which is higher than the first. For the third, make it an even bigger random number.

Now, spin the reels, and keep counting those tickers down, one by one.
Once a ticker hits 0, stop it's reel from spinning.
Wait till all three tickers are at 0, and that'll be your time to jump into all the scorings, and things like that..

I've not bothered to give you a coded example, because... A) It's not really all that hard, so you shouldn't have any trouble implementing it, but also B) There's a multitude of ways you can do it. Whether you choose to use Arrays, or Structs, or even just a bunch of variables for each reel, or what ever else, it's up to you.

-=-=-
''Load, Next List!''
Mon, 10 Mar 2008, 17:37
Afr0
Pseudo code:



-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Tue, 11 Mar 2008, 09:56
spanner
So do i use that code Afr0 posted and where in my code do it put it,How do i connect the Tickers to the reels..?

I need to read up on c++..

-=-=-
Spanner
Tue, 11 Mar 2008, 10:29
Jayenkai
No, don't use precisely Afr0's code.. It's approximate code to help guide you on your way.

Mine's more explainatory, if you can follow the general gist of mine, you should be able to understand what's needed.

To connect tickers to reels, basically, instead of having A start the reels moving, have the reels animate when ticker > 0, and then, as soon as ticker =0, stop the reels again.


-=-=-
''Load, Next List!''
Tue, 11 Mar 2008, 11:27
spanner
This is the ainimation of the reels and the press A button..



So do i replace the PA_StartSpriteAnim(0, 1, 0, 7, 5 ); with the ticker...never done this before read abit about c++ but didn't have tickers in there..?

-=-=-
Spanner
Tue, 11 Mar 2008, 12:22
mike_g
Maybe take a look in the PA lib documentation. I'm pretty sure it should feature some method of getting the time but I dont know as I never used it myself. If not maybe look up gettimeofday and code your own ticker. Its a portable way to get the time, but i'm not totally sure if it will work on a DS.

As for randomisation PA lib might do that for you too if you look for it, also when using random numbers make sure to seed it something that will be variable, such as the time, otherwise it will give you the same numbers each game.
Tue, 11 Mar 2008, 13:46
Jayenkai
The ticker described above does not require any timers, any special clocks, or anything like that.
I called it a ticker because it's something you'll be ticking away manualy.

Within your main loop, have something like this.

if (Ticker>0 ){Ticker--;}
(Obviously, you'll need 3 of these.. One for each reel. So you can probably use TickerA,B and C.)

When you set the ticker variable up to something like 120, it'll gradually reduce until it's back to 0.

So, when the player hits A, set the first reel's ticker to 100, then second to 140, and the third to 160. If you can get those randomly, that'll be better.

if (Pad.hit.A) {TickerA=100; TickerB=140;TickerC=160;}
And, set off the spinning like you did earlier.


Next, remember to keep the little reducer active, so it keep them ticking downwards, and once the ticker hits 0 again, stop the reels..
if (TickerA==0) {
// stop the 1st reel here.
}

if (TickerB==0) {
// stop the 1st reel here.
}

if (TickerC==0) {
// stop the 1st reel here.
}


And, that should roughly be enough.

Think of it like this. (assuming it were a real fruit machine..)

When you push the button, you set reel 1 off with enough momentum to pass 100 fruit, 2 with 140 and 2 with 160.
Then, as each fruit passes by the middle row, it clicks a little ticker which counts how many have gone by.
As soon as the momentum's done, the fruit machine knows how many fruit have passed, because it's been ticking along as it goes.

In our case, we're ticking backwards, but also using it to do the momentum too. It means rather than having both a momentum value, AND a ticker, we only really need one of them.
It's much easier this way.

-=-=-
''Load, Next List!''
Tue, 11 Mar 2008, 14:09
mike_g
Whoops, looks like I got a bit confused there o_0 Still getting the time will come in handy for seeding randomisation anyhow.
Tue, 11 Mar 2008, 14:18
Jayenkai
Yeah, I can't remember exactly what the PALib Randomiser is, so I'll check it once I get back home.
It's not too bad, though.. quite like Blitz's

-=-=-
''Load, Next List!''
Thu, 13 Mar 2008, 13:15
spanner
Well i changed the code abit to use the PALib Randomiser, now you can start the reels with the start buton on the image.The problem is you press the start button and the reels turn and they try to stop but they don't but if you use the A button they work fine..?

See for yourself..

Reel Crazy Fruit Sim

Heres the code..




-=-=-
Spanner
Sun, 16 Mar 2008, 19:01
spinal
try this...


I didn't test it, but it should work, you need to chek if the stylus is newly pressed, the stylus location is always remembered by palib, so it will always be in the zone, even if you're not pressing it.


-=-=-
Check out my excellent homepage!
Sun, 23 Mar 2008, 11:40
spanner
Thanks spin that did it..
Sun, 23 Mar 2008, 11:48
spanner
Now all i have to figer out is how to get the lights on the fruit machine to flicker at the right time with the reels.
so if a 1 and a 2 comes up the reel crazy name lights up 3 of its letters..

Any ideas..?

-=-=-
Spanner