-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnake.cpp
More file actions
85 lines (78 loc) · 2.55 KB
/
Copy pathsnake.cpp
File metadata and controls
85 lines (78 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include<raylib.h>
int main(){
const int screen_width=1000;
const int screen_height=1000;
const int rectW=60;
const int rectH=60;
const int rows=(screen_height/60);
const int cols=(screen_width/60);
const int gridSize=60;
int objectCol=0;
int objectRow=60;
InitWindow(screen_width,screen_height,"SABIN");
int maze[rows][cols]={
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,1,1,1,0,1},
{1,0,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,0,1},
{1,1,1,1,0,1,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,1,1,1,0,1,0,1},
{1,0,0,1,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,1},
{1,0,1,1,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,0,1},
{1,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,1},
{1,1,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,1,0,1},
{1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,1},
{1,0,1,0,1,1,1,0,1,0,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,0,0,1},
//{1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,1},
{1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,0,1,0,1,1,1,0,1,0,1,1,0,1},
{1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,1},
{1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,1},
{1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,0,1},
{1,0,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1}
};
SetTargetFPS(60);
while(!WindowShouldClose()){
static int newRow=1;
static int newCol=0;
if(IsKeyPressed(KEY_RIGHT)){
if(maze[newRow][newCol+1]==0){
newCol++;
objectCol+=1*gridSize;
}
}
if(IsKeyPressed(KEY_LEFT)){
if(maze[newRow][newCol-1]==0){
newCol--;
objectCol-=1*gridSize;
}
}
if(IsKeyPressed(KEY_DOWN)){
if(maze[newRow+1][newCol]==0){
newRow++;
objectRow+=1*gridSize;
}
}
if(IsKeyPressed(KEY_UP)){
if(maze[newRow-1][newCol]==0){
newRow--;
objectRow-=1*gridSize;
}
}
if(objectCol>screen_width-rectW)
objectCol=screen_width-rectW;
if(objectRow>screen_height-rectH)
objectRow=screen_height-rectH;
BeginDrawing();
ClearBackground(BLACK);
DrawRectangle(objectCol,objectRow,rectW,rectH,YELLOW);
for(int row=0; row<rows;row++){
for(int col=0;col<cols;col++){
if(maze[row][col]==1){
DrawRectangle(col*gridSize,row*gridSize,gridSize,gridSize,GRAY);
}
}
}
DrawRectangle((cols-1)*gridSize,(rows-2)*gridSize,gridSize,gridSize,GREEN);
EndDrawing();
}
CloseWindow();
}