-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcreate_new_preoject.sh
More file actions
executable file
·195 lines (159 loc) · 4.08 KB
/
Copy pathcreate_new_preoject.sh
File metadata and controls
executable file
·195 lines (159 loc) · 4.08 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/env bash
read -p "Enter project name: " PROJECT_NAME
if [[ "$PROJECT_NAME" =~ \ ]]; then
echo "Error: Project name cannot contain spaces."
exit 1
fi
PROJECT_NAME=${PROJECT_NAME:-YourFirstGame} # fallback if empty
# === Config ===
# PROJECT_NAME="YourFirstGame"
ENGINE_PATH=".." # Adjust if needed
ENTRY_SCENE="EntryScene"
# === Create project folder ===
mkdir -p "$PROJECT_NAME/Source/Scenes"
mkdir -p "$PROJECT_NAME/Source/GameObjects"
mkdir -p "$PROJECT_NAME/build"
# === Write CMakeLists.txt ===
cat > "$PROJECT_NAME/CMakeLists.txt" <<EOF
cmake_minimum_required(VERSION 3.12)
project(${PROJECT_NAME})
#set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Source files
file(GLOB_RECURSE ENGINE_SOURCES
${ENGINE_PATH}/Source/*.cpp
)
# Header files
file(GLOB_RECURSE ENGINE_HEADERS
${ENGINE_PATH}/Source/*.h
)
add_library(ConsoleCraftEngine SHARED \${ENGINE_SOURCES} )
file(GLOB_RECURSE GAME_SOURCES Source/*.cpp)
file(GLOB_RECURSE GAME_HEADERS Source/*.h)
# Executable
link_directories(\${CMAKE_CURRENT_SOURCE_DIR})
add_executable(${PROJECT_NAME} \${GAME_SOURCES} \${GAME_HEADERS})
# Include directories
target_include_directories(${PROJECT_NAME} PUBLIC
\${CMAKE_CURRENT_SOURCE_DIR}/Source
\${CMAKE_CURRENT_SOURCE_DIR}/${ENGINE_PATH}/Source
\${CMAKE_CURRENT_SOURCE_DIR}/${ENGINE_PATH}/Source/Core
)
# Link with ConsoleCraftEngine library
target_link_libraries(${PROJECT_NAME} PUBLIC ConsoleCraftEngine ncurses)
EOF
# === Write YourGameEntry.cpp ===
cat > "$PROJECT_NAME/Source/${PROJECT_NAME}Entry.cpp" <<EOF
#include "Scenes/${ENTRY_SCENE}.h"
#include "Core/EntryPoint.h"
#include <vector>
class ${PROJECT_NAME}
{
public:
~${PROJECT_NAME}()
{
};
Engine engine;
void StartGame()
{
engine.scenes.push_back(new $ENTRY_SCENE());
engine.StartGame();
}
void Clean()
{
engine.Clean();
}
};
int main()
{
${PROJECT_NAME} *game = new ${PROJECT_NAME}();
game->StartGame();
game->Clean();
delete game;
system("pause");
return 0;
}
EOF
# === Write YourScene.h ===
cat > "$PROJECT_NAME/Source/Scenes/$ENTRY_SCENE.h" <<EOF
#pragma once
#include "Core/Scene.h"
class $ENTRY_SCENE : public Scene
{
public:
void Init() override;
void Update(float deltaTime) override;
private:
void OnInput(int input);
};
EOF
# === Write YourScene.cpp ===
cat > "$PROJECT_NAME/Source/Scenes/$ENTRY_SCENE.cpp" <<EOF
#include "${ENTRY_SCENE}.h"
#include "GameObjects/ExampleGameObject.h"
void ${ENTRY_SCENE}::Init()
{
AddGameObject(new ExampleGameObject(*this), Vector2(5,5));
// TODO: Initialize your scene
}
void ${ENTRY_SCENE}::Update(float deltaTime)
{
Scene::Update(deltaTime);
// TODO: Update logic for scene
}
EOF
#create Source/GameObjects
#ExampleGameObject.h and ExampleGameObject.cpp
# === Write ExampleGameObject.h ===
cat > "$PROJECT_NAME/Source/GameObjects/ExampleGameObject.h" <<EOF
#pragma once
#include "GameObject.h"
class ExampleGameObject : public GameObject {
public:
ExampleGameObject(class Scene &scene) : GameObject("ExampleGameObject", scene) {}
void Init() override;
void OnInput(int input);
void Update(float deltaTime) override;
};
EOF
# === Write ExampleGameObject.cpp ===
cat > "$PROJECT_NAME/Source/GameObjects/ExampleGameObject.cpp" <<EOF
#include "ExampleGameObject.h"
#include "Input.h"
void ExampleGameObject::Init() {
symbol = '8';
Sprite sprite = {
{1, 1},
{1, 1},
};
SetSprite(sprite);
auto inputEvent = BIND_EVENT_FN(ExampleGameObject::OnInput);
Input::AddListener(inputEvent);
}
void ExampleGameObject::OnInput(int input)
{
if (std::tolower(input) == 'd')
{
transform.MovePosition(1, 0);
}
if (std::tolower(input) == 'a')
{
transform.MovePosition(-1, 0);
}
if (std::tolower(input) == 'w')
{
transform.MovePosition(0, -1);
}
if (std::tolower(input) == 's')
{
transform.MovePosition(0, 1);
}
}
void ExampleGameObject::Update(float deltaTime)
{
}
EOF
cat > "$PROJECT_NAME/build/build.sh" <<EOF
cmake .. && make && ./${PROJECT_NAME}
EOF
chmod +x "$PROJECT_NAME/build/build.sh"
echo "Project ${PROJECT_NAME} structure created!"