Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Games
KBounce
Commits
a0196872
Commit
a0196872
authored
Sep 08, 2020
by
Albert Astals Cid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Port away from KRandom
parent
3d19174d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
10 deletions
+10
-10
ball.cpp
ball.cpp
+2
-2
board.cpp
board.cpp
+6
-6
renderer.cpp
renderer.cpp
+2
-2
No files found.
ball.cpp
View file @
a0196872
...
...
@@ -21,7 +21,7 @@
#include <cmath>
#include <
K
Random>
#include <
Q
Random
Generator
>
#include "board.h"
#include "renderer.h"
...
...
@@ -110,7 +110,7 @@ void KBounceBall::setRandomFrame()
int
frame
=
1
;
if
(
m_framesNum
>
1
)
{
frame
=
K
Random
::
random
()
%
m_framesNum
;
frame
=
Q
Random
Generator
::
global
()
->
bounded
(
m_framesNum
)
;
}
setFrame
(
frame
);
}
...
...
board.cpp
View file @
a0196872
...
...
@@ -18,11 +18,10 @@
#include "board.h"
#include <KRandom>
#include <QGraphicsScene>
#include <QTimer>
#include <QPainter>
#include <QRandomGenerator>
#include "ball.h"
#include "gameobject.h"
...
...
@@ -127,10 +126,11 @@ void KBounceBoard::newLevel( int level )
}
foreach
(
KBounceBall
*
ball
,
m_balls
)
{
ball
->
setRelativePos
(
4
+
KRandom
::
random
()
%
(
TILE_NUM_W
-
8
),
4
+
KRandom
::
random
()
%
(
TILE_NUM_H
-
8
)
);
ball
->
setVelocity
(
((
KRandom
::
random
()
&
1
)
*
2
-
1
)
*
m_ballVelocity
,
((
KRandom
::
random
()
&
1
)
*
2
-
1
)
*
m_ballVelocity
);
ball
->
setRelativePos
(
4
+
QRandomGenerator
::
global
()
->
bounded
(
TILE_NUM_W
-
8
),
4
+
QRandomGenerator
::
global
()
->
bounded
(
TILE_NUM_H
-
8
)
);
ball
->
setVelocity
(
(
QRandomGenerator
::
global
()
->
bounded
(
2
)
*
2
-
1
)
*
m_ballVelocity
,
(
QRandomGenerator
::
global
()
->
bounded
(
2
)
*
2
-
1
)
*
m_ballVelocity
);
ball
->
setRandomFrame
();
ball
->
show
();
}
...
...
renderer.cpp
View file @
a0196872
...
...
@@ -25,8 +25,8 @@
#include "debug.h"
#include <QDir>
#include <QRandomGenerator>
#include <krandom.h>
#include <KgThemeProvider>
static
KgThemeProvider
*
provider
()
...
...
@@ -116,7 +116,7 @@ QPixmap KBounceRenderer::getRandomBackgroundPixmap(const QString& path)
{
QString
filename
;
// return random pixmap
uint
pos
=
K
Random
::
random
()
%
dir
.
count
();
const
uint
pos
=
Q
Random
Generator
::
global
()
->
bounded
(
dir
.
count
()
)
;
if
(
pos
<
dir
.
count
()
)
{
filename
=
dir
.
absoluteFilePath
(
dir
[
pos
]
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment