Skip to content

Commit

Permalink
Merge pull request #14 from abdothegreat/main
Browse files Browse the repository at this point in the history
[EXAMPLE] Moving Square
  • Loading branch information
OkiStuff authored Sep 5, 2021
2 parents fc24021 + 5cc4a37 commit b249d4e
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
29 changes: 29 additions & 0 deletions examples/Movable-Square/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
cmake_minimum_required(VERSION 3.18)

project(Muzzle)
INCLUDE_DIRECTORIES(../../include)
LINK_DIRECTORIES(../../deps/glfw/lib)
set(mz_source_dir "../../src")

#could use aux_source_directory() but its better to list each file to ensure new files are compiled
#https://stackoverflow.com/a/25077976/10415312


set(mz_source
${mz_source_dir}/Applet.c
${mz_source_dir}/callback.c
${mz_source_dir}/Drawing.c
${mz_source_dir}/Error.c
${mz_source_dir}/Loop.c
${mz_source_dir}/Muzzle.c
${mz_source_dir}/Rectangle.c
${mz_source_dir}/tint.c
${mz_source_dir}/Circle.c
${mz_source_dir}/Input.c
${mz_source_dir}/Sprite.c
${mz_source_dir}/Text.c
)


add_executable(main src/main.c ${mz_source})
TARGET_LINK_LIBRARIES(main glfw3 opengl32 gdi32)
7 changes: 7 additions & 0 deletions examples/Movable-Square/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mkdir build
cd build
cmake .. -G "MinGW Makefiles"
mingw32-make
.\main.exe
cd ..
rm build
39 changes: 39 additions & 0 deletions examples/Movable-Square/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#define MUZZLE_DEPS
#include <Muzzle.h>
#include <stdio.h>
#define SCREEN_WIDTH 500
#define SCREEN_HEIGHT 500

Applet applet;

void OnAppletUpdate()
{
rectangle player = {
.height = 50,
.width = 50,
.x = 225,
.y = 225
};

while (keep_applet(applet.window_handle))
{
begin_drawing();
clear_screen(GRAY);
if(key_down(&applet, KEY_W)&&player.y!=5) player.y -=5;
else if(key_down(&applet, KEY_S)&&player.y!=495&&player.y!=490) player.y +=5;
else if(key_down(&applet, KEY_A)&&player.x!=5) player.x -=5;
else if(key_down(&applet, KEY_D)&&player.x!=495&&player.x!=490) player.x +=5;
draw_rectangle_rec(player,WHITE);
end_drawing(&applet);
}

}

int main(void)
{
applet = InitializeApplet(SCREEN_WIDTH, SCREEN_HEIGHT, "Muzzle [EXAMPLE] - Movable Square", MUZZLE_FALSE, MUZZLE_TRUE);
StartApplet(&applet);

QuitMuzzle(applet);
return 0;
}

0 comments on commit b249d4e

Please sign in to comment.