Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
KGoldrunner
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Games
KGoldrunner
Commits
098e4d1a
Commit
098e4d1a
authored
Feb 01, 2009
by
Ian Wadham
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement a hero who runs, under mouse or keyboard control, and collects gold.
svn path=/branches/work/kgoldrunner/; revision=919490
parent
81e10f50
Changes
22
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
826 additions
and
996 deletions
+826
-996
src/kgoldrunner.cpp
src/kgoldrunner.cpp
+36
-110
src/kgoldrunner.h
src/kgoldrunner.h
+6
-12
src/kgrcanvas.cpp
src/kgrcanvas.cpp
+98
-98
src/kgrcanvas.h
src/kgrcanvas.h
+16
-15
src/kgrdialog.cpp
src/kgrdialog.cpp
+75
-73
src/kgrdialog.h
src/kgrdialog.h
+9
-9
src/kgreditor.cpp
src/kgreditor.cpp
+76
-1
src/kgreditor.h
src/kgreditor.h
+4
-2
src/kgrgame.cpp
src/kgrgame.cpp
+166
-517
src/kgrgame.h
src/kgrgame.h
+13
-90
src/kgrgameio.cpp
src/kgrgameio.cpp
+5
-5
src/kgrgameio.h
src/kgrgameio.h
+2
-2
src/kgrglobals.h
src/kgrglobals.h
+4
-0
src/kgrlevelgrid.h
src/kgrlevelgrid.h
+7
-0
src/kgrlevelplayer.cpp
src/kgrlevelplayer.cpp
+184
-18
src/kgrlevelplayer.h
src/kgrlevelplayer.h
+35
-4
src/kgrrulebook.cpp
src/kgrrulebook.cpp
+3
-0
src/kgrrulebook.h
src/kgrrulebook.h
+2
-0
src/kgrrunner.cpp
src/kgrrunner.cpp
+59
-28
src/kgrrunner.h
src/kgrrunner.h
+12
-8
src/kgrsprite.cpp
src/kgrsprite.cpp
+6
-3
src/kgrsprite.h
src/kgrsprite.h
+8
-1
No files found.
src/kgoldrunner.cpp
View file @
098e4d1a
...
...
@@ -48,8 +48,6 @@
#include <KCmdLineArgs>
#include <KAboutData>
// #include "kgrobject.h"
// #include "kgrfigure.h"
#include "kgrcanvas.h"
#include "kgrdialog.h"
#include "kgrgame.h"
...
...
@@ -101,8 +99,8 @@ KGoldrunner::KGoldrunner()
view
=
new
KGrCanvas
(
this
,
scale
,
systemDataDir
);
game
=
new
KGrGame
(
view
,
systemDataDir
,
userDataDir
);
// Initialise the
collections of levels (i.e. the list of game
s).
if
(
!
game
->
init
Collection
s
())
{
// Initialise the
lists of games (i.e. collections of level
s).
if
(
!
game
->
init
GameList
s
())
{
startupOK
=
false
;
return
;
// If no game files, abort.
}
...
...
@@ -110,16 +108,14 @@ KGoldrunner::KGoldrunner()
kDebug
()
<<
"Calling view->setBaseScale() ..."
;
view
->
setBaseScale
();
// Set scale for level-titles font.
// OBSOLESCENT - 9/1/09 hero = game->getHero(); // Get a pointer to the hero.
/******************************************************************************/
/************************* SET UP THE USER INTERFACE ************************/
/******************************************************************************/
// Get catalog for translation
// Get catalog for translation
.
KGlobal
::
locale
()
->
insertCatalog
(
"libkdegames"
);
// Tell the KMainWindow that th
is is the main widget
// Tell the KMainWindow that th
e KGrCanvas object is the main widget.
setCentralWidget
(
view
);
// Set up our actions (menu, toolbar and keystrokes) ...
...
...
@@ -195,7 +191,6 @@ void KGoldrunner::KGoldrunner_2()
KGoldrunner
::~
KGoldrunner
()
{
delete
kbMapper
;
}
void
KGoldrunner
::
setupActions
()
...
...
@@ -487,14 +482,15 @@ void KGoldrunner::setupActions()
kbMapper
=
new
QSignalMapper
(
this
);
connect
(
kbMapper
,
SIGNAL
(
mapped
(
int
)),
game
,
SLOT
(
kbControl
(
int
)));
tempMapper
=
kbMapper
;
// Save a parameter in keyControl().
k
b
Control
(
"stop"
,
i18n
(
"Stop"
),
Qt
::
Key_Space
,
STAND
);
k
b
Control
(
"move_right"
,
i18n
(
"Move Right"
),
Qt
::
Key_Right
,
RIGHT
);
k
b
Control
(
"move_left"
,
i18n
(
"Move Left"
),
Qt
::
Key_Left
,
LEFT
);
k
b
Control
(
"move_up"
,
i18n
(
"Move Up"
),
Qt
::
Key_Up
,
UP
);
k
b
Control
(
"move_down"
,
i18n
(
"Move Down"
),
Qt
::
Key_Down
,
DOWN
);
k
b
Control
(
"dig_right"
,
i18n
(
"Dig Right"
),
Qt
::
Key_C
,
DIG_RIGHT
);
k
b
Control
(
"dig_left"
,
i18n
(
"Dig Left"
),
Qt
::
Key_Z
,
DIG_LEFT
);
k
ey
Control
(
"stop"
,
i18n
(
"Stop"
),
Qt
::
Key_Space
,
STAND
);
k
ey
Control
(
"move_right"
,
i18n
(
"Move Right"
),
Qt
::
Key_Right
,
RIGHT
);
k
ey
Control
(
"move_left"
,
i18n
(
"Move Left"
),
Qt
::
Key_Left
,
LEFT
);
k
ey
Control
(
"move_up"
,
i18n
(
"Move Up"
),
Qt
::
Key_Up
,
UP
);
k
ey
Control
(
"move_down"
,
i18n
(
"Move Down"
),
Qt
::
Key_Down
,
DOWN
);
k
ey
Control
(
"dig_right"
,
i18n
(
"Dig Right"
),
Qt
::
Key_C
,
DIG_RIGHT
);
k
ey
Control
(
"dig_left"
,
i18n
(
"Dig Left"
),
Qt
::
Key_Z
,
DIG_LEFT
);
// Alternate one-handed controls. Set up in "kgoldrunnerui.rc".
...
...
@@ -506,7 +502,7 @@ void KGoldrunner::setupActions()
// Key_O, "dig_right"
// Key_U, "dig_left"
setupEditToolbarActions
();
// Uses pixmaps from "view".
setupEditToolbarActions
();
// Uses pixmaps from "view".
// Authors' debugging aids, effective when Pause is hit. Options include
// stepping through the animation, toggling a debug patch or log messages
...
...
@@ -518,96 +514,36 @@ void KGoldrunner::setupActions()
if
(
!
addDebuggingShortcuts
)
return
;
KAction
*
step
=
actionCollection
()
->
addAction
(
"do_step"
);
step
->
setText
(
i18n
(
"Step"
));
step
->
setShortcut
(
Qt
::
Key_Period
);
connect
(
step
,
SIGNAL
(
triggered
(
bool
)),
game
,
SLOT
(
doStep
()));
addAction
(
step
);
KAction
*
bugFix
=
actionCollection
()
->
addAction
(
"bug_fix"
);
bugFix
->
setText
(
i18n
(
"Test Bug Fix"
));
bugFix
->
setShortcut
(
Qt
::
Key_B
);
connect
(
bugFix
,
SIGNAL
(
triggered
(
bool
)),
game
,
SLOT
(
bugFix
()));
addAction
(
bugFix
);
KAction
*
showPos
=
actionCollection
()
->
addAction
(
"show_positions"
);
showPos
->
setText
(
i18n
(
"Show Positions"
));
showPos
->
setShortcut
(
Qt
::
Key_D
);
connect
(
showPos
,
SIGNAL
(
triggered
(
bool
)),
game
,
SLOT
(
showFigurePositions
()));
addAction
(
showPos
);
KAction
*
startLog
=
actionCollection
()
->
addAction
(
"logging"
);
startLog
->
setText
(
i18n
(
"Start Logging"
));
startLog
->
setShortcut
(
Qt
::
Key_G
);
connect
(
startLog
,
SIGNAL
(
triggered
(
bool
)),
game
,
SLOT
(
startLogging
()));
addAction
(
startLog
);
KAction
*
showHero
=
actionCollection
()
->
addAction
(
"show_hero"
);
showHero
->
setText
(
i18n
(
"Show Hero"
));
showHero
->
setShortcut
(
Qt
::
Key_R
);
// H is for Hint now.
connect
(
showHero
,
SIGNAL
(
triggered
(
bool
)),
game
,
SLOT
(
showHeroState
()));
addAction
(
showHero
);
KAction
*
showObj
=
actionCollection
()
->
addAction
(
"show_obj"
);
showObj
->
setText
(
i18n
(
"Show Object"
));
showObj
->
setShortcut
(
Qt
::
Key_Question
);
connect
(
showObj
,
SIGNAL
(
triggered
(
bool
)),
game
,
SLOT
(
showObjectState
()));
addAction
(
showObj
);
KAction
*
showEnemy0
=
actionCollection
()
->
addAction
(
"show_enemy_0"
);
showEnemy0
->
setText
(
i18n
(
"Show Enemy"
)
+
'0'
);
showEnemy0
->
setShortcut
(
Qt
::
Key_0
);
connect
(
showEnemy0
,
SIGNAL
(
triggered
(
bool
)),
this
,
SLOT
(
showEnemy0
()));
addAction
(
showEnemy0
);
KAction
*
showEnemy1
=
actionCollection
()
->
addAction
(
"show_enemy_1"
);
showEnemy1
->
setText
(
i18n
(
"Show Enemy"
)
+
'1'
);
showEnemy1
->
setShortcut
(
Qt
::
Key_1
);
connect
(
showEnemy1
,
SIGNAL
(
triggered
(
bool
)),
this
,
SLOT
(
showEnemy1
()));
addAction
(
showEnemy1
);
KAction
*
showEnemy2
=
actionCollection
()
->
addAction
(
"show_enemy_2"
);
showEnemy2
->
setText
(
i18n
(
"Show Enemy"
)
+
'2'
);
showEnemy2
->
setShortcut
(
Qt
::
Key_2
);
connect
(
showEnemy2
,
SIGNAL
(
triggered
(
bool
)),
this
,
SLOT
(
showEnemy2
()));
addAction
(
showEnemy2
);
KAction
*
showEnemy3
=
actionCollection
()
->
addAction
(
"show_enemy_3"
);
showEnemy3
->
setText
(
i18n
(
"Show Enemy"
)
+
'3'
);
showEnemy3
->
setShortcut
(
Qt
::
Key_3
);
connect
(
showEnemy3
,
SIGNAL
(
triggered
(
bool
)),
this
,
SLOT
(
showEnemy3
()));
addAction
(
showEnemy3
);
KAction
*
showEnemy4
=
actionCollection
()
->
addAction
(
"show_enemy_4"
);
showEnemy4
->
setText
(
i18n
(
"Show Enemy"
)
+
'4'
);
showEnemy4
->
setShortcut
(
Qt
::
Key_4
);
connect
(
showEnemy4
,
SIGNAL
(
triggered
(
bool
)),
this
,
SLOT
(
showEnemy4
()));
addAction
(
showEnemy4
);
KAction
*
showEnemy5
=
actionCollection
()
->
addAction
(
"show_enemy_5"
);
showEnemy5
->
setText
(
i18n
(
"Show Enemy"
)
+
'5'
);
showEnemy5
->
setShortcut
(
Qt
::
Key_5
);
connect
(
showEnemy5
,
SIGNAL
(
triggered
(
bool
)),
this
,
SLOT
(
showEnemy5
()));
addAction
(
showEnemy5
);
KAction
*
showEnemy6
=
actionCollection
()
->
addAction
(
"show_enemy_6"
);
showEnemy6
->
setText
(
i18n
(
"Show Enemy"
)
+
'6'
);
showEnemy6
->
setShortcut
(
Qt
::
Key_6
);
connect
(
showEnemy6
,
SIGNAL
(
triggered
(
bool
)),
this
,
SLOT
(
showEnemy6
()));
addAction
(
showEnemy6
);
dbgMapper
=
new
QSignalMapper
(
this
);
connect
(
dbgMapper
,
SIGNAL
(
mapped
(
int
)),
game
,
SLOT
(
dbgControl
(
int
)));
tempMapper
=
dbgMapper
;
// Saves a parameter in keyControl().
keyControl
(
"do_step"
,
i18n
(
"Do a Step"
),
Qt
::
Key_Period
,
DO_STEP
);
keyControl
(
"bug_fix"
,
i18n
(
"Test Bug Fix"
),
Qt
::
Key_B
,
BUG_FIX
);
keyControl
(
"show_positions"
,
i18n
(
"Show Positions"
),
Qt
::
Key_D
,
S_POSNS
);
keyControl
(
"logging"
,
i18n
(
"Start Logging"
),
Qt
::
Key_G
,
LOGGING
);
keyControl
(
"show_hero"
,
i18n
(
"Show Hero"
),
Qt
::
Key_R
,
S_HERO
);
keyControl
(
"show_obj"
,
i18n
(
"Show Object"
),
Qt
::
Key_Question
,
S_OBJ
);
keyControl
(
"show_enemy_0"
,
i18n
(
"Show Enemy"
)
+
'0'
,
Qt
::
Key_0
,
ENEMY_0
);
keyControl
(
"show_enemy_1"
,
i18n
(
"Show Enemy"
)
+
'1'
,
Qt
::
Key_1
,
ENEMY_1
);
keyControl
(
"show_enemy_2"
,
i18n
(
"Show Enemy"
)
+
'2'
,
Qt
::
Key_2
,
ENEMY_2
);
keyControl
(
"show_enemy_3"
,
i18n
(
"Show Enemy"
)
+
'3'
,
Qt
::
Key_3
,
ENEMY_3
);
keyControl
(
"show_enemy_4"
,
i18n
(
"Show Enemy"
)
+
'4'
,
Qt
::
Key_4
,
ENEMY_4
);
keyControl
(
"show_enemy_5"
,
i18n
(
"Show Enemy"
)
+
'5'
,
Qt
::
Key_5
,
ENEMY_5
);
keyControl
(
"show_enemy_6"
,
i18n
(
"Show Enemy"
)
+
'6'
,
Qt
::
Key_6
,
ENEMY_6
);
}
void
KGoldrunner
::
k
b
Control
(
const
QString
&
name
,
const
QString
&
text
,
const
QKeySequence
&
shortcut
,
const
int
dirn
)
void
KGoldrunner
::
k
ey
Control
(
const
QString
&
name
,
const
QString
&
text
,
const
QKeySequence
&
shortcut
,
const
int
code
)
{
// Create an action for keyboard control of KGoldrunner and connect it to
// slot game->kbControl(int), via kbMapper and mapping-code = direction.
// a game-> slot, via a QSignalMapper and a mapping-code (e.g. direction).
KAction
*
a
=
actionCollection
()
->
addAction
(
name
);
a
->
setText
(
text
);
a
->
setShortcut
(
shortcut
);
connect
(
a
,
SIGNAL
(
triggered
(
bool
)),
kb
Mapper
,
SLOT
(
map
()));
kbMapper
->
setMapping
(
a
,
dirn
);
connect
(
a
,
SIGNAL
(
triggered
(
bool
)),
temp
Mapper
,
SLOT
(
map
()));
tempMapper
->
setMapping
(
a
,
code
);
addAction
(
a
);
}
...
...
@@ -883,16 +819,6 @@ void KGoldrunner::setKGrRules()
// KGrFigure::searchStrategy = MEDIUM;
}
// Local slots for authors' debugging aids.
void
KGoldrunner
::
showEnemy0
()
{
game
->
showEnemyState
(
0
);}
void
KGoldrunner
::
showEnemy1
()
{
game
->
showEnemyState
(
1
);}
void
KGoldrunner
::
showEnemy2
()
{
game
->
showEnemyState
(
2
);}
void
KGoldrunner
::
showEnemy3
()
{
game
->
showEnemyState
(
3
);}
void
KGoldrunner
::
showEnemy4
()
{
game
->
showEnemyState
(
4
);}
void
KGoldrunner
::
showEnemy5
()
{
game
->
showEnemyState
(
5
);}
void
KGoldrunner
::
showEnemy6
()
{
game
->
showEnemyState
(
6
);}
void
KGoldrunner
::
saveProperties
(
KConfigGroup
&
/* config - unused */
)
{
// The 'config' object points to the session managed
...
...
src/kgoldrunner.h
View file @
098e4d1a
...
...
@@ -122,15 +122,6 @@ private slots:
void
setTradRules
();
void
setKGrRules
();
// Local slots for authors' debugging aids.
void
showEnemy0
();
void
showEnemy1
();
void
showEnemy2
();
void
showEnemy3
();
void
showEnemy4
();
void
showEnemy5
();
void
showEnemy6
();
// void optionsShowToolbar();
// void optionsShowStatusbar();
void
optionsConfigureKeys
();
...
...
@@ -160,9 +151,12 @@ private:
void
setupEditToolbarActions
();
void
setupThemes
();
QSignalMapper
*
kbMapper
;
void
kbControl
(
const
QString
&
name
,
const
QString
&
text
,
const
QKeySequence
&
shortcut
,
const
int
dirn
);
QSignalMapper
*
kbMapper
;
// Keyboard game-control mapper.
QSignalMapper
*
dbgMapper
;
// Debugging-key mapper.
QSignalMapper
*
tempMapper
;
// Temporary pointer.
void
keyControl
(
const
QString
&
name
,
const
QString
&
text
,
const
QKeySequence
&
shortcut
,
const
int
code
);
private:
bool
startupOK
;
...
...
src/kgrcanvas.cpp
View file @
098e4d1a
...
...
@@ -56,8 +56,8 @@ KGrCanvas::KGrCanvas (QWidget * parent, const double scale,
m_scoreDisplay
(
0
),
m_livesDisplay
(
0
),
m_fadingTimeLine
(
1000
,
this
),
emptySprites
(
0
),
theme
(
systemDataDir
)
{
resizeCount
=
0
;
// IDW
...
...
@@ -79,10 +79,8 @@ KGrCanvas::KGrCanvas (QWidget * parent, const double scale,
border
=
4
;
// Make border at least tiles wide all around.
lineDivider
=
8
;
// Make lines of inner border 1/8 tile wide.
heroSprite
=
0
;
// Create an empty list of enemy sprites.
enemySprites
=
new
QList
<
KGrSprite
*>
();
// Create an empty list of sprites.
sprites
=
new
QList
<
KGrSprite
*>
();
kDebug
()
<<
"Calling initView() ..."
;
initView
();
// Set up the graphics, etc.
...
...
@@ -121,7 +119,8 @@ KGrCanvas::~KGrCanvas()
tileset
->
clear
();
heroFrames
->
clear
();
enemyFrames
->
clear
();
deleteEnemySprites
();
deleteAllSprites
();
while
(
!
borderRectangles
.
isEmpty
())
delete
borderRectangles
.
takeFirst
();
while
(
!
borderElements
.
isEmpty
())
...
...
@@ -131,8 +130,7 @@ KGrCanvas::~KGrCanvas()
delete
tileset
;
delete
heroFrames
;
delete
enemyFrames
;
delete
heroSprite
;
delete
enemySprites
;
delete
sprites
;
delete
m_spotLight
;
delete
m_scoreText
;
delete
m_livesText
;
...
...
@@ -214,32 +212,29 @@ void KGrCanvas::drawTheScene (bool changePixmaps)
}
kDebug
()
<<
t
.
restart
()
<<
"msec. Hero + enemies done."
;
int
spriteframe
;
int
spriteframe
;
QPoint
spriteloc
;
// Draw the hero.
if
(
heroSprite
)
{
spriteframe
=
heroSprite
->
currentFrame
();
spriteloc
=
heroSprite
->
currentLoc
();
heroSprite
->
addFrames
(
heroFrames
,
topLeft
,
scale
);
// Force a re-draw of both pixmap and position.
heroSprite
->
move
(
0
,
0
,
(
spriteframe
>
0
)
?
0
:
1
);
heroSprite
->
move
(
spriteloc
.
x
(),
spriteloc
.
y
(),
spriteframe
);
}
if
(
enemySprites
)
{
for
(
int
i
=
0
;
i
<
enemySprites
->
size
();
++
i
)
{
// kDebug() << "accessing enemySprite" << i;
KGrSprite
*
thisenemy
=
enemySprites
->
at
(
i
);
if
(
thisenemy
)
{
spriteframe
=
thisenemy
->
currentFrame
();
spriteloc
=
thisenemy
->
currentLoc
();
thisenemy
->
addFrames
(
enemyFrames
,
topLeft
,
scale
);
char
spritetype
;
if
(
sprites
)
{
foreach
(
KGrSprite
*
sprite
,
(
*
sprites
))
{
if
(
sprite
)
{
spriteframe
=
sprite
->
currentFrame
();
spriteloc
=
sprite
->
currentLoc
();
spritetype
=
sprite
->
spriteType
();
switch
(
spritetype
)
{
case
HERO
:
sprite
->
addFrames
(
heroFrames
,
topLeft
,
scale
);
break
;
case
ENEMY
:
sprite
->
addFrames
(
enemyFrames
,
topLeft
,
scale
);
break
;
}
// Force re-draw of both pixmap and position.
thisenemy
->
move
(
0
,
0
,
(
spriteframe
>
0
)
?
0
:
1
);
thisenemy
->
move
(
spriteloc
.
x
(),
spriteloc
.
y
(),
spriteframe
);
sprite
->
move
(
0
,
0
,
(
spriteframe
>
0
)
?
0
:
1
);
sprite
->
move
(
spriteloc
.
x
(),
spriteloc
.
y
(),
spriteframe
);
}
}
}
...
...
@@ -510,33 +505,63 @@ void KGrCanvas::setMousePos (int i, int j)
void
KGrCanvas
::
animate
()
{
heroSprite
->
animate
();
foreach
(
KGrSprite
*
sprite
,
(
*
sprites
))
{
if
(
sprite
->
spriteType
()
==
HERO
)
{
sprite
->
animate
();
// Animate the hero.
}
}
}
void
KGrCanvas
::
setSpriteType
(
const
int
id
,
const
char
type
,
int
row
,
int
col
)
int
KGrCanvas
::
makeSprite
(
const
char
type
,
int
i
,
int
j
)
{
kDebug
()
<<
"id"
<<
id
<<
"sprite type"
<<
type
;
int
spriteId
;
KGrSprite
*
sprite
=
new
KGrSprite
(
this
,
type
);
// TODO - Improve and extend this code.
if
((
type
==
HERO
)
&&
(
id
==
0
))
{
if
(
!
heroSprite
)
{
kDebug
()
<<
"Call makeHeroSprite (row, col, FALL1);"
<<
row
<<
col
;
makeHeroSprite
(
row
,
col
,
FALL1
);
}
if
((
emptySprites
>
0
)
&&
((
spriteId
=
sprites
->
lastIndexOf
(
0
))
>=
0
))
{
// Re-use a slot previously occupied by a transient member of the list.
(
*
sprites
)
[
spriteId
]
=
sprite
;
emptySprites
--
;
}
if
(
type
==
ENEMY
)
{
kDebug
()
<<
"Call makeEnemySprite (row, col, FALL1);"
<<
row
<<
col
;
makeEnemySprite
(
row
,
col
,
FALL1
);
else
{
// Otherwise, add to the end of the list.
spriteId
=
sprites
->
count
();
sprites
->
append
(
sprite
);
emptySprites
=
0
;
}
int
z
=
0
;
double
scale
=
(
double
)
imgW
/
(
double
)
bgw
;
switch
(
type
)
{
case
HERO
:
sprite
->
addFrames
(
heroFrames
,
topLeft
,
scale
);
z
=
1
;
break
;
case
ENEMY
:
sprite
->
addFrames
(
enemyFrames
,
topLeft
,
scale
);
z
=
2
;
break
;
default:
break
;
}
// In KGoldrunner, the top-left visible cell is [1,1]: in KGrSprite [0,0].
sprite
->
move
((
i
-
1
)
*
bgw
,
(
j
-
1
)
*
bgh
,
FALL1
);
sprite
->
setZ
(
z
);
sprite
->
show
();
kDebug
()
<<
"Sprite ID"
<<
spriteId
<<
"sprite type"
<<
type
;
return
spriteId
;
}
void
KGrCanvas
::
startAnimation
(
const
int
id
,
const
int
row
,
const
int
col
,
void
KGrCanvas
::
startAnimation
(
const
int
id
,
const
int
i
,
const
int
j
,
const
int
time
,
const
Direction
dirn
,
const
AnimationType
type
)
{
// TODO - Save last direction somehow, to use in facing and centering code.
// TODO - Put most of this in helper code, based on theme parameters.
// TODO - Use a QList of animation parameters: one entry per id.
// TODO - Need to select plain or gold-carrying enemy frames somehow.
int
frame
;
int
nFrames
=
8
;
int
dx
=
0
;
...
...
@@ -577,71 +602,52 @@ void KGrCanvas::startAnimation (const int id, const int row, const int col,
default:
break
;
}
kDebug
()
<<
"row col dirn dx dy frame"
<<
row
<<
col
<<
dirn
<<
dx
<<
dy
<<
frame
;
// TODO - runAnimation (int id, int row, int col, int frame,
// int nFrames, int dx, int dy, int dt);
// TODO - Remove the following code.
if
(
id
==
0
)
{
heroSprite
->
setAnimation
((
row
-
1
)
*
bgw
,
(
col
-
1
)
*
bgh
,
frame
,
nFrames
,
dx
,
dy
,
dt
);
}
kDebug
()
<<
"id"
<<
id
<<
"x y dirn dx dy frame"
<<
i
<<
j
<<
dirn
<<
dx
<<
dy
<<
frame
;
sprites
->
at
(
id
)
->
setAnimation
((
i
-
1
)
*
bgw
,
(
j
-
1
)
*
bgh
,
frame
,
nFrames
,
dx
,
dy
,
dt
);
}
void
KGrCanvas
::
resynchAnimation
(
const
int
id
,
const
int
row
,
const
int
col
,
void
KGrCanvas
::
resynchAnimation
(
const
int
id
,
const
int
i
,
const
int
j
,
const
bool
stop
)
{
// TODO - Write this code.
}
void
KGrCanvas
::
deleteAnimation
(
const
int
id
)
{
// TODO - Improve and extend this code.
if
(
id
==
0
)
{
if
(
heroSprite
)
{
delete
heroSprite
;
heroSprite
=
0
;
}
}
}
void
KGrCanvas
::
makeHeroSprite
(
int
i
,
int
j
,
int
startFrame
)
void
KGrCanvas
::
gotGold
(
const
int
spriteID
,
const
int
i
,
const
int
j
,
const
bool
spriteHasGold
)
{
heroSprite
=
new
KGrSprite
(
this
);
// Hide collected gold or show dropped gold.
paintCell
(
i
,
j
,
(
spriteHasGold
)
?
FREE
:
NUGGET
);
double
scale
=
(
double
)
imgW
/
(
double
)
bgw
;
heroSprite
->
addFrames
(
heroFrames
,
topLeft
,
scale
);
// In KGoldrunner, the top-left visible cell is [1,1]: in KGrSprite [0,0].
i
--
;
j
--
;
heroSprite
->
move
(
i
*
bgw
,
j
*
bgh
,
startFrame
);
heroSprite
->
setZ
(
1
);
heroSprite
->
setVisible
(
true
);
// If the rules allow, show if an enemy sprite is carrying some gold.
if
(
enemiesShowGold
&&
(
sprites
->
at
(
spriteID
)
->
spriteType
()
==
ENEMY
))
{
sprites
->
at
(
spriteID
)
->
setFrameOffset
(
spriteHasGold
?
goldEnemy
:
0
);
}
}
void
KGrCanvas
::
setHeroVisible
(
bool
newState
)
void
KGrCanvas
::
deleteSprite
(
const
int
spriteId
)
{
heroSprite
->
setVisible
(
newState
);
// Show or hide the hero.
delete
sprites
->
at
(
spriteId
);
(
*
sprites
)[
spriteId
]
=
0
;
emptySprites
++
;
}
void
KGrCanvas
::
makeEnemySprite
(
int
i
,
int
j
,
int
startFrame
)
void
KGrCanvas
::
deleteAllSprites
(
)
{
KGrSprite
*
enemySprite
=
new
KGrSprite
(
this
);
double
scale
=
(
double
)
imgW
/
(
double
)
bgw
;
enemySprite
->
addFrames
(
enemyFrames
,
topLeft
,
scale
);
enemySprites
->
append
(
enemySprite
);
// In KGoldrunner, the top-left visible cell is [1,1]: in KGrSprite [0,0].
i
--
;
j
--
;
enemySprite
->
move
(
i
*
bgw
,
j
*
bgh
,
startFrame
);
enemySprite
->
setZ
(
2
);
enemySprite
->
show
();
KGrSprite
*
sprite
=
0
;
while
(
!
sprites
->
isEmpty
())
{
sprite
=
sprites
->
takeFirst
();
if
(
sprite
!=
0
)
{
delete
sprite
;
}
}
emptySprites
=
0
;
}
void
KGrCanvas
::
moveHero
(
int
x
,
int
y
,
int
fram
e
)
void
KGrCanvas
::
setHeroVisible
(
bool
newStat
e
)
{
//
In KGoldrunner, the top-left visible cell is [1,1]: in KGrSprite [0,0]
.
heroSprite
->
move
(
x
-
bgw
,
y
-
bgh
,
frame
);
//
TODO - Check whether this function is needed by KGrGame now
.
// heroSprite->setVisible (newState); // Show or hide the hero.
}
void
KGrCanvas
::
moveEnemy
(
int
id
,
int
x
,
int
y
,
int
frame
,
int
nuggets
)
...
...
@@ -652,13 +658,7 @@ void KGrCanvas::moveEnemy (int id, int x, int y, int frame, int nuggets)
// In KGoldrunner, the top-left visible cell is [1,1]: in KGrSprite [0,0].
// kDebug() << "accessing enemySprite" << id;
enemySprites
->
at
(
id
)
->
move
(
x
-
bgw
,
y
-
bgh
,
frame
);
}
void
KGrCanvas
::
deleteEnemySprites
()
{
while
(
!
enemySprites
->
isEmpty
())
delete
enemySprites
->
takeFirst
();
// OBSOLESCENT - 28/1/09 enemySprites->at (id)->move (x - bgw, y - bgh, frame);
}
QPixmap
KGrCanvas
::
getPixmap
(
char
type
)
...
...
src/kgrcanvas.h
View file @
098e4d1a
...
...
@@ -53,10 +53,8 @@ public:
void
setTitle
(
const
QString
&
);
void
setHeroVisible
(
bool
);
void
moveHero
(
int
x
,
int
y
,
int
frame
);
void
moveEnemy
(
int
,
int
,
int
,
int
,
int
);
void
deleteEnemySprites
();
void
goToBlack
();
void
fadeIn
();
...
...
@@ -73,23 +71,23 @@ public:
*/
void
setLevel
(
unsigned
int
level
);
inline
void
setGoldEnemiesRule
(
bool
showIt
)
{
enemiesShowGold
=
showIt
;}
public
slots
:
void
animate
();
void
paintCell
(
const
int
row
,
const
int
col
,
const
char
type
,
void
paintCell
(
const
int
i
,
const
int
j
,
const
char
type
,
const
int
offset
=
0
);
void
setSpriteType
(
const
int
id
,
const
char
type
,
int
row
,
int
col
);
void
startAnimation
(
const
int
id
,
const
int
row
,
const
int
col
,
int
makeSprite
(
const
char
type
,
int
i
,
int
j
);
void
startAnimation
(
const
int
id
,
const
int
i
,
const
int
j
,
const
int
time
,
const
Direction
dirn
,
const
AnimationType
type
);
void
resynchAnimation
(
const
int
id
,
const
int
row
,
const
int
col
,
void
resynchAnimation
(
const
int
id
,
const
int
i
,
const
int
j
,
const
bool
stop
);
void
deleteAnimation
(
const
int
id
);
void
makeHeroSprite
(
int
,
int
,
int
);
void
makeEnemySprite
(
int
,
int
,
int
);
inline
void
jumpHero
(
int
i
,
int
j
,
int
frame
)
// OBSOLESCENT? - 9/1/09
{
moveHero
(
i
*
bgw
,
j
*
bgh
,
frame
);
}
void
gotGold
(
const
int
spriteID
,
const
int
i
,
const
int
j
,
const
bool
spriteHasGold
);
void
deleteSprite
(
const
int
id
);
void
deleteAllSprites
();
signals:
void
mouseClick
(
int
);
...
...
@@ -157,8 +155,9 @@ private:
QTimeLine
m_fadingTimeLine
;
KGrSprite
*
heroSprite
;
QList
<
KGrSprite
*>
*
enemySprites
;
int
emptySprites
;
QList
<
KGrSprite
*>
*
sprites
;
QList
<
KGameCanvasRectangle
*>
borderRectangles
;
QList
<
KGameCanvasPixmap
*>
borderElements
;
QColor
colour
;
...
...
@@ -180,6 +179,8 @@ private:
// Keep current score and lives
int
lives
;
int
score
;
bool
enemiesShowGold
;
// Show or conceal if enemies have gold.
};
#endif // KGRCANVAS_H
// vi: set sw=4 :
src/kgrdialog.cpp
View file @
098e4d1a
...
...
@@ -10,7 +10,8 @@
#include "kgrdialog.h"
#include "kgrconsts.h"
#include "kgrconsts.h" // OBSOLESCENT - 30/1/09
#include "kgrglobals.h"
#include "kgrcanvas.h"
#include "kgrgame.h"
...
...
@@ -26,17 +27,17 @@
/***************** DIALOG BOX TO SELECT A GAME AND LEVEL *****************/
/******************************************************************************/
KGrSLDialog
::
KGrSLDialog
(
int
action
,
int
requestedLevel
,
int
colln
Index
,
QList
<
KGr
Collection
*>
&
games
List
,
KGrGame
*
theGame
,
KGrSLDialog
::
KGrSLDialog
(
int
action
,
int
requestedLevel
,
int
game
Index
,
QList
<
KGr
GameData
*>
&
game
List
,
KGrGame
*
theGame
,
QWidget
*
parent
)
:
KDialog
(
parent
)
{
slAction
=
action
;
defaultLevel
=
requestedLevel
;
defaultGame
=
colln
Index
;
collections
=
games
List
;
game
=
theGame
;
collection
=
collections
.
at
(
defaultGame
);
defaultGame
=
game
Index
;
myGameList
=
game
List
;