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
69fbf0f9
Commit
69fbf0f9
authored
Nov 01, 2020
by
Yoann Bordin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Line removing implementation
parent
24e6e5ff
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
15 deletions
+48
-15
tetris-main.c
tetris-main.c
+10
-4
tetris-main.exe
tetris-main.exe
+0
-0
tetris-struct.c
tetris-struct.c
+31
-7
tetris-struct.h
tetris-struct.h
+7
-4
No files found.
tetris-main.c
View file @
69fbf0f9
...
@@ -36,17 +36,23 @@ int main(void){
...
@@ -36,17 +36,23 @@ int main(void){
isFixed
=
false
;
isFixed
=
false
;
}
}
// Déplacer pièce toutes les 2s
// Déplacements saisis au clavier
if
(
frameCounter
%
10
==
0
){
if
(
IsKeyPressed
(
KEY_LEFT
))
movePieceHztl
(
p
,
-
1
);
if
(
IsKeyPressed
(
KEY_RIGHT
))
movePieceHztl
(
p
,
1
);
if
(
IsKeyPressed
(
KEY_A
))
rotatePiece
(
p
,
false
);
if
(
IsKeyPressed
(
KEY_Z
))
rotatePiece
(
p
,
true
);
// Déplacer pièce toutes les 1s
if
(
frameCounter
%
20
==
0
){
if
(
canMove
(
p
,
grid
)){
if
(
canMove
(
p
,
grid
)){
movePieceVert
(
p
,
1
);
movePieceVert
(
p
,
1
);
}
}
else
{
else
{
addPieceToGrid
(
p
,
grid
);
addPieceToGrid
(
p
,
grid
);
isFixed
=
true
;
isFixed
=
true
;
}
removeLinesIfCompleted
(
grid
);
}
}
}
drawPiece
(
p
);
drawPiece
(
p
);
...
...
tetris-main.exe
View file @
69fbf0f9
No preview for this file type
tetris-struct.c
View file @
69fbf0f9
...
@@ -108,19 +108,16 @@ void rotateSquare(Square sq, Square ref, bool rotation){
...
@@ -108,19 +108,16 @@ void rotateSquare(Square sq, Square ref, bool rotation){
int
posY
=
sq
->
posY
;
int
posY
=
sq
->
posY
;
if
(
rotation
){
if
(
rotation
){
sq
->
posX
=
refX
-
posY
;
sq
->
posX
=
refX
-
posY
+
refY
;
sq
->
posY
=
refY
+
posX
;
sq
->
posY
=
refY
+
posX
-
refX
;
}
}
else
{
else
{
sq
->
posX
=
refX
+
posY
;
sq
->
posX
=
refX
+
posY
-
refY
;
sq
->
posY
=
refY
-
posX
;
sq
->
posY
=
refY
-
posX
+
refX
;
}
}
}
}
void
rotatePiece
(
Piece
p
,
bool
rotation
){
void
rotatePiece
(
Piece
p
,
bool
rotation
){
//const int width = GRID_WIDTH;
//const int height = GRID_HEIGHT;
for
(
int
i
=
0
;
i
<
p
.
size
;
i
++
){
for
(
int
i
=
0
;
i
<
p
.
size
;
i
++
){
if
(
i
!=
1
){
if
(
i
!=
1
){
rotateSquare
(
p
.
squares
[
i
],
p
.
squares
[
1
],
rotation
);
rotateSquare
(
p
.
squares
[
i
],
p
.
squares
[
1
],
rotation
);
...
@@ -291,3 +288,30 @@ void movePieceHztl(Piece p, int shift){
...
@@ -291,3 +288,30 @@ void movePieceHztl(Piece p, int shift){
moveSquareHztl
(
p
.
squares
[
i
],
shift
);
moveSquareHztl
(
p
.
squares
[
i
],
shift
);
}
}
}
}
void
removeLine
(
Grid
g
,
int
lineIndex
){
int
i
=
lineIndex
;
while
(
i
>
0
){
i
--
;
for
(
int
j
=
0
;
j
<
g
.
width
;
j
++
){
g
.
grid
[
j
][
i
+
1
]
=
g
.
grid
[
j
][
i
];
}
for
(
int
k
=
0
;
k
<
g
.
width
;
k
++
){
g
.
grid
[
k
][
0
]
=
NULL
;
}
}
}
void
removeLinesIfCompleted
(
Grid
grid
){
for
(
int
k
=
0
;
k
<
grid
.
height
;
k
++
){
int
j
=
0
;
while
(
j
<
grid
.
width
&&
grid
.
grid
[
j
][
k
]
!=
NULL
){
j
++
;
}
if
(
j
==
grid
.
width
){
removeLine
(
grid
,
k
);
}
}
}
\ No newline at end of file
tetris-struct.h
View file @
69fbf0f9
...
@@ -5,9 +5,9 @@
...
@@ -5,9 +5,9 @@
#include "raylib.h"
#include "raylib.h"
#define PIECE_SIZE 4
;
#define PIECE_SIZE 4
#define GRID_WIDTH 10
;
#define GRID_WIDTH 10
#define GRID_HEIGHT 20
;
#define GRID_HEIGHT 20
typedef
struct
square_s
{
typedef
struct
square_s
{
int
posX
;
int
posX
;
...
@@ -63,3 +63,6 @@ void moveSquareVert(Square sq, int shift);
...
@@ -63,3 +63,6 @@ void moveSquareVert(Square sq, int shift);
void
movePieceVert
(
Piece
piece
,
int
shift
);
void
movePieceVert
(
Piece
piece
,
int
shift
);
void
moveSquareHztl
(
Square
sq
,
int
shift
);
void
moveSquareHztl
(
Square
sq
,
int
shift
);
void
movePieceHztl
(
Piece
p
,
int
shift
);
void
movePieceHztl
(
Piece
p
,
int
shift
);
void
removeLine
(
Grid
g
,
int
lineIndex
);
void
removeLinesIfCompleted
(
Grid
grid
);
\ No newline at end of file
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