summaryrefslogtreecommitdiffstats
path: root/ktux/spritemisc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ktux/spritemisc.cpp')
-rw-r--r--ktux/spritemisc.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/ktux/spritemisc.cpp b/ktux/spritemisc.cpp
new file mode 100644
index 0000000..f3a9a73
--- /dev/null
+++ b/ktux/spritemisc.cpp
@@ -0,0 +1,69 @@
+//-----------------------------------------------------------------------------
+//
+// spritemisc
+//
+// Copyright (c) Martin R. Jones 1999
+//
+
+#include <kapplication.h>
+#include "spritemisc.h"
+
+QSize SpriteRange::mFieldSize;
+
+SpriteRange::SpriteRange(const QString &str)
+{
+ set(str);
+}
+
+int SpriteRange::random() const
+{
+ int val = mMin;
+
+ if (mMax != mMin)
+ {
+ val = (KApplication::random()%(mMax-mMin)) + mMin;
+ }
+
+ return val;
+}
+
+void SpriteRange::set(const QString &str)
+{
+ int r = str.find("..");
+
+ if (r > 0)
+ {
+ mMin = parse(str.left(r));
+ mMax = parse(str.mid(r+2, 10));
+ }
+ else
+ {
+ mMin = mMax = parse(str);
+ }
+}
+
+void SpriteRange::setFieldSize(const QSize &size)
+{
+ mFieldSize = size;
+}
+
+int SpriteRange::parse(const QString &str)
+{
+ int val = 0;
+
+ if (str == "WIDTH")
+ {
+ val = mFieldSize.width();
+ }
+ else if (str == "HEIGHT")
+ {
+ val = mFieldSize.height();
+ }
+ else
+ {
+ val = str.toInt();
+ }
+
+ return val;
+}
+