summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Gamper <victor@wenzeslaus.de>2020-02-04 17:43:56 +0100
committerVictor Gamper <victor@wenzeslaus.de>2020-02-04 17:43:56 +0100
commitfa68923c6a941d8d55a3f06210e3483417c119c7 (patch)
tree0d317ac33ff6028856fa436433a5cba688f40ab9
parent28eaf649d1b359c34b57a344de8c1ec279292fd6 (diff)
downloadc-catch-fa68923c6a941d8d55a3f06210e3483417c119c7.tar.gz
c-catch-fa68923c6a941d8d55a3f06210e3483417c119c7.zip
Fixed timings after I confused milli- and microsecondsr2
-rw-r--r--.cproject52
-rw-r--r--.gitignore1
-rw-r--r--.settings/language.settings.xml11
-rw-r--r--.settings/org.eclipse.cdt.managedbuilder.core.prefs10
-rw-r--r--PidginImage.c2
-rw-r--r--catch.c46
-rw-r--r--catch.h11
7 files changed, 116 insertions, 17 deletions
diff --git a/.cproject b/.cproject
index f68fb8e..752e3ae 100644
--- a/.cproject
+++ b/.cproject
@@ -178,7 +178,7 @@
<tool command="i686-w64-mingw32-gcc" id="cdt.managedbuild.tool.gnu.c.compiler.mingw.base.1891503447" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.mingw.base">
<option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.option.optimization.level.1640295822" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
<option id="gnu.c.compiler.option.debugging.level.1018013008" name="Debug Level" superClass="gnu.c.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.none" valueType="enumerated"/>
- <option id="gnu.c.compiler.option.dialect.std.642399773" superClass="gnu.c.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.c.compiler.dialect.default" valueType="enumerated"/>
+ <option id="gnu.c.compiler.option.dialect.std.642399773" name="Language standard" superClass="gnu.c.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.c.compiler.dialect.default" valueType="enumerated"/>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1080507744" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool command="i686-w64-mingw32-gcc" id="cdt.managedbuild.tool.gnu.c.linker.mingw.base.660068251" name="MinGW C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.mingw.base">
@@ -199,6 +199,56 @@
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
+ <cconfiguration id="cdt.managedbuild.config.gnu.exe.release.1532734451.937370039.1368829244">
+ <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.release.1532734451.937370039.1368829244" moduleId="org.eclipse.cdt.core.settings" name="Windows32">
+ <externalSettings/>
+ <extensions>
+ <extension id="org.eclipse.cdt.core.PE" point="org.eclipse.cdt.core.BinaryParser"/>
+ <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ </extensions>
+ </storageModule>
+ <storageModule moduleId="cdtBuildSystem" version="4.0.0">
+ <configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.release.1532734451.937370039.1368829244" name="Windows32" parent="cdt.managedbuild.config.gnu.exe.release">
+ <folderInfo id="cdt.managedbuild.config.gnu.exe.release.1532734451.937370039.1368829244." name="/" resourcePath="">
+ <toolChain id="cdt.managedbuild.toolchain.gnu.mingw.base.1785056508" name="MinGW GCC" superClass="cdt.managedbuild.toolchain.gnu.mingw.base">
+ <targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.PE" id="cdt.managedbuild.target.gnu.platform.mingw.base.1949051144" name="Debug Platform" osList="win32" superClass="cdt.managedbuild.target.gnu.platform.mingw.base"/>
+ <builder buildPath="${workspace_loc:/cATch}/Windows" id="cdt.managedbuild.tool.gnu.builder.mingw.base.513784823" keepEnvironmentInBuildfile="false" name="CDT Internal Builder" superClass="cdt.managedbuild.tool.gnu.builder.mingw.base"/>
+ <tool id="cdt.managedbuild.tool.gnu.assembler.mingw.base.2016194037" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.mingw.base">
+ <inputType id="cdt.managedbuild.tool.gnu.assembler.input.1662008692" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
+ </tool>
+ <tool id="cdt.managedbuild.tool.gnu.archiver.mingw.base.53116124" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.mingw.base"/>
+ <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.mingw.base.1975896648" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.mingw.base">
+ <option id="gnu.cpp.compiler.option.optimization.level.1402938132" name="Optimization Level" superClass="gnu.cpp.compiler.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/>
+ <option id="gnu.cpp.compiler.option.debugging.level.142728203" name="Debug Level" superClass="gnu.cpp.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/>
+ </tool>
+ <tool command="i686-w64-mingw32-gcc" id="cdt.managedbuild.tool.gnu.c.compiler.mingw.base.1851139915" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.mingw.base">
+ <option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.option.optimization.level.1762796991" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
+ <option id="gnu.c.compiler.option.debugging.level.1782895517" name="Debug Level" superClass="gnu.c.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.none" valueType="enumerated"/>
+ <option id="gnu.c.compiler.option.dialect.std.1048556507" name="Language standard" superClass="gnu.c.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.c.compiler.dialect.default" valueType="enumerated"/>
+ <option id="gnu.c.compiler.option.misc.other.515173604" superClass="gnu.c.compiler.option.misc.other" useByScannerDiscovery="false" value="-c -fmessage-length=0 -m32" valueType="string"/>
+ <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1504073803" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
+ </tool>
+ <tool command="i686-w64-mingw32-gcc" id="cdt.managedbuild.tool.gnu.c.linker.mingw.base.435985961" name="MinGW C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.mingw.base">
+ <option id="gnu.c.link.option.libs.2120728593" name="Libraries (-l)" superClass="gnu.c.link.option.libs" useByScannerDiscovery="false" valueType="libs">
+ <listOptionValue builtIn="false" value="mingw32"/>
+ <listOptionValue builtIn="false" value="SDLmain"/>
+ <listOptionValue builtIn="false" value="SDL"/>
+ </option>
+ <option id="gnu.c.link.option.ldflags.437851574" superClass="gnu.c.link.option.ldflags" useByScannerDiscovery="false" value="-m32" valueType="string"/>
+ <inputType id="cdt.managedbuild.tool.gnu.c.linker.input.477408792" superClass="cdt.managedbuild.tool.gnu.c.linker.input">
+ <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
+ <additionalInput kind="additionalinput" paths="$(LIBS)"/>
+ </inputType>
+ </tool>
+ <tool id="cdt.managedbuild.tool.gnu.cpp.linker.mingw.base.439273424" name="MinGW C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.mingw.base"/>
+ </toolChain>
+ </folderInfo>
+ </configuration>
+ </storageModule>
+ <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
+ </cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="cATch.cdt.managedbuild.target.gnu.exe.319782583" name="Executable" projectType="cdt.managedbuild.target.gnu.exe"/>
diff --git a/.gitignore b/.gitignore
index 2779131..324180f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,4 +2,5 @@
/Debug
/Release32
/Windows
+/Windows32
/Release
diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml
index fba9e44..0361b61 100644
--- a/.settings/language.settings.xml
+++ b/.settings/language.settings.xml
@@ -44,4 +44,15 @@
</provider>
</extension>
</configuration>
+ <configuration id="cdt.managedbuild.config.gnu.exe.release.1532734451.937370039.1368829244" name="Windows32">
+ <extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
+ <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
+ <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
+ <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
+ <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1509751584800533257" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+ <language-scope id="org.eclipse.cdt.core.gcc"/>
+ <language-scope id="org.eclipse.cdt.core.g++"/>
+ </provider>
+ </extension>
+ </configuration>
</project>
diff --git a/.settings/org.eclipse.cdt.managedbuilder.core.prefs b/.settings/org.eclipse.cdt.managedbuilder.core.prefs
index e6fd9f9..f8fa1aa 100644
--- a/.settings/org.eclipse.cdt.managedbuilder.core.prefs
+++ b/.settings/org.eclipse.cdt.managedbuilder.core.prefs
@@ -1,10 +1,20 @@
eclipse.preferences.version=1
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.release.1532734451.937370039.1368829244/CPATH/delimiter=\:
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.release.1532734451.937370039.1368829244/CPATH/operation=remove
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.release.1532734451.937370039.1368829244/C_INCLUDE_PATH/delimiter=\:
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.release.1532734451.937370039.1368829244/C_INCLUDE_PATH/operation=remove
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.release.1532734451.937370039.1368829244/append=true
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.release.1532734451.937370039.1368829244/appendContributed=true
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.release.1532734451.937370039/CPATH/delimiter=\:
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.release.1532734451.937370039/CPATH/operation=remove
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.release.1532734451.937370039/C_INCLUDE_PATH/delimiter=\:
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.release.1532734451.937370039/C_INCLUDE_PATH/operation=remove
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.release.1532734451.937370039/append=true
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.release.1532734451.937370039/appendContributed=true
+environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.release.1532734451.937370039.1368829244/LIBRARY_PATH/delimiter=\:
+environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.release.1532734451.937370039.1368829244/LIBRARY_PATH/operation=remove
+environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.release.1532734451.937370039.1368829244/append=true
+environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.release.1532734451.937370039.1368829244/appendContributed=true
environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.release.1532734451.937370039/LIBRARY_PATH/delimiter=\:
environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.release.1532734451.937370039/LIBRARY_PATH/operation=remove
environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.release.1532734451.937370039/append=true
diff --git a/PidginImage.c b/PidginImage.c
index 791926d..9cd0b39 100644
--- a/PidginImage.c
+++ b/PidginImage.c
@@ -34,7 +34,7 @@ void draw_Pidgin(SDL_Surface* surface, int x, int y) {
void Pidgin_IncrementFrame() {
delay++;
//printf("%d\n", delay);
- if(delay >= 50) {
+ if(delay >= 10) {
delay = 0;
animation_index+=ax;
sdl_rect_source.y = animation_index * PIDGIN_HEIGHT;
diff --git a/catch.c b/catch.c
index 667a5b6..dc40c9f 100644
--- a/catch.c
+++ b/catch.c
@@ -19,7 +19,9 @@ SDL_Surface* image_chargebar, *image_chargebar_dark, *image_cat, *image_bird;
struct Cat cat;
struct Bird bird[BIRD_COUNT];
-int state, menu_state, score, time_left, ticks_to_next_second;
+unsigned int state, menu_state, score;
+int ticks_to_next_second, time_left;
+unsigned long last_delta_time;
int main(int argc, char* argv[]) {
memset(keyPressed,0,sizeof(keyPressed));
@@ -60,6 +62,8 @@ int main(int argc, char* argv[]) {
run = true;
state = 1;
while(run) {
+
+ // get the time
long deltaTime = clock();
// process all sdl events
@@ -200,6 +204,17 @@ int main(int argc, char* argv[]) {
Font_DrawString(screen, screen->w /2 - length * 4, 180, score_s);
}
+ // TODO draw the fps
+ /*
+ char fps_s[50]; // TODO this could create a buffer overflow
+ if(last_delta_time <= 0)
+ last_delta_time = 1;
+ printf("%d\n", last_delta_time);
+ sprintf(fps_s, "FPS: %ld", 1000000000 / last_delta_time);
+ int length = strlen(fps_s) + 1;
+ Font_DrawString(screen, screen->w - length * 8, 24, fps_s);
+ */
+
//Font_DrawString(screen, 0,5, "ABCDEFGHIJKLMNOPQRSTUVWXYZ\nabcdefghijklmnopqrstufwxyz\n 01234567890: +");
Font_DrawString(screen, screen->h-10, 5, "");
@@ -207,12 +222,23 @@ int main(int argc, char* argv[]) {
SDL_Flip(screen);
// get the delta time
- deltaTime = clock() - deltaTime;
- deltaTime /= CLOCKS_PER_SEC / 1000;
- deltaTime = TICK_SPEED - deltaTime;
- // wait 50 milliseconds
- if(deltaTime>0)
+ deltaTime = clock()-deltaTime;
+
+ // get the time in microseconds
+ deltaTime /= CLOCKS_PER_SEC/1000000;
+ last_delta_time = deltaTime;
+
+ // calculate the time until the next frame
+ deltaTime = TICK_SPEED * 1000 - deltaTime;
+
+ // if it is higher than 0, sleep
+ if(deltaTime > 0)
usleep(deltaTime);
+ //deltaTime = TICK_SPEED - deltaTime;
+ ///printf("%d\n", deltaTime);
+ // wait 50 milliseconds
+
+
}
// dispose the surfaces
@@ -231,7 +257,7 @@ void gameRoutine() {
// do the physics calculation
if(cat.jumping) {
- cat.downwardForce+=0.01;
+ cat.downwardForce+=0.1;
cat.y+=cat.downwardForce;
// the cat has touched the floor
@@ -248,7 +274,7 @@ void gameRoutine() {
}
else if(charge) {
if(cat.downwardForce > -MAXIMUM_JUMP_FORCE)
- cat.downwardForce-=0.02;
+ cat.downwardForce-=0.2;
}
}
@@ -299,7 +325,7 @@ void gameRoutine() {
// if the selected bird exists, move it
if(bird[i].type == BIRD_TYPE_PIDGIN) {
- bird[i].x+=0.5;
+ bird[i].x+= 1;
// if the bird left the screen, reset it
if(bird[i].x > screen->w) {
@@ -315,7 +341,7 @@ void gameRoutine() {
}
} else if(bird[i].type == BIRD_TYPE_DEAD_PIDGIN) {
- bird[i].y+=0.5;
+ bird[i].y+= 2;
if(bird[i].y > screen->h-FLOOR_HEIGHT) {
bird[i].type = BIRD_TYPE_NONE;
diff --git a/catch.h b/catch.h
index 936e6b2..1f2dd36 100644
--- a/catch.h
+++ b/catch.h
@@ -27,9 +27,9 @@
#define CHARGEBAR_POS_X 10
#define CHARGEBAR_POS_Y 10
-#define MAXIMUM_JUMP_FORCE 3
+#define MAXIMUM_JUMP_FORCE 9
-#define BIRD_COUNT 3
+#define BIRD_COUNT 5
#define BIRD_TYPE_NONE 0
#define BIRD_TYPE_PIDGIN 1
#define BIRD_TYPE_DEAD_PIDGIN 2
@@ -37,10 +37,10 @@
#define STATE_MAIN_MENU 1
#define STATE_GAME 2
#define STATE_GAME_OVER 3
-#define GAME_TIME 10
+#define GAME_TIME 60
-#define TICK_SPEED 100
-#define TICKS_PER_SECOND 10000 / TICK_SPEED
+#define TICK_SPEED 20
+#define TICKS_PER_SECOND 1000 / TICK_SPEED
// cat and bird structures
struct Cat {
@@ -58,6 +58,7 @@ struct Bird {
// function predefines
extern void gameRoutine();
extern bool checkCollision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2);
+extern int getRandomInt(int limit);
// BitmapFontRenderer.c
extern void Font_Init();