Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
MLOD Mini Projet
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yoann Bordin
MLOD Mini Projet
Commits
4b057466
Commit
4b057466
authored
Nov 02, 2020
by
Yoann Bordin
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'testing' into dev
parents
cc8a756c
24515210
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
125 additions
and
12 deletions
+125
-12
libraylib.a
lib/libraylib.a
+0
-0
tetris-graph.c
tetris-graph.c
+5
-1
tetris-graph.h
tetris-graph.h
+2
-0
tetris-main.c
tetris-main.c
+30
-3
tetris-struct.c
tetris-struct.c
+80
-4
tetris-struct.h
tetris-struct.h
+7
-3
tetris.data
tetris.data
+1
-1
No files found.
lib/libraylib.a
0 → 100644
View file @
4b057466
File added
tetris-graph.c
View file @
4b057466
...
...
@@ -38,11 +38,15 @@ void drawGrid(Grid g){
if
(
g
.
grid
[
x
][
y
]
!=
NULL
){
drawSquare
(
x
,
y
,
g
.
grid
[
x
][
y
]
->
color
);
}
//drawSquare(g.grid[x][y]);
}
}
}
void
displayScore
(
int
score
){
DrawText
(
"score"
,
400
,
50
,
20
,
RAYWHITE
);
DrawText
(
TextFormat
(
"%4i"
,
score
),
430
,
80
,
20
,
RAYWHITE
);
}
void
gameInstructions
(
Grid
grid
,
Piece
*
pList
){
Piece
piece
=
generePiece
(
pList
);
...
...
tetris-graph.h
View file @
4b057466
...
...
@@ -16,4 +16,6 @@ void drawSquare(int x, int y, Color color);
void
drawPiece
(
Piece
p
);
void
drawGrid
(
Grid
g
);
void
displayScore
(
int
score
);
void
gameInstructions
(
Grid
grid
,
Piece
*
pList
);
\ No newline at end of file
tetris-main.c
View file @
4b057466
...
...
@@ -9,12 +9,15 @@ int main(void){
Piece
p
=
pieceInit
();
bool
isFixed
=
true
;
int
score
=
0
;
int
frameCounter
=
0
;
while
(
!
WindowShouldClose
()
&&
!
gameOver
(
grid
)){
BeginDrawing
();
InitDisplay
();
displayScore
(
score
);
// Testing
char
text1
[
10
];
...
...
@@ -43,8 +46,32 @@ int main(void){
if
(
IsKeyPressed
(
KEY_RIGHT
)
&&
canMoveHztl
(
grid
,
p
,
1
)){
movePieceHztl
(
p
,
1
);
}
if
(
IsKeyPressed
(
KEY_A
))
rotatePiece
(
p
,
false
);
if
(
IsKeyPressed
(
KEY_Z
))
rotatePiece
(
p
,
true
);
if
(
IsKeyPressed
(
KEY_Q
)){
// A en AZERTY
while
(
rotateBorderLeft
(
p
,
false
)){
movePieceHztl
(
p
,
1
);
}
while
(
rotateBorderRight
(
p
,
false
)){
movePieceHztl
(
p
,
-
1
);
}
while
(
rotateCollideGrid
(
grid
,
p
,
false
)){
movePieceVert
(
p
,
-
1
);
}
rotatePiece
(
grid
,
p
,
false
);
}
if
(
IsKeyPressed
(
KEY_W
)){
// Z en AZERTY
while
(
rotateBorderLeft
(
p
,
true
)){
movePieceHztl
(
p
,
1
);
}
while
(
rotateBorderRight
(
p
,
true
)){
movePieceHztl
(
p
,
-
1
);
}
while
(
rotateCollideGrid
(
grid
,
p
,
true
)){
movePieceVert
(
p
,
-
1
);
}
rotatePiece
(
grid
,
p
,
true
);
}
// Déplacer pièce toutes les 1s
if
(
frameCounter
%
20
==
0
){
...
...
@@ -55,7 +82,7 @@ int main(void){
addPieceToGrid
(
p
,
grid
);
isFixed
=
true
;
removeLinesIfCompleted
(
grid
);
score
+=
removeLinesIfCompleted
(
grid
);
}
}
...
...
tetris-struct.c
View file @
4b057466
...
...
@@ -117,14 +117,12 @@ void rotateSquare(Square sq, Square ref, bool rotation){
}
}
void
rotatePiece
(
Piece
p
,
bool
rotation
){
void
rotatePiece
(
Grid
g
,
Piece
p
,
bool
rotation
){
for
(
int
i
=
0
;
i
<
p
.
size
;
i
++
){
if
(
i
!=
1
){
rotateSquare
(
p
.
squares
[
i
],
p
.
squares
[
1
],
rotation
);
}
}
}
void
addPieceToGrid
(
Piece
piece
,
Grid
grid
){
...
...
@@ -301,7 +299,8 @@ void movePieceHztl(Piece p, int shift){
}
}
void
removeLinesIfCompleted
(
Grid
grid
){
int
removeLinesIfCompleted
(
Grid
grid
){
int
nbLinesRemoved
=
0
;
bool
isLineCompleted
;
int
y
=
0
;
...
...
@@ -314,6 +313,7 @@ void removeLinesIfCompleted(Grid grid){
}
if
(
isLineCompleted
){
nbLinesRemoved
++
;
int
lineToRemove
=
y
;
//free
...
...
@@ -336,6 +336,7 @@ void removeLinesIfCompleted(Grid grid){
y
++
;
}
}
return
nbLinesRemoved
;
}
void
displayColumn
(
Square
*
line
,
int
index
,
int
height
){
...
...
@@ -350,4 +351,79 @@ void displayGrid(Grid g){
for
(
int
x
=
0
;
x
<
g
.
width
;
x
++
){
displayColumn
(
g
.
grid
[
x
],
x
,
g
.
height
);
}
}
bool
rotateBorderLeft
(
Piece
p
,
bool
rotation
){
int
refX
=
p
.
squares
[
1
]
->
posX
;
int
refY
=
p
.
squares
[
1
]
->
posY
;
for
(
int
i
=
0
;
i
<
p
.
size
;
i
++
){
int
posX
=
p
.
squares
[
i
]
->
posX
;
int
posY
=
p
.
squares
[
i
]
->
posY
;
int
newPosX
,
newPosY
;
if
(
rotation
){
newPosX
=
refX
-
posY
+
refY
;
newPosY
=
refY
+
posX
-
refX
;
}
else
{
newPosX
=
refX
+
posY
-
refY
;
newPosY
=
refY
-
posX
+
refX
;
}
if
(
newPosX
<
0
){
return
true
;
}
}
return
false
;
}
bool
rotateBorderRight
(
Piece
p
,
bool
rotation
){
int
refX
=
p
.
squares
[
1
]
->
posX
;
int
refY
=
p
.
squares
[
1
]
->
posY
;
for
(
int
i
=
0
;
i
<
p
.
size
;
i
++
){
int
posX
=
p
.
squares
[
i
]
->
posX
;
int
posY
=
p
.
squares
[
i
]
->
posY
;
int
newPosX
,
newPosY
;
if
(
rotation
){
newPosX
=
refX
-
posY
+
refY
;
newPosY
=
refY
+
posX
-
refX
;
}
else
{
newPosX
=
refX
+
posY
-
refY
;
newPosY
=
refY
-
posX
+
refX
;
}
if
(
newPosX
>=
GRID_WIDTH
){
return
true
;
}
}
return
false
;
}
bool
rotateCollideGrid
(
Grid
g
,
Piece
p
,
bool
rotation
){
int
refX
=
p
.
squares
[
1
]
->
posX
;
int
refY
=
p
.
squares
[
1
]
->
posY
;
for
(
int
i
=
0
;
i
<
p
.
size
;
i
++
){
int
posX
=
p
.
squares
[
i
]
->
posX
;
int
posY
=
p
.
squares
[
i
]
->
posY
;
int
newPosX
,
newPosY
;
if
(
rotation
){
newPosX
=
refX
-
posY
+
refY
;
newPosY
=
refY
+
posX
-
refX
;
}
else
{
newPosX
=
refX
+
posY
-
refY
;
newPosY
=
refY
-
posX
+
refX
;
}
if
(
newPosX
<
0
&&
newPosX
>=
GRID_WIDTH
&&
g
.
grid
[
newPosX
][
newPosY
]
!=
NULL
){
return
true
;
}
}
return
false
;
}
\ No newline at end of file
tetris-struct.h
View file @
4b057466
...
...
@@ -44,7 +44,7 @@ bool canMove(Piece piece, Grid grid);
bool
canMoveSquare
(
Square
sq
,
Grid
g
);
void
rotateSquare
(
Square
sq
,
Square
ref
,
bool
rotation
);
void
rotatePiece
(
Piece
p
,
bool
rotation
);
// False makes a counterclockwise rotation and true makes a clockwise rotation
void
rotatePiece
(
Grid
g
,
Piece
p
,
bool
rotation
);
// False makes a counterclockwise rotation and true makes a clockwise rotation
void
addPieceToGrid
(
Piece
piece
,
Grid
grid
);
void
addSquareToGrid
(
Square
sq
,
Grid
g
);
...
...
@@ -66,7 +66,11 @@ bool canMoveHztl(Grid g, Piece p, int moveNum);
void
moveSquareHztl
(
Square
sq
,
int
shift
);
void
movePieceHztl
(
Piece
p
,
int
shift
);
void
removeLinesIfCompleted
(
Grid
grid
);
int
removeLinesIfCompleted
(
Grid
grid
);
void
displayColumn
(
Square
*
line
,
int
index
,
int
height
);
void
displayGrid
(
Grid
g
);
\ No newline at end of file
void
displayGrid
(
Grid
g
);
bool
rotateBorderLeft
(
Piece
p
,
bool
rotation
);
bool
rotateBorderRight
(
Piece
p
,
bool
rotation
);
bool
rotateCollideGrid
(
Grid
g
,
Piece
p
,
bool
rotation
);
\ No newline at end of file
tetris.data
View file @
4b057466
...
...
@@ -5,4 +5,4 @@
(0,0)(1,0)(2,0)(0,1)
(0,0)(1,0)(2,0)(2,1)
(0,0)(1,0)(1,1)(2,1)
(
1,0)(2
,0)(0,1)(1,1)
(
2,0)(1
,0)(0,1)(1,1)
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