Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

We need a pristine table or diagram. Please deliver a perfect solution quickly. CH 1 0 ! : # # # #include #WIDTH 6

We need a pristine table or diagram. Please deliver a perfect solution quickly.
CH10
"!:
#
#
#
#include
#WIDTH 640
#480
#BLOCK_SIZE 16
#SNAKE_LENGTH 5
typedef {
int x;
int y;
}2;
typedef {
2
2
SDL_Window *
SDL_Renderer *renderer
SDL_Event
bool isRunning = true;
bool isGameOver =
[SNAKE_LENGTH]
2
void Init()
()
()
void ()
()
void SpawnFood()
int main(int argc char *argv[]){
SDL_Init(SDL_INIT_VIDEO)
window = SDL_CreateWindow(""Snake"", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WIDTH, HEIGHT, SDL_WINDOW_SHOWN)
renderer = SDL_CreateRenderer(window,-1, SDL_RENDERER_ACCELERATED)
()
(){
(SDL_PollEvent(&event)){
(event.type == SDL_QUIT){
isRunning =
}
}
()
()
()
SDL_Delay(100);
}
SDL_DestroyRenderer(renderer)
SDL_DestroyWindow()
SDL_Quit();
0
}
void Init(){
[0].position.x =/2
[0].position.y = HEIGHT /2
[0].velocity.x = BLOCK_SIZE
[0].velocity.y =0
(int i =1 i < SNAKE_LENGTH++i){
snake[i].position.x =[i -1].position.x - BLOCK_SIZE
snake[i].position.y =[i -1].position.y;
[i].velocity.x =[i -1].velocity.x;
[i].velocity.y =[i -1].velocity.y
}
()
}
(){
(isGameOver){
}
(int i = SNAKE_LENGTH -1; i >0; --i){
snake[i].position.x =[i -1].position.x;
snake[i].position.y =[i -1].position.y;
}
snake[0].position.x += snake[0].velocity.x;
[0].position.y +=[0].velocity.y
()
}
(){
SDL_SetRenderDrawColor(000255)
SDL_RenderClear(renderer)
SDL_SetRenderDrawColor(renderer,255,255,255,255);
(int i =0 i < SNAKE_LENGTH++i){
SDL_Rect rect ={snake[i].position.x, snake[i].position.y, BLOCK_SIZE, BLOCK_SIZE};
SDL_RenderFillRect(renderer, &rect);
}
SDL_Rect foodRect ={food.x, food.y, BLOCK_SIZE, BLOCK_SIZE};
SDL_RenderFillRect(renderer, &foodRect);
SDL_RenderPresent(renderer)
}
void HandleInput(){
(event.type == SDL_KEYDOWN){
(event.key.keysym.sym){
SDLK_UP:
(snake[0].velocity.y ==0){
[0].velocity.x =0
[0].velocity.y =-BLOCK_SIZE
}
SDLK_DOWN:
(snake[0].velocity.y ==0){
[0].velocity.x =0
[0].velocity.y = BLOCK_SIZE
}
SDLK_LEFT:
(snake[0].velocity.x ==0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions

Question

What background experience do you have?

Answered: 1 week ago

Question

DO CONTRACT WORKERSGETTHE SAME ENTITLEMENTS AS EMPLOYEES?

Answered: 1 week ago

Question

2.5 Describe the purpose of employment equity programs.

Answered: 1 week ago