summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rwxr-xr-xdeb-build.sh4
-rw-r--r--image/l2.trubka2.pngbin0 -> 4658 bytes
-rw-r--r--image/l2.trubka4.pngbin0 -> 3892 bytes
-rw-r--r--image/l2.trubka6.pngbin0 -> 5778 bytes
-rw-r--r--image/l2.trubka8.pngbin0 -> 5906 bytes
-rw-r--r--image/l3.teleport.pngbin0 -> 1043 bytes
-rw-r--r--image/tuxanci.pngbin0 -> 1697 bytes
-rw-r--r--include/arena.h4
-rw-r--r--include/pipe.h36
-rw-r--r--include/shot.h7
-rw-r--r--include/teleport.h31
-rw-r--r--include/tux.h5
-rwxr-xr-xsrc/Makefile10
-rw-r--r--src/arena.c4
-rw-r--r--src/arenaFile.c59
-rw-r--r--src/pipe.c174
-rw-r--r--src/screen_world.c15
-rw-r--r--src/shot.c112
-rw-r--r--src/teleport.c197
-rw-r--r--src/tux.c31
-rw-r--r--src/zal_pipe.c256
-rw-r--r--tuxanci-ng.desktop9
23 files changed, 943 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index 6382bdd..029b7fc 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
#DISTDIR=/usr/local
-DISTDIR:=/usr/local/
+DISTDIR:=/usr/
all:
make -C ./src DISTDIR=$(DISTDIR)
diff --git a/deb-build.sh b/deb-build.sh
index 6b889e6..91787f3 100755
--- a/deb-build.sh
+++ b/deb-build.sh
@@ -6,8 +6,10 @@ mkdir deb/DEBIAN
mkdir deb/usr
mkdir deb/usr/bin
mkdir deb/usr/share
+mkdir deb/usr/share/applications
cp control deb/DEBIAN/
+cp tuxanci-ng.desktop deb/usr/share/applications
cd deb
@@ -20,4 +22,4 @@ md5sum `find ./ -type f | awk '/.\// { print substr($0, 3) }'` > DEBIAN/md5sums
cd ..
rm -rf *.deb
-dpkg -b ./deb tuxanci-ng_i386.deb
+dpkg -b ./deb tuxanci-ng_svn8-1_i386.deb
diff --git a/image/l2.trubka2.png b/image/l2.trubka2.png
new file mode 100644
index 0000000..f874ccc
--- /dev/null
+++ b/image/l2.trubka2.png
Binary files differ
diff --git a/image/l2.trubka4.png b/image/l2.trubka4.png
new file mode 100644
index 0000000..7be65d2
--- /dev/null
+++ b/image/l2.trubka4.png
Binary files differ
diff --git a/image/l2.trubka6.png b/image/l2.trubka6.png
new file mode 100644
index 0000000..29755ae
--- /dev/null
+++ b/image/l2.trubka6.png
Binary files differ
diff --git a/image/l2.trubka8.png b/image/l2.trubka8.png
new file mode 100644
index 0000000..6026467
--- /dev/null
+++ b/image/l2.trubka8.png
Binary files differ
diff --git a/image/l3.teleport.png b/image/l3.teleport.png
new file mode 100644
index 0000000..f901589
--- /dev/null
+++ b/image/l3.teleport.png
Binary files differ
diff --git a/image/tuxanci.png b/image/tuxanci.png
new file mode 100644
index 0000000..34b770b
--- /dev/null
+++ b/image/tuxanci.png
Binary files differ
diff --git a/include/arena.h b/include/arena.h
index 59290fd..38a0a18 100644
--- a/include/arena.h
+++ b/include/arena.h
@@ -10,11 +10,15 @@
typedef struct arena_struct
{
char music[STR_SIZE];
+
SDL_Surface *background;
+
list_t *listTux;
list_t *listShot;
list_t *listWall;
list_t *listItem;
+ list_t *listTeleport;
+ list_t *listPipe;
} arena_t;
extern arena_t* newArena();
diff --git a/include/pipe.h b/include/pipe.h
new file mode 100644
index 0000000..e665e0a
--- /dev/null
+++ b/include/pipe.h
@@ -0,0 +1,36 @@
+
+#ifndef PIPE_H
+
+#define PIPE_H
+
+#include "interface.h"
+#include "list.h"
+
+typedef struct pipe_struct
+{
+ int x; // poloha steny
+ int y;
+
+ int w; // rozmery steny
+ int h;
+
+ int id;
+ int id_out;
+ int position;
+
+ int layer; // vrstva
+
+ SDL_Surface *img; //obrazok
+} pipe_t;
+
+extern pipe_t* newPipe(int x, int y, int w, int h, int layer,
+ int id, int id_out, int position, SDL_Surface *img);
+
+extern void drawPipe(pipe_t *p);
+extern void drawListPipe(list_t *listPipe);
+extern pipe_t* isConflictWithListPipe(list_t *listPipe, int x, int y, int w, int h);
+extern void eventConflictShotWithPipe(list_t *listPipe, list_t *listShot);
+extern void destroyPipe(pipe_t *p);
+
+#endif
+
diff --git a/include/shot.h b/include/shot.h
index c248538..749767f 100644
--- a/include/shot.h
+++ b/include/shot.h
@@ -19,8 +19,7 @@ typedef struct shot_struct
int px;
int py;
- int course;
- int speed;
+ int position;
int gun;
tux_t *author;
@@ -36,6 +35,10 @@ extern void drawShot(shot_t *p);
extern void drawListShot(list_t *listShot);
extern int isConflictWithListShot(list_t *listShot, int x, int y, int w, int h);
extern void eventMoveListShot(list_t *listShot);
+
+extern void moveShot(shot_t *shot, int position, int src_x, int src_y,
+ int dist_x, int dist_y, int dist_w, int dist_h);
+
extern void destroyShot(shot_t *p);
extern void quitShot();
diff --git a/include/teleport.h b/include/teleport.h
new file mode 100644
index 0000000..4b9ed66
--- /dev/null
+++ b/include/teleport.h
@@ -0,0 +1,31 @@
+
+#ifndef TELEPORT_H
+
+#define TELEPORT_H
+
+#include <interface.h>
+#include "list.h"
+
+typedef struct teleport_struct
+{
+ int x; // poloha steny
+ int y;
+
+ int w; // rozmery steny
+ int h;
+
+ int layer; // vrstva
+
+ SDL_Surface *img; //obrazok
+} teleport_t;
+
+extern teleport_t* newTeleport(int x, int y, int w, int h, int layer, SDL_Surface *img);
+extern void drawTeleport(teleport_t *p);
+extern void drawListTeleport(list_t *listTeleport);
+extern teleport_t* isConflictWithListTeleport(list_t *listTeleport, int x, int y, int w, int h);
+extern void eventConflictShotWithTeleport(list_t *listTeleport, list_t *listShot);
+extern void eventTeleportTux(list_t *listTeleport, teleport_t *teleport, tux_t *tux);
+extern void destroyTeleport(teleport_t *p);
+
+#endif
+
diff --git a/include/tux.h b/include/tux.h
index ed5e01e..ebc8ac7 100644
--- a/include/tux.h
+++ b/include/tux.h
@@ -10,7 +10,7 @@
#define TUX_LAYER 0
#define TUX_MAX_ANIMATION_FRAME 10
#define TUX_MAX_PICKUP 50
-#define TUX_MAX_BONUS 250
+#define TUX_MAX_BONUS 500
#define TUX_TIME_SPAWN 2000
#define TUX_TIME_CAN_SHOT 500
@@ -107,7 +107,8 @@ extern void drawListTux(list_t *listTux);
extern void eventTuxIsDead(tux_t *tux);
extern tux_t* isConflictWithListTux(list_t *listTux, int x, int y, int w, int h);
extern int isConflictTuxWithListTux(tux_t *tux, list_t *listTux);
-extern void eventConflictShotWithTux(list_t *listTux, list_t *listShot);
+extern void eventConflictTuxWithShot(list_t *listTux, list_t *listShot);
+extern void eventConflictTuxWithTeleport(list_t *listTux, list_t *listTeleport);
extern void tuxTeleport(tux_t *tux);
extern void actionTux(tux_t *tux, int action);
extern void eventListTux(list_t *listTux);
diff --git a/src/Makefile b/src/Makefile
index 2d5921b..2aafa95 100755
--- a/src/Makefile
+++ b/src/Makefile
@@ -2,7 +2,7 @@
CC = gcc
#CFLAGS = -g -O0 -DDISTDIR=\"$(DISTDIR)\" `sdl-config --cflags` -I../include -Wall
-CFLAGS = -O2 -DDISTDIR=\"$(DISTDIR)\" `sdl-config --cflags` -I../include -Wall
+CFLAGS = -g -O0 -DDISTDIR=\"$(DISTDIR)\" `sdl-config --cflags` -I../include -Wall
LIBS = `sdl-config --libs` -lSDL_image -lSDL_ttf -lSDL_mixer
@@ -11,8 +11,7 @@ FILES = interface.o font.o list.o image.o layer.o director.o configFile.o tux.o
buffer.o dynamicInt.o arena.o arenaFile.o textFile.o sound.o audio.o music.o gun.o \
item.o widget_label.o screen_mainMenu.o widget_button.o screen_analyze.o widget_textfield.o \
widget_check.o widget_image.o screen_setting.o screen_gameType.o screen_choiceArena.o \
- widget_buttonimage.o screen_credits.o
-
+ widget_buttonimage.o screen_credits.o teleport.o pipe.o
tuxanci-ng: $(FILES)
$(CC) $(CFLAGS) $(LIBS) -o tuxanci-ng $(FILES)
@@ -134,6 +133,11 @@ widget_check.o: widget_check.c ../include/widget_check.h
widget_image.o: widget_image.c ../include/widget_image.h
$(CC) $(CFLAGS) -o widget_image.o -c widget_image.c
+teleport.o: teleport.c ../include/teleport.h
+ $(CC) $(CFLAGS) -o teleport.o -c teleport.c
+
+pipe.o: pipe.c ../include/pipe.h
+ $(CC) $(CFLAGS) -o pipe.o -c pipe.c
clean:
rm -rf *.o *.c~ *.h~ tuxanci-ng
diff --git a/src/arena.c b/src/arena.c
index 320a697..6ce2712 100644
--- a/src/arena.c
+++ b/src/arena.c
@@ -22,6 +22,8 @@ arena_t* newArena()
new->listShot = newList();
new->listWall = newList();
new->listItem = newList();
+ new->listTeleport = newList();
+ new->listPipe = newList();
return new;
}
@@ -32,6 +34,8 @@ void destroyArena(arena_t *p)
destroyListItem(p->listShot, destroyShot);
destroyListItem(p->listWall, destroyWall);
destroyListItem(p->listItem, destroyItem);
+ destroyListItem(p->listTeleport, destroyItem);
+ destroyListItem(p->listPipe, destroyItem);
free(p);
}
diff --git a/src/arenaFile.c b/src/arenaFile.c
index e1cc5b4..64e59a4 100644
--- a/src/arenaFile.c
+++ b/src/arenaFile.c
@@ -12,6 +12,8 @@
#include "tux.h"
#include "shot.h"
#include "wall.h"
+#include "pipe.h"
+#include "teleport.h"
#include "item.h"
#include "director.h"
#include "path.h"
@@ -140,6 +142,61 @@ static void cmd_wall(arena_t *arena, char *line)
addList(arena->listWall, new);
}
+static void cmd_teleport(arena_t *arena, char *line)
+{
+ char str_x[STR_NUM_SIZE];
+ char str_y[STR_NUM_SIZE];
+ char str_w[STR_NUM_SIZE];
+ char str_h[STR_NUM_SIZE];
+ char str_layer[STR_NUM_SIZE];
+ char str_image[STR_SIZE];
+ teleport_t *new;
+
+ if( setValue(line, "x", str_x, STR_NUM_SIZE) != 0 )return;
+ if( setValue(line, "y", str_y, STR_NUM_SIZE) != 0 )return;
+ if( setValue(line, "w", str_w, STR_NUM_SIZE) != 0 )return;
+ if( setValue(line, "h", str_h, STR_NUM_SIZE) != 0 )return;
+ if( setValue(line, "layer", str_layer, STR_NUM_SIZE) != 0 )return;
+ if( setValue(line, "image", str_image, STR_SIZE) != 0 )return;
+
+ new = newTeleport(atoi(str_x), atoi(str_y),
+ atoi(str_w), atoi(str_h),
+ atoi(str_layer), getImage(IMAGE_GROUP_USER, str_image) );
+
+ addList(arena->listTeleport, new);
+}
+
+static void cmd_pipe(arena_t *arena, char *line)
+{
+ char str_x[STR_NUM_SIZE];
+ char str_y[STR_NUM_SIZE];
+ char str_w[STR_NUM_SIZE];
+ char str_h[STR_NUM_SIZE];
+ char str_id[STR_NUM_SIZE];
+ char str_id_out[STR_NUM_SIZE];
+ char str_position[STR_NUM_SIZE];
+ char str_layer[STR_NUM_SIZE];
+ char str_image[STR_SIZE];
+ pipe_t *new;
+
+ if( setValue(line, "x", str_x, STR_NUM_SIZE) != 0 )return;
+ if( setValue(line, "y", str_y, STR_NUM_SIZE) != 0 )return;
+ if( setValue(line, "w", str_w, STR_NUM_SIZE) != 0 )return;
+ if( setValue(line, "h", str_h, STR_NUM_SIZE) != 0 )return;
+ if( setValue(line, "id", str_id, STR_NUM_SIZE) != 0 )return;
+ if( setValue(line, "id_out", str_id_out, STR_NUM_SIZE) != 0 )return;
+ if( setValue(line, "position", str_position, STR_NUM_SIZE) != 0 )return;
+ if( setValue(line, "layer", str_layer, STR_NUM_SIZE) != 0 )return;
+ if( setValue(line, "image", str_image, STR_SIZE) != 0 )return;
+
+ new = newPipe(atoi(str_x), atoi(str_y),
+ atoi(str_w), atoi(str_h),
+ atoi(str_layer), atoi(str_id), atoi(str_id_out), atoi(str_position),
+ getImage(IMAGE_GROUP_USER, str_image) );
+
+ addList(arena->listPipe, new);
+}
+
int getArenaCount()
{
return listArenaFile->count;
@@ -225,6 +282,8 @@ arena_t* getArena(int id)
if( strncmp(line, "background", 10) == 0 )cmd_background(arena, line);
if( strncmp(line, "playMusic", 9) == 0 )cmd_playMusic(arena, line);
if( strncmp(line, "wall", 4) == 0 )cmd_wall(arena, line);
+ if( strncmp(line, "teleport", 8) == 0 )cmd_teleport(arena, line);
+ if( strncmp(line, "pipe", 4) == 0 )cmd_pipe(arena, line);
}
return arena;
diff --git a/src/pipe.c b/src/pipe.c
new file mode 100644
index 0000000..c82cb65
--- /dev/null
+++ b/src/pipe.c
@@ -0,0 +1,174 @@
+
+#include <stdlib.h>
+#include <assert.h>
+
+#include "pipe.h"
+#include "layer.h"
+#include "screen_world.h"
+#include "shot.h"
+
+pipe_t* newPipe(int x, int y, int w, int h, int layer, int id, int id_out, int position, SDL_Surface *img)
+{
+ pipe_t *new;
+
+ assert( img != NULL );
+
+ new = malloc( sizeof(pipe_t) );
+ assert( new != NULL );
+
+ new->x = x;
+ new->y = y;
+ new->w = w;
+ new->h = h;
+ new->layer = layer;
+ new->id = id;
+ new->id_out = id_out;
+ new->position = position;
+ new->img = img;
+
+ return new;
+}
+
+void drawPipe(pipe_t *p)
+{
+ assert( p != NULL );
+
+ addLayer(p->img, p->x, p->y, 0, 0, p->img->w, p->img->h, p->layer);
+}
+
+void drawListPipe(list_t *listPipe)
+{
+ pipe_t *thisPipe;
+ int i;
+
+ assert( listPipe != NULL );
+
+ for( i = 0 ; i < listPipe->count ; i++ )
+ {
+ thisPipe = (pipe_t *)listPipe->list[i];
+ assert( thisPipe != NULL );
+ drawPipe(thisPipe);
+ }
+}
+
+pipe_t* isConflictWithListPipe(list_t *listPipe, int x, int y, int w, int h)
+{
+ pipe_t *thisPipe;
+ int i;
+
+ assert( listPipe != NULL );
+
+ for( i = 0 ; i < listPipe->count ; i++ )
+ {
+ thisPipe = (pipe_t *)listPipe->list[i];
+ assert( thisPipe != NULL );
+
+ if( conflictSpace(x, y, w, h,
+ thisPipe->x, thisPipe->y, thisPipe->w, thisPipe->h) )
+ {
+ return thisPipe;
+ }
+ }
+
+ return NULL;
+}
+
+static int negPosition(int n)
+{
+ switch( n )
+ {
+ case TUX_UP :
+ return TUX_DOWN;
+
+ case TUX_LEFT :
+ return TUX_RIGHT;
+
+ case TUX_RIGHT :
+ return TUX_LEFT;
+
+ case TUX_DOWN :
+ return TUX_UP;
+
+ default :
+ assert( ! "premenna n ma zlu hodnotu !" );
+ break;
+ }
+}
+
+static pipe_t* getPipeId(list_t *listPipe, int id)
+{
+ int i;
+
+ for( i = 0 ; i < listPipe->count ; i++ )
+ {
+ pipe_t *thisPipe;
+
+ thisPipe = (pipe_t *) listPipe->list[i];
+
+ if( thisPipe->id == id )
+ {
+ return thisPipe;
+ }
+ }
+
+ return NULL;
+}
+
+static void moveShotFromPipe(shot_t *shot, pipe_t *pipe, list_t *listPipe)
+{
+ pipe_t *distPipe;
+
+ distPipe = getPipeId(listPipe, pipe->id_out);
+
+ if( distPipe == NULL )
+ {
+ fprintf(stderr, "Pipe %d ID not found\n", pipe->id);
+ return;
+ }
+
+ moveShot(shot, distPipe->position, pipe->x, pipe->y,
+ distPipe->x, distPipe->y, distPipe->w, distPipe->h);
+}
+
+void eventConflictShotWithPipe(list_t *listPipe, list_t *listShot)
+{
+ shot_t *thisShot;
+ pipe_t *thisPipe;
+ int i;
+
+ assert( listPipe != NULL );
+ assert( listShot != NULL );
+
+ for( i = 0 ; i < listShot->count ; i++ )
+ {
+ thisShot = (shot_t *)listShot->list[i];
+ assert( thisShot != NULL );
+
+ if( ( thisPipe = isConflictWithListPipe(listPipe, thisShot->x, thisShot->y,
+ thisShot->w, thisShot->h) ) != NULL )
+ {
+ if( thisShot->author->bonus == BONUS_GHOST &&
+ thisShot->author->bonus_time > 0 )
+ {
+ continue;
+ }
+
+ if( negPosition( thisShot->position ) == thisPipe->position )
+ {
+ moveShotFromPipe(thisShot, thisPipe, listPipe);
+ }
+ else
+ {
+ delListItem(listShot, i, destroyShot);
+ i--;
+ }
+ }
+ }
+}
+
+void destroyPipe(pipe_t *p)
+{
+ assert( p != NULL );
+ free(p);
+}
+
diff --git a/src/screen_world.c b/src/screen_world.c
index b7895e6..439cefa 100644
--- a/src/screen_world.c
+++ b/src/screen_world.c
@@ -19,6 +19,8 @@
#include "sound.h"
#include "tux.h"
#include "wall.h"
+#include "teleport.h"
+#include "pipe.h"
#include "item.h"
#include "shot.h"
#include "gun.h"
@@ -178,6 +180,8 @@ void drawWorld()
drawListTux(arena->listTux);
drawListWall(arena->listWall);
+ drawListTeleport(arena->listTeleport);
+ drawListPipe(arena->listPipe);
drawListShot(arena->listShot);
drawListItem(arena->listItem);
@@ -206,6 +210,8 @@ int isFreeSpace(int x, int y, int w, int h)
if ( isConflictWithListWall(arena->listWall, x, y, w, h) )return 0;
if ( isConflictWithListShot(arena->listShot, x, y, w, h) )return 0;
if ( isConflictWithListItem(arena->listItem, x, y, w, h) )return 0;
+ if ( isConflictWithListTeleport(arena->listTeleport, x, y, w, h) )return 0;
+ if ( isConflictWithListPipe(arena->listPipe, x, y, w, h) )return 0;
return 1;
}
@@ -356,11 +362,16 @@ void eventWorld()
return;
}
- eventConflictShotWithTux(arena->listTux, arena->listShot);
+ eventConflictTuxWithTeleport(arena->listTux, arena->listTeleport);
+ eventConflictTuxWithShot(arena->listTux, arena->listShot);
+
eventConflictShotWithWall(arena->listWall, arena->listShot);
+ eventConflictShotWithTeleport(arena->listTeleport, arena->listShot);
+ eventConflictShotWithPipe(arena->listPipe, arena->listShot);
+ eventConflictShotWithItem(arena->listItem, arena->listShot);
+
eventMoveListShot(arena->listShot);
eventListItem(arena->listItem);
- eventConflictShotWithItem(arena->listItem, arena->listShot);
eventListTux(arena->listTux);
eventTimer();
diff --git a/src/shot.c b/src/shot.c
index d57d2df..48fd223 100644
--- a/src/shot.c
+++ b/src/shot.c
@@ -48,6 +48,7 @@ shot_t* newShot(int x,int y, int px, int py, int gun, tux_t *author)
new->py = py;
new->gun = gun;
new->author = author;
+ new->position = author->position;
new->isCanKillAuthor = FALSE;
switch( gun )
@@ -152,6 +153,117 @@ void eventMoveListShot(list_t *listShot)
}
}
+static int myAbs(int n)
+{
+ return ( n > 0 ? n : -n );
+}
+
+static int getSppedShot(shot_t *shot)
+{
+ return ( myAbs(shot->px) > myAbs(shot->py) ? myAbs(shot->px) : myAbs(shot->py) );
+}
+
+static void eventOnlyLasser(shot_t *shot)
+{
+ switch( shot->position )
+ {
+ case TUX_RIGHT :
+ case TUX_LEFT :
+ shot->w = GUN_LASSER_HORIZONTAL;
+ shot->h = GUN_SHOT_VERTICAL;
+ shot->img = g_shot_lasserX;
+ break;
+ case TUX_UP :
+ case TUX_DOWN :
+ shot->w = GUN_SHOT_VERTICAL;
+ shot->h = GUN_LASSER_HORIZONTAL;
+ shot->img = g_shot_lasserY;
+ break;
+ }
+}
+
+static void transformShot(shot_t *shot, int position)
+{
+ int speed;
+
+ speed = getSppedShot(shot);
+
+ switch( position )
+ {
+ case TUX_UP :
+ shot->px = 0;
+ shot->py = -speed;
+ break;
+
+ case TUX_LEFT :
+ shot->px = -speed;
+ shot->py = 0;
+ break;
+
+ case TUX_RIGHT :
+ shot->px = speed;
+ shot->py = 0;
+ break;
+
+ case TUX_DOWN :
+ shot->px = 0;
+ shot->py = +speed;
+ break;
+ }
+
+ shot->position = position;
+ shot->isCanKillAuthor = TRUE;
+
+ if( shot->gun == GUN_LASSER )
+ {
+ eventOnlyLasser(shot);
+ }
+}
+
+void moveShot(shot_t *shot, int position, int src_x, int src_y,
+ int dist_x, int dist_y, int dist_w, int dist_h)
+{
+ int offset;
+
+ switch( shot->position )
+ {
+ case TUX_UP :
+ case TUX_DOWN :
+ offset = shot->x - src_x;
+ break;
+
+ case TUX_RIGHT :
+ case TUX_LEFT :
+ offset = shot->y - src_y;
+ break;
+ }
+
+ transformShot(shot, position);
+
+ switch( shot->position )
+ {
+ case TUX_UP :
+ shot->x = dist_x + offset;
+ shot->y = dist_y;
+ break;
+
+ case TUX_LEFT :
+ shot->x = dist_x;
+ shot->y = dist_y + offset;
+ break;
+
+ case TUX_RIGHT :
+ shot->x = dist_x + dist_w;
+ shot->y = dist_y + offset;
+ break;
+
+ case TUX_DOWN :
+ shot->x = dist_x + offset;
+ shot->y = dist_y + dist_h;
+ break;
+ }
+}
+
void destroyShot(shot_t *p)
{
assert( p != NULL );
diff --git a/src/teleport.c b/src/teleport.c
new file mode 100644
index 0000000..f0d9c57
--- /dev/null
+++ b/src/teleport.c
@@ -0,0 +1,197 @@
+
+#include <stdlib.h>
+#include <assert.h>
+
+#include "tux.h"
+#include "teleport.h"
+#include "layer.h"
+#include "screen_world.h"
+#include "shot.h"
+#include "sound.h"
+
+teleport_t* newTeleport(int x, int y, int w, int h, int layer, SDL_Surface *img)
+{
+ teleport_t *new;
+
+ assert( img != NULL );
+
+ new = malloc( sizeof(teleport_t) );
+ assert( new != NULL );
+
+ new->x = x;
+ new->y = y;
+ new->w = w;
+ new->h = h;
+ new->layer = layer;
+ new->img = img;
+
+ return new;
+}
+
+void drawTeleport(teleport_t *p)
+{
+ assert( p != NULL );
+
+ addLayer(p->img, p->x, p->y, 0, 0, p->img->w, p->img->h, p->layer);
+}
+
+void drawListTeleport(list_t *listTeleport)
+{
+ teleport_t *thisTeleport;
+ int i;
+
+ assert( listTeleport != NULL );
+
+ for( i = 0 ; i < listTeleport->count ; i++ )
+ {
+ thisTeleport = (teleport_t *)listTeleport->list[i];
+ assert( thisTeleport != NULL );
+ drawTeleport(thisTeleport);
+ }
+}
+
+teleport_t* isConflictWithListTeleport(list_t *listTeleport, int x, int y, int w, int h)
+{
+ teleport_t *thisTeleport;
+ int i;
+
+ assert( listTeleport != NULL );
+
+ for( i = 0 ; i < listTeleport->count ; i++ )
+ {
+ thisTeleport = (teleport_t *)listTeleport->list[i];
+ assert( thisTeleport != NULL );
+
+ if( conflictSpace(x, y, w, h,
+ thisTeleport->x, thisTeleport->y, thisTeleport->w, thisTeleport->h) )
+ {
+ return thisTeleport;
+ }
+ }
+
+ return NULL;
+}
+
+static teleport_t* getRandomTeleportBut(list_t *listTeleport, teleport_t *teleport)
+{
+ int x;
+
+ do{
+ x = random() % listTeleport->count;
+ }while( listTeleport->list[x] == teleport );
+
+ return (teleport_t *) listTeleport->list[x];
+}
+
+static int getRandomPosition()
+{
+ switch( random() % 4 )
+ {
+ case 0 :
+ return TUX_UP;
+
+ case 1 :
+ return TUX_LEFT;
+
+ case 2 :
+ return TUX_RIGHT;
+
+ case 3 :
+ return TUX_DOWN;
+ }
+
+ assert( ! "Stupid error ! " );
+}
+
+static void moveShotFromTeleport(shot_t *shot, teleport_t *teleport, list_t *listTeleport)
+{
+ teleport_t *distTeleport;
+
+ distTeleport = getRandomTeleportBut(listTeleport, teleport);
+
+ moveShot(shot, getRandomPosition(), teleport->x, teleport->y,
+ distTeleport->x, distTeleport->y, distTeleport->w, distTeleport->h);
+}
+
+void eventConflictShotWithTeleport(list_t *listTeleport, list_t *listShot)
+{
+ shot_t *thisShot;
+ teleport_t *thisTeleport;
+ int i;
+
+ assert( listTeleport != NULL );
+ assert( listShot != NULL );
+
+ for( i = 0 ; i < listShot->count ; i++ )
+ {
+ thisShot = (shot_t *)listShot->list[i];
+ assert( thisShot != NULL );
+
+ if( ( thisTeleport = isConflictWithListTeleport(listTeleport, thisShot->x, thisShot->y, thisShot->w, thisShot->h) ) != NULL )
+ {
+ if( thisShot->author->bonus == BONUS_GHOST &&
+ thisShot->author->bonus_time > 0 )
+ {
+ continue;
+ }
+
+ moveShotFromTeleport(thisShot, thisTeleport, listTeleport);
+ }
+ }
+}
+
+void eventTeleportTux(list_t *listTeleport, teleport_t *teleport, tux_t *tux)
+{
+ teleport_t *distTeleport;
+ int current_x, current_y;
+ int dist_x, dist_y;
+
+ if( tux->bonus == BONUS_GHOST )
+ {
+ return;
+ }
+
+ distTeleport = getRandomTeleportBut(listTeleport, teleport);
+
+ getTuxProportion(tux, &current_x, &current_y, NULL, NULL);
+
+ switch( tux->position )
+ {
+ case TUX_UP :
+ dist_x = distTeleport->x + distTeleport->w/2;
+ dist_y = distTeleport->y - ( TUX_HEIGHT + 10 );
+ break;
+
+ case TUX_LEFT :
+ dist_y = distTeleport->y + distTeleport->h/2;
+ dist_x = distTeleport->x - ( TUX_WIDTH + 10 );
+ break;
+
+ case TUX_RIGHT :
+ dist_y = distTeleport->y + distTeleport->h/2;
+ dist_x = distTeleport->x + distTeleport->w + 10;
+ break;
+
+ case TUX_DOWN :
+ dist_x = distTeleport->x + distTeleport->w/2;
+ dist_y = distTeleport->y + distTeleport->h + 10;
+ break;
+
+ default :
+ assert( ! "premenna p->control ma zlu hodnotu !" );
+ break;
+ }
+
+ if( isFreeSpace(dist_x, dist_y, TUX_WIDTH, TUX_HEIGHT) )
+ {
+ setTuxProportion(tux, dist_x, dist_y);
+ playSound("teleport", SOUND_GROUP_BASE);
+ }
+}
+
+void destroyTeleport(teleport_t *p)
+{
+ assert( p != NULL );
+ free(p);
+}
+
diff --git a/src/tux.c b/src/tux.c
index 31964b6..8180094 100644
--- a/src/tux.c
+++ b/src/tux.c
@@ -13,6 +13,8 @@
#include "shot.h"
#include "gun.h"
#include "wall.h"
+#include "teleport.h"
+#include "pipe.h"
#include "item.h"
#include "arena.h"
#include "myTimer.h"
@@ -385,7 +387,7 @@ void tuxTeleport(tux_t *tux)
}
}
-void eventConflictShotWithTux(list_t *listTux, list_t *listShot)
+void eventConflictTuxWithShot(list_t *listTux, list_t *listShot)
{
shot_t *thisShot;
tux_t *thisTux;
@@ -428,6 +430,29 @@ void eventConflictShotWithTux(list_t *listTux, list_t *listShot)
}
}
+void eventConflictTuxWithTeleport(list_t *listTux, list_t *listTeleport)
+{
+ teleport_t *thisTeleport;
+ tux_t *thisTux;
+
+ int i;
+
+ assert( listTux != NULL );
+ assert( listTeleport != NULL );
+
+ for( i = 0 ; i < listTeleport->count ; i++ )
+ {
+ thisTeleport = (teleport_t *)listTeleport->list[i];
+ assert( thisTeleport != NULL );
+
+ if( ( thisTux = isConflictWithListTux(listTux, thisTeleport->x, thisTeleport->y,
+ thisTeleport->w, thisTeleport->h) ) != NULL )
+ {
+ eventTeleportTux(listTeleport, thisTeleport, thisTux);
+ }
+ }
+}
+
void moveTux(tux_t *tux, int n)
{
int px, py;
@@ -480,9 +505,11 @@ void moveTux(tux_t *tux, int n)
getTuxProportion(tux, &x, &y, &w, &h);
+
if( tux->bonus != BONUS_GHOST && (
isConflictTuxWithListTux(tux, arena->listTux) ||
- isConflictWithListWall(arena->listWall, x, y, w, h) ) )
+ isConflictWithListWall(arena->listWall, x, y, w, h) ||
+ isConflictWithListPipe(arena->listPipe, x, y, w, h) ) )
{
tux->x = zal_x;
tux->y = zal_y;
diff --git a/src/zal_pipe.c b/src/zal_pipe.c
new file mode 100644
index 0000000..65ba6b2
--- /dev/null
+++ b/src/zal_pipe.c
@@ -0,0 +1,256 @@
+
+#include <stdlib.h>
+#include <assert.h>
+
+#include "pipe.h"
+#include "layer.h"
+#include "screen_world.h"
+#include "shot.h"
+
+pipe_t* newPipe(int x, int y, int w, int h, int layer, int id, int id_out, int position, SDL_Surface *img)
+{
+ pipe_t *new;
+
+ assert( img != NULL );
+
+ new = malloc( sizeof(pipe_t) );
+ assert( new != NULL );
+
+ new->x = x;
+ new->y = y;
+ new->w = w;
+ new->h = h;
+ new->layer = layer;
+ new->id = id;
+ new->id_out = id_out;
+ new->position = position;
+ new->img = img;
+
+ return new;
+}
+
+void drawPipe(pipe_t *p)
+{
+ assert( p != NULL );
+
+ addLayer(p->img, p->x, p->y, 0, 0, p->img->w, p->img->h, p->layer);
+}
+
+void drawListPipe(list_t *listPipe)
+{
+ pipe_t *thisPipe;
+ int i;
+
+ assert( listPipe != NULL );
+
+ for( i = 0 ; i < listPipe->count ; i++ )
+ {
+ thisPipe = (pipe_t *)listPipe->list[i];
+ assert( thisPipe != NULL );
+ drawPipe(thisPipe);
+ }
+}
+
+pipe_t* isConflictWithListPipe(list_t *listPipe, int x, int y, int w, int h)
+{
+ pipe_t *thisPipe;
+ int i;
+
+ assert( listPipe != NULL );
+
+ for( i = 0 ; i < listPipe->count ; i++ )
+ {
+ thisPipe = (pipe_t *)listPipe->list[i];
+ assert( thisPipe != NULL );
+
+ if( conflictSpace(x, y, w, h,
+ thisPipe->x, thisPipe->y, thisPipe->w, thisPipe->h) )
+ {
+ return thisPipe;
+ }
+ }
+
+ return NULL;
+}
+
+static int negPosition(int n)
+{
+ switch( n )
+ {
+ case TUX_UP :
+ return TUX_DOWN;
+
+ case TUX_LEFT :
+ return TUX_RIGHT;
+
+ case TUX_RIGHT :
+ return TUX_LEFT;
+
+ case TUX_DOWN :
+ return TUX_UP;
+
+ default :
+ assert( ! "premenna n ma zlu hodnotu !" );
+ break;
+ }
+}
+
+static pipe_t* getPipeId(list_t *listPipe, int id)
+{
+ int i;
+
+ for( i = 0 ; i < listPipe->count ; i++ )
+ {
+ pipe_t *thisPipe;
+
+ thisPipe = (pipe_t *) listPipe->list[i];
+
+ if( thisPipe->id == id )
+ {
+ return thisPipe;
+ }
+ }
+
+ return NULL;
+}
+
+static int myAbs(int n)
+{
+ return ( n > 0 ? n : -n );
+}
+
+static int getSppedShot(shot_t *shot)
+{
+ return ( myAbs(shot->px) > myAbs(shot->py) ? myAbs(shot->px) : myAbs(shot->py) );
+}
+
+static void transformShot(shot_t *shot, int position)
+{
+ int speed;
+
+ speed = getSppedShot(shot);
+
+ switch( position )
+ {
+ case TUX_UP :
+ shot->px = 0;
+ shot->py = -speed;
+ break;
+
+ case TUX_LEFT :
+ shot->px = -speed;
+ shot->py = 0;
+ break;
+
+ case TUX_RIGHT :
+ shot->px = speed;
+ shot->py = 0;
+ break;
+
+ case TUX_DOWN :
+ shot->px = 0;
+ shot->py = +speed;
+ break;
+
+ }
+
+ shot->position = position;
+ shot->isCanKillAuthor = TRUE;
+}
+
+static void moveShot(shot_t *shot, pipe_t *pipe, list_t *listPipe)
+{
+ pipe_t *distPipe;
+ int offset;
+
+ distPipe = getPipeId(listPipe, pipe->id_out);
+
+ if( distPipe == NULL )
+ {
+ fprintf(stderr, "Pipe %d ID not found\n", pipe->id);
+ return;
+ }
+
+ printf("XXX\n");
+
+ switch( shot->position )
+ {
+ case TUX_UP :
+ case TUX_DOWN :
+ offset = shot->x - pipe->x;
+ break;
+
+ case TUX_RIGHT :
+ case TUX_LEFT :
+ offset = shot->y - pipe->y;
+ break;
+ }
+
+ transformShot(shot, distPipe->position);
+
+ switch( shot->position )
+ {
+ case TUX_UP :
+ shot->x = distPipe->x + offset;
+ shot->y = distPipe->y;
+ break;
+
+ case TUX_LEFT :
+ shot->x = distPipe->x;
+ shot->y = distPipe->y + offset;
+ break;
+
+ case TUX_RIGHT :
+ shot->x = distPipe->x + distPipe->w;
+ shot->y = distPipe->y + offset;
+ break;
+
+ case TUX_DOWN :
+ shot->x = distPipe->x + offset;
+ shot->y = distPipe->y + distPipe->h;
+ break;
+ }
+}
+
+void eventConflictShotWithPipe(list_t *listPipe, list_t *listShot)
+{
+ shot_t *thisShot;
+ pipe_t *thisPipe;
+ int i;
+
+ assert( listPipe != NULL );
+ assert( listShot != NULL );
+
+ for( i = 0 ; i < listShot->count ; i++ )
+ {
+ thisShot = (shot_t *)listShot->list[i];
+ assert( thisShot != NULL );
+
+ if( ( thisPipe = isConflictWithListPipe(listPipe, thisShot->x, thisShot->y,
+ thisShot->w, thisShot->h) ) != NULL )
+ {
+ if( thisShot->author->bonus == BONUS_GHOST &&
+ thisShot->author->bonus_time > 0 )
+ {
+ continue;
+ }
+
+ if( negPosition( thisShot->position ) == thisPipe->position )
+ {
+ moveShot(thisShot, thisPipe, listPipe);
+ }
+ else
+ {
+ delListItem(listShot, i, destroyShot);
+ i--;
+ }
+ }
+ }
+}
+
+void destroyPipe(pipe_t *p)
+{
+ assert( p != NULL );
+ free(p);
+}
+
diff --git a/tuxanci-ng.desktop b/tuxanci-ng.desktop
new file mode 100644
index 0000000..45ed4b0
--- /dev/null
+++ b/tuxanci-ng.desktop
@@ -0,0 +1,9 @@
+[Desktop Entry]
+Name=tuxanci-ng
+Comment=game tuxanci next generation
+Exec=/usr/bin/tuxanci-ng
+Terminal=false
+Type=Application
+Icon=/usr/share/tuxanci-ng/image/tuxanci.png
+Encoding=UTF-8
+Categories=Game