Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
ProjetZZ1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marc BERET
ProjetZZ1
Commits
858b46e5
Commit
858b46e5
authored
2 years ago
by
belkhiritaha
Browse files
Options
Downloads
Patches
Plain Diff
fixed errors and warnings
parent
51b4df6c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
travail_de_groupe/jeu_appren_par_renfo/src/player.h
+1
-1
1 addition, 1 deletion
travail_de_groupe/jeu_appren_par_renfo/src/player.h
travail_de_groupe/jeu_appren_par_renfo/src/render.c
+6
-37
6 additions, 37 deletions
travail_de_groupe/jeu_appren_par_renfo/src/render.c
with
7 additions
and
38 deletions
travail_de_groupe/jeu_appren_par_renfo/src/player.h
+
1
−
1
View file @
858b46e5
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
#define HIT_RANGE 2
#define HIT_RANGE 2
#define HIT_FORCE 10
#define HIT_FORCE 10
#define MOVEMENT_SPEED
2
0
#define MOVEMENT_SPEED
1
0
typedef
struct
player
typedef
struct
player
{
{
...
...
This diff is collapsed.
Click to expand it.
travail_de_groupe/jeu_appren_par_renfo/src/render.c
+
6
−
37
View file @
858b46e5
...
@@ -508,10 +508,6 @@ void drawEnnemy()
...
@@ -508,10 +508,6 @@ void drawEnnemy()
{
{
float
ennemyAngle
=
atan2
((
ennemy
.
y
+
ennemy
.
w
/
2
)
-
(
player
.
y
+
player
.
w
/
2
),
(
ennemy
.
x
+
ennemy
.
w
/
2
)
-
(
player
.
x
+
player
.
w
/
2
));
float
ennemyAngle
=
atan2
((
ennemy
.
y
+
ennemy
.
w
/
2
)
-
(
player
.
y
+
player
.
w
/
2
),
(
ennemy
.
x
+
ennemy
.
w
/
2
)
-
(
player
.
x
+
player
.
w
/
2
));
float
ennemyDistance
=
sqrt
((
ennemy
.
x
-
player
.
x
)
*
(
ennemy
.
x
-
player
.
x
)
+
(
ennemy
.
y
-
player
.
y
)
*
(
ennemy
.
y
-
player
.
y
))
*
BLOCK_SIZE
;
float
ennemyDistance
=
sqrt
((
ennemy
.
x
-
player
.
x
)
*
(
ennemy
.
x
-
player
.
x
)
+
(
ennemy
.
y
-
player
.
y
)
*
(
ennemy
.
y
-
player
.
y
))
*
BLOCK_SIZE
;
float
ennemyBaseWidth
=
BLOCK_SIZE
;
float
ennemyDistanceX
=
ennemyDistance
*
cos
(
ennemyAngle
-
player
.
angle
)
*
BLOCK_SIZE
;
float
ennemyDistanceY
=
ennemyDistance
*
fabs
(
sin
(
ennemyAngle
-
player
.
angle
))
*
BLOCK_SIZE
;
float
scaledEnnemyWidth
=
ennemyBaseWidth
/
sqrt
(
3
);
int
ennemyWidth
=
50
;
int
ennemyWidth
=
50
;
int
ennemyHeight
=
200
;
int
ennemyHeight
=
200
;
float
angleMin
=
player
.
angle
-
(
FOV_ANGLE
*
DR
)
/
2
;
float
angleMin
=
player
.
angle
-
(
FOV_ANGLE
*
DR
)
/
2
;
...
@@ -571,9 +567,8 @@ void drawEnnemy()
...
@@ -571,9 +567,8 @@ void drawEnnemy()
void
castSingleRay
(
float
angle
,
float
*
distanceWall
,
float
*
distanceNet
,
int
*
returnXWall
,
int
*
returnYWall
,
int
*
returnXNet
,
int
*
returnYNet
)
void
castSingleRay
(
float
angle
,
float
*
distanceWall
,
float
*
distanceNet
,
int
*
returnXWall
,
int
*
returnYWall
,
int
*
returnXNet
,
int
*
returnYNet
)
{
{
// ray casting variables
// ray casting variables
float
htexture
,
htexture2
;
int
mx
,
my
,
dof
;
int
r
,
mx
,
my
,
dof
;
double
rx
,
ry
,
rx2
,
ry2
,
xo
,
yo
,
distT2
;
double
rx
,
ry
,
rx2
,
ry2
,
xo
,
yo
,
distT
,
distT2
;
double
ra
;
double
ra
;
mx
=
0
;
mx
=
0
;
my
=
0
;
my
=
0
;
...
@@ -586,7 +581,7 @@ void castSingleRay(float angle, float *distanceWall, float *distanceNet, int *re
...
@@ -586,7 +581,7 @@ void castSingleRay(float angle, float *distanceWall, float *distanceNet, int *re
// check horizontal rays
// check horizontal rays
int
foundSolidWallH
=
0
;
int
foundSolidWallH
=
0
;
dof
=
0
;
dof
=
0
;
float
disH
=
100000
,
disH2
=
100000
,
hx
=
player
.
x
,
hy
=
player
.
y
,
hx2
=
player
.
x
,
hy2
=
player
.
y
;
float
disH
,
hx
=
player
.
x
,
hy
=
player
.
y
,
hx2
=
player
.
x
,
hy2
=
player
.
y
;
float
aTan
=
-
1
/
tan
(
ra
);
float
aTan
=
-
1
/
tan
(
ra
);
if
(
ra
>
pi
)
if
(
ra
>
pi
)
{
// looking up
{
// looking up
...
@@ -626,7 +621,6 @@ void castSingleRay(float angle, float *distanceWall, float *distanceNet, int *re
...
@@ -626,7 +621,6 @@ void castSingleRay(float angle, float *distanceWall, float *distanceNet, int *re
{
{
hx2
=
rx
;
hx2
=
rx
;
hy2
=
ry
;
hy2
=
ry
;
disH2
=
sqrt
((
rx
-
player
.
x
)
*
(
rx
-
player
.
x
)
+
(
ry
-
player
.
y
)
*
(
ry
-
player
.
y
));
dof
++
;
dof
++
;
rx
+=
xo
;
rx
+=
xo
;
ry
+=
yo
;
ry
+=
yo
;
...
@@ -699,26 +693,18 @@ void castSingleRay(float angle, float *distanceWall, float *distanceNet, int *re
...
@@ -699,26 +693,18 @@ void castSingleRay(float angle, float *distanceWall, float *distanceNet, int *re
}
}
}
}
int
direction
,
direction2
;
if
(
foundTransparentWallV
)
if
(
foundTransparentWallV
)
{
{
if
(
disH
<
disV2
)
if
(
disH
<
disV2
)
{
{
rx
=
hx2
;
rx
=
hx2
;
ry
=
hy2
;
ry
=
hy2
;
distT
=
disH2
;
distT2
=
disV2
;
distT2
=
disV2
;
direction
=
0
;
htexture
=
(
int
)(
rx
)
%
BLOCK_SIZE
;
}
}
else
else
{
{
rx
=
vx2
;
rx
=
vx2
;
ry
=
vy2
;
ry
=
vy2
;
distT
=
disV2
;
direction
=
1
;
htexture
=
(
int
)(
ry
)
%
BLOCK_SIZE
;
}
}
if
(
foundSolidWallV
)
if
(
foundSolidWallV
)
{
{
...
@@ -727,16 +713,12 @@ void castSingleRay(float angle, float *distanceWall, float *distanceNet, int *re
...
@@ -727,16 +713,12 @@ void castSingleRay(float angle, float *distanceWall, float *distanceNet, int *re
rx2
=
hx
;
rx2
=
hx
;
ry2
=
hy
;
ry2
=
hy
;
distT2
=
disH
;
distT2
=
disH
;
direction2
=
0
;
htexture2
=
(
int
)(
rx2
)
%
BLOCK_SIZE
;
}
}
else
else
{
{
rx2
=
vx
;
rx2
=
vx
;
ry2
=
vy
;
ry2
=
vy
;
distT2
=
disV
;
distT2
=
disV
;
direction2
=
1
;
htexture2
=
(
int
)(
ry2
)
%
BLOCK_SIZE
;
}
}
}
}
if
(
foundSolidWallH
)
if
(
foundSolidWallH
)
...
@@ -746,16 +728,12 @@ void castSingleRay(float angle, float *distanceWall, float *distanceNet, int *re
...
@@ -746,16 +728,12 @@ void castSingleRay(float angle, float *distanceWall, float *distanceNet, int *re
rx2
=
hx
;
rx2
=
hx
;
ry2
=
hy
;
ry2
=
hy
;
distT2
=
disH
;
distT2
=
disH
;
direction2
=
0
;
htexture2
=
(
int
)(
rx2
)
%
BLOCK_SIZE
;
}
}
else
else
{
{
rx2
=
vx
;
rx2
=
vx
;
ry2
=
vy
;
ry2
=
vy
;
distT2
=
disV
;
distT2
=
disV
;
direction2
=
1
;
htexture2
=
(
int
)(
ry2
)
%
BLOCK_SIZE
;
}
}
}
}
}
}
...
@@ -765,17 +743,11 @@ void castSingleRay(float angle, float *distanceWall, float *distanceNet, int *re
...
@@ -765,17 +743,11 @@ void castSingleRay(float angle, float *distanceWall, float *distanceNet, int *re
{
{
rx
=
hx
;
rx
=
hx
;
ry
=
hy
;
ry
=
hy
;
distT
=
disH
;
direction
=
0
;
htexture
=
(
int
)(
rx
)
%
BLOCK_SIZE
;
}
}
else
else
{
{
rx
=
vx
;
rx
=
vx
;
ry
=
vy
;
ry
=
vy
;
distT
=
disV
;
direction
=
1
;
htexture
=
(
int
)(
ry
)
%
BLOCK_SIZE
;
}
}
}
}
...
@@ -799,10 +771,7 @@ void drawBall()
...
@@ -799,10 +771,7 @@ void drawBall()
float
ballDistance
=
sqrt
((
ball
.
x
-
player
.
x
)
*
(
ball
.
x
-
player
.
x
)
+
(
ball
.
y
-
player
.
y
)
*
(
ball
.
y
-
player
.
y
))
*
BLOCK_SIZE
;
float
ballDistance
=
sqrt
((
ball
.
x
-
player
.
x
)
*
(
ball
.
x
-
player
.
x
)
+
(
ball
.
y
-
player
.
y
)
*
(
ball
.
y
-
player
.
y
))
*
BLOCK_SIZE
;
float
ballBaseWidth
=
BLOCK_SIZE
/
2
;
float
ballBaseWidth
=
BLOCK_SIZE
/
2
;
float
ballDistanceX
=
ballDistance
*
cos
(
ballAngle
-
player
.
angle
);
float
ballDistanceX
=
ballDistance
*
cos
(
ballAngle
-
player
.
angle
);
float
ballDistanceY
=
ballDistance
*
fabs
(
sin
(
ballAngle
-
player
.
angle
));
float
ballDistanceZ
=
(
ball
.
z
-
player
.
h
);
float
ballViewAngle
=
atan2
(
ball
.
z
*
BLOCK_SIZE
,
ballDistanceX
);
float
ballViewAngle
=
atan2
(
ball
.
z
*
BLOCK_SIZE
,
ballDistanceX
);
float
scaledBallWidth
=
ballBaseWidth
/
sqrt
(
3
);
int
ballWidth
=
25
;
int
ballWidth
=
25
;
int
ballHeight
=
25
;
int
ballHeight
=
25
;
float
angleMin
=
player
.
angle
-
(
FOV_ANGLE
*
DR
)
/
2
;
float
angleMin
=
player
.
angle
-
(
FOV_ANGLE
*
DR
)
/
2
;
...
@@ -825,9 +794,9 @@ void drawBall()
...
@@ -825,9 +794,9 @@ void drawBall()
if
(
ballAngle
>=
angleMin
&&
ballAngle
<=
angleMax
)
if
(
ballAngle
>=
angleMin
&&
ballAngle
<=
angleMax
)
{
{
rect
.
x
=
screenDimension
.
w
/
2
+
(
screenDimension
.
w
*
tan
(
ballAngle
-
player
.
angle
))
*
sqrt
(
3
)
*
0
.
5
;
rect
.
x
=
screenDimension
.
w
/
2
+
(
screenDimension
.
w
*
tan
(
ballAngle
-
player
.
angle
))
*
sqrt
(
3
)
*
0
.
5
;
rect
.
w
=
(
ballWidth
*
screenDimension
.
w
)
/
(
ballDistance
/
BLOCK_SIZE
);
rect
.
w
=
(
ballWidth
*
screenDimension
.
w
)
/
(
2
*
ballDistance
/
BLOCK_SIZE
);
rect
.
h
=
(
ballHeight
*
screenDimension
.
h
)
/
(
ballDistance
/
BLOCK_SIZE
);
rect
.
h
=
(
ballHeight
*
screenDimension
.
h
)
/
(
2
*
ballDistance
/
BLOCK_SIZE
);
rect
.
y
=
(
3
*
screenDimension
.
h
/
4
+
player
.
viewAngle
)
-
1
.
2
*
tan
(
ballViewAngle
)
*
ballDistance
;
rect
.
y
=
(
3
*
screenDimension
.
h
/
4
+
player
.
viewAngle
)
-
2
*
tan
(
ballViewAngle
)
*
ballDistance
;
destRect
.
x
=
32
*
(
SDL_GetTicks
()
/
150
%
4
);
destRect
.
x
=
32
*
(
SDL_GetTicks
()
/
150
%
4
);
destRect
.
y
=
0
;
destRect
.
y
=
0
;
...
...
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