Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GCCProg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Claudio Hoffmann
GCCProg
Commits
14fe89b8
Commit
14fe89b8
authored
4 years ago
by
kruegerzo72182
Browse files
Options
Downloads
Patches
Plain Diff
level.cpp comments
parent
8dcd7507
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Level.cpp
+15
-5
15 additions, 5 deletions
Level.cpp
with
15 additions
and
5 deletions
Level.cpp
+
15
−
5
View file @
14fe89b8
...
@@ -112,6 +112,7 @@ void Level::addEnemy(std::unique_ptr<Enemy> enemy_)
...
@@ -112,6 +112,7 @@ void Level::addEnemy(std::unique_ptr<Enemy> enemy_)
enemyVector
.
push_back
(
std
::
move
(
enemy_
));
enemyVector
.
push_back
(
std
::
move
(
enemy_
));
}
}
// primes the trooperSpawner
void
Level
::
fillTrooperSpawner
(
float
posX
,
float
posY
,
unsigned
int
nmbrEnemies
)
void
Level
::
fillTrooperSpawner
(
float
posX
,
float
posY
,
unsigned
int
nmbrEnemies
)
{
{
direction
dir
=
direction
::
LEFT
;
direction
dir
=
direction
::
LEFT
;
...
@@ -139,6 +140,7 @@ void Level::addPlayerProjectile(const PlayerProjectile& projectile)
...
@@ -139,6 +140,7 @@ void Level::addPlayerProjectile(const PlayerProjectile& projectile)
// weberma73121> ----------------------------------------------------------------------
// weberma73121> ----------------------------------------------------------------------
// <kruegerzo72182 ----------------------------------------------------------------------
// <kruegerzo72182 ----------------------------------------------------------------------
// pops the last trooper from the trooperSpawner and reduces the vector capacity
std
::
unique_ptr
<
Enemy
>
Level
::
getTrooperSpawn
()
std
::
unique_ptr
<
Enemy
>
Level
::
getTrooperSpawn
()
{
{
if
(
trooperSpawner
.
back
()
!=
0
){
if
(
trooperSpawner
.
back
()
!=
0
){
...
@@ -160,6 +162,7 @@ void Level::enemyVector_PushBack(std::unique_ptr<Enemy> enemy_)
...
@@ -160,6 +162,7 @@ void Level::enemyVector_PushBack(std::unique_ptr<Enemy> enemy_)
this
->
enemyVector
.
push_back
(
std
::
move
(
enemy_
));
this
->
enemyVector
.
push_back
(
std
::
move
(
enemy_
));
}
}
// do all the Steps for movement and animations
bool
Level
::
doDoSteps
(
FloatSeconds
const
&
frame_time
)
bool
Level
::
doDoSteps
(
FloatSeconds
const
&
frame_time
)
{
{
player
.
step
(
player
.
getTopLeft
(),
frame_time
,
*
this
);
player
.
step
(
player
.
getTopLeft
(),
frame_time
,
*
this
);
...
@@ -191,6 +194,7 @@ bool Level::doDoSteps(FloatSeconds const &frame_time)
...
@@ -191,6 +194,7 @@ bool Level::doDoSteps(FloatSeconds const &frame_time)
for
(
auto
it
=
sceneryVector
.
begin
();
it
!=
sceneryVector
.
end
();)
{
for
(
auto
it
=
sceneryVector
.
begin
();
it
!=
sceneryVector
.
end
();)
{
auto
&
i
=
*
it
;
auto
&
i
=
*
it
;
if
(
!
i
.
step
(
player
.
getTopLeft
(),
frame_time
,
*
this
))
{
if
(
!
i
.
step
(
player
.
getTopLeft
(),
frame_time
,
*
this
))
{
// call the step method from the Entity class to see if the object was hit
it
=
sceneryVector
.
erase
(
it
);
it
=
sceneryVector
.
erase
(
it
);
}
else
{
}
else
{
it
++
;
it
++
;
...
@@ -200,6 +204,7 @@ bool Level::doDoSteps(FloatSeconds const &frame_time)
...
@@ -200,6 +204,7 @@ bool Level::doDoSteps(FloatSeconds const &frame_time)
for
(
auto
it
=
wallVector
.
begin
();
it
!=
wallVector
.
end
();)
{
for
(
auto
it
=
wallVector
.
begin
();
it
!=
wallVector
.
end
();)
{
auto
&
i
=
*
it
;
auto
&
i
=
*
it
;
if
(
!
i
.
step
(
player
.
getTopLeft
(),
frame_time
,
*
this
))
{
if
(
!
i
.
step
(
player
.
getTopLeft
(),
frame_time
,
*
this
))
{
// call the step method from the Entity class to see if the object was hit
it
=
wallVector
.
erase
(
it
);
it
=
wallVector
.
erase
(
it
);
}
else
{
}
else
{
it
++
;
it
++
;
...
@@ -208,6 +213,7 @@ bool Level::doDoSteps(FloatSeconds const &frame_time)
...
@@ -208,6 +213,7 @@ bool Level::doDoSteps(FloatSeconds const &frame_time)
return
true
;
return
true
;
}
}
// checks if the two given buffers are overlaping
bool
Level
::
collHelper
(
Position
const
&
vecPos
,
PixelBuffer
const
&
vecBuf
,
float
buffPosX
,
float
buffPosY
,
int
buffWidth
,
int
buffHeigth
)
bool
Level
::
collHelper
(
Position
const
&
vecPos
,
PixelBuffer
const
&
vecBuf
,
float
buffPosX
,
float
buffPosY
,
int
buffWidth
,
int
buffHeigth
)
{
{
for
(
int
x
=
static_cast
<
int
>
(
vecPos
.
X
);
x
<=
static_cast
<
int
>
(
vecPos
.
X
)
+
vecBuf
.
w
();
++
x
){
for
(
int
x
=
static_cast
<
int
>
(
vecPos
.
X
);
x
<=
static_cast
<
int
>
(
vecPos
.
X
)
+
vecBuf
.
w
();
++
x
){
...
@@ -220,6 +226,7 @@ bool Level::collHelper(Position const& vecPos, PixelBuffer const& vecBuf, float
...
@@ -220,6 +226,7 @@ bool Level::collHelper(Position const& vecPos, PixelBuffer const& vecBuf, float
return
false
;
return
false
;
}
}
// iterates through the border, walls and the scenery and checks for collisions
bool
Level
::
checkCollision
(
float
posX
,
float
posY
,
int
bufferWidth
,
int
bufferHeigth
)
bool
Level
::
checkCollision
(
float
posX
,
float
posY
,
int
bufferWidth
,
int
bufferHeigth
)
{
{
for
(
auto
i
=
this
->
wallVector
.
begin
();
i
!=
this
->
wallVector
.
end
();
i
++
){
for
(
auto
i
=
this
->
wallVector
.
begin
();
i
!=
this
->
wallVector
.
end
();
i
++
){
...
@@ -246,6 +253,11 @@ bool Level::HitEnemy(float posX, float posY, int bufferWidth, int bufferHeigth)
...
@@ -246,6 +253,11 @@ bool Level::HitEnemy(float posX, float posY, int bufferWidth, int bufferHeigth)
}
}
return
false
;
return
false
;
}
}
int
Level
::
getScore
()
const
{
return
score
;
}
// hauerch71498> ----------------------------------------------------------------------
// hauerch71498> ----------------------------------------------------------------------
// <weberma73121 ----------------------------------------------------------------------
// <weberma73121 ----------------------------------------------------------------------
...
@@ -268,6 +280,8 @@ bool Level::HitPlayer(float posX, float posY, int bufferWidth, int bufferHeigth)
...
@@ -268,6 +280,8 @@ bool Level::HitPlayer(float posX, float posY, int bufferWidth, int bufferHeigth)
// weberma73121> ----------------------------------------------------------------------
// weberma73121> ----------------------------------------------------------------------
// <kruegerzo72182 ----------------------------------------------------------------------
// <kruegerzo72182 ----------------------------------------------------------------------
// remove scenery and wall objects from their corresponding vectors if theay are hit
// vector.erase() happens in doDoSteps() do to animation by Claudio
bool
Level
::
HitObstacle
(
float
posX
,
float
posY
,
Color
hitColor
,
int
bufferWidth
,
int
bufferHeigth
)
bool
Level
::
HitObstacle
(
float
posX
,
float
posY
,
Color
hitColor
,
int
bufferWidth
,
int
bufferHeigth
)
{
{
for
(
auto
&
i
:
wallVector
){
for
(
auto
&
i
:
wallVector
){
...
@@ -287,11 +301,7 @@ bool Level::HitObstacle(float posX, float posY, Color hitColor, int bufferWidth,
...
@@ -287,11 +301,7 @@ bool Level::HitObstacle(float posX, float posY, Color hitColor, int bufferWidth,
return
false
;
return
false
;
}
}
int
Level
::
getScore
()
const
// blit all objects, enemies and the player stored in the level class to the levelBuffer
{
return
score
;
}
DynamicPixelBuffer
const
&
Level
::
draw
()
DynamicPixelBuffer
const
&
Level
::
draw
()
{
{
this
->
levelBuffer
.
clear
(
_t
);
this
->
levelBuffer
.
clear
(
_t
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment