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
105d65c6
Commit
105d65c6
authored
Apr 11, 2010
by
alistert
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bonus levels are now "3D", and have working collision.
parent
e1248b96
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
237 additions
and
134 deletions
+237
-134
bonus.cpp
src/bonus/bonus.cpp
+146
-72
bonus.h
src/bonus/bonus.h
+24
-11
font.cpp
src/io/gfx/font.cpp
+2
-0
bullet.cpp
src/level/bullet.cpp
+1
-1
level.cpp
src/level/level.cpp
+13
-5
level.h
src/level/level.h
+3
-4
player.h
src/player/player.h
+19
-18
playerframe.cpp
src/player/playerframe.cpp
+29
-23
No files found.
src/bonus/bonus.cpp
View file @
105d65c6
...
@@ -41,13 +41,15 @@
...
@@ -41,13 +41,15 @@
#include <math.h>
#include <math.h>
#include <string.h>
#include <string.h>
#define PI 3.141592f
int
Bonus
::
loadTiles
(
char
*
fileName
)
{
int
Bonus
::
loadTiles
(
char
*
fileName
)
{
File
*
file
;
File
*
file
;
unsigned
char
*
pixels
;
unsigned
char
*
pixels
;
unsigned
char
*
sorted
;
unsigned
char
*
sorted
;
int
count
;
int
count
,
x
,
y
;
try
{
try
{
...
@@ -74,7 +76,28 @@ int Bonus::loadTiles (char *fileName) {
...
@@ -74,7 +76,28 @@ int Bonus::loadTiles (char *fileName) {
file
->
loadPalette
(
palette
);
file
->
loadPalette
(
palette
);
// Load tile graphics
// Load tile graphics
tileSet
=
file
->
loadSurface
(
32
,
32
*
60
);
pixels
=
file
->
loadRLE
(
1024
*
60
);
tileSet
=
createSurface
(
pixels
,
32
,
32
*
60
);
// Create mask
for
(
count
=
0
;
count
<
60
;
count
++
)
{
memset
(
mask
[
count
],
0
,
64
);
for
(
y
=
0
;
y
<
32
;
y
++
)
{
for
(
x
=
0
;
x
<
32
;
x
++
)
{
if
((
pixels
[(
count
<<
10
)
+
(
y
<<
5
)
+
x
]
&
240
)
==
192
)
mask
[
count
][((
y
<<
1
)
&
56
)
+
((
x
>>
2
)
&
7
)]
=
1
;
}
}
}
delete
[]
pixels
;
delete
file
;
delete
file
;
...
@@ -130,9 +153,9 @@ Bonus::Bonus (char * fileName, unsigned char diff) {
...
@@ -130,9 +153,9 @@ Bonus::Bonus (char * fileName, unsigned char diff) {
for
(
x
=
0
;
x
<
BLW
;
x
++
)
{
for
(
x
=
0
;
x
<
BLW
;
x
++
)
{
tiles
[
y
][
x
]
=
buffer
[
x
+
(
y
*
BLW
)];
grid
[
y
][
x
].
tile
=
buffer
[
x
+
(
y
*
BLW
)];
if
(
tiles
[
y
][
x
]
>
59
)
tiles
[
y
][
x
]
=
59
;
if
(
grid
[
y
][
x
].
tile
>
59
)
grid
[
y
][
x
].
tile
=
59
;
}
}
...
@@ -152,7 +175,7 @@ Bonus::Bonus (char * fileName, unsigned char diff) {
...
@@ -152,7 +175,7 @@ Bonus::Bonus (char * fileName, unsigned char diff) {
for
(
x
=
0
;
x
<
BLH
;
x
++
)
{
for
(
x
=
0
;
x
<
BLH
;
x
++
)
{
events
[
y
][
x
]
=
buffer
[
x
+
(
y
*
BLW
)];
grid
[
y
][
x
].
event
=
buffer
[
x
+
(
y
*
BLW
)];
}
}
...
@@ -206,7 +229,7 @@ Bonus::Bonus (char * fileName, unsigned char diff) {
...
@@ -206,7 +229,7 @@ Bonus::Bonus (char * fileName, unsigned char diff) {
paletteEffects
=
new
RotatePaletteEffect
(
192
,
16
,
F32
,
paletteEffects
);
paletteEffects
=
new
RotatePaletteEffect
(
192
,
16
,
F32
,
paletteEffects
);
// Bouncy things
// Bouncy things
paletteEffects
=
new
RotatePaletteEffect
(
240
,
16
,
-
F32
,
paletteEffects
);
paletteEffects
=
new
RotatePaletteEffect
(
240
,
16
,
F32
,
paletteEffects
);
// Adjust fontsFont to use bonus level palette
// Adjust fontsFont to use bonus level palette
...
@@ -237,6 +260,29 @@ Bonus::~Bonus () {
...
@@ -237,6 +260,29 @@ Bonus::~Bonus () {
}
}
bool
Bonus
::
isEvent
(
fixed
x
,
fixed
y
)
{
return
((
x
&
32767
)
>
F12
)
&&
((
x
&
32767
)
<
F20
)
&&
((
y
&
32767
)
>
F12
)
&&
((
y
&
32767
)
<
F20
);
}
bool
Bonus
::
checkMask
(
fixed
x
,
fixed
y
)
{
BonusGridElement
*
ge
;
ge
=
grid
[
FTOT
(
y
)
&
255
]
+
(
FTOT
(
x
)
&
255
);
// Hand
if
((
ge
->
event
==
3
)
&&
isEvent
(
x
,
y
))
return
true
;
// Check the mask in the tile in question
return
mask
[
ge
->
tile
][((
y
>>
9
)
&
56
)
+
((
x
>>
12
)
&
7
)];
}
int
Bonus
::
step
()
{
int
Bonus
::
step
()
{
fixed
playerX
,
playerY
;
fixed
playerX
,
playerY
;
...
@@ -260,33 +306,29 @@ int Bonus::step () {
...
@@ -260,33 +306,29 @@ int Bonus::step () {
// Process players
// Process players
for
(
count
=
0
;
count
<
nPlayers
;
count
++
)
{
for
(
count
=
0
;
count
<
nPlayers
;
count
++
)
{
players
[
count
].
bonusStep
(
ticks
,
msps
);
playerX
=
players
[
count
].
getX
();
playerX
=
players
[
count
].
getX
();
playerY
=
players
[
count
].
getY
();
playerY
=
players
[
count
].
getY
();
gridX
=
FTOT
(
playerX
);
players
[
count
].
bonusStep
(
ticks
,
msps
,
this
);
gridY
=
FTOT
(
playerY
);
if
((
playerX
>
TTOF
(
gridX
)
+
F12
)
&&
(
playerX
<
TTOF
(
gridX
)
+
F20
)
&&
if
(
isEvent
(
playerX
,
playerY
))
{
(
playerY
>
TTOF
(
gridY
)
+
F12
)
&&
(
playerY
<
TTOF
(
gridY
)
+
F20
))
{
while
(
gridX
<
0
)
gridX
+=
BLW
;
gridX
=
FTOT
(
playerX
)
&
255
;
while
(
gridY
<
0
)
gridY
+=
BLH
;
gridY
=
FTOT
(
playerY
)
&
255
;
switch
(
events
[
gridY
][
gridX
]
)
{
switch
(
grid
[
gridY
][
gridX
].
event
)
{
case
1
:
// Extra time
case
1
:
// Extra time
addTimer
();
addTimer
();
events
[
gridY
][
gridX
]
=
0
;
grid
[
gridY
][
gridX
].
event
=
0
;
break
;
break
;
case
2
:
// Gem
case
2
:
// Gem
players
[
count
].
addItem
();
players
[
count
].
addItem
();
events
[
gridY
][
gridX
]
=
0
;
grid
[
gridY
][
gridX
].
event
=
0
;
if
(
players
[
count
].
getItems
()
>=
items
)
{
if
(
players
[
count
].
getItems
()
>=
items
)
{
...
@@ -298,12 +340,6 @@ int Bonus::step () {
...
@@ -298,12 +340,6 @@ int Bonus::step () {
break
;
break
;
case
3
:
// Hand
players
[
count
].
setSpeed
(
0
,
0
);
break
;
case
4
:
// Exit
case
4
:
// Exit
return
LOST
;
return
LOST
;
...
@@ -320,6 +356,8 @@ int Bonus::step () {
...
@@ -320,6 +356,8 @@ int Bonus::step () {
}
}
direction
=
localPlayer
->
getDirection
();
return
E_NONE
;
return
E_NONE
;
}
}
...
@@ -327,32 +365,88 @@ int Bonus::step () {
...
@@ -327,32 +365,88 @@ int Bonus::step () {
void
Bonus
::
draw
()
{
void
Bonus
::
draw
()
{
SDL_Rect
src
,
dst
;
SDL_Rect
dst
;
fixed
playerX
,
playerY
,
playerSin
,
playerCos
;
fixed
distance
,
opposite
,
adjacent
;
int
levelX
,
levelY
;
int
spriteW
,
spriteH
;
int
x
,
y
;
int
x
,
y
;
// Draw the background
for
(
x
=
-
(
localPlayer
->
getDirection
()
&
1023
);
x
<
canvasW
;
x
+=
background
->
w
)
{
dst
.
x
=
x
;
dst
.
y
=
(
canvasH
>>
1
)
-
4
;
SDL_BlitSurface
(
background
,
NULL
,
canvas
,
&
dst
);
}
x
=
171
;
for
(
y
=
(
canvasH
>>
1
)
-
5
;
(
y
>=
0
)
&&
(
x
>
128
);
y
--
)
drawRect
(
0
,
y
,
canvasW
,
1
,
x
--
);
if
(
y
>
0
)
drawRect
(
0
,
0
,
canvasW
,
y
+
1
,
128
);
// Draw the ground
// Draw the ground
src
.
x
=
0
;
playerX
=
localPlayer
->
getX
();
src
.
w
=
32
;
playerY
=
localPlayer
->
getY
();
src
.
h
=
32
;
playerSin
=
fixed
(
1024.0
f
*
sinf
(
PI
*
float
(
direction
)
/
512.0
f
));
playerCos
=
fixed
(
1024.0
f
*
cosf
(
PI
*
float
(
direction
)
/
512.0
f
));
if
(
SDL_MUSTLOCK
(
canvas
))
SDL_LockSurface
(
canvas
);
for
(
y
=
1
;
y
<=
(
canvasH
>>
1
)
-
15
;
y
++
)
{
distance
=
fixed
(
1024.0
f
*
tanf
((
float
(
y
)
/
float
(
canvasH
>>
1
))
+
((
PI
/
2.0
f
)
-
1.0
f
))
*
20.0
f
);
opposite
=
MUL
(
distance
,
playerSin
);
adjacent
=
MUL
(
distance
,
playerCos
);
for
(
x
=
0
;
x
<
canvasW
;
x
++
)
{
fixed
nX
=
ITOF
(
x
-
(
canvasW
>>
1
))
/
canvasW
;
levelX
=
FTOI
(
playerX
+
opposite
+
MUL
(
nX
,
adjacent
));
levelY
=
FTOI
(
playerY
-
adjacent
+
MUL
(
nX
,
opposite
));
((
unsigned
char
*
)(
canvas
->
pixels
))[(
canvas
->
pitch
*
(
canvasH
-
y
))
+
x
]
=
((
unsigned
char
*
)(
tileSet
->
pixels
))
[(
grid
[
ITOT
(
levelY
)
&
255
][
ITOT
(
levelX
)
&
255
].
tile
*
1024
)
+
((
levelY
&
31
)
*
tileSet
->
pitch
)
+
(
levelX
&
31
)];
}
}
if
(
SDL_MUSTLOCK
(
canvas
))
SDL_UnlockSurface
(
canvas
);
int
vX
=
FTOI
(
localPlayer
->
getX
())
-
(
canvasW
>>
1
);
// Draw the events
int
vY
=
FTOI
(
localPlayer
->
getY
())
-
(
canvasH
>>
2
);
for
(
y
=
0
;
y
<=
ITOT
((
canvasH
>>
1
)
-
1
)
+
1
;
y
++
)
{
for
(
y
=
-
7
;
y
<
8
;
y
++
)
{
f
or
(
x
=
0
;
x
<=
ITOT
(
canvasW
-
1
)
+
1
;
x
++
)
{
f
ixed
sY
=
TTOF
(
y
)
+
F16
-
(
playerY
&
32767
);
src
.
y
=
TTOI
(
tiles
[(
y
+
ITOT
(
vY
)
+
BLH
)
%
BLH
][(
x
+
ITOT
(
vX
)
+
BLW
)
%
BLW
]);
for
(
x
=
-
7
;
x
<
8
;
x
++
)
{
dst
.
x
=
TTOI
(
x
)
-
(
vX
&
31
);
dst
.
y
=
(
canvasH
>>
1
)
+
TTOI
(
y
)
-
(
vY
&
31
);
SDL_BlitSurface
(
tileSet
,
&
src
,
canvas
,
&
dst
);
fixed
sX
=
TTOF
(
x
)
+
F16
-
(
playerX
&
32767
);
dst
.
x
=
12
+
TTOI
(
x
)
-
(
vX
&
31
);
fixed
divisor
=
MUL
(
sX
,
playerSin
)
-
MUL
(
sY
,
playerCos
);
dst
.
y
=
(
canvasH
>>
1
)
+
12
+
TTOI
(
y
)
-
(
vY
&
31
);
switch
(
events
[(
y
+
ITOT
(
vY
)
+
BLH
)
%
BLH
][(
x
+
ITOT
(
vX
)
+
BLW
)
%
BLW
])
{
if
(
FTOI
(
divisor
)
>
0
)
{
spriteW
=
1000
/
FTOI
(
divisor
);
spriteH
=
1000
/
FTOI
(
divisor
);
fixed
nX
=
DIV
(
MUL
(
sX
,
playerCos
)
+
MUL
(
sY
,
playerSin
),
divisor
);
dst
.
x
=
FTOI
(
nX
*
canvasW
)
+
((
canvasW
-
spriteW
)
>>
1
);
dst
.
y
=
(
canvasH
-
spriteH
)
>>
1
;
switch
(
grid
[(
y
+
FTOT
(
playerY
))
&
255
][(
x
+
FTOT
(
playerX
))
&
255
].
event
)
{
case
0
:
// No event
case
0
:
// No event
...
@@ -360,31 +454,31 @@ void Bonus::draw () {
...
@@ -360,31 +454,31 @@ void Bonus::draw () {
case
1
:
// Extra time
case
1
:
// Extra time
drawRect
(
dst
.
x
,
dst
.
y
,
8
,
8
,
60
);
drawRect
(
dst
.
x
,
dst
.
y
,
spriteW
,
spriteH
,
60
);
break
;
break
;
case
2
:
// Gem
case
2
:
// Gem
drawRect
(
dst
.
x
,
dst
.
y
,
8
,
8
,
67
);
drawRect
(
dst
.
x
,
dst
.
y
,
spriteW
,
spriteH
,
67
);
break
;
break
;
case
3
:
// Hand
case
3
:
// Hand
drawRect
(
dst
.
x
,
dst
.
y
,
8
,
8
,
15
);
drawRect
(
dst
.
x
,
dst
.
y
,
spriteW
,
spriteH
,
15
);
break
;
break
;
case
4
:
// Exit
case
4
:
// Exit
drawRect
(
dst
.
x
,
dst
.
y
,
8
,
8
,
45
);
drawRect
(
dst
.
x
,
dst
.
y
,
spriteW
,
spriteH
,
45
);
break
;
break
;
default
:
default
:
drawRect
(
dst
.
x
,
dst
.
y
,
8
,
8
,
0
);
drawRect
(
dst
.
x
,
dst
.
y
,
spriteW
,
spriteH
,
0
);
break
;
break
;
...
@@ -394,30 +488,8 @@ void Bonus::draw () {
...
@@ -394,30 +488,8 @@ void Bonus::draw () {
}
}
// Draw the background
for
(
x
=
-
(
localPlayer
->
getDirection
()
&
1023
);
x
<
canvasW
;
x
+=
background
->
w
)
{
dst
.
x
=
x
;
dst
.
y
=
(
canvasH
>>
1
)
-
4
;
SDL_BlitSurface
(
background
,
NULL
,
canvas
,
&
dst
);
}
}
x
=
171
;
for
(
y
=
(
canvasH
>>
1
)
-
5
;
(
y
>=
0
)
&&
(
x
>
128
);
y
--
)
drawRect
(
0
,
y
,
canvasW
,
1
,
x
--
);
if
(
y
>
0
)
drawRect
(
0
,
0
,
canvasW
,
y
+
1
,
128
);
// Draw the "player"
drawRect
(
(
canvasW
>>
1
)
+
fixed
(
sin
(
localPlayer
->
getDirection
()
*
6.283185
/
1024.0
)
*
3
)
-
4
,
((
canvasH
*
3
)
>>
2
)
-
fixed
(
cos
(
localPlayer
->
getDirection
()
*
6.283185
/
1024.0
)
*
3
)
-
4
,
8
,
8
,
0
);
drawRect
((
canvasW
>>
1
)
-
4
,
((
canvasH
*
3
)
>>
2
)
-
4
,
8
,
8
,
22
);
// Show gem count
// Show gem count
fontsFont
->
showString
(
"x"
,
15
,
0
);
fontsFont
->
showString
(
"x"
,
15
,
0
);
...
@@ -562,6 +634,8 @@ int Bonus::play () {
...
@@ -562,6 +634,8 @@ int Bonus::play () {
// Draw the graphics
// Draw the graphics
if
(
ticks
<
returnTime
)
direction
+=
(
ticks
-
prevTicks
)
*
T_BONUS_END
/
(
returnTime
-
ticks
);
draw
();
draw
();
...
...
src/bonus/bonus.h
View file @
105d65c6
...
@@ -34,7 +34,17 @@
...
@@ -34,7 +34,17 @@
#define BLW 256
/* Bonus level width */
#define BLW 256
/* Bonus level width */
#define BLH 256
/* Bonus level height */
#define BLH 256
/* Bonus level height */
#define T_BONUS_END 1500
#define T_BONUS_END 2000
// Datatype
typedef
struct
{
unsigned
char
tile
;
// Indexes the tile set
unsigned
char
event
;
}
BonusGridElement
;
// Class
// Class
...
@@ -42,18 +52,21 @@
...
@@ -42,18 +52,21 @@
class
Bonus
:
public
BaseLevel
{
class
Bonus
:
public
BaseLevel
{
private
:
private
:
SDL_Surface
*
background
;
SDL_Surface
*
background
;
unsigned
char
tiles
[
BLH
][
BLW
];
BonusGridElement
grid
[
BLH
][
BLW
];
unsigned
char
events
[
BLH
][
BLW
];
char
mask
[
60
][
64
];
// At most 60 tiles, all with 8 * 8 masks
fixed
direction
;
int
loadTiles
(
char
*
fileName
);
int
loadTiles
(
char
*
fileName
);
bool
isEvent
(
fixed
x
,
fixed
y
);
int
step
();
int
step
();
void
draw
();
void
draw
();
public
:
public
:
Bonus
(
char
*
fileName
,
unsigned
char
diff
);
Bonus
(
char
*
fileName
,
unsigned
char
diff
);
~
Bonus
();
~
Bonus
();
bool
checkMask
(
fixed
x
,
fixed
y
);
int
play
();
int
play
();
};
};
...
...
src/io/gfx/font.cpp
View file @
105d65c6
...
@@ -165,6 +165,8 @@ Font::Font (unsigned char* pixels, bool big) {
...
@@ -165,6 +165,8 @@ Font::Font (unsigned char* pixels, bool big) {
characters
[
count
]
=
createSurface
(
chrPixels
,
8
,
lineHeight
);
characters
[
count
]
=
createSurface
(
chrPixels
,
8
,
lineHeight
);
if
(
big
)
SDL_SetColorKey
(
characters
[
count
],
SDL_SRCCOLORKEY
,
0
);
}
}
nCharacters
=
40
;
nCharacters
=
40
;
...
...
src/level/bullet.cpp
View file @
105d65c6
...
@@ -268,7 +268,7 @@ Bullet* Bullet::step (unsigned int ticks, int msps) {
...
@@ -268,7 +268,7 @@ Bullet* Bullet::step (unsigned int ticks, int msps) {
set
=
level
->
getBullet
(
type
);
set
=
level
->
getBullet
(
type
);
// If the scenery has been hit and this is not a bouncer, destroy the bullet
// If the scenery has been hit and this is not a bouncer, destroy the bullet
if
(
level
->
checkMask
(
x
,
y
)
&&
(
set
[
B_BEHAVIOUR
]
!=
4
))
{
if
(
level
->
checkMask
Up
(
x
,
y
)
&&
(
set
[
B_BEHAVIOUR
]
!=
4
))
{
level
->
playSound
(
set
[
B_FINISHSOUND
]);
level
->
playSound
(
set
[
B_FINISHSOUND
]);
...
...
src/level/level.cpp
View file @
105d65c6
...
@@ -123,17 +123,21 @@ Level::~Level () {
...
@@ -123,17 +123,21 @@ Level::~Level () {
}
}
bool
Level
::
checkMask
(
fixed
x
,
fixed
y
)
{
bool
Level
::
checkMaskUp
(
fixed
x
,
fixed
y
)
{
GridElement
*
ge
;
// Anything off the edge of the map is solid
// Anything off the edge of the map is solid
if
((
x
<
0
)
||
(
y
<
0
)
||
(
x
>
TTOF
(
LW
))
||
(
y
>
TTOF
(
LH
)))
if
((
x
<
0
)
||
(
y
<
0
)
||
(
x
>
TTOF
(
LW
))
||
(
y
>
TTOF
(
LH
)))
return
true
;
return
true
;
ge
=
grid
[
FTOT
(
y
)]
+
FTOT
(
x
);
// Event 122 is one-way
// Event 122 is one-way
if
(
g
rid
[
FTOT
(
y
)][
FTOT
(
x
)].
event
==
122
)
return
false
;
if
(
g
e
->
event
==
122
)
return
false
;
// Check the mask in the tile in question
// Check the mask in the tile in question
return
mask
[
g
rid
[
FTOT
(
y
)][
FTOT
(
x
)].
tile
][((
y
>>
9
)
&
56
)
+
((
x
>>
12
)
&
7
)];
return
mask
[
g
e
->
tile
][((
y
>>
9
)
&
56
)
+
((
x
>>
12
)
&
7
)];
}
}
...
@@ -152,15 +156,19 @@ bool Level::checkMaskDown (fixed x, fixed y) {
...
@@ -152,15 +156,19 @@ bool Level::checkMaskDown (fixed x, fixed y) {
bool
Level
::
checkSpikes
(
fixed
x
,
fixed
y
)
{
bool
Level
::
checkSpikes
(
fixed
x
,
fixed
y
)
{
GridElement
*
ge
;
// Anything off the edge of the map is not spikes
// Anything off the edge of the map is not spikes
// Ignore the bottom, as it is deadly anyway
// Ignore the bottom, as it is deadly anyway
if
((
x
<
0
)
||
(
y
<
0
)
||
(
x
>
TTOF
(
LW
)))
return
false
;
if
((
x
<
0
)
||
(
y
<
0
)
||
(
x
>
TTOF
(
LW
)))
return
false
;
ge
=
grid
[
FTOT
(
y
)]
+
FTOT
(
x
);
// Event 126 is spikes
// Event 126 is spikes
if
(
g
rid
[
FTOT
(
y
)][
FTOT
(
x
)].
event
!=
126
)
return
false
;
if
(
g
e
->
event
!=
126
)
return
false
;
// Check the mask in the tile in question
// Check the mask in the tile in question
return
mask
[
g
rid
[
FTOT
(
y
)][
FTOT
(
x
)].
tile
][((
y
>>
9
)
&
56
)
+
((
x
>>
12
)
&
7
)];
return
mask
[
g
e
->
tile
][((
y
>>
9
)
&
56
)
+
((
x
>>
12
)
&
7
)];
}
}
...
...
src/level/level.h
View file @
105d65c6
...
@@ -68,8 +68,7 @@ typedef struct {
...
@@ -68,8 +68,7 @@ typedef struct {
unsigned
char
bg
;
// 0 = Effect background, 1 = Black background
unsigned
char
bg
;
// 0 = Effect background, 1 = Black background
unsigned
char
event
;
// Indexes the event set
unsigned
char
event
;
// Indexes the event set
unsigned
char
hits
;
// Number of times the event has been shot
unsigned
char
hits
;
// Number of times the event has been shot
int
time
;
/* Point at which the event will do something, e.g.
int
time
;
/* Point at which the event will do something, e.g. terminate */
terminate */
}
GridElement
;
}
GridElement
;
...
@@ -131,7 +130,7 @@ class Level : public BaseLevel {
...
@@ -131,7 +130,7 @@ class Level : public BaseLevel {
Level
(
char
*
fileName
,
unsigned
char
diff
,
bool
checkpoint
);
Level
(
char
*
fileName
,
unsigned
char
diff
,
bool
checkpoint
);
virtual
~
Level
();
virtual
~
Level
();
bool
checkMask
(
fixed
x
,
fixed
y
);
bool
checkMask
Up
(
fixed
x
,
fixed
y
);
bool
checkMaskDown
(
fixed
x
,
fixed
y
);
bool
checkMaskDown
(
fixed
x
,
fixed
y
);
bool
checkSpikes
(
fixed
x
,
fixed
y
);
bool
checkSpikes
(
fixed
x
,
fixed
y
);
void
setNext
(
int
nextLevel
,
int
nextWorld
);
void
setNext
(
int
nextLevel
,
int
nextWorld
);
...
...
src/player/player.h
View file @
105d65c6
...
@@ -162,12 +162,13 @@ enum PlayerReaction {
...
@@ -162,12 +162,13 @@ enum PlayerReaction {
class
Anim
;
class
Anim
;
class
Bird
;
class
Bird
;
class
Bonus
;
class
Player
:
public
Movable
{
class
Player
:
public
Movable
{
private
:
private
:
Bird
*
bird
;
Bird
*
bird
;
char
*
name
;
char
*
name
;
char
anims
[
PANIMS
];
char
anims
[
PANIMS
];
bool
pcontrols
[
PCONTROLS
];
bool
pcontrols
[
PCONTROLS
];
SDL_Color
palette
[
256
];
SDL_Color
palette
[
256
];
...
@@ -206,19 +207,19 @@ class Player : public Movable {
...
@@ -206,19 +207,19 @@ class Player : public Movable {
Player
();
Player
();
~
Player
();
~
Player
();
void
init
(
char
*
playerName
,
unsigned
char
*
cols
,
unsigned
char
newTeam
);
void
init
(
char
*
playerName
,
unsigned
char
*
cols
,
unsigned
char
newTeam
);
void
deinit
();
void
deinit
();
void
setAnims
(
char
*
newAnims
);
void
setAnims
(
char
*
newAnims
);
char
*
getName
();
char
*
getName
();
unsigned
char
*
getCols
();
unsigned
char
*
getCols
();
void
reset
();
void
reset
();
void
setControl
(
int
control
,
bool
state
);
void
setControl
(
int
control
,
bool
state
);
bool
takeEvent
(
unsigned
char
gridX
,
unsigned
char
gridY
,
unsigned
int
ticks
);
bool
takeEvent
(
unsigned
char
gridX
,
unsigned
char
gridY
,
unsigned
int
ticks
);
bool
touchEvent
(
unsigned
char
gridX
,
unsigned
char
gridY
,
unsigned
int
ticks
,
int
msps
);
bool
touchEvent
(
unsigned
char
gridX
,
unsigned
char
gridY
,
unsigned
int
ticks
,
int
msps
);
void
setEvent
(
unsigned
char
gridX
,
unsigned
char
gridY
);
void
setEvent
(
unsigned
char
gridX
,
unsigned
char
gridY
);
void
clearEvent
(
unsigned
char
gridX
,
unsigned
char
gridY
);
void
clearEvent
(
unsigned
char
gridX
,
unsigned
char
gridY
);
bool
hit
(
Player
*
source
,
unsigned
int
ticks
);
bool
hit
(
Player
*
source
,
unsigned
int
ticks
);
void
kill
(
Player
*
source
,
unsigned
int
ticks
);
void
kill
(
Player
*
source
,
unsigned
int
ticks
);
void
addItem
();
void
addItem
();
void
addLife
();
void
addLife
();
void
addScore
(
int
addedScore
);
void
addScore
(
int
addedScore
);
...
@@ -233,13 +234,13 @@ class Player : public Movable {
...
@@ -233,13 +234,13 @@ class Player : public Movable {
void
setSpeed
(
fixed
newDx
,
fixed
newDy
);
void
setSpeed
(
fixed
newDx
,
fixed
newDy
);
bool
getFacing
();
bool
getFacing
();
fixed
getDirection
();
fixed
getDirection
();
Anim
*
getAnim
();
Anim
*
getAnim
();
unsigned
char
getTeam
();
unsigned
char
getTeam
();
void
send
(
unsigned
char
*
data
);
void
send
(
unsigned
char
*
data
);
void
receive
(
unsigned
char
*
buffer
);
void
receive
(
unsigned
char
*
buffer
);
void
control
(
unsigned
int
ticks
,
int
msps
);
void
control
(
unsigned
int
ticks
,
int
msps
);
void
move
(
unsigned
int
ticks
,
int
msps
);
void
move
(
unsigned
int
ticks
,
int
msps
);
void
bonusStep
(
unsigned
int
ticks
,
int
msps
);
void
bonusStep
(
unsigned
int
ticks
,
int
msps
,
Bonus
*
bonus
);
void
view
(
unsigned
int
ticks
,
int
mspf
);
void
view
(
unsigned
int
ticks
,
int
mspf
);
void
draw
(
unsigned
int
ticks
,
int
change
);
void
draw
(
unsigned
int
ticks
,
int
change
);
PlayerReaction
reacted
(
unsigned
int
ticks
);
PlayerReaction
reacted
(
unsigned
int
ticks
);
...
@@ -249,12 +250,12 @@ class Player : public Movable {
...
@@ -249,12 +250,12 @@ class Player : public Movable {
// Variables
// Variables
EXTERN
Player
*
players
;
EXTERN
Player
*
players
;
EXTERN
Player
*
localPlayer
;
EXTERN
Player
*
localPlayer
;
EXTERN
int
nPlayers
;
EXTERN
int
nPlayers
;
// Configuration data
// Configuration data
EXTERN
char
*
characterName
;
EXTERN
char
*
characterName
;
EXTERN
unsigned
char
characterCols
[
4
];
EXTERN
unsigned
char
characterCols
[
4
];
#endif
#endif
...
...
src/player/playerframe.cpp
View file @
105d65c6
...
@@ -28,6 +28,7 @@
...
@@ -28,6 +28,7 @@
#include "bird.h"
#include "bird.h"
#include "player.h"
#include "player.h"
#include "bonus/bonus.h"
#include "game/gamemode.h"
#include "game/gamemode.h"
#include "io/controls.h"
#include "io/controls.h"
#include "io/gfx/font.h"
#include "io/gfx/font.h"
...
@@ -179,7 +180,7 @@ void Player::control (unsigned int ticks, int msps) {
...
@@ -179,7 +180,7 @@ void Player::control (unsigned int ticks, int msps) {
// Prepare to jump upon leaving the water
// Prepare to jump upon leaving the water
if
(
!
level
->
checkMask
(
x
+
PXO_MID
,
y
-
F36
))
{
if
(
!
level
->
checkMask
Up
(
x
+
PXO_MID
,
y
-
F36
))
{
jumpY
=
y
-
jumpHeight
;
jumpY
=
y
-
jumpHeight
;
...
@@ -213,7 +214,7 @@ void Player::control (unsigned int ticks, int msps) {
...
@@ -213,7 +214,7 @@ void Player::control (unsigned int ticks, int msps) {
}
else
{
}
else
{
if
(
platform
&&
pcontrols
[
C_JUMP
]
&&
if
(
platform
&&
pcontrols
[
C_JUMP
]
&&
!
level
->
checkMask
(
x
+
PXO_MID
,
y
-
F36
))
{
!
level
->
checkMask
Up
(
x
+
PXO_MID
,
y
-
F36
))
{
// Jump
// Jump
...
@@ -281,7 +282,7 @@ void Player::control (unsigned int ticks, int msps) {
...
@@ -281,7 +282,7 @@ void Player::control (unsigned int ticks, int msps) {
// If there is an obstacle above and the player is not floating up, stop
// If there is an obstacle above and the player is not floating up, stop
// rising
// rising
if
(
level
->
checkMask
(
x
+
PXO_MID
,
y
+
PYO_TOP
-
F4
)
&&
(
jumpY
<
y
)
&&
(
event
!=
2
))
{
if
(
level
->
checkMask
Up
(
x
+
PXO_MID
,
y
+
PYO_TOP
-
F4
)
&&
(
jumpY
<
y
)
&&
(
event
!=
2
))
{
jumpY
=
TTOF
(
LH
);
jumpY
=
TTOF
(
LH
);
if
(
dy
<
0
)
dy
=
0
;
if
(
dy
<
0
)
dy
=
0
;
...
@@ -452,7 +453,7 @@ void Player::move (unsigned int ticks, int msps) {
...
@@ -452,7 +453,7 @@ void Player::move (unsigned int ticks, int msps) {
while
(
count
>
0
)
{
while
(
count
>
0
)
{
if
(
level
->
checkMask
(
x
+
PXO_MID
,
y
+
PYO_TOP
-
F4
))
{
if
(
level
->
checkMask
Up
(
x
+
PXO_MID
,
y
+
PYO_TOP
-
F4
))
{
y
&=
~
4095
;
y
&=
~
4095
;
dy
=
0
;
dy
=
0
;
...
@@ -468,7 +469,7 @@ void Player::move (unsigned int ticks, int msps) {
...
@@ -468,7 +469,7 @@ void Player::move (unsigned int ticks, int msps) {
pdy
=
(
-
pdy
)
&
4095
;
pdy
=
(
-
pdy
)
&
4095
;
if
(
!
level
->
checkMask
(
x
+
PXO_MID
,
y
+
PYO_TOP
-
pdy
))
if
(
!
level
->
checkMask
Up
(
x
+
PXO_MID
,
y
+
PYO_TOP
-
pdy
))
y
-=
pdy
;
y
-=
pdy
;
else
{
else
{
...
@@ -529,7 +530,7 @@ void Player::move (unsigned int ticks, int msps) {
...
@@ -529,7 +530,7 @@ void Player::move (unsigned int ticks, int msps) {
while
(
count
>
0
)
{
while
(
count
>
0
)
{
// If there is an obstacle, stop
// If there is an obstacle, stop
if
(
level
->
checkMask
(
x
+
PXO_L
-
F4
,
y
+
PYO_MID
))
{
if
(
level
->
checkMask
Up
(
x
+
PXO_L
-
F4
,
y
+
PYO_MID
))
{
x
&=
~
4095
;
x
&=
~
4095
;
...
@@ -541,19 +542,19 @@ void Player::move (unsigned int ticks, int msps) {
...
@@ -541,19 +542,19 @@ void Player::move (unsigned int ticks, int msps) {
count
--
;
count
--
;
// If on an uphill slope, push the player upwards
// If on an uphill slope, push the player upwards
if
(
level
->
checkMask
(
x
+
PXO_ML
,
y
)
&&
if
(
level
->
checkMask
Up
(
x
+
PXO_ML
,
y
)
&&
!
level
->
checkMask
(
x
+
PXO_ML
,
y
-
F4
))
y
-=
F4
;
!
level
->
checkMask
Up
(
x
+
PXO_ML
,
y
-
F4
))
y
-=
F4
;
}
}
pdx
=
(
-
pdx
)
&
4095
;
pdx
=
(
-
pdx
)
&
4095
;
if
(
!
level
->
checkMask
(
x
+
PXO_L
-
pdx
,
y
+
PYO_MID
))
x
-=
pdx
;
if
(
!
level
->
checkMask
Up
(
x
+
PXO_L
-
pdx
,
y
+
PYO_MID
))
x
-=
pdx
;
else
x
&=
~
4095
;
else
x
&=
~
4095
;
// If on an uphill slope, push the player upwards
// If on an uphill slope, push the player upwards
while
(
level
->
checkMask
(
x
+
PXO_ML
,
y
)
&&
while
(
level
->
checkMask
Up
(
x
+
PXO_ML
,
y
)
&&
!
level
->
checkMask
(
x
+
PXO_ML
,
y
-
F4
))
y
-=
F1
;
!
level
->
checkMask
Up
(
x
+
PXO_ML
,
y
-
F4
))
y
-=
F1
;
}
else
if
(
pdx
>
0
)
{
}
else
if
(
pdx
>
0
)
{
...
@@ -564,7 +565,7 @@ void Player::move (unsigned int ticks, int msps) {
...
@@ -564,7 +565,7 @@ void Player::move (unsigned int ticks, int msps) {
while
(
count
>
0
)
{
while
(
count
>
0
)
{
// If there is an obstacle, stop
// If there is an obstacle, stop
if
(
level
->
checkMask
(
x
+
PXO_R
+
F4
,
y
+
PYO_MID
))
{
if
(
level
->
checkMask
Up
(
x
+
PXO_R
+
F4
,
y
+
PYO_MID
))
{
x
|=
4095
;
x
|=
4095
;
...
@@ -576,25 +577,25 @@ void Player::move (unsigned int ticks, int msps) {
...
@@ -576,25 +577,25 @@ void Player::move (unsigned int ticks, int msps) {
count
--
;
count
--
;
// If on an uphill slope, push the player upwards
// If on an uphill slope, push the player upwards
if
(
level
->
checkMask
(
x
+
PXO_MR
,
y
)
&&
if
(
level
->
checkMask
Up
(
x
+
PXO_MR
,
y
)
&&
!
level
->
checkMask
(
x
+
PXO_MR
,
y
-
F4
))
y
-=
F4
;
!
level
->
checkMask
Up
(
x
+
PXO_MR
,
y
-
F4
))
y
-=
F4
;
}
}
pdx
&=
4095
;
pdx
&=
4095
;
if
(
!
level
->
checkMask
(
x
+
PXO_R
+
pdx
,
y
+
PYO_MID
))
x
+=
pdx
;
if
(
!
level
->
checkMask
Up
(
x
+
PXO_R
+
pdx
,
y
+
PYO_MID
))
x
+=
pdx
;
else
x
|=
4095
;
else
x
|=
4095
;
// If on an uphill slope, push the player upwards
// If on an uphill slope, push the player upwards
while
(
level
->
checkMask
(
x
+
PXO_MR
,
y
)
&&
while
(
level
->
checkMask
Up
(
x
+
PXO_MR
,
y
)
&&
!
level
->
checkMask
(
x
+
PXO_MR
,
y
-
F4
))
y
-=
F1
;
!
level
->
checkMask
Up
(
x
+
PXO_MR
,
y
-
F4
))
y
-=
F1
;
}
}
// If using a float up event and have hit a ceiling, ignore event
// If using a float up event and have hit a ceiling, ignore event
if
((
event
==
2
)
&&
level
->
checkMask
(
x
+
PXO_MID
,
y
+
PYO_TOP
-
F4
))
{
if
((
event
==
2
)
&&
level
->
checkMask
Up
(
x
+
PXO_MID
,
y
+
PYO_TOP
-
F4
))
{
jumpY
=
TTOF
(
LH
);
jumpY
=
TTOF
(
LH
);
event
=
0
;
event
=
0
;
...
@@ -621,7 +622,9 @@ void Player::move (unsigned int ticks, int msps) {
...
@@ -621,7 +622,9 @@ void Player::move (unsigned int ticks, int msps) {
}
}
void
Player
::
bonusStep
(
unsigned
int
ticks
,
int
msps
)
{
void
Player
::
bonusStep
(
unsigned
int
ticks
,
int
msps
,
Bonus
*
bonus
)
{
fixed
cdx
,
cdy
;
// Bonus stages use polar coordinates for movement (but not position)
// Bonus stages use polar coordinates for movement (but not position)
// Treat dx as change in radius
// Treat dx as change in radius
...
@@ -664,14 +667,17 @@ void Player::bonusStep (unsigned int ticks, int msps) {
...
@@ -664,14 +667,17 @@ void Player::bonusStep (unsigned int ticks, int msps) {
}
}
if
(
pcontrols
[
C_LEFT
])
direction
-=
msps
>>
1
;
if
(
pcontrols
[
C_LEFT
])
direction
-=
msps
>>
2
;
if
(
pcontrols
[
C_RIGHT
])
direction
+=
msps
>>
1
;
if
(
pcontrols
[
C_RIGHT
])
direction
+=
msps
>>
2
;
// Apply trajectory
// Apply trajectory
x
+=
fixed
(
sin
(
direction
*
6.283185
/
1024.0
)
*
dx
*
msps
)
>>
10
;
cdx
=
fixed
(
sin
(
direction
*
6.283185
f
/
1024.0
f
)
*
dx
*
msps
)
>>
10
;
y
-=
fixed
(
cos
(
direction
*
6.283185
/
1024.0
)
*
dx
*
msps
)
>>
10
;
cdy
=
fixed
(
-
cos
(
direction
*
6.283185
f
/
1024.0
f
)
*
dx
*
msps
)
>>
10
;
if
(
!
bonus
->
checkMask
(
x
+
cdx
,
y
))
x
+=
cdx
;
if
(
!
bonus
->
checkMask
(
x
,
y
+
cdy
))
y
+=
cdy
;
return
;
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