Skip to content

Commit

Permalink
Merge pull request #6 from Apaczer/quit_event
Browse files Browse the repository at this point in the history
add EXIT event if physical button is pressed + basic Linux Makefile
  • Loading branch information
TriForceX authored Feb 1, 2023
2 parents a2a8a0b + b7b0ab4 commit 9508d8f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

BUILDTIME=$(shell date +'\"%Y-%m-%d %H:%M\"')

CC = gcc
CXX = g++
STRIP = strip
SDL_CFLAGS := `sdl-config --cflags`

OUTPUTNAME = boot-logo

DEFINES = -DHAVE_STDINT_H -DVERSION_BITTBOY
INCLUDES = -Iinclude $(SDL_CFLAGS)
EXTRA_LDFLAGS = -lmpg123 -Wl,--as-needed -Wl,--gc-sections -flto -s

CFLAGS = $(DEFINES) $(INCLUDES) $(OPT_FLAGS) -std=gnu11
CXXFLAGS = $(DEFINES) $(INCLUDES) $(OPT_FLAGS) -std=gnu++11
LDFLAGS = -Wl,--start-group -lSDL -lSDL_image -lpng -ljpeg -lSDL_mixer -lfreetype -lSDL_ttf -logg -lm -pthread -lz -lstdc++ $(EXTRA_LDFLAGS) -Wl,--end-group

# Redream (main engine)
OBJS = \
main.o

.c.o:
$(CC) $(CFLAGS) -c -o $@ $<

.cpp.o:
$(CXX) $(CXXFLAGS) -c -o $@ $<

all: executable

executable : $(OBJS)
$(CC) -o $(OUTPUTNAME) $(OBJS) $(CFLAGS) $(LDFLAGS)

clean:
rm $(OBJS) $(OUTPUTNAME)
17 changes: 17 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,15 @@ int main(int argc, char* argv[]) {
uint32_t color = SDL_MapRGB(screen->format, R, G, B);
SDL_Rect rect;
SDL_Rect dstrect;
SDL_Event event;
for (int i = 0 - logoimg->h - ANIMDELAY; i <= dest_y; i = i + ANIMSPEED) {
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_KEYDOWN:
exit(0);
break;
}
}
rect.x = 0;
rect.y = 0;
rect.w = screen->w;
Expand All @@ -86,6 +94,15 @@ int main(int argc, char* argv[]) {
SDL_BlitSurface(logoimg, NULL, screen, &dstrect);
if (i == dest_y) {
Mix_PlayChannel(-1, logosound, 0);
while(1) {
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_KEYDOWN:
exit(0);
break;
}
}
}
}
while (curr_time < old_time + 16) {
curr_time = SDL_GetTicks();
Expand Down

0 comments on commit 9508d8f

Please sign in to comment.