-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphics.cpp
More file actions
178 lines (153 loc) · 10.4 KB
/
graphics.cpp
File metadata and controls
178 lines (153 loc) · 10.4 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// ============================================
// The Graphics file
//
// Copyright 2025 Georgia Tech. All rights reserved.
// The materials provided by the instructor in this course are for
// the use of the students currently enrolled in the course.
// Copyrighted course materials may not be further disseminated.
// This file must NOT be made publicly available anywhere.
//==================================================================
#include "graphics.h"
#include "globals.h"
#define WHITE 0xFFFFFF
#define BLACK 0x000000
#define RED 0xFF0000
#define GREEN 0x00FF00
#define BLUE 0x0000FF
#define LGREY 0xBFBFBF
#define DGREY 0x5F5F5F
#define YELLOW 0xFFFF00
#define BROWN 0xD2691E
#define ORANGE 0xFFA500
#define PURPLE 0xA020F0
#define CYAN 0x00D7FF // Color for boost sprite
#include <stdint.h>
// 2035TODO
// You should create your own sprite, but feel free to use this one while setting up your game!
const char* fruit_img =
"000BG000"
"000B0000"
"0RRRRRR0"
"RRRRRRRR"
"RRRRRRRR"
"RRRRRRRR"
"0RRRRRR0"
"00RRRR00";
// Create a lightning bolt sprite for the boost item
const char* boost_img =
"00CCCC00"
"000CC000"
"00CCCC00"
"0CCCCCC0"
"CCCCCC00"
"0CCCC000"
"00CC0000"
"000C0000";
// New boost sprite 32x32 pixels
#define NEW_PISKEL_FRAME_COUNT 1
#define NEW_PISKEL_FRAME_WIDTH 32
#define NEW_PISKEL_FRAME_HEIGHT 32
/* Piskel data for "New Piskel" */
static const uint32_t boost_sprite_data[1][1024] = {
{
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xff00d7ff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0x00000000, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0xff00d7ff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
}
};
void draw_img(int x, int y, const char* img)
{
// Convert char-based sprite data to int array that BLIT expects
// Each character represents a color
int colors[CELL_SIZE * CELL_SIZE];
for (int i = 0; i < CELL_SIZE * CELL_SIZE; i++) {
char c = img[i];
// Map characters to colors
switch(c) {
case 'R': colors[i] = RED; break;
case 'G': colors[i] = GREEN; break;
case 'B': colors[i] = BLUE; break;
case 'Y': colors[i] = YELLOW; break;
case 'W': colors[i] = WHITE; break;
case 'O': colors[i] = ORANGE; break;
case 'P': colors[i] = PURPLE; break;
case 'C': colors[i] = CYAN; break;
case '0': colors[i] = BLACK; break;
default: colors[i] = BLACK; break;
}
}
// Now pass the int array to BLIT
uLCD.BLIT(x*CELL_SIZE, y*CELL_SIZE, CELL_SIZE, CELL_SIZE, colors);
wait_us(250); // Recovery time!
}
// 2035TODO
void draw_fruit(int x, int y)
{
// 1. call draw_img OR uLCD.BLIT() to draw a custom sprite that you create
// 2. OR implement functionality that draws a CELL_SIZExCELL_SIZE square using the uLCD.filled_rectangle function
// Recall the grid structure of the uLCD screen.
// CELL_SIZE is 8 in the provided code, and the real size of the uLCD screen is 128x128
// filled_rectangle takes x1, y1, x2, y2 that define the bounding points (top left, bottom right) of a filled rectangle IN uLCD COORDINATES
// you must convert the passed in x,y coordinates (which correspond to a 16x16 grid of cells) to uLCD coordinates before drawing the rectangle
draw_img(x, y, fruit_img);
}
// 2035TODO
// the remainder of these functions should be handled the same way as draw_fruit
void draw_poison(int x, int y)
{
uLCD.filled_rectangle(
x * CELL_SIZE,
y * CELL_SIZE,
(x + 1) * CELL_SIZE - 1,
(y + 1) * CELL_SIZE - 1,
PURPLE
);
}
void draw_boost(int x, int y)
{
// Draw the lightning bolt sprite for the boost item
draw_img(x, y, boost_img);
}
void draw_snake_body(int x, int y)
{
uLCD.filled_rectangle(
x * CELL_SIZE,
y * CELL_SIZE,
(x + 1) * CELL_SIZE - 1,
(y + 1) * CELL_SIZE - 1,
GREEN // Snake body color
);
}
void draw_snake_head(int x, int y)
{
uLCD.filled_rectangle(
x * CELL_SIZE,
y * CELL_SIZE,
(x + 1) * CELL_SIZE - 1,
(y + 1) * CELL_SIZE - 1,
BLUE // Snake head color
);
}
void draw_nothing(int x, int y)
{
uLCD.filled_rectangle(
x * CELL_SIZE,
y * CELL_SIZE,
(x + 1) * CELL_SIZE - 1,
(y + 1) * CELL_SIZE - 1,
BLACK // Clear cell with background color
);
}