Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
openjazz
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
openjazz
Commits
5e941c85
Commit
5e941c85
authored
Jan 19, 2010
by
alistert
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Gameplay processing now takes place a maximum of ~60 times per second. Improved bridges.
parent
2cbd2c54
Changes
24
Show whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
526 additions
and
411 deletions
+526
-411
clientgame.cpp
src/game/clientgame.cpp
+4
-4
game.cpp
src/game/game.cpp
+6
-8
game.h
src/game/game.h
+5
-5
servergame.cpp
src/game/servergame.cpp
+1
-1
paletteeffects.cpp
src/io/gfx/paletteeffects.cpp
+29
-22
paletteeffects.h
src/io/gfx/paletteeffects.h
+11
-11
video.h
src/io/gfx/video.h
+0
-1
bullet.cpp
src/level/bullet.cpp
+18
-14
bullet.h
src/level/bullet.h
+14
-12
demolevel.cpp
src/level/demolevel.cpp
+9
-3
event.cpp
src/level/event/event.cpp
+16
-17
event.h
src/level/event/event.h
+7
-9
eventframe.cpp
src/level/event/eventframe.cpp
+118
-117
level.cpp
src/level/level.cpp
+33
-21
level.h
src/level/level.h
+6
-6
levelframe.cpp
src/level/levelframe.cpp
+31
-25
main.cpp
src/main.cpp
+7
-9
movable.cpp
src/movable.cpp
+58
-0
movable.h
src/movable.h
+48
-0
bird.cpp
src/player/bird.cpp
+11
-25
bird.h
src/player/bird.h
+4
-6
player.cpp
src/player/player.cpp
+10
-22
player.h
src/player/player.h
+17
-19
playerframe.cpp
src/player/playerframe.cpp
+63
-54
No files found.
src/game/clientgame.cpp
View file @
5e941c85
...
...
@@ -209,7 +209,7 @@ ClientGame::ClientGame (char *address) {
clearScreen
(
0
);
fontmn2
->
showString
(
"JOINING GAME"
,
screenW
>>
2
,
(
screenH
>>
1
)
-
16
);
ret
=
playFrame
(
-
1
);
ret
=
step
(
0
);
if
(
ret
<
0
)
{
...
...
@@ -270,7 +270,7 @@ int ClientGame::setLevel (char *fileName) {
fontmn2
->
showString
(
"WAITING FOR SERVER"
,
screenW
>>
2
,
(
screenH
>>
1
)
-
16
);
ret
=
playFrame
(
-
1
);
ret
=
step
(
0
);
if
(
ret
<
0
)
return
ret
;
...
...
@@ -290,7 +290,7 @@ int ClientGame::setLevel (char *fileName) {
fontmn2
->
showNumber
(
file
->
tell
(),
(
screenW
>>
2
)
+
56
,
screenH
>>
1
);
fontmn2
->
showString
(
"bytes"
,
(
screenW
>>
2
)
+
64
,
screenH
>>
1
);
ret
=
playFrame
(
-
1
);
ret
=
step
(
0
);
if
(
ret
<
0
)
return
ret
;
...
...
@@ -310,7 +310,7 @@ void ClientGame::send (unsigned char *buffer) {
}
int
ClientGame
::
playFrame
(
int
ticks
)
{
int
ClientGame
::
step
(
unsigned
int
ticks
)
{
unsigned
char
sendBuffer
[
BUFFER_LENGTH
];
int
length
,
count
;
...
...
src/game/game.cpp
View file @
5e941c85
...
...
@@ -179,17 +179,15 @@ int Game::play () {
}
void
Game
::
view
()
{
void
Game
::
view
(
int
change
)
{
// Move the viewport towards the exit sign
if
(
TTOF
(
checkX
)
>
viewX
+
(
viewW
<<
9
)
+
(
160
*
mspf
))
viewX
+=
160
*
mspf
;
else
if
(
TTOF
(
checkX
)
<
viewX
+
(
viewW
<<
9
)
-
(
160
*
mspf
))
viewX
-=
160
*
mspf
;
if
(
TTOF
(
checkX
)
>
viewX
+
(
viewW
<<
9
)
+
change
)
viewX
+=
change
;
else
if
(
TTOF
(
checkX
)
<
viewX
+
(
viewW
<<
9
)
-
change
)
viewX
-=
change
;
if
(
TTOF
(
checkY
)
>
viewY
+
(
viewH
<<
9
)
+
(
160
*
mspf
))
viewY
+=
160
*
mspf
;
else
if
(
TTOF
(
checkY
)
<
viewY
+
(
viewH
<<
9
)
-
(
160
*
mspf
))
viewY
-=
160
*
mspf
;
if
(
TTOF
(
checkY
)
>
viewY
+
(
viewH
<<
9
)
+
change
)
viewY
+=
change
;
else
if
(
TTOF
(
checkY
)
<
viewY
+
(
viewH
<<
9
)
-
change
)
viewY
-=
change
;
return
;
...
...
@@ -205,7 +203,7 @@ void Game::send (unsigned char *buffer) {
}
int
Game
::
playFrame
(
int
ticks
)
{
int
Game
::
step
(
unsigned
int
ticks
)
{
// Do nothing
...
...
src/game/game.h
View file @
5e941c85
...
...
@@ -85,7 +85,7 @@ class Game {
protected
:
char
*
levelFile
;
int
difficulty
;
int
sendTime
,
checkTime
;
unsigned
int
sendTime
,
checkTime
;
unsigned
char
checkX
,
checkY
;
Game
();
...
...
@@ -96,9 +96,9 @@ class Game {
virtual
int
setLevel
(
char
*
fileName
);
int
play
();
void
view
();
void
view
(
int
change
);
virtual
void
send
(
unsigned
char
*
buffer
);
virtual
int
playFrame
(
int
ticks
);
virtual
int
step
(
unsigned
int
ticks
);
virtual
void
score
(
unsigned
char
team
);
virtual
void
setCheckpoint
(
unsigned
char
gridX
,
unsigned
char
gridY
);
void
resetPlayer
(
Player
*
player
);
...
...
@@ -127,7 +127,7 @@ class ServerGame : public Game {
int
setLevel
(
char
*
fileName
);
void
send
(
unsigned
char
*
buffer
);
int
playFrame
(
int
ticks
);
int
step
(
unsigned
int
ticks
);
void
score
(
unsigned
char
team
);
void
setCheckpoint
(
unsigned
char
gridX
,
unsigned
char
gridY
);
...
...
@@ -150,7 +150,7 @@ class ClientGame : public Game {
int
setLevel
(
char
*
fileName
);
void
send
(
unsigned
char
*
buffer
);
int
playFrame
(
int
ticks
);
int
step
(
unsigned
int
ticks
);
void
score
(
unsigned
char
team
);
void
setCheckpoint
(
unsigned
char
gridX
,
unsigned
char
gridY
);
...
...
src/game/servergame.cpp
View file @
5e941c85
...
...
@@ -181,7 +181,7 @@ void ServerGame::send (unsigned char *buffer) {
}
int
ServerGame
::
playFrame
(
int
ticks
)
{
int
ServerGame
::
step
(
unsigned
int
ticks
)
{
unsigned
char
sendBuffer
[
BUFFER_LENGTH
];
int
count
,
pcount
,
length
;
...
...
src/io/gfx/paletteeffects.cpp
View file @
5e941c85
...
...
@@ -48,10 +48,10 @@ PaletteEffect::~PaletteEffect () {
}
void
PaletteEffect
::
apply
(
SDL_Color
*
shownPalette
,
bool
direct
)
{
void
PaletteEffect
::
apply
(
SDL_Color
*
shownPalette
,
bool
direct
,
int
mspf
)
{
// Apply the next palette effect
if
(
next
)
next
->
apply
(
shownPalette
,
direct
);
if
(
next
)
next
->
apply
(
shownPalette
,
direct
,
mspf
);
return
;
...
...
@@ -69,12 +69,13 @@ WhiteInPaletteEffect::WhiteInPaletteEffect (fixed newDuration,
}
void
WhiteInPaletteEffect
::
apply
(
SDL_Color
*
shownPalette
,
bool
direct
)
{
void
WhiteInPaletteEffect
::
apply
(
SDL_Color
*
shownPalette
,
bool
direct
,
int
mspf
)
{
int
count
;
// Apply the next palette effect
if
(
next
)
next
->
apply
(
shownPalette
,
direct
);
if
(
next
)
next
->
apply
(
shownPalette
,
direct
,
mspf
);
if
(
whiteness
>
F1
)
{
...
...
@@ -119,12 +120,13 @@ FadeInPaletteEffect::FadeInPaletteEffect (int newDuration,
}
void
FadeInPaletteEffect
::
apply
(
SDL_Color
*
shownPalette
,
bool
direct
)
{
void
FadeInPaletteEffect
::
apply
(
SDL_Color
*
shownPalette
,
bool
direct
,
int
mspf
)
{
int
count
;
// Apply the next palette effect
if
(
next
)
next
->
apply
(
shownPalette
,
direct
);
if
(
next
)
next
->
apply
(
shownPalette
,
direct
,
mspf
);
if
(
blackness
>
F1
)
{
...
...
@@ -169,12 +171,13 @@ WhiteOutPaletteEffect::WhiteOutPaletteEffect (int newDuration,
}
void
WhiteOutPaletteEffect
::
apply
(
SDL_Color
*
shownPalette
,
bool
direct
)
{
void
WhiteOutPaletteEffect
::
apply
(
SDL_Color
*
shownPalette
,
bool
direct
,
int
mspf
)
{
int
count
;
// Apply the next palette effect
if
(
next
)
next
->
apply
(
shownPalette
,
direct
);
if
(
next
)
next
->
apply
(
shownPalette
,
direct
,
mspf
);
if
(
whiteness
>
F1
)
{
...
...
@@ -217,12 +220,13 @@ FadeOutPaletteEffect::FadeOutPaletteEffect (int newDuration,
}
void
FadeOutPaletteEffect
::
apply
(
SDL_Color
*
shownPalette
,
bool
direct
)
{
void
FadeOutPaletteEffect
::
apply
(
SDL_Color
*
shownPalette
,
bool
direct
,
int
mspf
)
{
int
count
;
// Apply the next palette effect
if
(
next
)
next
->
apply
(
shownPalette
,
direct
);
if
(
next
)
next
->
apply
(
shownPalette
,
direct
,
mspf
);
if
(
blackness
>
F1
)
{
...
...
@@ -268,12 +272,13 @@ FlashPaletteEffect::FlashPaletteEffect (unsigned char newRed,
}
void
FlashPaletteEffect
::
apply
(
SDL_Color
*
shownPalette
,
bool
direct
)
{
void
FlashPaletteEffect
::
apply
(
SDL_Color
*
shownPalette
,
bool
direct
,
int
mspf
)
{
int
count
;
// Apply the next palette effect
if
(
next
)
next
->
apply
(
shownPalette
,
direct
);
if
(
next
)
next
->
apply
(
shownPalette
,
direct
,
mspf
);
if
(
progress
<
0
)
{
...
...
@@ -329,12 +334,13 @@ RotatePaletteEffect::RotatePaletteEffect (unsigned char newFirst,
}
void
RotatePaletteEffect
::
apply
(
SDL_Color
*
shownPalette
,
bool
direct
)
{
void
RotatePaletteEffect
::
apply
(
SDL_Color
*
shownPalette
,
bool
direct
,
int
mspf
)
{
int
count
;
// Apply the next palette effect
if
(
next
)
next
->
apply
(
shownPalette
,
direct
);
if
(
next
)
next
->
apply
(
shownPalette
,
direct
,
mspf
);
for
(
count
=
0
;
count
<
amount
;
count
++
)
{
...
...
@@ -371,12 +377,12 @@ SkyPaletteEffect::SkyPaletteEffect (unsigned char newFirst,
}
void
SkyPaletteEffect
::
apply
(
SDL_Color
*
shownPalette
,
bool
direct
)
{
void
SkyPaletteEffect
::
apply
(
SDL_Color
*
shownPalette
,
bool
direct
,
int
mspf
)
{
int
position
,
count
,
y
;
// Apply the next palette effect
if
(
next
)
next
->
apply
(
shownPalette
,
direct
);
if
(
next
)
next
->
apply
(
shownPalette
,
direct
,
mspf
);
position
=
viewY
+
(
viewH
<<
9
)
-
F4
;
...
...
@@ -438,12 +444,12 @@ P2DPaletteEffect::P2DPaletteEffect (unsigned char newFirst,
}
void
P2DPaletteEffect
::
apply
(
SDL_Color
*
shownPalette
,
bool
direct
)
{
void
P2DPaletteEffect
::
apply
(
SDL_Color
*
shownPalette
,
bool
direct
,
int
mspf
)
{
int
count
,
x
,
y
,
j
;
// Apply the next palette effect
if
(
next
)
next
->
apply
(
shownPalette
,
direct
);
if
(
next
)
next
->
apply
(
shownPalette
,
direct
,
mspf
);
x
=
FTOI
(((
256
*
32
)
-
FTOI
(
viewX
))
*
speed
);
...
...
@@ -483,13 +489,13 @@ P1DPaletteEffect::P1DPaletteEffect (unsigned char newFirst,
}
void
P1DPaletteEffect
::
apply
(
SDL_Color
*
shownPalette
,
bool
direct
)
{
void
P1DPaletteEffect
::
apply
(
SDL_Color
*
shownPalette
,
bool
direct
,
int
mspf
)
{
fixed
position
;
int
count
;
// Apply the next palette effect
if
(
next
)
next
->
apply
(
shownPalette
,
direct
);
if
(
next
)
next
->
apply
(
shownPalette
,
direct
,
mspf
);
position
=
viewX
+
viewY
;
...
...
@@ -522,12 +528,13 @@ WaterPaletteEffect::WaterPaletteEffect (fixed newDepth, PaletteEffect * nextPE)
}
void
WaterPaletteEffect
::
apply
(
SDL_Color
*
shownPalette
,
bool
direct
)
{
void
WaterPaletteEffect
::
apply
(
SDL_Color
*
shownPalette
,
bool
direct
,
int
mspf
)
{
int
position
,
count
;
// Apply the next palette effect
if
(
next
)
next
->
apply
(
shownPalette
,
direct
);
if
(
next
)
next
->
apply
(
shownPalette
,
direct
,
mspf
);
position
=
localPlayer
->
getY
()
-
level
->
getWaterLevel
(
0
);
...
...
src/io/gfx/paletteeffects.h
View file @
5e941c85
...
...
@@ -55,7 +55,7 @@ class PaletteEffect {
PaletteEffect
(
PaletteEffect
*
nextPE
);
virtual
~
PaletteEffect
();
virtual
void
apply
(
SDL_Color
*
shownPalette
,
bool
direct
);
virtual
void
apply
(
SDL_Color
*
shownPalette
,
bool
direct
,
int
mspf
);
};
...
...
@@ -69,7 +69,7 @@ class WhiteInPaletteEffect : public PaletteEffect {
public
:
WhiteInPaletteEffect
(
int
newDuration
,
PaletteEffect
*
nextPE
);
void
apply
(
SDL_Color
*
shownPalette
,
bool
direct
);
void
apply
(
SDL_Color
*
shownPalette
,
bool
direct
,
int
mspf
);
};
...
...
@@ -83,7 +83,7 @@ class FadeInPaletteEffect : public PaletteEffect {
public
:
FadeInPaletteEffect
(
int
newDuration
,
PaletteEffect
*
nextPE
);
void
apply
(
SDL_Color
*
shownPalette
,
bool
direct
);
void
apply
(
SDL_Color
*
shownPalette
,
bool
direct
,
int
mspf
);
};
...
...
@@ -97,7 +97,7 @@ class WhiteOutPaletteEffect : public PaletteEffect {
public
:
WhiteOutPaletteEffect
(
int
newDuration
,
PaletteEffect
*
nextPE
);
void
apply
(
SDL_Color
*
shownPalette
,
bool
direct
);
void
apply
(
SDL_Color
*
shownPalette
,
bool
direct
,
int
mspf
);
};
...
...
@@ -111,7 +111,7 @@ class FadeOutPaletteEffect : public PaletteEffect {
public
:
FadeOutPaletteEffect
(
int
newDuration
,
PaletteEffect
*
nextPE
);
void
apply
(
SDL_Color
*
shownPalette
,
bool
direct
);
void
apply
(
SDL_Color
*
shownPalette
,
bool
direct
,
int
mspf
);
};
...
...
@@ -127,7 +127,7 @@ class FlashPaletteEffect : public PaletteEffect {
FlashPaletteEffect
(
unsigned
char
newRed
,
unsigned
char
newGreen
,
unsigned
char
newBlue
,
int
newDuration
,
PaletteEffect
*
nextPE
);
void
apply
(
SDL_Color
*
shownPalette
,
bool
direct
);
void
apply
(
SDL_Color
*
shownPalette
,
bool
direct
,
int
mspf
);
};
...
...
@@ -146,7 +146,7 @@ class RotatePaletteEffect : public PaletteEffect {
RotatePaletteEffect
(
unsigned
char
newFirst
,
int
newAmount
,
fixed
newSpeed
,
PaletteEffect
*
nextPE
);
void
apply
(
SDL_Color
*
shownPalette
,
bool
direct
);
void
apply
(
SDL_Color
*
shownPalette
,
bool
direct
,
int
mspf
);
};
...
...
@@ -165,7 +165,7 @@ class SkyPaletteEffect : public PaletteEffect {
SkyPaletteEffect
(
unsigned
char
newFirst
,
int
newAmount
,
fixed
newSpeed
,
SDL_Color
*
newSkyPalette
,
PaletteEffect
*
nextPE
);
void
apply
(
SDL_Color
*
shownPalette
,
bool
direct
);
void
apply
(
SDL_Color
*
shownPalette
,
bool
direct
,
int
mspf
);
};
...
...
@@ -183,7 +183,7 @@ class P2DPaletteEffect : public PaletteEffect {
P2DPaletteEffect
(
unsigned
char
newFirst
,
int
newAmount
,
fixed
newSpeed
,
PaletteEffect
*
nextPE
);
void
apply
(
SDL_Color
*
shownPalette
,
bool
direct
);
void
apply
(
SDL_Color
*
shownPalette
,
bool
direct
,
int
mspf
);
};
...
...
@@ -201,7 +201,7 @@ class P1DPaletteEffect : public PaletteEffect {
P1DPaletteEffect
(
unsigned
char
newFirst
,
int
newAmount
,
fixed
newSpeed
,
PaletteEffect
*
nextPE
);
void
apply
(
SDL_Color
*
shownPalette
,
bool
direct
);
void
apply
(
SDL_Color
*
shownPalette
,
bool
direct
,
int
mspf
);
};
...
...
@@ -215,7 +215,7 @@ class WaterPaletteEffect : public PaletteEffect {
public
:
WaterPaletteEffect
(
fixed
newDepth
,
PaletteEffect
*
nextPE
);
void
apply
(
SDL_Color
*
shownPalette
,
bool
direct
);
void
apply
(
SDL_Color
*
shownPalette
,
bool
direct
,
int
mspf
);
};
...
...
src/io/gfx/video.h
View file @
5e941c85
...
...
@@ -43,7 +43,6 @@ EXTERN int viewW, viewH, screenW, screenH;
EXTERN
bool
fullscreen
;
#endif
EXTERN
bool
fakePalette
;
EXTERN
int
mspf
;
// Palettes
EXTERN
SDL_Color
*
currentPalette
;
...
...
src/level/bullet.cpp
View file @
5e941c85
...
...
@@ -32,7 +32,7 @@
#include "player/player.h"
Bullet
::
Bullet
(
Player
*
sourcePlayer
,
bool
lower
,
int
ticks
)
{
Bullet
::
Bullet
(
Player
*
sourcePlayer
,
bool
lower
,
unsigned
int
ticks
)
{
// Properties based on the player
...
...
@@ -54,6 +54,7 @@ Bullet::Bullet (Player *sourcePlayer, bool lower, int ticks) {
direction
|=
lower
?
2
:
0
;
x
=
source
->
getX
()
+
(
source
->
getFacing
()
?
PXO_R
:
PXO_L
);
y
=
source
->
getY
()
-
F8
;
dx
=
level
->
getBullet
(
type
)[
B_XSPEED
+
direction
]
*
500
*
F1
;
if
(
type
==
4
)
{
...
...
@@ -79,7 +80,7 @@ Bullet::Bullet (Player *sourcePlayer, bool lower, int ticks) {
}
Bullet
::
Bullet
(
Event
*
sourceEvent
,
bool
facing
,
int
ticks
)
{
Bullet
::
Bullet
(
Event
*
sourceEvent
,
bool
facing
,
unsigned
int
ticks
)
{
// Properties based on the event
...
...
@@ -89,7 +90,8 @@ Bullet::Bullet (Event *sourceEvent, bool facing, int ticks) {
direction
=
facing
?
1
:
0
;
x
=
sourceEvent
->
getX
()
+
(
sourceEvent
->
getWidth
()
>>
1
);
y
=
sourceEvent
->
getY
()
+
(
sourceEvent
->
getHeight
()
>>
1
);
y
=
sourceEvent
->
getY
()
-
(
sourceEvent
->
getHeight
()
>>
1
);
dx
=
level
->
getBullet
(
type
)[
B_XSPEED
+
direction
]
*
500
*
F1
;
dy
=
level
->
getBullet
(
type
)[
B_YSPEED
+
direction
]
*
250
*
F1
;
time
=
ticks
+
T_BULLET
;
...
...
@@ -100,7 +102,7 @@ Bullet::Bullet (Event *sourceEvent, bool facing, int ticks) {
}
Bullet
::
Bullet
(
Bird
*
sourceBird
,
bool
lower
,
int
ticks
)
{
Bullet
::
Bullet
(
Bird
*
sourceBird
,
bool
lower
,
unsigned
int
ticks
)
{
// Properties based on the bird and its player
...
...
@@ -122,6 +124,7 @@ Bullet::Bullet (Bird *sourceBird, bool lower, int ticks) {
direction
|=
lower
?
2
:
0
;
x
=
sourceBird
->
getX
()
+
(
source
->
getFacing
()
?
PXO_R
:
PXO_L
);
y
=
sourceBird
->
getY
();
dx
=
level
->
getBullet
(
type
)[
B_XSPEED
+
direction
]
*
500
*
F1
;
dy
=
level
->
getBullet
(
type
)[
B_YSPEED
+
direction
]
*
250
*
F1
;
time
=
ticks
+
T_BULLET
;
...
...
@@ -170,7 +173,7 @@ Player * Bullet::getSource () {
}
bool
Bullet
::
playFrame
(
int
tick
s
)
{
bool
Bullet
::
step
(
unsigned
int
ticks
,
int
msp
s
)
{
signed
char
*
set
;
Event
*
event
;
...
...
@@ -179,7 +182,7 @@ bool Bullet::playFrame (int ticks) {
// Process the next bullet
if
(
next
)
{
if
(
next
->
playFrame
(
tick
s
))
removeNext
();
if
(
next
->
step
(
ticks
,
msp
s
))
removeNext
();
}
...
...
@@ -276,14 +279,14 @@ bool Bullet::playFrame (int ticks) {
else
if
(
level
->
checkMaskDown
(
x
,
y
+
F4
))
dy
=
-
600
*
F1
;
else
if
(
level
->
checkMaskDown
(
x
-
F4
,
y
))
direction
|=
1
;
else
if
(
level
->
checkMaskDown
(
x
+
F4
,
y
))
direction
&=
~
1
;
else
dy
+=
6400
*
msp
f
*
set
[
B_GRAVITY
];
else
dy
+=
6400
*
msp
s
*
set
[
B_GRAVITY
];
}
else
dy
+=
6400
*
msp
f
*
set
[
B_GRAVITY
];
}
else
dy
+=
6400
*
msp
s
*
set
[
B_GRAVITY
];
// Apply trajectory
x
+=
(
set
[
B_XSPEED
+
direction
]
*
500
*
F1
*
mspf
)
>>
10
;
y
+=
(
dy
*
msp
f
)
>>
10
;
x
+=
(
dx
*
msps
)
>>
10
;
y
+=
(
dy
*
msp
s
)
>>
10
;
// Do not destroy the bullet
...
...
@@ -292,11 +295,11 @@ bool Bullet::playFrame (int ticks) {
}
void
Bullet
::
draw
()
{
void
Bullet
::
draw
(
int
change
)
{
Sprite
*
sprite
;
if
(
next
)
next
->
draw
();
if
(
next
)
next
->
draw
(
change
);
if
(
type
==
-
1
)
sprite
=
level
->
getSprite
(
130
);
else
sprite
=
...
...
@@ -304,8 +307,9 @@ void Bullet::draw () {
[
B_SPRITE
+
direction
]);
// Show the bullet
sprite
->
draw
(
FTOI
(
x
)
-
(
sprite
->
getWidth
()
>>
1
)
-
FTOI
(
viewX
),
FTOI
(
y
)
-
(
sprite
->
getWidth
()
>>
1
)
-
FTOI
(
viewY
));
sprite
->
draw
(
FTOI
(
getDrawX
(
change
))
-
(
sprite
->
getWidth
()
>>
1
)
-
FTOI
(
viewX
),
FTOI
(
getDrawY
(
change
))
-
(
sprite
->
getHeight
()
>>
1
)
-
FTOI
(
viewY
));
return
;
...
...
src/level/bullet.h
View file @
5e941c85
...
...
@@ -24,6 +24,7 @@
#define _BULLET_H
#include "movable.h"
#include "OpenJazz.h"
...
...
@@ -51,27 +52,28 @@ class Bird;
class
Event
;
class
Player
;
class
Bullet
{
class
Bullet
:
public
Movable
{
private
:
Bullet
*
next
;
Player
*
source
;
// If NULL, was fired by an event
int
type
;
// -1 is TNT, otherwise this
indexes the bullet set
int
type
;
// -1 is TNT, otherwise
indexes the bullet set
int
direction
;
// 0: Left, 1: Right, 2: L (lower), 3: R (lower)
fixed
x
,
y
,
dy
;
int
time
;
// The time at which the bullet will self-destruct
unsigned
int
time
;
// Time at which the bullet will self-destruct
public
:
Bullet
(
Player
*
sourcePlayer
,
bool
lower
,
int
ticks
);
Bullet
(
Event
*
sourceEvent
,
bool
facing
,
int
ticks
);
Bullet
(
Bird
*
sourceBird
,
bool
lower
,
int
ticks
);
Bullet
(
Player
*
sourcePlayer
,
bool
lower
,
unsigned
int
ticks
);
Bullet
(
Event
*
sourceEvent
,
bool
facing
,
unsigned
int
ticks
);
Bullet
(
Bird
*
sourceBird
,
bool
lower
,
unsigned
int
ticks
);
~
Bullet
();
Bullet
*
getNext
();
void
removeNext
();
Player
*
getSource
();
bool
playFrame
(
int
tick
s
);
void
draw
();
bool
step
(
unsigned
int
ticks
,
int
msp
s
);
void
draw
(
int
change
);
};
...
...
src/level/demolevel.cpp
View file @
5e941c85
...
...
@@ -101,7 +101,8 @@ int DemoLevel::play () {
smoothfps
=
50.0
f
;
tickOffset
=
globalTicks
;
ticks
=
-
10
;
ticks
=
16
;
prevStepTicks
=
0
;
stats
=
S_NONE
;
...
...
@@ -152,10 +153,15 @@ int DemoLevel::play () {
// Process frame-by-frame activity
ret
=
playFrame
();
// Process step
if
(
ticks
>=
prevStepTicks
+
16
)
{
ret
=
step
();
if
(
ret
<
0
)
return
ret
;
}
// Handle player reactions
if
(
localPlayer
->
reacted
(
ticks
)
==
PR_KILLED
)
return
LOST
;
...
...
src/level/event/event.cpp
View file @
5e941c85
...
...
@@ -50,7 +50,7 @@ Event::Event (unsigned char gX, unsigned char gY, Event *nextEvent) {
y
=
TTOF
(
gY
+
1
);
flashTime
=
0
;
// Choose initial
animation and direction
// Choose initial
settings
switch
(
getProperty
(
E_BEHAVIOUR
))
{
...
...
@@ -70,6 +70,19 @@ Event::Event (unsigned char gX, unsigned char gY, Event *nextEvent) {
break
;
case
28
:
animType
=
E_LEFTANIM
;
x
-=
F2
;
y
+=
ITOF
(
getProperty
(
E_YAXIS
))
-
F40
;
// dx and dy used to store leftmost and rightmost player on bridge
// Start with minimum values
dx
=
getProperty
(
E_MULTIPURPOSE
)
*
F8
;
dy
=
0
;
break
;
default
:
animType
=
E_LEFTANIM
;
...
...
@@ -114,7 +127,7 @@ void Event::removeNext () {
}
void
Event
::
destroy
(
int
ticks
)
{
void
Event
::
destroy
(
unsigned
int
ticks
)
{
level
->
setEventTime
(
gridX
,
gridY
,
ticks
+
T_FINISH
);
...
...
@@ -128,7 +141,7 @@ void Event::destroy (int ticks) {
}
bool
Event
::
hit
(
Player
*
source
,
int
ticks
)
{
bool
Event
::
hit
(
Player
*
source
,
unsigned
int
ticks
)
{
int
hitsRemaining
;
...
...
@@ -160,20 +173,6 @@ bool Event::isFrom (unsigned char gX, unsigned char gY) {
}
fixed
Event
::
getX
()
{
return
x
;
}
fixed
Event
::
getY
()
{
return
y
-
getHeight
();
}
fixed
Event
::
getWidth
()
{
fixed
width
;
...
...
src/level/event/event.h
View file @
5e941c85
...
...
@@ -27,6 +27,7 @@
#define _EVENTS_H
#include "movable.h"
#include "OpenJazz.h"
...
...
@@ -74,17 +75,16 @@
class
Player
;
class
Event
{
class
Event
:
public
Movable
{
private
:
Event
*
next
;
unsigned
char
gridX
,
gridY
;
// Grid position of the event
fixed
x
,
y
;
// Actual position of the event
unsigned
char
animType
;
// E_LEFTANIM, etc, or 0
unsigned
char
frame
;
int
flashTime
;
unsigned
int
flashTime
;
void
destroy
(
int
ticks
);
void
destroy
(
unsigned
int
ticks
);
public
:
Event
(
unsigned
char
gX
,
unsigned
char
gY
,
...
...
@@ -93,17 +93,15 @@ class Event {
Event
*
getNext
();
void
removeNext
();
bool
hit
(
Player
*
source
,
int
ticks
);
bool
hit
(
Player
*
source
,
unsigned
int
ticks
);
bool
isFrom
(
unsigned
char
gX
,
unsigned
char
gY
);
fixed
getX
();
fixed
getY
();
fixed
getWidth
();
fixed
getHeight
();
bool
overlap
(
fixed
left
,
fixed
top
,
fixed
width
,
fixed
height
);
signed
char
getProperty
(
unsigned
char
property
);
bool
playFrame
(
int
tick
s
);
void
draw
(
int
ticks
);
bool
step
(
unsigned
int
ticks
,
int
msp
s
);
void
draw
(
unsigned
int
ticks
,
int
change
);
};
...
...
src/level/event/eventframe.cpp
View file @
5e941c85
...
...
@@ -36,18 +36,18 @@
#include <math.h>
bool
Event
::
playFrame
(
int
tick
s
)
{
bool
Event
::
step
(
unsigned
int
ticks
,
int
msp
s
)
{
fixed
width
,
height
;
signed
char
*
set
;
fixed
startX
;
int
count
,
offset
;
int
count
;
fixed
offset
;
float
angle
;
// Process the next event
if
(
next
)
{
if
(
next
->
playFrame
(
tick
s
))
removeNext
();
if
(
next
->
step
(
ticks
,
msp
s
))
removeNext
();
}
...
...
@@ -87,8 +87,13 @@ bool Event::playFrame (int ticks) {
height
=
getHeight
();
// Pre-movement platform position
startX
=
x
;
if
(
set
[
E_BEHAVIOUR
]
!=
28
)
{
// Pre-movement position
dx
=
x
;
dy
=
y
;
}
// Handle behaviour
...
...
@@ -98,16 +103,16 @@ bool Event::playFrame (int ticks) {
case
1
:
// Sink down
y
+=
ES_FAST
*
msp
f
/
set
[
E_MOVEMENTSP
];
y
+=
ES_FAST
*
msp
s
/
set
[
E_MOVEMENTSP
];
break
;
case
2
:
// Walk from side to side
if
(
animType
==
E_LEFTANIM
)
x
-=
ES_FAST
*
msp
f
/
set
[
E_MOVEMENTSP
];
if
(
animType
==
E_LEFTANIM
)
x
-=
ES_FAST
*
msp
s
/
set
[
E_MOVEMENTSP
];
else
if
(
animType
==
E_RIGHTANIM
)
x
+=
ES_FAST
*
msp
f
/
set
[
E_MOVEMENTSP
];
x
+=
ES_FAST
*
msp
s
/
set
[
E_MOVEMENTSP
];
break
;
...
...
@@ -115,9 +120,9 @@ bool Event::playFrame (int ticks) {
// Seek jazz
if
(
localPlayer
->
getX
()
+
PXO_R
<
x
)
x
-=
ES_FAST
*
msp
f
/
set
[
E_MOVEMENTSP
];
x
-=
ES_FAST
*
msp
s
/
set
[
E_MOVEMENTSP
];
else
if
(
localPlayer
->
getX
()
+
PXO_L
>
x
+
width
)
x
+=
ES_FAST
*
msp
f
/
set
[
E_MOVEMENTSP
];
x
+=
ES_FAST
*
msp
s
/
set
[
E_MOVEMENTSP
];
break
;
...
...
@@ -128,15 +133,15 @@ bool Event::playFrame (int ticks) {
if
(
!
level
->
checkMaskDown
(
x
+
(
width
>>
1
),
y
))
{
// Fall downwards
y
+=
ES_FAST
*
msp
f
/
set
[
E_MOVEMENTSP
];
y
+=
ES_FAST
*
msp
s
/
set
[
E_MOVEMENTSP
];
}
else
{
// Walk from side to side
if
(
animType
==
E_LEFTANIM
)
x
-=
ES_FAST
*
msp
f
/
set
[
E_MOVEMENTSP
];
x
-=
ES_FAST
*
msp
s
/
set
[
E_MOVEMENTSP
];
else
if
(
animType
==
E_RIGHTANIM
)
x
+=
ES_FAST
*
msp
f
/
set
[
E_MOVEMENTSP
];
x
+=
ES_FAST
*
msp
s
/
set
[
E_MOVEMENTSP
];
}
...
...
@@ -159,9 +164,9 @@ bool Event::playFrame (int ticks) {
case
7
:
// Move back and forth horizontally with tail
if
(
animType
==
E_LEFTANIM
)
x
-=
ES_SLOW
*
msp
f
/
set
[
E_MOVEMENTSP
];
if
(
animType
==
E_LEFTANIM
)
x
-=
ES_SLOW
*
msp
s
/
set
[
E_MOVEMENTSP
];
else
if
(
animType
==
E_RIGHTANIM
)
x
+=
ES_SLOW
*
msp
f
/
set
[
E_MOVEMENTSP
];
x
+=
ES_SLOW
*
msp
s
/
set
[
E_MOVEMENTSP
];
break
;
...
...
@@ -187,25 +192,25 @@ bool Event::playFrame (int ticks) {
// Sink to ground
if
(
!
level
->
checkMaskDown
(
x
+
(
width
>>
1
),
y
))
y
+=
ES_FAST
*
msp
f
/
set
[
E_MOVEMENTSP
];
y
+=
ES_FAST
*
msp
s
/
set
[
E_MOVEMENTSP
];
break
;
case
12
:
// Move back and forth horizontally
if
(
animType
==
E_LEFTANIM
)
x
-=
ES_SLOW
*
msp
f
/
set
[
E_MOVEMENTSP
];
if
(
animType
==
E_LEFTANIM
)
x
-=
ES_SLOW
*
msp
s
/
set
[
E_MOVEMENTSP
];
else
if
(
animType
==
E_RIGHTANIM
)
x
+=
ES_SLOW
*
msp
f
/
set
[
E_MOVEMENTSP
];
x
+=
ES_SLOW
*
msp
s
/
set
[
E_MOVEMENTSP
];
break
;
case
13
:
// Move up and down
if
(
animType
==
E_LEFTANIM
)
y
-=
ES_SLOW
*
msp
f
/
set
[
E_MOVEMENTSP
];
if
(
animType
==
E_LEFTANIM
)
y
-=
ES_SLOW
*
msp
s
/
set
[
E_MOVEMENTSP
];
else
if
(
animType
==
E_RIGHTANIM
)
y
+=
ES_SLOW
*
msp
f
/
set
[
E_MOVEMENTSP
];
y
+=
ES_SLOW
*
msp
s
/
set
[
E_MOVEMENTSP
];
break
;
...
...
@@ -224,7 +229,7 @@ bool Event::playFrame (int ticks) {
case
16
:
// Move across level to the left or right
x
+=
set
[
E_MAGNITUDE
]
*
ES_SLOW
*
msp
f
/
set
[
E_MOVEMENTSP
];
x
+=
set
[
E_MAGNITUDE
]
*
ES_SLOW
*
msp
s
/
set
[
E_MOVEMENTSP
];
break
;
...
...
@@ -286,9 +291,9 @@ bool Event::playFrame (int ticks) {
if
(
players
[
count
].
overlap
(
x
,
y
-
height
,
width
,
height
))
{
if
(
set
[
E_YAXIS
])
players
[
count
].
floatUp
(
set
);
if
(
set
[
E_YAXIS
])
players
[
count
].
floatUp
(
set
,
msps
);
players
[
count
].
belt
(
set
[
E_MAGNITUDE
]);
players
[
count
].
belt
(
set
[
E_MAGNITUDE
]
*
msps
);
}
...
...
@@ -312,46 +317,42 @@ bool Event::playFrame (int ticks) {
// Bridge
if
(
localPlayer
->
overlap
(
x
-
F10
,
y
+
ITOF
(
set
[
E_YAXIS
])
-
F32
,
set
[
E_MULTIPURPOSE
]
*
F8
,
F8
+
F20
))
{
if
(
!
level
->
checkMaskDown
(
localPlayer
->
getX
()
+
PXO_MID
,
y
+
ITOF
(
set
[
E_YAXIS
])
-
F32
-
F20
))
{
// Player is on the bridge
localPlayer
->
setEvent
(
set
);
localPlayer
->
setPosition
(
localPlayer
->
getX
(),
y
+
ITOF
(
set
[
E_YAXIS
])
-
F32
);
// Gradually stop the bridge sagging
if
(
dx
<
set
[
E_MULTIPURPOSE
]
*
F8
)
dx
+=
320
*
msps
;
if
(
dx
>
set
[
E_MULTIPURPOSE
]
*
F8
)
dx
=
set
[
E_MULTIPURPOSE
]
*
F8
;
if
(
dy
>
0
)
dy
-=
320
*
msps
;
if
(
dy
<
0
)
dy
=
0
;
offset
=
(
localPlayer
->
getX
()
+
PXO_MID
-
x
)
>>
13
;
for
(
count
=
0
;
count
<
nPlayers
;
count
++
)
{
if
(
offset
<
set
[
E_MULTIPURPOSE
]
>>
1
)
{
if
(
players
[
count
].
overlap
(
x
,
y
,
set
[
E_MULTIPURPOSE
]
*
F8
,
F8
))
{
// Player is to the left of the centre of the bridge
offset
=
players
[
count
].
getX
()
+
PXO_MID
;
y
=
TTOF
(
gridY
)
+
F24
+
ITOF
(
offset
);
animType
=
E_LEFTANIM
;
if
(
!
level
->
checkMaskDown
(
offset
,
y
-
F32
))
{
}
else
{
// Player is on the bridge
// Player is to the right of the centre of the bridge
players
[
count
].
setEvent
(
set
);
y
=
TTOF
(
gridY
)
+
F24
+
ITOF
(
set
[
E_MULTIPURPOSE
]
-
offset
);
animType
=
E_RIGHTANIM
;
offset
-=
x
;
}
if
(
offset
<
dx
)
dx
=
offset
;
}
else
localPlayer
->
clearEvent
(
set
,
E_BEHAVIOUR
);
if
((
offset
>
dy
)
&&
(
offset
<
set
[
E_MULTIPURPOSE
]
*
F8
))
dy
=
offset
;
}
else
{
if
(
offset
<
set
[
E_MULTIPURPOSE
]
*
F4
)
players
[
count
].
setPosition
(
players
[
count
].
getX
(),
y
+
(
offset
>>
3
)
-
F8
);
else
players
[
count
].
setPosition
(
players
[
count
].
getX
(),
y
+
(
set
[
E_MULTIPURPOSE
]
*
F1
)
-
(
offset
>>
3
)
-
F8
);
// Player is not on the bridge
}
else
players
[
count
].
clearEvent
(
set
,
E_BEHAVIOUR
);
// Gradually stop the bridge sagging
if
(
y
-
F24
>
TTOF
(
gridY
))
y
-=
16
*
mspf
;
}
}
...
...
@@ -386,16 +387,16 @@ bool Event::playFrame (int ticks) {
case
31
:
// Move horizontally
if
(
animType
==
E_LEFTANIM
)
x
-=
ES_FAST
*
msp
f
/
set
[
E_MOVEMENTSP
];
else
x
+=
ES_FAST
*
msp
f
/
set
[
E_MOVEMENTSP
];
if
(
animType
==
E_LEFTANIM
)
x
-=
ES_FAST
*
msp
s
/
set
[
E_MOVEMENTSP
];
else
x
+=
ES_FAST
*
msp
s
/
set
[
E_MOVEMENTSP
];
break
;
case
32
:
// Move horizontally
if
(
animType
==
E_LEFTANIM
)
x
-=
ES_FAST
*
msp
f
/
set
[
E_MOVEMENTSP
];
else
x
+=
ES_FAST
*
msp
f
/
set
[
E_MOVEMENTSP
];
if
(
animType
==
E_LEFTANIM
)
x
-=
ES_FAST
*
msp
s
/
set
[
E_MOVEMENTSP
];
else
x
+=
ES_FAST
*
msp
s
/
set
[
E_MOVEMENTSP
];
break
;
...
...
@@ -405,22 +406,22 @@ bool Event::playFrame (int ticks) {
if
(
localPlayer
->
getFacing
()
&&
(
x
+
width
<
localPlayer
->
getX
()))
{
x
+=
ES_FAST
*
msp
f
/
set
[
E_MOVEMENTSP
];
x
+=
ES_FAST
*
msp
s
/
set
[
E_MOVEMENTSP
];
if
(
y
+
height
<
localPlayer
->
getY
()
+
PYO_TOP
)
y
+=
ES_SLOW
*
msp
f
/
set
[
E_MOVEMENTSP
];
y
+=
ES_SLOW
*
msp
s
/
set
[
E_MOVEMENTSP
];
else
if
(
y
>
localPlayer
->
getY
())
y
-=
ES_SLOW
*
msp
f
/
set
[
E_MOVEMENTSP
];
y
-=
ES_SLOW
*
msp
s
/
set
[
E_MOVEMENTSP
];
}
else
if
(
!
localPlayer
->
getFacing
()
&&
(
x
>
localPlayer
->
getX
()
+
F32
))
{
x
-=
ES_FAST
*
msp
f
/
set
[
E_MOVEMENTSP
];
x
-=
ES_FAST
*
msp
s
/
set
[
E_MOVEMENTSP
];
if
(
y
+
height
<
localPlayer
->
getY
()
+
PYO_TOP
)
y
+=
ES_SLOW
*
msp
f
/
set
[
E_MOVEMENTSP
];
y
+=
ES_SLOW
*
msp
s
/
set
[
E_MOVEMENTSP
];
else
if
(
y
>
localPlayer
->
getY
())
y
-=
ES_SLOW
*
msp
f
/
set
[
E_MOVEMENTSP
];
y
-=
ES_SLOW
*
msp
s
/
set
[
E_MOVEMENTSP
];
}
...
...
@@ -436,12 +437,12 @@ bool Event::playFrame (int ticks) {
level
->
setEventTime
(
gridX
,
gridY
,
ticks
+
(
set
[
E_MODIFIER
]
*
500
));
else
y
-=
(
y
+
(
set
[
E_YAXIS
]
*
F2
)
-
TTOF
(
gridY
))
*
msp
f
/
320
;
y
-=
(
y
+
(
set
[
E_YAXIS
]
*
F2
)
-
TTOF
(
gridY
))
*
msp
s
/
320
;
}
else
{
if
(
y
<
TTOF
(
gridY
)
+
F16
)
y
+=
(
y
+
(
set
[
E_YAXIS
]
*
F2
)
-
TTOF
(
gridY
))
*
msp
f
/
320
;
y
+=
(
y
+
(
set
[
E_YAXIS
]
*
F2
)
-
TTOF
(
gridY
))
*
msp
s
/
320
;
else
y
=
TTOF
(
gridY
)
+
F16
;
}
...
...
@@ -461,15 +462,15 @@ bool Event::playFrame (int ticks) {
if
(
!
level
->
checkMaskDown
(
x
+
(
width
>>
1
),
y
))
{
// Fall downwards
y
+=
ES_FAST
*
msp
f
/
set
[
E_MOVEMENTSP
];
y
+=
ES_FAST
*
msp
s
/
set
[
E_MOVEMENTSP
];
}
else
{
// Walk from side to side, staying on-screen
if
(
animType
==
E_LEFTANIM
)
x
-=
ES_FAST
*
msp
f
/
set
[
E_MOVEMENTSP
];
x
-=
ES_FAST
*
msp
s
/
set
[
E_MOVEMENTSP
];
else
if
(
animType
==
E_RIGHTANIM
)
x
+=
ES_FAST
*
msp
f
/
set
[
E_MOVEMENTSP
];
x
+=
ES_FAST
*
msp
s
/
set
[
E_MOVEMENTSP
];
}
...
...
@@ -554,9 +555,9 @@ bool Event::playFrame (int ticks) {
if
(
y
>
level
->
getWaterLevel
(
0
))
{
if
(
animType
==
E_LEFTANIM
)
x
-=
ES_SLOW
*
msp
f
/
set
[
E_MOVEMENTSP
];
x
-=
ES_SLOW
*
msp
s
/
set
[
E_MOVEMENTSP
];
else
if
(
animType
==
E_RIGHTANIM
)
x
+=
ES_SLOW
*
msp
f
/
set
[
E_MOVEMENTSP
];
x
+=
ES_SLOW
*
msp
s
/
set
[
E_MOVEMENTSP
];
}
...
...
@@ -824,7 +825,8 @@ bool Event::playFrame (int ticks) {
// Generate bullet
if
(
set
[
E_BULLETSP
])
{
if
((
ticks
%
(
set
[
E_BULLETSP
]
*
25
)
>
(
set
[
E_BULLETSP
]
*
25
)
-
200
)
&&
if
((
ticks
%
(
set
[
E_BULLETSP
]
*
25
)
>
(
unsigned
int
)(
set
[
E_BULLETSP
]
*
25
)
-
200
)
&&
((
animType
==
E_LEFTANIM
)
||
(
animType
==
E_RIGHTANIM
)))
{
if
(
animType
==
E_LEFTANIM
)
animType
=
E_LSHOOTANIM
;
...
...
@@ -832,7 +834,8 @@ bool Event::playFrame (int ticks) {
}
if
((
ticks
%
(
set
[
E_BULLETSP
]
*
25
)
<
(
set
[
E_BULLETSP
]
*
25
)
-
200
)
&&
if
((
ticks
%
(
set
[
E_BULLETSP
]
*
25
)
<
(
unsigned
int
)(
set
[
E_BULLETSP
]
*
25
)
-
200
)
&&
((
animType
==
E_LSHOOTANIM
)
||
(
animType
==
E_RSHOOTANIM
)))
{
if
(
animType
==
E_RSHOOTANIM
)
{
...
...
@@ -893,13 +896,13 @@ bool Event::playFrame (int ticks) {
// Platform
if
((
players
[
count
].
getY
()
<=
y
+
(
PYS_FALL
/
msp
f
)
-
height
)
y
+
(
PYS_FALL
/
msp
s
)
-
height
)
&&
!
level
->
checkMaskDown
(
players
[
count
].
getX
()
+
PXO_MID
,
y
-
height
-
F20
))
{
players
[
count
].
setEvent
(
set
);
players
[
count
].
setPosition
(
players
[
count
].
getX
()
+
x
-
startX
,
y
-
height
);
x
-
dx
,
y
-
height
);
}
else
players
[
count
].
clearEvent
(
set
,
E_MODIFIER
);
...
...
@@ -916,21 +919,31 @@ bool Event::playFrame (int ticks) {
}
if
(
set
[
E_BEHAVIOUR
]
!=
28
)
{
// Store change in position
dx
=
x
-
dx
;
dy
=
y
-
dy
;
}
return
false
;
}
void
Event
::
draw
(
int
ticks
)
{
void
Event
::
draw
(
unsigned
int
ticks
,
int
change
)
{
Anim
*
anim
;
signed
char
*
set
;
int
count
,
midpoint
;
fixed
bridge
x
,
bridgey
,
dsty
;
int
count
;
fixed
bridge
Length
,
dipA
,
dipB
;
// Uncomment the following to see the area of the event
/*drawRect(FTOI(getX() - viewX), FTOI(getY() - viewY), FTOI(getWidth()),
/*drawRect(FTOI(getDrawX(change) - viewX),
FTOI(getDrawY(change) - (viewY + getHeight())), FTOI(getWidth()),
FTOI(getHeight()), 88);*/
...
...
@@ -960,57 +973,45 @@ void Event::draw (int ticks) {
if
(
set
[
E_BEHAVIOUR
]
==
28
)
{
bridgex
=
x
-
F10
;
dsty
=
y
+
ITOF
(
set
[
E_YAXIS
])
-
F32
;
bridgeLength
=
set
[
E_MULTIPURPOSE
]
*
F8
;
if
(
y
-
F24
>
TTOF
(
gridY
)
)
{
if
(
dy
>=
dx
)
{
if
(
animType
==
E_LEFTANIM
)
midpoint
=
FTOI
(
y
-
F24
-
TTOF
(
gridY
));
else
midpoint
=
set
[
E_MULTIPURPOSE
]
-
FTOI
(
y
-
F24
-
TTOF
(
gridY
));
}
else
midpoint
=
0
;
if
(
midpoint
<
set
[
E_MULTIPURPOSE
]
>>
1
)
{
for
(
count
=
0
;
count
<
set
[
E_MULTIPURPOSE
];
count
++
)
{
dipA
=
(
dx
<=
(
bridgeLength
>>
1
))
?
dx
>>
3
:
(
bridgeLength
-
dx
)
>>
3
;
dipB
=
(
dy
<=
(
bridgeLength
>>
1
))
?
dy
>>
3
:
(
bridgeLength
-
dy
)
>>
3
;
bridgex
+=
F8
;
for
(
count
=
0
;
count
<
bridgeLength
;
count
+=
F8
)
{
if
(
midpoint
==
0
)
bridgey
=
dsty
;
else
if
(
count
<
midpoint
)
bridgey
=
((
dsty
-
ITOF
(
midpoint
))
*
(
midpoint
-
count
)
/
midpoint
)
+
(
dsty
*
count
/
midpoint
);
if
(
count
<
dx
)
anim
->
draw
(
x
+
count
,
y
+
(
count
*
dipA
/
dx
));
else
if
(
count
<
dy
)
anim
->
draw
(
x
+
count
,
y
+
dipA
+
((
count
-
dx
)
*
(
dipB
-
dipA
)
/
(
dy
-
dx
)));
else
bridgey
=
((
dsty
-
ITOF
(
midpoint
))
*
(
count
-
midpoint
)
/
(
set
[
E_MULTIPURPOSE
]
-
midpoint
))
+
(
dsty
*
(
set
[
E_MULTIPURPOSE
]
-
count
)
/
(
set
[
E_MULTIPURPOSE
]
-
midpoint
));
anim
->
draw
(
bridgex
,
bridgey
);
anim
->
draw
(
x
+
count
,
y
+
((
bridgeLength
-
count
)
*
dipB
/
(
bridgeLength
-
dy
)));
}
}
else
{
for
(
count
=
0
;
count
<
set
[
E_MULTIPURPOSE
];
count
++
)
{
// No players on the bridge, de-sagging in progress
bridgex
+=
F8
;
dipA
=
(
dx
+
dy
)
>>
1
;
dipB
=
(
dy
<
bridgeLength
-
dx
)
?
dy
>>
3
:
(
bridgeLength
-
dx
)
>>
3
;
if
(
midpoint
==
0
)
bridgey
=
dsty
;
else
if
(
count
<
midpoint
)
bridgey
=
((
dsty
+
ITOF
(
midpoint
-
set
[
E_MULTIPURPOSE
]))
*
(
midpoint
-
count
)
/
midpoint
)
+
(
dsty
*
count
/
midpoint
);
else
bridgey
=
((
dsty
+
ITOF
(
midpoint
-
set
[
E_MULTIPURPOSE
]))
*
(
count
-
midpoint
)
/
(
set
[
E_MULTIPURPOSE
]
-
midpoint
))
+
(
dsty
*
(
set
[
E_MULTIPURPOSE
]
-
count
)
/
(
set
[
E_MULTIPURPOSE
]
-
midpoint
));
for
(
count
=
0
;
count
<
bridgeLength
;
count
+=
F8
)
{
anim
->
draw
(
bridgex
,
bridgey
);
if
(
count
<
dipA
)
anim
->
draw
(
x
+
count
,
y
+
(
count
*
dipB
/
dipA
));
else
anim
->
draw
(
x
+
count
,
y
+
((
bridgeLength
-
count
)
*
dipB
/
(
bridgeLength
-
dipA
)));
}
...
...
@@ -1018,7 +1019,7 @@ void Event::draw (int ticks) {
}
else
{
anim
->
draw
(
x
,
y
);
anim
->
draw
(
getDrawX
(
change
),
getDrawY
(
change
)
);
}
...
...
@@ -1030,7 +1031,7 @@ void Event::draw (int ticks) {
anim
=
level
->
getMiscAnim
(
2
);
anim
->
setFrame
(
frame
,
false
);
anim
->
draw
(
x
,
y
);
anim
->
draw
(
getDrawX
(
change
),
getDrawY
(
change
)
);
}
...
...
src/level/level.cpp
View file @
5e941c85
...
...
@@ -237,7 +237,7 @@ unsigned char Level::getEventHits (unsigned char gridX, unsigned char gridY) {
}
int
Level
::
getEventTime
(
unsigned
char
gridX
,
unsigned
char
gridY
)
{
unsigned
int
Level
::
getEventTime
(
unsigned
char
gridX
,
unsigned
char
gridY
)
{
return
grid
[
gridY
][
gridX
].
time
;
...
...
@@ -322,7 +322,8 @@ int Level::hitEvent (Player *source, unsigned char gridX, unsigned char gridY) {
}
void
Level
::
setEventTime
(
unsigned
char
gridX
,
unsigned
char
gridY
,
int
time
)
{
void
Level
::
setEventTime
(
unsigned
char
gridX
,
unsigned
char
gridY
,
unsigned
int
time
)
{
grid
[
gridY
][
gridX
].
time
=
time
;
...
...
@@ -511,11 +512,12 @@ void Level::receive (unsigned char *buffer) {
void
Level
::
timeCalcs
(
bool
paused
)
{
// Calculate smoothed fps
smoothfps
=
smoothfps
+
1
-
(
smoothfps
*
((
float
)
mspf
)
/
1000.0
f
);
smoothfps
=
smoothfps
+
1.0
f
-
(
smoothfps
*
((
float
)(
ticks
-
prevTicks
))
/
1000.0
f
);
/* This equation is a simplified version of
(fps * c) + (smoothfps * (1 - c))
where c = (1 / fps)
and fps = 1000 /
mspf
and fps = 1000 /
(ticks - prevTicks)
In other words, the response of smoothFPS to changes in FPS decreases as the
framerate increases
The following version is for c = (1 / smoothfps)
...
...
@@ -523,24 +525,27 @@ void Level::timeCalcs (bool paused) {
// smoothfps = (fps / smoothfps) + smoothfps - 1;
// Ignore outlandish values
if
(
smoothfps
>
9999
)
smoothfps
=
9999
;
if
(
smoothfps
<
1
)
smoothfps
=
1
;
if
(
smoothfps
>
9999
.0
f
)
smoothfps
=
9999.0
f
;
if
(
smoothfps
<
1
.0
f
)
smoothfps
=
1.0
f
;
// Number of ticks of gameplay since the level started
prevTicks
=
ticks
;
ticks
=
globalTicks
-
tickOffset
;
// Track number of ticks of gameplay since the level started
if
(
paused
)
{
tickOffset
+=
ticks
-
prevTicks
;
ticks
=
prevTicks
;
tickOffset
=
globalTicks
-
ticks
;
}
else
if
(
globalTicks
-
tickOffset
>
ticks
+
100
)
{
prevTicks
=
ticks
;
ticks
+=
100
;
tickOffset
=
globalTicks
-
ticks
;
}
else
if
(
ticks
>
prevTicks
+
100
)
{
}
else
{
tickOffset
+=
ticks
-
(
prevTicks
+
100
)
;
ticks
=
prevTicks
+
100
;
prevTicks
=
ticks
;
ticks
=
globalTicks
-
tickOffset
;
}
...
...
@@ -557,7 +562,7 @@ int Level::play () {
char
*
string
;
bool
paused
,
pmenu
;
int
stats
,
option
;
int
returnTime
;
unsigned
int
returnTime
;
int
perfect
;
int
timeBonus
;
int
count
;
...
...
@@ -568,7 +573,8 @@ int Level::play () {
smoothfps
=
50.0
f
;
tickOffset
=
globalTicks
;
ticks
=
-
10
;
ticks
=
16
;
prevStepTicks
=
0
;
pmenu
=
paused
=
false
;
option
=
0
;
...
...
@@ -688,10 +694,16 @@ int Level::play () {
for
(
count
=
0
;
count
<
PCONTROLS
;
count
++
)
localPlayer
->
setControl
(
count
,
controls
.
getState
(
count
));
count
=
playFrame
();
// Process step
if
(
ticks
>=
prevStepTicks
+
16
)
{
count
=
step
();
if
(
count
<
0
)
return
count
;
}
// Handle player reactions
for
(
count
=
0
;
count
<
nPlayers
;
count
++
)
{
...
...
@@ -772,7 +784,7 @@ int Level::play () {
if
(
timeBonus
)
{
count
=
mspf
/
100
;
count
=
(
ticks
-
prevTicks
)
/
100
;
if
(
!
count
)
count
=
1
;
if
(
timeBonus
==
-
1
)
{
...
...
@@ -870,7 +882,7 @@ int Level::play () {
if
(
gameMode
)
{
count
=
game
->
playFrame
(
ticks
);
count
=
game
->
step
(
ticks
);
switch
(
count
)
{
...
...
src/level/level.h
View file @
5e941c85
...
...
@@ -115,7 +115,7 @@ class Level {
int
levelNum
,
worldNum
,
nextLevelNum
,
nextWorldNum
;
unsigned
char
difficulty
;
int
pathLength
;
int
endTime
;
unsigned
int
endTime
;
int
enemies
,
items
;
fixed
waterLevel
;
fixed
energyBar
;
...
...
@@ -126,10 +126,10 @@ class Level {
protected
:
float
smoothfps
;
int
tickOffset
,
prevTicks
,
ticks
;
unsigned
int
tickOffset
,
prevStepTicks
,
prevTicks
,
ticks
;
int
load
(
char
*
fileName
,
unsigned
char
diff
,
bool
checkpoint
);
int
playFrame
();
int
step
();
void
draw
();
void
timeCalcs
(
bool
paused
);
...
...
@@ -152,12 +152,12 @@ class Level {
unsigned
char
tile
);
signed
char
*
getEvent
(
unsigned
char
gridX
,
unsigned
char
gridY
);
unsigned
char
getEventHits
(
unsigned
char
gridX
,
unsigned
char
gridY
);
int
getEventTime
(
unsigned
char
gridX
,
unsigned
char
gridY
);
unsigned
int
getEventTime
(
unsigned
char
gridX
,
unsigned
char
gridY
);
void
clearEvent
(
unsigned
char
gridX
,
unsigned
char
gridY
);
int
hitEvent
(
Player
*
source
,
unsigned
char
gridX
,
unsigned
char
gridY
);
void
setEventTime
(
unsigned
char
gridX
,
unsigned
char
gridY
,
int
time
);
unsigned
int
time
);
signed
char
*
getBullet
(
unsigned
char
bullet
);
Sprite
*
getSprite
(
unsigned
char
sprite
);
Anim
*
getAnim
(
unsigned
char
anim
);
...
...
src/level/levelframe.cpp
View file @
5e941c85
...
...
@@ -36,11 +36,17 @@
#include "player/player.h"
int
Level
::
playFrame
()
{
int
Level
::
step
()
{
Bullet
*
nextBullet
;
Event
*
nextEvent
;
int
x
,
y
;
int
msps
;
// Milliseconds per step
msps
=
ticks
-
prevStepTicks
;
prevStepTicks
=
ticks
;
// Search for active events
...
...
@@ -74,7 +80,7 @@ int Level::playFrame () {
// Determine the players' trajectories
for
(
x
=
0
;
x
<
nPlayers
;
x
++
)
players
[
x
].
control
(
ticks
);
for
(
x
=
0
;
x
<
nPlayers
;
x
++
)
players
[
x
].
control
(
ticks
,
msps
);
// Process active events
...
...
@@ -83,7 +89,7 @@ int Level::playFrame () {
if
(
firstEvent
)
{
if
(
firstEvent
->
playFrame
(
tick
s
))
{
if
(
firstEvent
->
step
(
ticks
,
msp
s
))
{
nextEvent
=
firstEvent
->
getNext
();
delete
firstEvent
;
...
...
@@ -98,7 +104,7 @@ int Level::playFrame () {
if
(
firstBullet
)
{
if
(
firstBullet
->
playFrame
(
tick
s
))
{
if
(
firstBullet
->
step
(
ticks
,
msp
s
))
{
nextBullet
=
firstBullet
->
getNext
();
delete
firstBullet
;
...
...
@@ -111,7 +117,7 @@ int Level::playFrame () {
// Apply as much of those trajectories as possible, without going into the
// scenery
for
(
x
=
0
;
x
<
nPlayers
;
x
++
)
players
[
x
].
move
(
ticks
);
for
(
x
=
0
;
x
<
nPlayers
;
x
++
)
players
[
x
].
move
(
ticks
,
msps
);
...
...
@@ -128,17 +134,6 @@ int Level::playFrame () {
}
// Calculate viewport
if
(
game
&&
(
stage
==
LS_END
))
game
->
view
();
else
localPlayer
->
view
(
ticks
);
// Ensure the new viewport is within the level
if
(
viewX
<
0
)
viewX
=
0
;
if
(
FTOI
(
viewX
)
+
viewW
>=
TTOI
(
LW
))
viewX
=
ITOF
(
TTOI
(
LW
)
-
viewW
);
if
(
viewY
<
0
)
viewY
=
0
;
if
(
FTOI
(
viewY
)
+
viewH
>=
TTOI
(
LH
))
viewY
=
ITOF
(
TTOI
(
LH
)
-
viewH
);
return
E_NONE
;
}
...
...
@@ -161,7 +156,17 @@ void Level::draw () {
src
.
x
=
0
;
// Use the local player's viewport
// Calculate viewport
if
(
game
&&
(
stage
==
LS_END
))
game
->
view
((
ticks
-
prevTicks
)
*
160
);
else
localPlayer
->
view
(
ticks
,
ticks
-
prevTicks
);
// Ensure the new viewport is within the level
if
(
viewX
<
0
)
viewX
=
0
;
if
(
FTOI
(
viewX
)
+
viewW
>=
TTOI
(
LW
))
viewX
=
ITOF
(
TTOI
(
LW
)
-
viewW
);
if
(
viewY
<
0
)
viewY
=
0
;
if
(
FTOI
(
viewY
)
+
viewH
>=
TTOI
(
LH
))
viewY
=
ITOF
(
TTOI
(
LH
)
-
viewH
);
// Use the viewport
dst
.
x
=
0
;
dst
.
y
=
0
;
vX
=
FTOI
(
viewX
);
...
...
@@ -240,15 +245,15 @@ void Level::draw () {
while
(
event
)
{
event
->
draw
(
ticks
);
event
->
draw
(
ticks
,
ticks
-
prevStepTicks
);
event
=
event
->
getNext
();
}
// Show the players
for
(
x
=
0
;
x
<
nPlayers
;
x
++
)
players
[
x
].
draw
(
t
icks
);
for
(
x
=
0
;
x
<
nPlayers
;
x
++
)
players
[
x
].
draw
(
ticks
,
ticks
-
prevStepT
icks
);
// Show bullets
...
...
@@ -256,7 +261,7 @@ void Level::draw () {
while
(
bullet
)
{
bullet
->
draw
();
bullet
->
draw
(
ticks
-
prevStepTicks
);
bullet
=
bullet
->
getNext
();
}
...
...
@@ -362,16 +367,17 @@ void Level::draw () {
dst
.
x
=
20
;
x
=
localPlayer
->
getEnergy
();
y
=
(
ticks
-
prevTicks
)
*
40
;
if
(
FTOI
(
energyBar
)
<
(
x
<<
4
))
{
if
((
x
<<
14
)
-
energyBar
<
mspf
*
40
)
energyBar
=
x
<<
14
;
else
energyBar
+=
mspf
*
40
;
if
((
x
<<
14
)
-
energyBar
<
y
)
energyBar
=
x
<<
14
;
else
energyBar
+=
y
;
}
else
if
(
FTOI
(
energyBar
)
>
(
x
<<
4
))
{
if
(
energyBar
-
(
x
<<
14
)
<
mspf
*
40
)
energyBar
=
x
<<
14
;
else
energyBar
-=
mspf
*
40
;
if
(
energyBar
-
(
x
<<
14
)
<
y
)
energyBar
=
x
<<
14
;
else
energyBar
-=
y
;
}
...
...
src/main.cpp
View file @
5e941c85
...
...
@@ -325,7 +325,6 @@ int loadMain () {
// Establish arbitrary timing
mspf
=
20
;
globalTicks
=
SDL_GetTicks
()
-
20
;
...
...
@@ -435,17 +434,14 @@ int loop (int type) {
SDL_Color
shownPalette
[
256
];
SDL_Event
event
;
int
ret
;
int
prevTicks
,
ret
;
// Show everything that has been drawn so far
SDL_Flip
(
screen
);
// Calculate frame rate and key timing
ret
=
SDL_GetTicks
();
mspf
=
ret
-
globalTicks
;
if
(
mspf
>
100
)
mspf
=
100
;
globalTicks
=
ret
;
prevTicks
=
globalTicks
;
globalTicks
=
SDL_GetTicks
();
// Process system events
while
(
SDL_PollEvent
(
&
event
))
{
...
...
@@ -532,20 +528,22 @@ int loop (int type) {
memcpy
(
shownPalette
,
currentPalette
,
sizeof
(
SDL_Color
)
*
256
);
firstPE
->
apply
(
shownPalette
,
false
);
firstPE
->
apply
(
shownPalette
,
false
,
globalTicks
-
prevTicks
);
SDL_SetPalette
(
screen
,
SDL_PHYSPAL
,
shownPalette
,
0
,
256
);
}
else
{
firstPE
->
apply
(
shownPalette
,
true
);
firstPE
->
apply
(
shownPalette
,
true
,
globalTicks
-
prevTicks
);
}
}
#ifdef WIZ
WIZ_AdjustVolume
(
volume_direction
);
#endif
return
E_NONE
;
}
...
...
src/movable.cpp
0 → 100644
View file @
5e941c85
/*
*
* movable.cpp
*
* 15th January 2005: Created movable.cpp
*
* Part of the OpenJazz project
*
*
* Copyright (c) 2005-2009 Alister Thomson
*
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
/*
* Contains the base class for all movable objects.
*
*/
#include "movable.h"
fixed
Movable
::
getDrawX
(
int
change
)
{
return
x
+
((
dx
*
change
)
>>
10
);
}
fixed
Movable
::
getDrawY
(
int
change
)
{
return
y
+
((
dy
*
change
)
>>
10
);
}
fixed
Movable
::
getX
()
{
return
x
;
}
fixed
Movable
::
getY
()
{
return
y
;
}
src/movable.h
0 → 100644
View file @
5e941c85
/*
*
* movable.h
*
* 15th January 2005: Created movable.h
*
* Part of the OpenJazz project
*
*
* Copyright (c) 2005-2009 Alister Thomson
*
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef _MOVABLE_H
#define _MOVABLE_H
#include "OpenJazz.h"
// Class
class
Movable
{
protected
:
fixed
x
,
y
,
dx
,
dy
;
fixed
getDrawX
(
int
change
);
fixed
getDrawY
(
int
change
);
public
:
fixed
getX
();
fixed
getY
();
};
#endif
src/player/bird.cpp
View file @
5e941c85
...
...
@@ -78,21 +78,7 @@ void Bird::hit () {
}
fixed
Bird
::
getX
()
{
return
x
;
}
fixed
Bird
::
getY
()
{
return
y
;
}
bool
Bird
::
playFrame
(
int
ticks
)
{
bool
Bird
::
step
(
unsigned
int
ticks
,
int
msps
)
{
Event
*
nextEvent
;
fixed
eventX
,
eventY
;
...
...
@@ -122,13 +108,13 @@ bool Bird::playFrame (int ticks) {
// To the left of the player, so move right
if
(
dx
<
F160
)
dx
+=
400
*
msp
f
;
if
(
dx
<
F160
)
dx
+=
400
*
msp
s
;
}
else
{
// To the right of the player, so move left
if
(
dx
>
-
F160
)
dx
-=
400
*
msp
f
;
if
(
dx
>
-
F160
)
dx
-=
400
*
msp
s
;
}
...
...
@@ -152,13 +138,13 @@ bool Bird::playFrame (int ticks) {
// Above the player, so move downwards
if
(
dy
<
F160
)
dy
+=
400
*
msp
f
;
if
(
dy
<
F160
)
dy
+=
400
*
msp
s
;
}
else
{
// Below the player, so move upwards
if
(
dy
>
-
F160
)
dy
-=
400
*
msp
f
;
if
(
dy
>
-
F160
)
dy
-=
400
*
msp
s
;
}
...
...
@@ -178,7 +164,7 @@ bool Bird::playFrame (int ticks) {
while
(
nextEvent
)
{
eventX
=
nextEvent
->
getX
();
eventY
=
nextEvent
->
getY
();
eventY
=
nextEvent
->
getY
()
-
nextEvent
->
getHeight
()
;
if
(
nextEvent
->
getProperty
(
E_HITSTOKILL
)
&&
(
eventX
>
x
)
&&
(
eventX
<
x
+
F160
)
&&
(
eventY
>
y
)
&&
...
...
@@ -199,7 +185,7 @@ bool Bird::playFrame (int ticks) {
while
(
nextEvent
)
{
eventX
=
nextEvent
->
getX
();
eventY
=
nextEvent
->
getY
();
eventY
=
nextEvent
->
getY
()
-
nextEvent
->
getHeight
()
;
if
(
nextEvent
->
getProperty
(
E_HITSTOKILL
)
&&
(
eventX
>
x
-
F160
)
&&
(
eventX
<
x
)
&&
(
eventY
>
y
)
&&
...
...
@@ -231,15 +217,15 @@ bool Bird::playFrame (int ticks) {
}
// Apply trajectory
x
+=
(
dx
*
msp
f
)
>>
10
;
y
+=
(
dy
*
msp
f
)
>>
10
;
x
+=
(
dx
*
msp
s
)
>>
10
;
y
+=
(
dy
*
msp
s
)
>>
10
;
return
false
;
}
void
Bird
::
draw
(
int
ticks
)
{
void
Bird
::
draw
(
unsigned
int
ticks
,
int
change
)
{
Anim
*
anim
;
...
...
@@ -247,7 +233,7 @@ void Bird::draw (int ticks) {
BIRD_LEFTANIM
);
anim
->
setFrame
(
ticks
/
80
,
true
);
anim
->
draw
(
x
,
y
);
anim
->
draw
(
getDrawX
(
change
),
getDrawY
(
change
)
);
return
;
...
...
src/player/bird.h
View file @
5e941c85
...
...
@@ -24,6 +24,7 @@
#define _BIRD_H
#include "movable.h"
#include "OpenJazz.h"
...
...
@@ -41,11 +42,10 @@
class
Player
;
class
Bird
{
class
Bird
:
public
Movable
{
private
:
Player
*
player
;
fixed
x
,
y
,
dx
,
dy
;
bool
fleeing
;
int
fireTime
;
...
...
@@ -56,10 +56,8 @@ class Bird {
void
reset
();
Player
*
getPlayer
();
void
hit
();
fixed
getX
();
fixed
getY
();
bool
playFrame
(
int
ticks
);
void
draw
(
int
ticks
);
bool
step
(
unsigned
int
ticks
,
int
msps
);
void
draw
(
unsigned
int
ticks
,
int
change
);
};
...
...
src/player/player.cpp
View file @
5e941c85
...
...
@@ -237,7 +237,8 @@ void Player::setControl (int control, bool state) {
}
bool
Player
::
shootEvent
(
unsigned
char
gridX
,
unsigned
char
gridY
,
int
ticks
)
{
bool
Player
::
shootEvent
(
unsigned
char
gridX
,
unsigned
char
gridY
,
unsigned
int
ticks
)
{
signed
char
*
set
;
...
...
@@ -331,7 +332,8 @@ bool Player::shootEvent (unsigned char gridX, unsigned char gridY, int ticks) {
}
bool
Player
::
touchEvent
(
unsigned
char
gridX
,
unsigned
char
gridY
,
int
ticks
)
{
bool
Player
::
touchEvent
(
unsigned
char
gridX
,
unsigned
char
gridY
,
unsigned
int
ticks
)
{
signed
char
*
set
;
...
...
@@ -485,7 +487,7 @@ bool Player::touchEvent (unsigned char gridX, unsigned char gridY, int ticks) {
}
bool
Player
::
hit
(
Player
*
source
,
int
ticks
)
{
bool
Player
::
hit
(
Player
*
source
,
unsigned
int
ticks
)
{
// Invulnerable if reacting to e.g. having been hit
if
(
reaction
!=
PR_NONE
)
return
false
;
...
...
@@ -534,7 +536,7 @@ bool Player::hit (Player *source, int ticks) {
}
void
Player
::
kill
(
Player
*
source
,
int
ticks
)
{
void
Player
::
kill
(
Player
*
source
,
unsigned
int
ticks
)
{
if
(
reaction
!=
PR_NONE
)
return
;
...
...
@@ -615,20 +617,6 @@ int Player::getItems () {
}
fixed
Player
::
getX
()
{
return
x
;
}
fixed
Player
::
getY
()
{
return
y
;
}
bool
Player
::
overlap
(
fixed
left
,
fixed
top
,
fixed
width
,
fixed
height
)
{
return
(
x
+
PXO_R
>=
left
)
&&
(
x
+
PXO_L
<
left
+
width
)
&&
(
y
>=
top
)
&&
...
...
@@ -671,7 +659,7 @@ unsigned char Player::getTeam () {
}
void
Player
::
floatUp
(
signed
char
*
newEvent
)
{
void
Player
::
floatUp
(
signed
char
*
newEvent
,
int
speed
)
{
event
=
newEvent
;
...
...
@@ -679,7 +667,7 @@ void Player::floatUp (signed char *newEvent) {
dy
=
event
[
E_MULTIPURPOSE
]
*
-
F40
;
if
(
dy
>
event
[
E_MULTIPURPOSE
]
*
-
F40
)
dy
-=
event
[
E_MULTIPURPOSE
]
*
320
*
mspf
;
dy
-=
event
[
E_MULTIPURPOSE
]
*
320
*
speed
;
jumpY
=
y
-
(
8
*
F16
);
...
...
@@ -690,7 +678,7 @@ void Player::floatUp (signed char *newEvent) {
void
Player
::
belt
(
int
speed
)
{
dx
+=
speed
*
160
*
mspf
;
dx
+=
speed
*
160
;
return
;
...
...
@@ -835,7 +823,7 @@ void Player::receive (unsigned char *buffer) {
}
int
Player
::
reacted
(
int
ticks
)
{
int
Player
::
reacted
(
unsigned
int
ticks
)
{
int
oldReaction
;
...
...
src/player/player.h
View file @
5e941c85
...
...
@@ -29,6 +29,7 @@
#define _PLAYER_H
#include "movable.h"
#include "OpenJazz.h"
#include <SDL/SDL.h>
...
...
@@ -154,7 +155,7 @@
class
Bird
;
class
Player
{
class
Player
:
public
Movable
{
private
:
Bird
*
bird
;
...
...
@@ -175,18 +176,17 @@ class Player {
3 = 1 orange, 4 = 2 orange, 5 = 3 orange, 6 = 4 orange */
bool
floating
;
// false = normal, true = boarding/bird/etc.
bool
facing
;
int
lookTime
;
/* Negative if looking up, positive if looking
unsigned
int
lookTime
;
/* Negative if looking up, positive if looking
down, 0 if neither */
int
reaction
;
int
reactionTime
;
unsigned
int
reactionTime
;
int
fireSpeed
;
int
fireTime
;
unsigned
int
fireTime
;
fixed
jumpHeight
;
fixed
jumpY
;
int
fastFeetTime
;
unsigned
int
fastFeetTime
;
unsigned
char
warpX
,
warpY
;
int
warpTime
;
fixed
x
,
y
,
dx
,
dy
;
unsigned
int
warpTime
;
int
enemies
,
items
;
unsigned
char
team
;
...
...
@@ -207,11 +207,11 @@ class Player {
void
reset
();
void
setControl
(
int
control
,
bool
state
);
bool
shootEvent
(
unsigned
char
gridX
,
unsigned
char
gridY
,
int
ticks
);
unsigned
int
ticks
);
bool
touchEvent
(
unsigned
char
gridX
,
unsigned
char
gridY
,
int
ticks
);
bool
hit
(
Player
*
source
,
int
ticks
);
void
kill
(
Player
*
source
,
int
ticks
);
unsigned
int
ticks
);
bool
hit
(
Player
*
source
,
unsigned
int
ticks
);
void
kill
(
Player
*
source
,
unsigned
int
ticks
);
void
addScore
(
int
addedScore
);
int
getScore
();
int
getEnergy
();
...
...
@@ -219,26 +219,24 @@ class Player {
int
getAmmo
(
bool
amount
);
int
getEnemies
();
int
getItems
();
fixed
getX
();
fixed
getY
();
bool
overlap
(
fixed
left
,
fixed
top
,
fixed
width
,
fixed
height
);
void
setPosition
(
fixed
newX
,
fixed
newY
);
void
setSpeed
(
fixed
newDx
,
fixed
newDy
);
bool
getFacing
();
unsigned
char
getTeam
();
void
floatUp
(
signed
char
*
newEvent
);
void
floatUp
(
signed
char
*
newEvent
,
int
speed
);
void
belt
(
int
speed
);
void
setEvent
(
signed
char
*
newEvent
);
void
clearEvent
(
signed
char
*
newEvent
,
unsigned
char
property
);
void
send
(
unsigned
char
*
data
);
void
receive
(
unsigned
char
*
buffer
);
void
control
(
int
tick
s
);
void
move
(
int
tick
s
);
void
view
(
int
ticks
);
void
draw
(
int
ticks
);
int
reacted
(
int
ticks
);
void
control
(
unsigned
int
ticks
,
int
msp
s
);
void
move
(
unsigned
int
ticks
,
int
msp
s
);
void
view
(
unsigned
int
ticks
,
int
mspf
);
void
draw
(
unsigned
int
ticks
,
int
change
);
int
reacted
(
unsigned
int
ticks
);
};
...
...
src/player/playerframe.cpp
View file @
5e941c85
...
...
@@ -40,7 +40,7 @@
#include <math.h>
void
Player
::
control
(
int
tick
s
)
{
void
Player
::
control
(
unsigned
int
ticks
,
int
msp
s
)
{
// Respond to controls, unless the player has been killed
...
...
@@ -52,7 +52,7 @@ void Player::control (int ticks) {
if
(
floating
)
dy
=
0
;
else
{
dy
+=
PYA_GRAVITY
*
msp
f
;
dy
+=
PYA_GRAVITY
*
msp
s
;
if
(
dy
>
PYS_FALL
)
dy
=
PYS_FALL
;
}
...
...
@@ -65,9 +65,9 @@ void Player::control (int ticks) {
// Walk/run right
if
(
dx
<
0
)
dx
+=
PXA_REVERSE
*
msp
f
;
else
if
(
dx
<
PXS_WALK
)
dx
+=
PXA_WALK
*
msp
f
;
else
if
(
dx
<
PXS_RUN
)
dx
+=
PXA_RUN
*
msp
f
;
if
(
dx
<
0
)
dx
+=
PXA_REVERSE
*
msp
s
;
else
if
(
dx
<
PXS_WALK
)
dx
+=
PXA_WALK
*
msp
s
;
else
if
(
dx
<
PXS_RUN
)
dx
+=
PXA_RUN
*
msp
s
;
facing
=
true
;
...
...
@@ -75,9 +75,9 @@ void Player::control (int ticks) {
// Walk/run left
if
(
dx
>
0
)
dx
-=
PXA_REVERSE
*
msp
f
;
else
if
(
dx
>
-
PXS_WALK
)
dx
-=
PXA_WALK
*
msp
f
;
else
if
(
dx
>
-
PXS_RUN
)
dx
-=
PXA_RUN
*
msp
f
;
if
(
dx
>
0
)
dx
-=
PXA_REVERSE
*
msp
s
;
else
if
(
dx
>
-
PXS_WALK
)
dx
-=
PXA_WALK
*
msp
s
;
else
if
(
dx
>
-
PXS_RUN
)
dx
-=
PXA_RUN
*
msp
s
;
facing
=
false
;
...
...
@@ -87,15 +87,15 @@ void Player::control (int ticks) {
if
(
dx
>
0
)
{
if
(
dx
<
PXA_STOP
*
msp
f
)
dx
=
0
;
else
dx
-=
PXA_STOP
*
msp
f
;
if
(
dx
<
PXA_STOP
*
msp
s
)
dx
=
0
;
else
dx
-=
PXA_STOP
*
msp
s
;
}
if
(
dx
<
0
)
{
if
(
dx
>
-
PXA_STOP
*
msp
f
)
dx
=
0
;
else
dx
+=
PXA_STOP
*
msp
f
;
if
(
dx
>
-
PXA_STOP
*
msp
s
)
dx
=
0
;
else
dx
+=
PXA_STOP
*
msp
s
;
}
...
...
@@ -111,17 +111,17 @@ void Player::control (int ticks) {
// Fly upwards
if
(
dy
>
0
)
dy
-=
PXA_REVERSE
*
msp
f
;
else
if
(
dy
>
-
PXS_WALK
)
dy
-=
PXA_WALK
*
msp
f
;
else
if
(
dy
>
-
PXS_RUN
)
dy
-=
PXA_RUN
*
msp
f
;
if
(
dy
>
0
)
dy
-=
PXA_REVERSE
*
msp
s
;
else
if
(
dy
>
-
PXS_WALK
)
dy
-=
PXA_WALK
*
msp
s
;
else
if
(
dy
>
-
PXS_RUN
)
dy
-=
PXA_RUN
*
msp
s
;
}
else
if
(
pcontrols
[
C_DOWN
])
{
// Fly downwards
if
(
dy
<
0
)
dy
+=
PXA_REVERSE
*
msp
f
;
else
if
(
dy
<
PXS_WALK
)
dy
+=
PXA_WALK
*
msp
f
;
else
if
(
dy
<
PXS_RUN
)
dy
+=
PXA_RUN
*
msp
f
;
if
(
dy
<
0
)
dy
+=
PXA_REVERSE
*
msp
s
;
else
if
(
dy
<
PXS_WALK
)
dy
+=
PXA_WALK
*
msp
s
;
else
if
(
dy
<
PXS_RUN
)
dy
+=
PXA_RUN
*
msp
s
;
}
else
{
...
...
@@ -129,15 +129,15 @@ void Player::control (int ticks) {
if
(
dy
>
0
)
{
if
(
dy
<
PXA_STOP
*
msp
f
)
dy
=
0
;
else
dy
-=
PXA_STOP
*
msp
f
;
if
(
dy
<
PXA_STOP
*
msp
s
)
dy
=
0
;
else
dy
-=
PXA_STOP
*
msp
s
;
}
if
(
dy
<
0
)
{
if
(
dy
>
-
PXA_STOP
*
msp
f
)
dy
=
0
;
else
dy
+=
PXA_STOP
*
msp
f
;
if
(
dy
>
-
PXA_STOP
*
msp
s
)
dy
=
0
;
else
dy
+=
PXA_STOP
*
msp
s
;
}
...
...
@@ -159,9 +159,9 @@ void Player::control (int ticks) {
// Swim upwards
if
(
dy
>
0
)
dy
-=
PXA_REVERSE
*
msp
f
;
else
if
(
dy
>
-
PXS_WALK
)
dy
-=
PXA_WALK
*
msp
f
;
else
if
(
dy
>
-
PXS_RUN
)
dy
-=
PXA_RUN
*
msp
f
;
if
(
dy
>
0
)
dy
-=
PXA_REVERSE
*
msp
s
;
else
if
(
dy
>
-
PXS_WALK
)
dy
-=
PXA_WALK
*
msp
s
;
else
if
(
dy
>
-
PXS_RUN
)
dy
-=
PXA_RUN
*
msp
s
;
// Prepare to jump upon leaving the water
...
...
@@ -180,15 +180,15 @@ void Player::control (int ticks) {
// Swim downwards
if
(
dy
<
0
)
dy
+=
PXA_REVERSE
*
msp
f
;
else
if
(
dy
<
PXS_WALK
)
dy
+=
PXA_WALK
*
msp
f
;
else
if
(
dy
<
PXS_RUN
)
dy
+=
PXA_RUN
*
msp
f
;
if
(
dy
<
0
)
dy
+=
PXA_REVERSE
*
msp
s
;
else
if
(
dy
<
PXS_WALK
)
dy
+=
PXA_WALK
*
msp
s
;
else
if
(
dy
<
PXS_RUN
)
dy
+=
PXA_RUN
*
msp
s
;
}
else
{
// Sink
dy
+=
PYA_SINK
*
msp
f
;
dy
+=
PYA_SINK
*
msp
s
;
if
(
dy
>
PYS_SINK
)
dy
=
PYS_SINK
;
}
...
...
@@ -255,7 +255,7 @@ void Player::control (int ticks) {
}
else
{
// Fall under gravity
dy
+=
PYA_GRAVITY
*
msp
f
;
dy
+=
PYA_GRAVITY
*
msp
s
;
if
(
dy
>
PYS_FALL
)
dy
=
PYS_FALL
;
}
...
...
@@ -331,7 +331,7 @@ void Player::control (int ticks) {
if
(
bird
)
{
if
(
bird
->
playFrame
(
tick
s
))
{
if
(
bird
->
step
(
ticks
,
msp
s
))
{
delete
bird
;
bird
=
NULL
;
...
...
@@ -346,7 +346,7 @@ void Player::control (int ticks) {
}
void
Player
::
move
(
int
tick
s
)
{
void
Player
::
move
(
unsigned
int
ticks
,
int
msp
s
)
{
fixed
pdx
,
pdy
;
int
count
;
...
...
@@ -364,13 +364,13 @@ void Player::move (int ticks) {
if
(
fastFeetTime
>
ticks
)
{
pdx
=
(
dx
*
msp
f
*
3
)
>>
11
;
pdy
=
(
dy
*
msp
f
*
3
)
>>
11
;
pdx
=
(
dx
*
msp
s
*
3
)
>>
11
;
pdy
=
(
dy
*
msp
s
*
3
)
>>
11
;
}
else
{
pdx
=
(
dx
*
msp
f
)
>>
10
;
pdy
=
(
dy
*
msp
f
)
>>
10
;
pdx
=
(
dx
*
msp
s
)
>>
10
;
pdy
=
(
dy
*
msp
s
)
>>
10
;
}
...
...
@@ -516,7 +516,7 @@ void Player::move (int ticks) {
}
void
Player
::
view
(
int
ticks
)
{
void
Player
::
view
(
unsigned
int
ticks
,
int
mspf
)
{
int
oldViewX
,
oldViewY
,
speed
;
...
...
@@ -569,10 +569,11 @@ void Player::view (int ticks) {
}
void
Player
::
draw
(
int
ticks
)
{
void
Player
::
draw
(
unsigned
int
ticks
,
int
change
)
{
Anim
*
an
;
int
anim
,
frame
;
fixed
drawX
,
drawY
;
fixed
xOffset
,
yOffset
;
// The current frame for animations
...
...
@@ -580,6 +581,12 @@ void Player::draw (int ticks) {
else
frame
=
ticks
/
75
;
// Get position
drawX
=
getDrawX
(
change
);
drawY
=
getDrawY
(
change
);
// Choose player animation
if
(
reaction
==
PR_KILLED
)
anim
=
anims
[
facing
?
PA_RDIE
:
PA_LDIE
];
...
...
@@ -604,6 +611,9 @@ void Player::draw (int ticks) {
level
->
checkMaskDown
(
x
+
PXO_MID
,
y
+
F8
)
||
level
->
checkMaskDown
(
x
+
PXO_MR
,
y
+
F8
))
{
drawX
=
x
;
drawY
=
y
;
if
(
dx
)
{
if
(
dx
<=
-
PXS_RUN
)
anim
=
anims
[
PA_LRUN
];
...
...
@@ -671,11 +681,10 @@ void Player::draw (int ticks) {
// Draw "motion blur"
if
(
fastFeetTime
>
ticks
)
an
->
draw
(
x
-
(
dx
>>
6
),
y
);
if
(
fastFeetTime
>
ticks
)
an
->
draw
(
drawX
-
(
dx
>>
6
),
drawY
);
// Draw player
an
->
draw
(
x
,
y
);
an
->
draw
(
drawX
,
drawY
);
// Remove red flash or player colour from sprite
...
...
@@ -692,16 +701,16 @@ void Player::draw (int ticks) {
an
=
level
->
getMiscAnim
(
0
);
an
->
setFrame
(
frame
,
true
);
an
->
draw
(
x
+
PXO_MID
+
xOffset
,
y
+
PYO_MID
+
yOffset
);
an
->
draw
(
drawX
+
PXO_MID
+
xOffset
,
drawY
+
PYO_MID
+
yOffset
);
an
->
setFrame
(
frame
+
1
,
true
);
an
->
draw
(
x
+
PXO_MID
-
xOffset
,
y
+
PYO_MID
-
yOffset
);
an
->
draw
(
drawX
+
PXO_MID
-
xOffset
,
drawY
+
PYO_MID
-
yOffset
);
an
->
setFrame
(
frame
+
2
,
true
);
an
->
draw
(
x
+
PXO_MID
+
yOffset
,
y
+
PYO_MID
+
xOffset
);
an
->
draw
(
drawX
+
PXO_MID
+
yOffset
,
drawY
+
PYO_MID
+
xOffset
);
an
->
setFrame
(
frame
+
3
,
true
);
an
->
draw
(
x
+
PXO_MID
-
yOffset
,
y
+
PYO_MID
-
xOffset
);
an
->
draw
(
drawX
+
PXO_MID
-
yOffset
,
drawY
+
PYO_MID
-
xOffset
);
}
else
if
(
shield
>
2
)
{
...
...
@@ -712,13 +721,13 @@ void Player::draw (int ticks) {
an
=
level
->
getAnim
(
59
);
an
->
draw
(
x
+
xOffset
,
y
+
PYO_TOP
+
yOffset
);
an
->
draw
(
drawX
+
xOffset
,
drawY
+
PYO_TOP
+
yOffset
);
if
(
shield
>
3
)
an
->
draw
(
x
-
xOffset
,
y
+
PYO_TOP
-
yOffset
);
if
(
shield
>
3
)
an
->
draw
(
drawX
-
xOffset
,
drawY
+
PYO_TOP
-
yOffset
);
if
(
shield
>
4
)
an
->
draw
(
x
+
yOffset
,
y
+
PYO_TOP
-
xOffset
);
if
(
shield
>
4
)
an
->
draw
(
drawX
+
yOffset
,
drawY
+
PYO_TOP
-
xOffset
);
if
(
shield
>
5
)
an
->
draw
(
x
-
yOffset
,
y
+
PYO_TOP
+
xOffset
);
if
(
shield
>
5
)
an
->
draw
(
drawX
-
yOffset
,
drawY
+
PYO_TOP
+
xOffset
);
}
else
if
(
shield
)
{
...
...
@@ -729,21 +738,21 @@ void Player::draw (int ticks) {
an
=
level
->
getAnim
(
50
);
an
->
draw
(
x
+
xOffset
,
y
+
yOffset
+
PYO_TOP
);
an
->
draw
(
drawX
+
xOffset
,
drawY
+
yOffset
+
PYO_TOP
);
if
(
shield
==
2
)
an
->
draw
(
x
-
xOffset
,
y
+
PYO_TOP
-
yOffset
);
if
(
shield
==
2
)
an
->
draw
(
drawX
-
xOffset
,
drawY
+
PYO_TOP
-
yOffset
);
}
// Show the bird
if
(
bird
)
bird
->
draw
(
ticks
);
if
(
bird
)
bird
->
draw
(
ticks
,
change
);
// Show the player's name
if
(
gameMode
)
panelBigFont
->
showString
(
name
,
FTOI
(
x
-
viewX
),
FTOI
(
y
-
F32
-
F16
-
viewY
));
panelBigFont
->
showString
(
name
,
FTOI
(
drawX
-
viewX
),
FTOI
(
drawY
-
F32
-
F16
-
viewY
));
return
;
...
...
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