--- /dev/null
+# -*- Makefile -*-
+#
+#
+# Copyright (C) 2006 Pat Thoyts <patthoyts@users.sourceforge.net>
+#
+#-------------------------------------------------------------------------
+# $Id$
+#-------------------------------------------------------------------------
+
+VERSION=0.2
+
+# You should set SDLDIR to the directory containing your SDL include
+# and lib directories.
+!ifndef SDLDIR
+SDLDIR =/opt
+!endif
+
+#-------------------------------------------------------------------------
+# There should be no need to edit below this point.
+#-------------------------------------------------------------------------
+
+SRCDIR =src
+
+!ifndef DEBUG
+DEBUG =0
+!endif
+!ifndef PROFILE
+PROFILE =0
+!endif
+!ifndef SYMBOLS
+SYMBOLS = 0
+!endif
+!ifndef CC
+CC=cl
+!endif
+!ifndef LINK
+LINK=link
+!endif
+
+!if $(DEBUG)
+OUTDIR =Debug
+CFLAGS =-Od -Zi -GZ -MDd -D_DEBUG
+LDFLAGS=-debug:full -debugtype:cv
+!else
+OUTDIR =Release
+!if $(SYMBOLS)
+CFLAGS =-Od -Zi -Op -Gs -MD -DNDEBUG
+LDFLAGS=-debug -opt:ref -opt:icf,3
+!else
+CFLAGS =-O2 -Otip -Gs -MD -DNDEBUG
+LDFLAGS=-release -opt:ref -opt:icf,3
+!endif
+!endif
+
+!if $(PROFILE)
+CFLAGS =$(CFLAGS) -Zi
+LDFLAGS=$(LDFLAGS) -profile -map
+!endif
+
+!if "$(OS)" == "Windows_NT"
+RMDIR = rmdir /s /q >NUL
+!else
+RMDIR = deltree /y
+!endif
+DEL = del /f /q
+
+TMPDIR =$(OUTDIR)\Objects
+
+CC =$(CC) -nologo
+LD =$(LINK) -nologo
+
+CFLAGS =$(CFLAGS) -W3 -YX -Fp$(TMPDIR)^\
+INC =-I$(SDLDIR)/include
+DEFS =-DWIN32 -DHAVE_OPENGL -Dmain=SDL_main
+LIBS =-libpath:$(SDLDIR)/lib SDLmain.lib SDL.lib SDL_mixer.lib kernel32.lib
+LDFLAGS=$(LDFLAGS) -subsystem:windows
+
+OBJS = \
+ $(TMPDIR)\ag.obj \
+ $(TMPDIR)\dlb.obj \
+ $(TMPDIR)\linked.obj \
+ $(TMPDIR)\sprite.obj \
+ $(TMPDIR)\ag.res
+
+all: ag
+ag: setup $(OUTDIR)\ag.exe
+
+$(OUTDIR)\ag.exe: $(OBJS)
+ $(LD) $(LDFLAGS) -out:$@ $** $(LIBS)
+
+.PHONY: all ag
+
+#-------------------------------------------------------------------------
+setup:
+ @if not exist $(OUTDIR) mkdir $(OUTDIR)
+ @if not exist $(TMPDIR) mkdir $(TMPDIR)
+
+clean:
+ @if exist $(TMPDIR)\NUL $(RMDIR) $(TMPDIR) >NUL
+
+realclean: clean
+ @if exist $(OUTDIR)\NUL $(RMDIR) $(OUTDIR) >NUL
+
+.PHONY: setup clean realclean
+#-------------------------------------------------------------------------
+
+.SUFFIXES:.c .cpp .rc
+
+{$(SRCDIR)}.c{$(TMPDIR)}.obj::
+ $(CC) $(CFLAGS) $(DEFS) $(INC) -Fo$(TMPDIR)\ -c @<<
+$<
+<<
+
+{$(SRCDIR)}.cpp{$(TMPDIR)}.obj::
+ $(CC) $(CFLAGS) $(DEFS) $(INC) -Fo$(TMPDIR)\ -c @<<
+$<
+<<
+
+{$(SRCDIR)}.rc{$(TMPDIR)}.res:
+ $(RC) -fo $@ -r -D__WIN32__ \
+ -DCOMMAVERSION=$(VERSION:.=,),0,0 \
+ -DVERSION=\"$(VERSION)\" \
+!if $(DEBUG)
+ -d DEBUG \
+!endif
+ $<
+
+#-------------------------------------------------------------------------
#include "sprite.h"
#include "ag.h"
+#ifdef _MSC_VER
+#define snprintf _snprintf
+#endif
+
//module level variables for game control
char shuffle[] = "£££££££";
char answer[] = "£££££££";
char* newGuess;
char* newRemain;
-int totalLen=0, guessLen=0, remainLen=0, i;
+int totalLen=0, guessLen=0, remainLen=0;
// allocate space for our working variables
guessLen = strlen(*guess);
}
if (strlen(newRemain)){
+ size_t i;
ag(&(*head), dlbHead, &newGuess, &newRemain);
for (i=totalLen-1;i>0;i--){
// we'll display the total Score, this is the game score
char buffer [256];
-int i;
+size_t i;
SDL_Rect fromrect, torect, blankRect;
blankRect.x = SCORE_WIDTH * 11;
while(thisLetter != NULL){
if (thisLetter->box == SHUFFLE){
- thisLetter->toX = (whereinstr(shufflePos, thisLetter->index+1) * (GAME_LETTER_WIDTH + GAME_LETTER_SPACE)) + BOX_START_X;
- thisLetter->index = whereinstr(shufflePos, thisLetter->index+1);
+ thisLetter->toX = (whereinstr(shufflePos, (char)(thisLetter->index+1)) * (GAME_LETTER_WIDTH + GAME_LETTER_SPACE)) + BOX_START_X;
+ thisLetter->index = whereinstr(shufflePos, (char)(thisLetter->index+1));
}
thisLetter = thisLetter->next;
// show background
ShowBMP("images/background.bmp",screen, 0,0);
- destroyLetters(&(*letters));
+ destroyLetters(letters);
guess = malloc(sizeof(char)*50);
remain = malloc(sizeof(char)*50);
}
-
-
+static Uint32
+TimerCallback(Uint32 interval, void *param)
+{
+ SDL_UserEvent evt;
+ evt.type = SDL_USEREVENT;
+ evt.code = 0;
+ evt.data1 = 0;
+ evt.data2 = 0;
+ SDL_PushEvent((SDL_Event *)&evt);
+ return 0;
+}
/***********************************************************
synopsis: a big while loop that runs the full length of the
int done=0;
SDL_Event event;
int timeNow;
+SDL_TimerID timer;
+int timer_delay = 20;
+ timer = SDL_AddTimer(timer_delay, TimerCallback, NULL);
// main game loop
while (!done){
//displayLetters(screen);
shuffleRemaining = 0;
-
-
}
if (clearGuess){
// clear the guess;
- if (clearWord(&(*letters)) > 0)
+ if (clearWord(letters) > 0)
Mix_PlayChannel(-1, getSound("clear"),0);
clearGuess = 0;
done=1;
}
- while (SDL_PollEvent(&event))
+ while (SDL_WaitEvent(&event))
{
- switch (event.type) {
- case SDL_MOUSEBUTTONDOWN:
- clickDetect(event.button.button, event.button.x, event.button.y, screen, *head, &(*letters));
- break;
-
- case SDL_KEYUP:
- handleKeyboardEvent(&event, *head, &(*letters));
- break;
- case SDL_QUIT:
- done=1;
+ if (event.type == SDL_USEREVENT) {
+ timer_delay = anySpritesMoving(letters) ? 10 : 100;
+ moveSprites(&screen, letters, letterSpeed);
+ timer = SDL_AddTimer(timer_delay, TimerCallback, NULL);
+ break;
+ } else if (event.type == SDL_MOUSEBUTTONDOWN) {
+ clickDetect(event.button.button, event.button.x,
+ event.button.y, screen, *head, letters);
+ } else if (event.type == SDL_KEYUP) {
+ handleKeyboardEvent(&event, *head, letters);
+ } else if (event.type == SDL_QUIT) {
+ done = 1;
+ break;
}
- }
- moveSprites(&screen, &(*letters), letterSpeed);
+ moveSprites(&screen, letters, letterSpeed);
}
+ }
}
struct sprite* letters = NULL;
//pthread_t audio;
+ // buffer sounds
+ int audio_rate = MIX_DEFAULT_FREQUENCY;
+ Uint16 audio_format = AUDIO_S16;
+ int audio_channels = 1;
+ int audio_buffers = 256;
+
+
// seed the random generator
srand(time(NULL));
- if (SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0){
+ if (SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO|SDL_INIT_TIMER) < 0){
fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
exit(1);
}
SDL_WM_SetCaption("Anagramarama", "ANAGRAMARAMA");
- // buffer sounds
- int audio_rate = MIX_DEFAULT_FREQUENCY;
- Uint16 audio_format = AUDIO_S16;
- int audio_channels = 1;
- int audio_buffers = 256;
-
if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)){
printf("unable to open audio!\n");
exit(1);