summaryrefslogtreecommitdiff
path: root/src/teleport.c
diff options
context:
space:
mode:
authororoborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-03-07 21:12:57 +0000
committeroroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-03-07 21:12:57 +0000
commit858f01dedbb681c8e62c9dae4d7c3174991844bf (patch)
treeefe86d519ff4965373b1a2fe1f59b30e14d73d7e /src/teleport.c
parent44404eb5063bd5f040c7a4d8605aa3d43e3a968a (diff)
-podpora teleportov
-podpora rur git-svn-id: http://opensvn.csie.org/tuxanci_ng@9 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src/teleport.c')
-rw-r--r--src/teleport.c197
1 files changed, 197 insertions, 0 deletions
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);
+}
+