Skip to content

Commit

Permalink
Fixed timings after I confused milli- and microseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
TheZeldakatze committed Feb 4, 2020
1 parent 28eaf64 commit fa68923
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 17 deletions.
52 changes: 51 additions & 1 deletion .cproject
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand All @@ -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"/>
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/Debug
/Release32
/Windows
/Windows32
/Release
11 changes: 11 additions & 0 deletions .settings/language.settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
10 changes: 10 additions & 0 deletions .settings/org.eclipse.cdt.managedbuilder.core.prefs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion PidginImage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
46 changes: 36 additions & 10 deletions catch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -200,19 +204,41 @@ 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, "");

// draw the screen
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
Expand All @@ -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
Expand All @@ -248,7 +274,7 @@ void gameRoutine() {
}
else if(charge) {
if(cat.downwardForce > -MAXIMUM_JUMP_FORCE)
cat.downwardForce-=0.02;
cat.downwardForce-=0.2;
}
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
11 changes: 6 additions & 5 deletions catch.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@
#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

#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 {
Expand All @@ -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();
Expand Down

0 comments on commit fa68923

Please sign in to comment.