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
4886f8fb
Commit
4886f8fb
authored
2 years ago
by
Taha Belkhiri
Browse files
Options
Downloads
Patches
Plain Diff
la bonne version
parent
6aa942db
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
travail_de_groupe/jeu_appren_par_renfo/src/player.c
+18
-38
18 additions, 38 deletions
travail_de_groupe/jeu_appren_par_renfo/src/player.c
with
18 additions
and
38 deletions
travail_de_groupe/jeu_appren_par_renfo/src/player.c
+
18
−
38
View file @
4886f8fb
...
@@ -5,7 +5,6 @@ player_t ennemy;
...
@@ -5,7 +5,6 @@ player_t ennemy;
int
*
landingPoint
;
int
*
landingPoint
;
int
*
lastHitPoint
;
int
*
lastHitPoint
;
int
landingPointIsFind
=
0
;
void
initPlayer
()
void
initPlayer
()
{
{
...
@@ -30,22 +29,15 @@ void initPlayer()
...
@@ -30,22 +29,15 @@ void initPlayer()
player
.
viewAngle
=
0
;
player
.
viewAngle
=
0
;
}
}
int
*
generateLandingPoint
(
int
rxWall
)
int
*
generateLandingPoint
()
{
{
int
*
landingPoint
=
malloc
(
sizeof
(
int
)
*
2
);
int
*
landingPoint
=
malloc
(
sizeof
(
int
)
*
2
);
srand
(
time
(
NULL
));
int
randomLength
=
rand
()
%
(
int
)((
MAP_WIDTH
/
2
)
*
BLOCK_SIZE
)
+
(
MAP_WIDTH
/
2
)
*
BLOCK_SIZE
;
//printf("wall x :%d=>%d\n", rxWall, rxWall/BLOCK_SIZE);
int
randomPointX
=
randomLength
*
cos
(
player
.
angle
)
+
player
.
x
;
int
randomPointY
=
randomLength
*
sin
(
player
.
angle
)
+
player
.
y
;
int
randomPointX
=
MAP_WIDTH
/
2
+
1
+
rand
()
%
(
rxWall
/
BLOCK_SIZE
-
(
MAP_WIDTH
/
2
));
landingPoint
[
0
]
=
randomPointX
/
BLOCK_SIZE
;
int
randomPointY
=
-
1
;
//printf("entre %d et %d\n", MAP_WIDTH/2, MAP_WIDTH/2+rxWall/BLOCK_SIZE - (MAP_WIDTH/2));
//printf("randomPointX: %d => %d\n", randomPointX, randomPointX*BLOCK_SIZE);
landingPoint
[
0
]
=
randomPointX
;
landingPoint
[
1
]
=
randomPointY
/
BLOCK_SIZE
;
landingPoint
[
1
]
=
randomPointY
/
BLOCK_SIZE
;
landingPointIsFind
=
1
;
// printf("landing point: %d %d\n", landingPoint[0], landingPoint[1]);
return
landingPoint
;
return
landingPoint
;
}
}
...
@@ -67,8 +59,6 @@ void freeIntList(int *list)
...
@@ -67,8 +59,6 @@ void freeIntList(int *list)
void
hitBall
()
void
hitBall
()
{
{
<<<<<<<
HEAD
=======
// printf("map edges: %d %d\n", BLOCK_SIZE * MAP_WIDTH/2, BLOCK_SIZE *MAP_HEIGHT/2);
// printf("map edges: %d %d\n", BLOCK_SIZE * MAP_WIDTH/2, BLOCK_SIZE *MAP_HEIGHT/2);
// printf("ray1: %d %d\n", ray1[0], ray1[1]);
// printf("ray1: %d %d\n", ray1[0], ray1[1]);
int
fermetureAngle
=
2
;
int
fermetureAngle
=
2
;
...
@@ -82,7 +72,6 @@ void hitBall()
...
@@ -82,7 +72,6 @@ void hitBall()
//printf("angle min: %d\n", angleMin);
//printf("angle min: %d\n", angleMin);
//printf("angle max: %d\n", angleMax);
//printf("angle max: %d\n", angleMax);
//printf("distance to ball: %f\n", sqrt(pow(ball.x - player.x, 2) + pow(ball.y - player.y, 2))/BLOCK_SIZE);
//printf("distance to ball: %f\n", sqrt(pow(ball.x - player.x, 2) + pow(ball.y - player.y, 2))/BLOCK_SIZE);
>>>>>>>
03
83
eb7e8ec1fcd92d8fd2c6846d5e9ab2d08f17
if
(
sqrt
(
pow
(
player
.
x
-
ball
.
x
,
2
)
+
pow
(
player
.
y
-
ball
.
y
,
2
))
/
BLOCK_SIZE
<
HIT_RANGE
)
if
(
sqrt
(
pow
(
player
.
x
-
ball
.
x
,
2
)
+
pow
(
player
.
y
-
ball
.
y
,
2
))
/
BLOCK_SIZE
<
HIT_RANGE
)
{
{
int
rxWall
,
ryWall
;
int
rxWall
,
ryWall
;
...
@@ -93,47 +82,39 @@ void hitBall()
...
@@ -93,47 +82,39 @@ void hitBall()
if
(
player
.
isHitting
)
if
(
player
.
isHitting
)
{
{
castSingleRay
(
player
.
angle
,
&
distanceWall
,
&
distanceNet
,
&
rxWall
,
&
ryWall
,
&
rxNet
,
&
ryNet
);
castSingleRay
(
player
.
angle
,
&
distanceWall
,
&
distanceNet
,
&
rxWall
,
&
ryWall
,
&
rxNet
,
&
ryNet
);
//printf("rayWall: %d %d\n", rxWall/BLOCK_SIZE, ryWall/BLOCK_SIZE);
printf
(
"rayWall: %d %d
\n
"
,
rxWall
/
BLOCK_SIZE
,
ryWall
/
BLOCK_SIZE
);
//printf("distanceWall: %f\n", distanceWall);
printf
(
"distanceWall: %f
\n
"
,
distanceWall
);
<<<<<<<
HEAD
//printf("rayNet: %d %d\n", rxNet/BLOCK_SIZE, ryNet/BLOCK_SIZE);
//printf("distanceNet: %f\n", distanceNet);
if
(
rxWall
>
MAP_WIDTH
/
2
)
{
if
(
player
.
isHitting
)
=======
printf
(
"rayNet: %d %d
\n
"
,
rxNet
/
BLOCK_SIZE
,
ryNet
/
BLOCK_SIZE
);
printf
(
"rayNet: %d %d
\n
"
,
rxNet
/
BLOCK_SIZE
,
ryNet
/
BLOCK_SIZE
);
printf
(
"distanceNet: %f
\n
"
,
distanceNet
);
printf
(
"distanceNet: %f
\n
"
,
distanceNet
);
// printf("hit\n");
// printf("hit\n");
if
(
rxWall
>
MAP_WIDTH
/
2
)
if
(
rxWall
>
MAP_WIDTH
/
2
)
>>>>>>>
03
83
eb7e8ec1fcd92d8fd2c6846d5e9ab2d08f17
{
{
freeIntList
(
landingPoint
);
freeIntList
(
lastHitPoint
);
freeIntList
(
lastHitPoint
);
lastHitPoint
=
allocLastHitPoint
();
//cherche et trouve point de chute, UNE SEULE FOIS!
if
(
landingPointIsFind
==
0
){
freeIntList
(
landingPoint
);
landingPoint
=
generateLandingPoint
(
rxWall
);
printf
(
"landing point: x=%d; y=%d
\n
"
,
landingPoint
[
0
],
landingPoint
[
1
]);
}
lastHitPoint
=
allocLastHitPoint
();
landingPoint
=
generateLandingPoint
();
lastHitPoint
[
0
]
=
ball
.
x
;
lastHitPoint
[
0
]
=
ball
.
x
;
lastHitPoint
[
1
]
=
player
.
h
;
lastHitPoint
[
1
]
=
player
.
h
;
/*ball.x = player.x;
ball.y = player.y;
ball.z = player.h;*/
ball
.
angle
=
player
.
angle
;
ball
.
angle
=
player
.
angle
;
ball
.
speed
=
2
*
HIT_FORCE
;
ball
.
speed
=
2
*
HIT_FORCE
;
ball
.
z
=
player
.
h
;
ball
.
z
=
player
.
h
;
ball
.
isHit
=
1
;
ball
.
isHit
=
1
;
}
}
// printf("valid hit\n");
}
}
else
else
{
{
// printf("unvalid hit\n");
// printf("unvalid hit\n");
}
}
}
}
//}
}
}
void
updateBall
()
void
updateBall
()
...
@@ -142,7 +123,6 @@ void updateBall()
...
@@ -142,7 +123,6 @@ void updateBall()
ball
.
y
=
ball
.
y
+
ball
.
speed
*
sin
(
ball
.
angle
);
ball
.
y
=
ball
.
y
+
ball
.
speed
*
sin
(
ball
.
angle
);
if
(
ball
.
isHit
)
if
(
ball
.
isHit
)
{
{
// landingPoint est déjà / BLOCK_SIZE de base
// landingPoint est déjà / BLOCK_SIZE de base
ball
.
z
=
lagrangeInterpolation
(
ball
.
x
/
BLOCK_SIZE
,
lastHitPoint
[
0
]
/
BLOCK_SIZE
,
lastHitPoint
[
1
]
/
BLOCK_SIZE
,
15
,
2
*
player
.
h
/
BLOCK_SIZE
,
landingPoint
[
0
],
0
);
ball
.
z
=
lagrangeInterpolation
(
ball
.
x
/
BLOCK_SIZE
,
lastHitPoint
[
0
]
/
BLOCK_SIZE
,
lastHitPoint
[
1
]
/
BLOCK_SIZE
,
15
,
2
*
player
.
h
/
BLOCK_SIZE
,
landingPoint
[
0
],
0
);
if
(
ball
.
z
>
0
)
if
(
ball
.
z
>
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