Adding Main files

This commit is contained in:
DarthMooMancer
2025-05-08 10:24:34 -04:00
parent 7bd4f2b0ff
commit 636ebae6a3
5 changed files with 99 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
build/
+14
View File
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.10)
project(snake)
include_directories(include)
set(SOURCES
src/main.cpp
src/snake.cpp
)
add_executable(snake ${SOURCES})
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_C_STANDARD 23)
set(CMAKE_C_STANDARD_REQUIRED ON)
# find_package(SDL3 CONFIG REQUIRED) # An example of how to import libraries from vcpkg
# target_link_libraries(Game PRIVATE SDL3::SDL3)
+7
View File
@@ -0,0 +1,7 @@
#ifndef SNAKE_HPP
#define SNAKE_HPP
void create_snake();
void draw_snake();
#endif
+60
View File
@@ -0,0 +1,60 @@
#include <iostream>
#include <termios.h>
#include <unistd.h>
#include "snake.hpp"
const int ROW = 10;
const int COL = 10;
char getch();
void create_board();
void draw_board();
struct {
char board[ROW][COL];
} window;
char (*g_pboard)[ROW][COL] = &window.board;
char getch() {
termios oldt, newt;
char ch;
tcgetattr(STDIN_FILENO, &oldt); // get current terminal attributes
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO); // disable canonical mode and echo
tcsetattr(STDIN_FILENO, TCSANOW, &newt); // apply new settings
read(STDIN_FILENO, &ch, 1); // read one char
tcsetattr(STDIN_FILENO, TCSANOW, &oldt); // restore original settings
return ch;
}
void create_board() {
for(int i = 0; i < ROW; i++) {
for(int a = 0; a < COL; a++) {
(*g_pboard)[i][a] = '.';
}
}
}
void draw_board() {
for(int i = 0; i < ROW; i++) {
for(int a = 0; a < COL; a++) {
std::cout << (*g_pboard)[i][a] << " ";
}
std::cout << "\n";
}
}
int main() {
create_board();
draw_board();
draw_snake();
// int count = 0;
// std::cout << "Press any key other than space or esc: " << std::endl;
// while(count < 10) {
// char ch = getch();
// std::cout << "\nYou pressed: " << ch << '\n';
// ++count;
// }
return 0;
}
+17
View File
@@ -0,0 +1,17 @@
#include "snake.hpp"
#include <iostream>
void create_snake() {
std::cout << "Create Snake Test" << std::endl;
}
void draw_snake() {
std::cout << "Draw Snake Test" << std::endl;
}
/* snake head for instance is (3, 0)
* the direct body to the head when going down would be (snake_head_x, snake_head_y - 1)
* the next and so on would be (previous_body_segment_x - 1, previous_body_segment_y - 1)
* so save the head and body positions as previous and then do the math until the segment hits a point at direction changes.
* so if I change direction at (0, 0) from north to west then at (0, 0) there is a postion change saved and once a body hits that
* switch direction
*/