Help :)
BlitzMax Forums/BlitzMax Programming/Help :)
| ||
| Hi I'm trying to improve movement in a slot machine. here is what I have done, but does not move naturally. http://ubuntuone.com/27fMg1n8D9BGRCekQW5eQa How does the reel of a slot machine. 1 - Accelerates 2 - Run freely 3 - Determine the symbol which has to stop. 4 - Slows 5 - Detention This piece of code does exactly that. but lacks things, but what I want is a more natural movement. Anyone have a better idea?! Regards I P/D My english is not my natural language, sorry if i made any mistake |
| ||
| You did a lot of code, but it is not necessary.... f.e. the degrees do not serve anything until you do not work with real 3D. So I would suggest to think about a ribbon of elements and only a few are visible. This would make the code much shorter. Also direction# is not necessary, you could simply change speed# to negative value to get a other direction. And to get speed# negativ you only have to set aceleration# negativ. here are some of my ideas: SuperStrict
Local images:TImage[10]
Local counter:Int = 0
Local total:Int = 10
For counter = 0 To total - 1
Local Nummer$= counter+1
Nummer=Right("00" + Nummer,2)
images[counter] = LoadImage("graphics/base/sym_" + Nummer + ".png")
Next
Graphics 640,480
Local ItemHight:Int = ImageHeight(images[0])
Local Position:Float = 1
Local Speed:Float = 0
Const TOP_SPEED:Float = 0.22
Local Aceleration:Float = 0
Const ACCEL:Float=0.001
Local X:Int = 100
Local Y:Int = 100
Local pos:Float
Global StartView% =50, EndView% =350
Global FPS:TTimer=CreateTimer(60)
While Not KeyHit( KEY_ESCAPE )
Speed = Speed + Aceleration
If Speed > TOP_SPEED Then
Speed = TOP_SPEED
ElseIf Speed < -TOP_SPEED Then
Speed = -TOP_SPEED
EndIf
Position = Position + Speed
If ( Position > Total) Then
Position = 0
ElseIf ( Position < 0 ) Then
Position = Total
End If
Cls
SetColor 255,255,255
For counter = 0 To total - 1
pos=((Position+Counter)*Itemhight) Mod (Total*Itemhight)
If ( pos >= StartView And pos <= EndView ) Then
DrawImage images[counter], X+200, pos
DrawImage images[counter], X+400, pos
End If
DrawImage images[counter], X+0, pos
Next
SetColor 221,1,1
DrawRect 400,0,300,150
DrawRect 400,300,300,200
Flip 0
WaitTimer fps
If KeyHit( KEY_1 )
Aceleration= ACCEL
ElseIf KeyHit( KEY_2 )
Aceleration= -ACCEL
End If
Wend the kernel is the handling of the acceleration. The KEYS only change aceleration#. This will change speed# and this will change position#. always do thing like this: check speed# limits immediately after you change it with aceleration#. check position# limits immediately after you change it with speed#. I did not add your status% things. But let me say: status should never control speed or position but events like KEYS or RND() here is a sample how to stop it correct. Use KEYs 1 2 to run the slotmachine and 3 to stop it: Last edited 2012 |
| ||
| Midi .. these are the days that I think how much i need to learn.. less code and better performance :) let me see |
| ||
| Midimaster, What do you think about this, and simulates stop effect of wheel.
SuperStrict
Const DOWN:Int = 1
Const UP:Int = -1
Const STOPED:Int = 0
Const ROLLING:Int = 1
Const STOPPING:Int = 2
Const SPEED_FACTOR:Float = 200
Local images:TImage[10]
Local counter:Int = 0
Local total:Int = 10
For counter = 0 To total - 1
Local Nummer$= counter+1
Nummer=Right("00" + Nummer,2)
images[counter] = LoadImage("graphics/base/sym_" + Nummer + ".png")
Next
Graphics 640,480
Local ItemHight:Int = ImageHeight(images[0])
Local Position:Float = 1
Local Direction:Int = DOWN
Local start_at:Float = 0
Local offset:Float = 0
Local state:Int = 0
Local stopto:Int = 10
Local loop:Int = 0
Local speed:Float = 0
Local angle:Float = 0
Local ShowStart:Int
Local ShowEnd:Int
Local pos:Int
Local X:Int = 100
Local Y:Int = 100
Global FPS:TTimer=CreateTimer(60)
While Not KeyHit( KEY_ESCAPE )
If state = ROLLING Then
If Direction = DOWN And offset >= ItemHight Then
start_at = start_at + 1
offset = 0
If ( start_at Mod total ) = stopto Then
loop :+ 1
If loop = 2 Then
speed = SPEED_FACTOR * 0.1
state = STOPPING
angle = 20
End If
End If
Else If Direction = UP And Offset <= ( ItemHight * -1 ) Then
start_at :+ 1
offset = 0
If ( start_at Mod total ) = stopto Then
loop :+ 1
If loop = 2 Then
speed = SPEED_FACTOR = 0.1
state = STOPPING
angle = 20
End If
End If
End If
Else If State = STOPPING
speed = SPEED_FACTOR * 0.03 * Sin(angle * 3.14 / 180)
angle :+ 25
If angle >= 365 Then
offset = 0
speed = 0
state = STOPED
End If
End If
If Direction = DOWN Then
ShowStart = -1
ShowEnd = 3
Else
ShowStart = 0
ShowEnd = 4
End If
Cls
For counter = ShowStart To ShowEnd
pos = ( start_at + counter ) Mod Total
If pos < 0 Then
pos = pos + Total
End If
' Print "POS : " + String(pos)
DrawImage images[pos], X, Y + ( ItemHight * Counter ) + offset
Next
Flip 0
WaitTimer fps
If state = ROLLING Then
speed = SPEED_FACTOR;
Else If state = STOPED
speed = 0;
End If
offset = offset + speed * Float(direction)
If KeyHit( KEY_1 )
' start downward
State = ROLLING
Loop = 0
StopTo = Rand(1, Total)
ElseIf KeyHit( KEY_2 )
' start upward
ElseIf KeyHit( KEY_3 )
' stop it
End If
Wend
|
| ||
| if you see some advantage for you.. why not... what I see: the pictures are now jumping to their next position, but do not move smooth. the pictures running incredibel fast and not like a rolling wheel. what is the reason you would prefer your code now? what do you try to get finally. Simulating the last moment of the movement, this "a little bit back" of the wheel, is not trivial.... I would do it by driving a little bit to far then go back then shake the pictures two three times. I my code to can play with the values of ACCEL# and TOP_SPEED# to adjust speed behavior. Perhaps it it necessary to have two different acelerations: RISE_ACCEL# and REDUCE_ACCEL# For different direction of three wheels I would use three variables like ..., aceleration_wheel1#, aceleration_wheel2#, aceleration_wheel3# Speed_wheel1#,... etc.. For the random I would manipulate the time each wheel is running and in the end have a look on which picture got in the center (like in reality) If you want to see a slot-machine in one of my software, install this music education game: http://www.midimaster.de/download/InterMezzo.exe the slot-machine is a fake, but shows a nice "in-motion unsharpness" Last edited 2012 |