Added Pachi el Martiano game, it's 640x480 so it's slow like hell

This commit is contained in:
pelya
2010-10-27 19:41:25 +03:00
parent 98a405a96a
commit 584a43282d
36 changed files with 4223 additions and 7 deletions

View File

@@ -0,0 +1,56 @@
char creditstext[] =
" CONGRATULATIONS!!! \0"
" YOU WON THE GAME!! \0"
" \0"
" NOW THANKS TO YOU, \0"
" THE MISTERY IS SOLVED AND PACHI \0"
" WILL BE ABLE TO GO BACK TO MARS, \0"
" PLAY martian memory \0"
" AND VISIT \0"
" dragontech.sourceforge.net \0"
" \0"
" \0"
" \0"
" \0"
" AND NOW THE CREDITS \0"
" \0"
" PROJECT MANAGER, PROGRAMMER: \0"
" santiago radeff \0"
" \0"
" DRAWINGS, PACHI FATHER \0"
" nicolas radeff \0"
" \0"
" GRAPHICS: \0"
" nicolas radeff \0"
" santiago radeff \0"
" \0"
" MUSICS COMPOSED BY \0"
" peter -skaven- hajba \0"
" \0"
" \0"
" \0"
" \0"
" THANKS TO THE PROGRAMMERS, \0"
" AND PLAYERS FOR THEIR SUPPORT \0"
" \0"
" \0"
" \0"
" \0"
" \0"
" \0"
" \0"
" \0"
" \0"
" \0"
" \0"
" ThAnKs fOr pLaYiNg \0"
" \0";
int creditslines = 46; // esta variable determina cuantas lineas de texto hay en los creditos
int creditslinecounter = 0; // esta variable almacena que linea de texto dee imprimirse (es un contador)
int needinput = 1; // esta variable indica si debe imprimirse una nueva linea de texto en los creditos
int linegone = 0; // esta variable indica cuando una linea de texto ya hizo scroll por completo para imprimir la proxima
int wrapcounter = 0; // esta variable es un contador que una vez que termino el texto de los creditos empieza a incrementarse y cuando llega a cierto valor reinicia los creditos
char curchar;
int charcounter;

View File

@@ -0,0 +1,130 @@
SDL_Joystick * joystick;
enum joynames {JOY_LEFT, JOY_RIGHT, JOY_UP, JOY_DOWN, JOY_BUTTON0, JOY_BUTTON1};
Uint8 joypos[JOY_BUTTON1+1]={0,0,0,0,0,0};
// --- Screen related
#define screen_w 800
#define screen_h 600
#define screen_bpp 16
// --- Room related
#define R_tileside 32
#define R_maxobjects 5
#define R_max_x 40
#define R_max_y 10
#define R_gamearea_x 28
#define R_gamearea_y 15
#define R_maxtiles_h 23
#define R_maxtiles_v 14
#define R_back_x 92
#define R_back_y 112
#define R_maxbacks_h 8
#define R_maxbacks_v 4
int R_current; // habitacion actual
int R_backdata[R_maxbacks_h][R_maxbacks_v]; //esta matriz contiene la informacion sobre el fondo del nivel actual
int R_x; // variable utilizada para ubicar la habitacion actual en la matriz
int R_y; // variable utilizada para ubicar la habitacion actual en la matriz
int R_object;
int roommap[R_max_x][R_max_y]; // mapeado de habitaciones, aca se comprueba que habitaciones pertenecen a cada stage
int chk_exits;
int objects; // cantidad de objetos en la stage actual
int score = 0;
int gameexit, startgame, help, hiscores;
// --- Timing related
double playtime;
double roomtime;
// -- FX related
int brightframe;
int sequence; // variable que almacena cual es el objeto siguiente en la secuencia (para recogerlos por orden)
int fadingobject; // esta variable indica si un objeto es esta desvaneciendo
float alphade;
#define arrow_left 1
#define arrow_right 2
#define arrow_up 3
#define arrow_down 4
int namechar;
int gameover=0;
// --- Scores related
char playername[]=" ";
char scorename[10][10];
int scorestage[10];
int scoretime[10];
int scoredif[10];
int scorescore[10];
int scorepos;
int codechar;
char code[]="....";
int inputloop;
int menuvalue = 1;
int fullscreen = 1;
int dificulty = 2;
// --- Monsters related
#define M_w 48
#define M_h 48
#define M_frames 6
#define M_max4room 10
#define M_easyspeed 130
#define M_normalspeed 150
#define M_hardspeed 200
int M_type[M_max4room];// el 10 es el maximo de monstruos en pantalla
float M_x[M_max4room]; // el 10 es el maximo de monstruos en pantalla
float M_y[M_max4room];// el 10 es el maximo de monstruos en pantalla
float M_old_x[M_max4room];// el 10 es el maximo de monstruos en pantalla
float M_old_y[M_max4room];// el 10 es el maximo de monstruos en pantalla
int M_direction[M_max4room]; // estas variables se usan para saber si el monstruo va hacia un lado o hacia otro
int M_frame = 1;
int monsters_c; // cantidad de monstruos en la pantalla actual
int M_initspeed=M_normalspeed;
int M_speed[4];
SDL_Rect monstersrc;
SDL_Rect monsterpos;
SDL_Rect monsterposreal;
SDL_Rect oldmonsterpos;
SDL_Rect oldmonsterposreal;
// --- Player related
#define maxlives 10
#define P_h 64
#define P_w 48
int respawned=0; // variable que indica cuando el personaje termino de aparecer despues de morirse
SDL_Rect playersrc; // esto es para leer del bmp del player el frame a imprimir
SDL_Rect playerpos; // esta es la posicion en la pantalla del player (sin contar los bordes del panel)
SDL_Rect playerposreal; // esta es la posicion en la pantalla del player (contando los bordes del panel) se utiliza automaticamente
SDL_Rect oldplayerpos; //esta es la posicion que abandona el player
SDL_Rect oldplayerposreal; //esta es la posicion que abandona el player (contando los bordes del panel)
// --- Timing related
Uint32 lasttime=0;
Uint32 curtime=0;
double imove=0;
double gametimer=0;
int minutes, seconds;
int oldsec; // variable que almacena el valor de los segundos
float animcounter = 0; //contador usado para las animaciones de los enemigos y del personaje
int escape_exit;
int game_exit;
// --- Stage Related
#define NUM_STAGES 16
#define CEMETERY 1
#define CAVES 7
#define CASTLE 10
#define LAB 16
#define END 17
int startstage = 0; // stage inicial
int stage; //stage actual
int stagecompleted = 0; // esta variable es un flag que se pone en 1 cuando se agarran todos los objetos del nivel

View File

@@ -0,0 +1,94 @@
/***************************************************************************
* Pachi el marciano *
* ----------------- *
* (c) Santiago Radeff (coding) *
* (c) Nicolas Radeff (graphics) *
* (c) Peter Hajba (music) *
* *
* T-1000@Bigfoot.com *
****************************************************************************
*******************************************************************
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version *
* 2 of the License, or (at your option) any later version. *
* *
*******************************************************************/
#include<stdio.h>
#include<stdlib.h>
#include<stdarg.h>
#include<string.h>
#include<SDL/SDL.h>
#include<SDL/SDL_mixer.h>
#include"definitions.h"
#include"structs.h"
#include"surfaces.h"
#include"sounds.h"
#include"config.h"
#include"proto.h"
#include"credits.h"
#include"text.h"
#include"init.h"
#include"gfx.h"
#include"input.h"
#include"file.h"
#include"output.h"
#include"stages.h"
#include"menu.h"
#include"intro.h"
#include"gameover.h"
#include"player.h"
#include"monsters.h"
#include"game.h"
#include"fx.h"
#include"setgame.h"
void flushevents()
{
SDL_Event event;
while(SDL_PollEvent(&event)==1);
}
int main(int argc, char *argv[])
{
initsdl();
if(argc > 1)
if(strcmp(argv[1], "--fullscreen")==0 || strcmp(argv[1], "-f")==0)
screen_mode();
gameexit=0;
startgame=0;
intro();
init_stages(); // carga los valores de los niveles del juego
load_roommap(); // carga el mapeado de habitaciones
while(gameexit==0)
{
flushevents();
menu();
if(startgame==1)
{
startgame=0;
start_game();
}
if(help==1)
{
help=0;
do_help();
}
if(hiscores==1)
{
hiscores=0;
do_hiscores();
}
}
// outro();
SDL_JoystickClose(joystick);
SDL_Quit();
fprintf(stderr,"\nThanks for playing.\n");
return 0;
}

View File

@@ -0,0 +1,299 @@
/***************************************************************************
* Pachi el marciano *
* ----------------- *
* (c) Santiago Radeff (coding) *
* (c) Nicolas Radeff (graphics) *
* (c) Peter Hajba (music) *
* *
* T-1000@Bigfoot.com *
****************************************************************************
*******************************************************************
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version *
* 2 of the License, or (at your option) any later version. *
* *
*******************************************************************/
void load_gamedata()
{
background=LoadT8(DATADIR"/Tgfx/gamepanel.T8");
backs=LoadT8(DATADIR"/Tgfx/backgrounds.T8");
player=LoadT8(DATADIR"/Tgfx/pachi.T8");
monsters=LoadT8(DATADIR"/Tgfx/monsters.T8");
tiles=LoadT8(DATADIR"/Tgfx/tiles.T8");
bright=LoadT8(DATADIR"/Tgfx/bright.T8");
left=LoadT8(DATADIR"/Tgfx/left.T8");
right=LoadT8(DATADIR"/Tgfx/right.T8");
menufont=LoadT8(DATADIR"/fonts/font32v.T8");
LoadT(&scorefont,DATADIR"/fonts/font16b.T");
LoadT(&scorefont1,DATADIR"/fonts/font16a.T");
LoadT(&scorefont2,DATADIR"/fonts/font16c.T");
SDL_Surface *temp;
temp = SDL_CreateRGBSurface(SDL_SWSURFACE,736,448,16,0,0,0,0); //esto es para reestablecer la pantalla
screenbak = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
SDL_SetColorKey(menufont, SDL_SRCCOLORKEY, SDL_MapRGB(menufont->format,0,255,0));
SDL_SetColorKey(monsters, SDL_SRCCOLORKEY, SDL_MapRGB(monsters->format,0,255,0));
SDL_SetColorKey(player, SDL_SRCCOLORKEY, SDL_MapRGB(player->format,0,0,0)); // el negro es transparente
SDL_SetColorKey(tiles, SDL_SRCCOLORKEY, SDL_MapRGB(tiles->format,0,255,0));
SDL_SetColorKey(bright, SDL_SRCCOLORKEY, SDL_MapRGB(bright->format,0,255,0));
SDL_SetAlpha(bright, SDL_SRCALPHA, 128);
SDL_SetColorKey(left, SDL_SRCCOLORKEY, SDL_MapRGB(left->format,0,0,0));
SDL_SetColorKey(right, SDL_SRCCOLORKEY, SDL_MapRGB(right->format,0,0,0));
jump = Mix_LoadWAV(DATADIR"/sounds/jump.wav");
obj = Mix_LoadWAV(DATADIR"/sounds/obj.wav");
objseq = Mix_LoadWAV(DATADIR"/sounds/objseq.wav");
die = Mix_LoadWAV(DATADIR"/sounds/die.wav");
timer = Mix_LoadWAV(DATADIR"/sounds/timer.wav");
exitlevel = Mix_LoadWAV(DATADIR"/sounds/exit.wav");
stageready = Mix_LoadWAV(DATADIR"/sounds/stageready.wav");
storm = Mix_LoadWAV(DATADIR"/sounds/storm.wav");
respawnsnd = Mix_LoadWAV(DATADIR"/sounds/respawn.wav");
}
void unload_gamedata()
{
SDL_FreeSurface(background);
SDL_FreeSurface(tiles);
SDL_FreeSurface(backs);
SDL_FreeSurface(player);
SDL_FreeSurface(bright);
SDL_FreeSurface(monsters);
SDL_FreeSurface(screenbak);
SDL_FreeSurface(scorefont);
SDL_FreeSurface(scorefont1);
SDL_FreeSurface(scorefont2);
SDL_FreeSurface(menufont);
SDL_FreeSurface(left);
SDL_FreeSurface(right);
Mix_FreeChunk(exitlevel);
Mix_FreeChunk(jump);
Mix_FreeChunk(obj);
Mix_FreeChunk(die);
Mix_FreeChunk(timer);
Mix_FreeChunk(storm);
Mix_FreeChunk(stageready);
Mix_FreeChunk(respawnsnd);
}
void stop_music()
{
if(Mix_PlayingMusic())
{
Mix_FadeOutMusic(1000);
SDL_Delay(1000);
Mix_FreeMusic(music);
}
}
void load_hiscoredata()
{
background=LoadT8(DATADIR"/Tgfx/gameover.T8");
LoadT(&scorefont,DATADIR"/fonts/font16b.T");
LoadT(&scorefont1,DATADIR"/fonts/font16d.T");
FILE *file = fopen(SCOREDIR"/data/scores.dat","rb");
for(int a=0; a < 10; a++)
{
for(int b=0; b < 10; b++)
{
scorename[a][b]=getc(file);
}
scorestage[a]=getc(file);
int lobyte,hibyte,vhibyte;
hibyte=getc(file);
lobyte=getc(file);
scoretime[a]=(hibyte*256)+lobyte;
scoredif[a]=getc(file);
vhibyte=getc(file);
hibyte=getc(file);
lobyte=getc(file);
scorescore[a]=(vhibyte*65536)+(hibyte*256)+lobyte;
}
fclose(file);
}
void unload_hiscoredata()
{
SDL_FreeSurface(background);
SDL_FreeSurface(scorefont);
SDL_FreeSurface(scorefont1);
}
void save_hiscoredata()
{
FILE *file = fopen(SCOREDIR"/data/scores.dat","rb+");
for(int a=0;a<10;a++)
{
for(int b=0;b<10;b++)
{
putc(scorename[a][b],file);
}
putc(scorestage[a],file);
int lobyte,hibyte,vhibyte;
hibyte=int(scoretime[a]/256);
lobyte=int(scoretime[a]-(hibyte+256));
putc(hibyte,file);
putc(lobyte,file);
putc(scoredif[a],file);
vhibyte=int(scorescore[a]/65536);
hibyte=int((scorescore[a] - (scorescore[a]/65536))/256);
lobyte=int(scorescore[a] - (vhibyte*65536 + hibyte*256));
putc(vhibyte,file);
putc(hibyte,file);
putc(lobyte,file);
}
fclose(file);
}
void load_helpgfx()
{
background=LoadT8(DATADIR"/Tgfx/help.T8");
LoadT(&scorefont,DATADIR"/fonts/font16b.T");
LoadT(&scorefont1,DATADIR"/fonts/font16a.T");
SDL_SetColorKey(scorefont, SDL_SRCCOLORKEY, SDL_MapRGB(scorefont->format,0,0,0));
SDL_SetColorKey(scorefont1, SDL_SRCCOLORKEY, SDL_MapRGB(scorefont1->format,0,0,0));
}
void unload_helpgfx()
{
SDL_FreeSurface(background);
SDL_FreeSurface(scorefont);
SDL_FreeSurface(scorefont1);
}
void load_menudata()
{
menufont=LoadT8(DATADIR"/fonts/font32v.T8");
menufont1=LoadT8(DATADIR"/fonts/font32r.T8");
background=LoadT8(DATADIR"/Tgfx/intro.T8");
SDL_SetColorKey(menufont, SDL_SRCCOLORKEY, SDL_MapRGB(menufont->format,0,255,0));
SDL_SetColorKey(menufont1, SDL_SRCCOLORKEY, SDL_MapRGB(menufont1->format,0,255,0));
option=Mix_LoadWAV(DATADIR"/sounds/option.wav");
coderight=Mix_LoadWAV(DATADIR"/sounds/exit.wav");
codewrong=Mix_LoadWAV(DATADIR"/sounds/die.wav");
music=Mix_LoadMUS(DATADIR"/music/menu.s3m.ogg");
}
void unload_menudata()
{
SDL_FreeSurface(menufont);
SDL_FreeSurface(menufont1);
SDL_FreeSurface(background);
Mix_FreeChunk(option);
Mix_FreeChunk(coderight);
Mix_FreeChunk(codewrong);
}
void init_monsters()
{
FILE *mnstr = fopen(DATADIR"/data/monsters.dat","rb");
long filepos = ((R_current-1) * M_max4room*3);
fseek(mnstr,filepos,SEEK_SET);
for(int n=0;n<=M_max4room-1;n++)
{
M_type[n]=getc(mnstr);
M_x[n]=getc(mnstr)*R_tileside;
M_y[n]=getc(mnstr)*R_tileside-M_h+R_tileside;
}
fclose(mnstr);
}
void load_room()
{
long filepos;
FILE *bck = fopen(DATADIR"/data/backs.dat","rb");
filepos = (R_current - 1) * (R_maxbacks_h*R_maxbacks_v); // filepos es el puntero del archivo, lo utilizamos para leer la habitacion donde estemos
fseek(bck,filepos,SEEK_SET);
int x, y;
for(y = 0;y < R_maxbacks_v; y++)
{
for(x = 0;x < R_maxbacks_h; x++)
{
R_backdata[x][y]=getc(bck);
}
}
fclose(bck);
FILE *lvl = fopen(DATADIR"/data/rooms_v2.dat","rb");
filepos = (200 + ((R_current-1) * (R_maxtiles_h*R_maxtiles_v))+R_current); // filepos es el puntero del archivo, lo utilizamos para leer la habitacion donde estemos
fseek(lvl,filepos,SEEK_SET);
for(y = 0;y < R_maxtiles_v;y++)
{
for(x = 0;x < R_maxtiles_h; x++)
{
mroom.data[x][y]=getc(lvl);
}
}
fclose(lvl);
int contador;
for(contador=0;contador < 5; contador++)
{
R_object=mobject[((R_current-1)*5)+contador].type;
x=mobject[((R_current-1)*5)+contador].x;
y=mobject[((R_current-1)*5)+contador].y;
if(R_object != 0)
mroom.data[x][y]=R_object;
}
}
void load_roommap()
{
long filepos;
int x, y;
FILE *lvl = fopen(DATADIR"/data/rooms_v2.dat","rb");
for(y = 0;y < R_max_y;y++)
{
for(x = 0;x < R_max_x; x++)
{
filepos=((x+1)*(R_maxtiles_h*R_maxtiles_v)+(x+1))+(y*(R_max_x*(R_maxtiles_h*R_maxtiles_v)+R_max_x));
fseek(lvl,200+filepos,SEEK_SET);
roommap[x][y]=getc(lvl);
}
}
fclose(lvl);
}
void init_objects() // esta rutina copia en la matriz objects el archivo objects.dat
{
FILE *obj = fopen(DATADIR"/data/objects_v2.dat","rb");
for(int n=0;n<2000;n++)
{
mobject[n].type=getc(obj);
mobject[n].x=getc(obj);
mobject[n].y=getc(obj);
mobject[n].seq=getc(obj);
mobject[n].stage=getc(obj);
}
fclose(obj);
}
void initcredits()
{
creditslinecounter=0;
background=LoadT8(DATADIR"/Tgfx/endcredits.T8");
creditsfont=LoadT8(DATADIR"/fonts/font1.T8");
SDL_SetColorKey(creditsfont, SDL_SRCCOLORKEY, SDL_MapRGB(creditsfont->format,0,255,0));
SDL_Surface *temp;
temp = SDL_CreateRGBSurface(SDL_SWSURFACE,600,440,16,0,0,0,0);
creditsbuffer = SDL_DisplayFormat(temp);
creditsbuffer1 = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
setback();
music = Mix_LoadMUS(DATADIR"/music/credits.s3m.ogg");
}
void unloadcredits()
{
SDL_FreeSurface(creditsbuffer);
SDL_FreeSurface(creditsbuffer1);
SDL_FreeSurface(background);
SDL_FreeSurface(creditsfont);
}

View File

@@ -0,0 +1,181 @@
/*
Rutina de efectos especiales
*/
SDL_Surface *fadeobject;
SDL_Rect fadingpos; // posicion del objeto que esta desvaneciendose
SDL_Rect realfadingpos; // posicion del objeto que esta desvaneciendose en el area de juego
float fade_y;
float scanpos_y=R_gamearea_y - (P_h*P_h);
void respawn() // rutina que hace reaparecer a Pachi
{
int scanspeed=1500;
SDL_Rect P_oldscansrect[P_h];
SDL_Rect P_scansrect[P_h];
SDL_Rect P_srcscan[P_h];
//imprimimos los scans
for(int a=P_h-1;a>=0;a--)
{
P_scansrect[a].x=int(mplayer[dificulty].x+R_gamearea_x);P_scansrect[a].w=mplayer[dificulty].w;P_scansrect[a].h=1;
P_scansrect[a].y=int(scanpos_y+(a*P_h));
P_srcscan[a].h=1;P_srcscan[a].w=mplayer[dificulty].w;P_srcscan[a].x=(mplayer[dificulty].w*(mplayer[dificulty].frame));P_srcscan[a].y=0+a;
P_oldscansrect[a]=P_scansrect[a];
if((P_scansrect[a].y<mplayer[dificulty].y+R_gamearea_y+P_h-(P_h-a))&&(P_scansrect[a].y>R_gamearea_y))
{
SDL_BlitSurface(player,&P_srcscan[a],screen,&P_scansrect[a]);
SDL_UpdateRect(screen,P_scansrect[a].x,P_scansrect[a].y,P_scansrect[a].w,P_scansrect[a].h);
}
}
if(scanpos_y<mplayer[dificulty].y+P_h)
scanpos_y+=scanspeed*imove;
else
{
scanpos_y=R_gamearea_y - (P_h*P_h);
respawned=1;
imove=0.01;
SDL_Flip(screen);
}
//borramos los scans recuperando el fondo que habia antes
SDL_Rect bakscansrect[P_h];
for(int a=P_h-1;a>=0;a--)
{
bakscansrect[a]=P_oldscansrect[a];
P_oldscansrect[a].x-=R_gamearea_x;
P_oldscansrect[a].y-=R_gamearea_y;
SDL_BlitSurface(screenbak,&P_oldscansrect[a],screen,&bakscansrect[a]);
}
}
void initfade_object(int x, int y, int object)
{
alphade=255;
object-=200;
fadeobject=SDL_CreateRGBSurface(SDL_SWSURFACE,R_tileside,R_tileside,16,0,0,0,0);
SDL_SetColorKey(fadeobject,SDL_SRCCOLORKEY,(fadeobject->format,0,255,0));
SDL_Rect objectsrc;
objectsrc.w=R_tileside;objectsrc.h=R_tileside;
objectsrc.y=R_tileside*10;objectsrc.x=R_tileside*object;
SDL_BlitSurface(tiles,&objectsrc,fadeobject,NULL);
fadingpos.x=x*R_tileside;fadingpos.y=y*R_tileside;
fadingpos.w=R_tileside;fadingpos.h=R_tileside;
fade_y=fadingpos.y;
}
float fade_object(float alpha)
{
int fadealpha = int(alpha);
SDL_SetAlpha(fadeobject,SDL_SRCALPHA,fadealpha);
realfadingpos.x=R_gamearea_x+fadingpos.x;realfadingpos.y=R_gamearea_y+fadingpos.y;realfadingpos.w=fadingpos.w;realfadingpos.h=fadingpos.h;
SDL_BlitSurface(screenbak,&fadingpos,screen,&realfadingpos);
SDL_BlitSurface(fadeobject,NULL,screen,&realfadingpos);
SDL_UpdateRect(screen,realfadingpos.x,realfadingpos.y,realfadingpos.w,realfadingpos.h+2);
if(fadealpha<5)
{
fadingobject=0;
SDL_BlitSurface(screenbak,&fadingpos,screen,&realfadingpos);
print_room();
SDL_Flip(screen);
}
else
{
alpha-=500*imove;
fade_y-=150*imove;
if(fade_y<32)
fade_y+=150*imove;
fadingpos.y=int(fade_y);
}
return(alpha);
}
void screen_fx()
{
Mix_Volume(7,128);
if(seconds==15 || seconds==45)
{
if(stage<6) // en el cementerio
{
if(int(oldsec-1)==int(seconds))
{
Mix_PlayChannel(7,storm,0);
blinkscreen(220,220,255,128);
load_room();
print_room();
}
}
}
}
void bright_obj(int bright_x, int bright_y)
{
SDL_Rect brsrc;
brsrc.x=(brightframe*40);
brsrc.y=0;brsrc.w=40;brsrc.h=40;
SDL_Rect brdst;
brdst.x=bright_x*R_tileside-4;brdst.y=bright_y*R_tileside-4;brdst.w=40;brdst.h=40;
SDL_Rect brdstreal;
brdstreal.x=bright_x*R_tileside-4+R_gamearea_x;brdstreal.y=bright_y*R_tileside-4+R_gamearea_y;brdstreal.w=40;brdstreal.h=40;
SDL_Rect objsrc;
objsrc.w=R_tileside;objsrc.w=R_tileside;
objsrc.x=(mroom.data[bright_x][bright_y] - (int(mroom.data[bright_x][bright_y]/20) * 20))*R_tileside;
objsrc.y=(int(mroom.data[bright_x][bright_y]/20) * R_tileside);
SDL_Rect objdst;
objdst.x=bright_x*R_tileside;
objdst.y=bright_y*R_tileside;
objdst.w=R_tileside;objdst.h=R_tileside;
SDL_Rect objdstreal;
objdstreal.x=bright_x*R_tileside+R_gamearea_x;
objdstreal.y=bright_y*R_tileside+R_gamearea_y;
objdstreal.w=R_tileside;objdst.h=R_tileside;
SDL_BlitSurface(screenbak,&brdst,screen,&brdstreal);
// SDL_BlitSurface(tiles,&objsrc,screen,&objdstreal);
SDL_BlitSurface(bright,&brsrc,screen,&brdstreal);
SDL_UpdateRect(screen,brdstreal.x,brdstreal.y,brdstreal.w,brdstreal.h);
}
void show_arrow(int arrow, int show)
{
SDL_Rect dst;
dst.w=150; dst.h=30;dst.y=R_gamearea_y+1;
SDL_Rect src;
src.w=dst.w; src.h=dst.h; src.y=dst.y - R_gamearea_y;
switch(arrow)
{
case arrow_left:
dst.x=R_gamearea_x+1;
src.x=dst.x-R_gamearea_x;
if(show==1)
SDL_BlitSurface(left, NULL, screen, &dst);
else
SDL_BlitSurface(screenbak, &src, screen, &dst);
SDL_UpdateRect(screen, dst.x, dst.y, dst.w, dst.h);
break;
case arrow_right:
dst.x=R_gamearea_x+(R_maxtiles_h*R_tileside)-(10+dst.w);
src.x=dst.x-R_gamearea_x;
if(show==1)
SDL_BlitSurface(right, NULL, screen, &dst);
else
SDL_BlitSurface(screenbak, &src, screen, &dst);
SDL_UpdateRect(screen, dst.x, dst.y, dst.w, dst.h);
break;
case arrow_up:
//fprintf(stderr,"up");
break;
case arrow_down:
//fprintf(stderr,"down");
break;
}
}

View File

@@ -0,0 +1,358 @@
/***************************************************************************
* Pachi el marciano *
* ----------------- *
* (c) Santiago Radeff (coding) *
* (c) Nicolas Radeff (graphics) *
* (c) Peter Hajba (music) *
* *
* T-1000@Bigfoot.com *
****************************************************************************
*******************************************************************
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version *
* 2 of the License, or (at your option) any later version. *
* *
*******************************************************************/
void win_game()
{
background=LoadT8(DATADIR"/Tgfx/comic_09.T8");
fadesurface(background, 0, 0, 200);
escape_exit=0;
while(escape_exit==0) { credits_events(); SDL_Delay(1); }
background=LoadT8(DATADIR"/Tgfx/comic_10.T8");
fadesurface(background, 0, 0, 200);
escape_exit=0;
while(escape_exit==0) { credits_events(); SDL_Delay(1); }
background=LoadT8(DATADIR"/Tgfx/comic_11.T8");
fadesurface(background, 0, 0, 200);
escape_exit=0;
while(escape_exit==0) { credits_events(); SDL_Delay(1); }
background=LoadT8(DATADIR"/Tgfx/comic_12.T8");
fadesurface(background, 0, 0, 200);
escape_exit=0;
while(escape_exit==0) { credits_events(); SDL_Delay(1); }
background=LoadT8(DATADIR"/Tgfx/comic_13.T8");
fadesurface(background, 0, 0, 200);
escape_exit=0;
while(escape_exit==0) { credits_events(); SDL_Delay(1); }
background=LoadT8(DATADIR"/Tgfx/comic_14.T8");
fadesurface(background, 0, 0, 200);
escape_exit=0;
while(escape_exit==0) { credits_events(); SDL_Delay(1); }
SDL_FreeSurface(background);
initcredits();
escape_exit=0;
while(escape_exit==0)
{
if(!Mix_PlayingMusic())
Mix_PlayMusic(music,0);
credits_events();
print_credits();
}
SDL_BlitSurface(background, NULL, screen, NULL);
SDL_Flip(screen);
stop_music();
unloadcredits();
}
void check_exits() // esta funcion se fija si hay salidas disponibles
{
int y = int(R_current/R_max_x);
int x = (R_current-y*R_max_x)-1;
int show; // esta variable indica si se debe imprimir la flecha o borrarla
if((roomtime>1 && roomtime<1.5) || (roomtime>2 && roomtime <2.5) || (roomtime > 3 && roomtime <3.5) || (roomtime > 4 && roomtime <4.5))
show=1;
else
show=0;
if(x < R_max_x)
if(roommap[x+1][y]==stage)
show_arrow(arrow_right, show);
if(x > 0)
if(roommap[x-1][y]==stage)
show_arrow(arrow_left, show);
if(y < R_max_y)
if(roommap[x][y+1]==stage)
show_arrow(arrow_down, show);
if(y < 0)
if(roommap[x][y-1]==stage)
show_arrow(arrow_up, show);
}
void stage_up()
{
long filepos;
SDL_Rect scorerect;
scorerect.x = 30; scorerect.y = 484; scorerect.w = 400; scorerect.h = 96;
if(stage+1 != CEMETERY && stage+1 != CAVES && stage+1 != CASTLE && stage+1 != LAB)
{
SDL_FillRect(screen, &scorerect, 0); // limpiamos el cuadrado de los marcadores
SDL_UpdateRect(screen, scorerect.x, scorerect.y, scorerect.w, scorerect.h);
}
mplayer[dificulty].objects = 0; mplayer[dificulty].stageup = 0;
mplayer[dificulty].left = 0; mplayer[dificulty].right = 0;
mplayer[dificulty].jump = 0; mplayer[dificulty].duck = 0; mplayer[dificulty].jumpcounter = 0;
Mix_HaltChannel(-1);
// ahora agregamos el puntaje correspondiente al tiempo que nos sobró
if(minutes>0||seconds>0) // esto lo hacemos por si se perdio por tiempo
{
for(int a=int(gametimer);a>0;a--)
{
score=score+(dificulty*45)+(int(dificulty/3)*45);
gametimer--;
minutes = int(gametimer/60);
seconds = int(gametimer-minutes*60);
Mix_Volume(0,100);
Mix_PlayChannel(0,timer,0);
print_monitor();
print_timer();
SDL_Delay(20);
}
}
stage++;
if(stage <= NUM_STAGES)
{
gametimer = mstage[stage-1].time-((dificulty-1)*20); // para los niveles normal y dificil el tiempo es 30 y 60 segundos menor respectivamente
showcode(mstage[stage-1].code);
showposter(stage);
music=Mix_LoadMUS(mstage[stage-1].music);
stagecompleted = 0;
FILE *lvl = fopen(DATADIR"/data/rooms_v2.dat","rb");
filepos = (stage - 1) * 4; // filepos es el puntero del archivo, lo utilizamos para leer en que habitacion estamos
fseek(lvl,filepos,SEEK_SET);
R_x = getc(lvl);
R_y = getc(lvl);
mplayer[dificulty].start_x = getc(lvl) * R_tileside; // variables de posicion inicial en la pantalla
mplayer[dificulty].start_y = getc(lvl) * R_tileside; // variables de posicion inicial en la pantalla
mplayer[dificulty].x = mplayer[dificulty].start_x;
mplayer[dificulty].y = mplayer[dificulty].start_y;
R_current = (R_x + ((R_y - 1)*R_max_x));
fclose(lvl);
init_room();
}
else
{
game_exit=1;
}
}
void start_game()
{
LoadT(&font,DATADIR"/fonts/font16d.T");
SDL_SetColorKey(font, SDL_SRCCOLORKEY, SDL_MapRGB(font->format,0,0,0));
print_text(font,screen,16,16,140,90,"LOADING GAME DATA... PLEASE WAIT");
SDL_UpdateRect(screen,140,90,520,16);
SDL_FreeSurface(font);
setgame();
load_gamedata();
init_objects();
if(stage+1 != CEMETERY && stage+1 != CAVES && stage+1 != CASTLE && stage+1 != LAB)
setback();
stage_up(); // con esta rutina aumentamos la fase en 1 y leemos la pantalla inicial y la posicion inicial del personaje
init_monsters();
playtime=SDL_GetTicks();
game_exit=0;
while(game_exit==0)
{
game_loop();
}
playtime=SDL_GetTicks()-playtime;
unload_gamedata();
stop_music();
if(stage>NUM_STAGES)
{
escape_exit=0;
win_game();
}
if(mplayer[dificulty].lives == 0 || stage > NUM_STAGES)
game_over();
}
void init_room()
{
roomtime=0; // indica el tiempo que llevamos en una habitacion
flushevents();
load_room();
init_monsters();
print_room();
if(stage<=3) // solamente se muestra la flecha indicadora en las 3 primeras pantallas
chk_exits=1;
else
chk_exits=0;
}
void animatemonsters()
{
M_frame++;
if(M_frame > M_frames)
M_frame=1;
}
void animatefx()
{
brightframe++;
if(brightframe > 9)
brightframe=0;
}
void animate() //rutina para la animacion de los sprites
{
int animspeed=100;
animcounter=animcounter+(imove*animspeed);
if(animcounter > 10)
{
animatemonsters();
animateplayer();
animatefx();
animcounter = 0;
}
}
void play_music()
{
if(!Mix_PlayingMusic())
Mix_PlayMusic(music,0);
}
void chk_state()
{
if(mplayer[dificulty].dead==1)
{
loose_life();
if(mplayer[dificulty].lives<1)
game_exit=1;
else
{
respawned=0;
Mix_Volume(1,90);
Mix_PlayChannel(1,respawnsnd,1);
while(respawned==0)
{
delta_time();
respawn();
}
}
}
if(mplayer[dificulty].stageup==1)
{
while(Mix_Playing(0))
{}
stage_up();
}
if(chk_exits==1 && roomtime < 5)
check_exits();
}
double delta_time(void)
{
curtime=SDL_GetTicks();
imove=(curtime-lasttime)/1000.0;
lasttime=curtime;
if(imove>.2)
imove=0.01;
return imove;
}
void print_timer()
{
print_text(scorefont,screen,16,16,224,564,"TIME :");
if(minutes==0 && seconds <=10)
{
Mix_Volume(0,100);
font=scorefont2;
if((int(oldsec-1)==int(seconds))&& seconds > 0)
Mix_PlayChannel(0,timer,0);
}
else
font=scorefont1;
if(seconds>=10)
print_text(font,screen,16,16,352,564,"%d:%d",minutes,seconds);
else
print_text(font,screen,16,16,352,564,"%d:0%d",minutes,seconds);
SDL_UpdateRect(screen,224,544,208,40);
}
void do_gametimer()
{
gametimer-=imove;
roomtime+=imove;
minutes = int(gametimer/60);
seconds = int(gametimer-minutes*60);
print_timer();
screen_fx(); // efectos especiales de pantalla
if(minutes==0 && seconds == 0)
{
stage--;
init_objects();
loose_life();
if(Mix_PlayingMusic())
Mix_FreeMusic(music);
stage_up();
}
oldsec=seconds;
}
void chk_sequence()
{
int n;
sequence=mstage[stage-1].objects+1;
for(n=0;n<2000;n++)
{
if(mobject[n].stage==stage)
{
if(mobject[n].seq<sequence && mobject[n].seq>0)
sequence=mobject[n].seq;
//fprintf(stderr,"stage=%d object stage=%d\n",stage, mobject[n].stage);
//fprintf(stderr,"proximo objeto de la secuencia es=%d, numero=%d, x=%d, y=%d stage=%d \n",mobject[n].seq, n, mobject[n].x, mobject[n].y, mobject[n].stage);
}
}
int object_is_here=0; // esta variable indica si el objeto que sigue en la secuencia esta en la pantalla actual
int bright_x, bright_y; // variables que indica en que posicion debe aparecer el brillo del proximo objeto a recoger
for(n=0;n<5;n++)
{
if(mobject[(R_current-1)*5+n].seq==sequence)
{
object_is_here=1;
bright_x=mobject[(R_current-1)*5+n].x;
bright_y=mobject[(R_current-1)*5+n].y;
}
}
if(object_is_here==1)
{
bright_obj(bright_x, bright_y);
}
}
void game_loop()
{
delta_time();
do_gametimer(); // esta rutina decrementa e imprime el timer
play_music();
game_events();
animate();
clean_player();
if(fadingobject==1) // chquea si se debe eliminar un objeto
alphade=fade_object(alphade);
print_monsters();
print_player();
chk_sequence(); // esta rutina se fija cual es el proximo objeto de la sequencia (Bomb Jack feature)
chk_state(); // esta rutina chequea si el personaje se murio, o si paso de nivel
SDL_Delay(1);
}

View File

@@ -0,0 +1,125 @@
/***************************************************************************
* Pachi el marciano *
* ----------------- *
* (c) Santiago Radeff (coding) *
* (c) Nicolas Radeff (graphics) *
* (c) Peter Hajba (music) *
* *
* T-1000@Bigfoot.com *
****************************************************************************
*******************************************************************
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version *
* 2 of the License, or (at your option) any later version. *
* *
*******************************************************************/
void show_hiscores()
{
SDL_SetColorKey(scorefont,SDL_SRCCOLORKEY,SDL_MapRGB(scorefont->format,0,0,0));
SDL_SetColorKey(scorefont1,SDL_SRCCOLORKEY,SDL_MapRGB(scorefont1->format,0,0,0));
SDL_SetColorKey(scorefont1,SDL_SRCCOLORKEY,SDL_MapRGB(scorefont1->format,0,0,0));
char plyername[]=" ";
char diflevel[] =" ";
print_text(scorefont1,screen,16,16,30, 55," PACHI EL MARCIANO TOP TEN ");//scorename[a]);
print_text(scorefont1,screen,16,16,30, 95,"NAME STAGE TIME LEVEL SCORE ");//scorename[a]);
print_text(scorefont1,screen,16,16,30,120,"----------------------------------------------");//scorename[a]);
print_text(scorefont1,screen,16,16,30,535,"----------------------------------------------");//scorename[a]);
for(int a=0; a < 10;a++)
{
strncpy(playername,scorename[a],10);
print_text(scorefont,screen,16,16,30,170+(35*a),"%s",playername);//scorename[a]);
print_text(scorefont,screen,16,16,268,170+(35*a),"%d",scorestage[a]);
int mins=int(scoretime[a]/60);
int secs=int(scoretime[a]-(mins*60));
if(secs>9)
print_text(scorefont,screen,16,16,386,170+(35*a),"%d:%d",mins,secs);
else
print_text(scorefont,screen,16,16,386,170+(35*a),"%d:0%d",mins,secs);
if(scoredif[a]==1)
strcpy(diflevel," EASY ");
if(scoredif[a]==2)
strcpy(diflevel,"NORMAL");
if(scoredif[a]==3)
strcpy(diflevel," HARD ");
print_text(scorefont,screen,16,16,502,170+(35*a),"%s",diflevel);
print_text(scorefont,screen,16,16,672,170+(35*a),"%d",scorescore[a]);
}
SDL_Flip(screen);
}
void do_hiscores()
{
load_hiscoredata();
setback();
show_hiscores();
escape_exit=0;
while(escape_exit==0)
{
credits_events();
SDL_Delay(1);
}
unload_hiscoredata();
}
void do_gameover()
{
load_hiscoredata();
char nameplayer[]=" ";
strncpy(playername,nameplayer,10);
namechar=0;
int highscore=0;
for(int a=9; a>=0;a--)
{
if(score>scorescore[a])
{
highscore=1;
scorepos=a;
}
}
if(highscore==1) // si se hizo una buena puntuacion
{
for(int b=8;b>=scorepos;b--)
{
strncpy(scorename[b+1],scorename[b],10);
scorescore[b+1]=scorescore[b];
scorestage[b+1]=scorestage[b];
scoretime [b+1]=scoretime [b];
scoredif [b+1]=scoredif [b];
}
inputloop=1;
SDL_Rect box;
box.x=270;box.y=220;box.w=260;box.h=52;
SDL_FillRect(screen,&box,SDL_MapRGB(screen->format,255,255,255));
box.x=273;box.y=223;box.w=254;box.h=46;
while(inputloop==1)
{
hiscore_events();
SDL_FillRect(screen,&box,SDL_MapRGB(screen->format,0,0,0));
print_text(scorefont1,screen,16,16,box.x+10,box.y+5,"ENTER YOUR NAME");
print_text(scorefont1,screen,16,16,box.x+51+(namechar*16),box.y+29,".");
print_text(scorefont,screen,16,16,box.x+51,box.y+24,"%s",playername);
SDL_Flip(screen);
}
strncpy(scorename[scorepos],playername,10);
scorescore[scorepos]=score;
scorestage[scorepos]=stage;
scoredif[scorepos]=dificulty;
scoretime[scorepos]=int(playtime/1000);
save_hiscoredata();
}
unload_hiscoredata();
}
void game_over()
{
do_gameover();
do_hiscores();
}

View File

@@ -0,0 +1,117 @@
/***************************************************************************
* Gfx Functions *
* ------------- *
* *
* T-1000@Bigfoot.com *
****************************************************************************
*******************************************************************
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version *
* 2 of the License, or (at your option) any later version. *
* *
*******************************************************************/
/*
LoadT carga un grafico en formato .T de 24 bits en una superficie SDL
*/
void LoadT(SDL_Surface **Tsurface, char *str)
{
FILE *Tsrc;
int T_lwidth, T_hwidth, T_lheight, T_hheight; // bytes alto y bajo de anchura y altura del grafico
long T_width, T_height;
int R, G, B;
Uint32 pixel;
Tsrc=fopen(str, "rb");
if ( Tsrc == NULL)
{
fprintf(stderr, "can't read from file \n");
return;
}
// leer tamaño del bmp
T_lwidth = getc(Tsrc);
T_hwidth = getc(Tsrc);
T_lheight = getc(Tsrc);
T_hheight = getc(Tsrc);
T_width = T_hwidth*256+T_lwidth;
T_height = T_hheight*256+T_lheight;
SDL_Surface *temp;
temp = SDL_CreateRGBSurface(SDL_SWSURFACE,T_width,T_height,24,0,0,0,0);
if(SDL_MUSTLOCK(temp))
SDL_LockSurface(temp);
for(int n=1;n<=T_height;n++) //el tamaño del grafico es de ancho * alto * 3 (24 bits)
{
for(int m=1;m<=T_width;m++)
{
R=getc(Tsrc);
G=getc(Tsrc);
B=getc(Tsrc);
pixel=SDL_MapRGB(temp->format,R,G,B);
Uint8 *p = (Uint8 *)temp->pixels + (n-1) * temp->pitch + (m-1) * 3;
p[0] = pixel & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = (pixel >> 16) & 0xff;
}
}
if(SDL_MUSTLOCK(temp))
SDL_UnlockSurface(temp);
*Tsurface = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
fclose(Tsrc);
}
SDL_Surface * LoadT8(char *str)
{
SDL_Surface *Tsurface;
FILE *Tsrc;
Tsrc=fopen(str, "rb");
if ( Tsrc == NULL)
{
fprintf(stderr, "can't read from file \n");
SDL_Quit();
exit(0);
}
// leer tamaño del bmp
fseek(Tsrc,6,SEEK_SET); // Saltamos la cabecera "T-1000"
// leemos tamaño del bitmap
int wh=getc(Tsrc); int wl=getc(Tsrc); int hh=getc(Tsrc); int hl=getc(Tsrc);
int width=wh*256+wl; int height=hh*256+hl;
// leemos la paleta
int paleta[768];
for(int pal=0;pal<768;pal++)
paleta[pal]=getc(Tsrc);
// leemos el bitmap en una superficie de 24 bits
SDL_Surface *temp;
temp = SDL_CreateRGBSurface(SDL_SWSURFACE,width,height,24,0,0,0,0);
if(SDL_MUSTLOCK(temp))
SDL_LockSurface(temp);
Uint32 pixel;
int x,y,color;
for(y=0;y<height;y++) //el tamaño del grafico es de ancho * alto * 3 (24 bits)
{
for(x=0;x<width;x++)
{
color=getc(Tsrc);
pixel = SDL_MapRGB(temp->format,paleta[color*3],paleta[(color*3)+1],paleta[(color*3)+2]);
Uint8 *p = (Uint8 *)temp->pixels + (y) * temp->pitch + (x) * 3;
p[0] = pixel & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = (pixel >> 16) & 0xff;
}
}
if(SDL_MUSTLOCK(temp))
SDL_UnlockSurface(temp);
Tsurface = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
fclose(Tsrc);
return(Tsurface);
}

View File

@@ -0,0 +1,55 @@
/***************************************************************************
* Pachi el marciano *
* ----------------- *
* (c) Santiago Radeff (coding) *
* (c) Nicolas Radeff (graphics) *
* (c) Peter Hajba (music) *
* *
* T-1000@Bigfoot.com *
****************************************************************************
*******************************************************************
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version *
* 2 of the License, or (at your option) any later version. *
* *
*******************************************************************/
void initsdl()
{
int have_joystick=0;
if(SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO|SDL_INIT_JOYSTICK) < 0)
{
fprintf(stderr,"Could not Initialize SDL.\nError: %s\n", SDL_GetError());
exit (1);
}
if(Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 2048) < 0)
{
fprintf(stderr,"Warning: Couldn't set 44100 Hz 16-bit audio\n: %s\n", SDL_GetError());
}
SDL_WM_SetIcon(SDL_LoadBMP(DATADIR"/Tgfx/icon.bmp"),NULL);
fullscreen=0;
screen = SDL_SetVideoMode(screen_w,screen_h,screen_bpp, SDL_HWSURFACE|SDL_DOUBLEBUF);
if (screen == NULL)
{
fprintf(stderr, "Can't set the video mode. Quitting.\nError; %s\n", SDL_GetError());
exit (1);
}
have_joystick = SDL_NumJoysticks();
// fprintf(stderr, "%i joysticks were found.\n", have_joystick );
if (have_joystick)
{
SDL_JoystickEventState(SDL_ENABLE);
joystick = SDL_JoystickOpen(0);
}
SDL_ShowCursor(0);
SDL_WM_GrabInput(SDL_GRAB_ON);
SDL_WM_GrabInput(SDL_GRAB_OFF);
SDL_WM_SetCaption("Pachi el marciano", "Pachi el marciano");
}

View File

@@ -0,0 +1,401 @@
/***************************************************************************
* Pachi el marciano *
* ----------------- *
* (c) Santiago Radeff (coding) *
* (c) Nicolas Radeff (graphics) *
* (c) Peter Hajba (music) *
* *
* T-1000@Bigfoot.com *
****************************************************************************
*******************************************************************
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version *
* 2 of the License, or (at your option) any later version. *
* *
*******************************************************************/
void credits_events()
{
SDL_Event event;
while(SDL_PollEvent(&event))
{
check_joystick_events(&event, joypos);
if(event.type==SDL_KEYDOWN)
if(event.key.keysym.sym==SDLK_ESCAPE || event.key.keysym.sym==SDLK_RETURN || event.key.keysym.sym==SDLK_SPACE)
escape_exit=1;
if(joypos[JOY_BUTTON0])
escape_exit=1;
}
}
void pause_events()
{
SDL_Event event;
while(SDL_PollEvent(&event))
{
if(event.type==SDL_KEYDOWN)
if(event.key.keysym.sym==SDLK_h || event.key.keysym.sym==SDLK_F1)
escape_exit=1;
}
}
void hiscore_events()
{
int n;
SDL_Event event;
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_KEYDOWN:
{
if(event.key.keysym.sym>41)
{
playername[namechar] = event.key.keysym.sym;
if(playername[namechar]>=97 && playername[namechar]<=122)
playername[namechar]=event.key.keysym.sym-32;
if(namechar < 9)
namechar++;
}
else
{
if(event.key.keysym.sym==SDLK_RETURN || event.key.keysym.sym == SDLK_ESCAPE)
inputloop=0;
if(event.key.keysym.sym==SDLK_BACKSPACE)
{
namechar=0;
for(n=0;n<10;n++)
playername[n] = '.';
}
}
}
}
check_joystick_events(&event, joypos);
if (joypos[JOY_UP])
{
playername[namechar]++;
if(playername[namechar]>=97 && playername[namechar]<=122)
playername[namechar]-=32;
}
if (joypos[JOY_DOWN])
{
playername[namechar]--;
if(playername[namechar]>=97 && playername[namechar]<=122)
playername[namechar]-=32;
}
if (joypos[JOY_BUTTON0])
{
namechar++;
if(namechar > 3)
namechar=0;
}
if (joypos[JOY_BUTTON1])
inputloop=0;
}
}
void menu_events()
{
SDL_Event event;
Uint8 *keys;
Mix_Volume(0,100);
while(SDL_PollEvent(&event)==1)
{
if(event.type==SDL_QUIT)
gameexit=1;
check_joystick_events(&event, joypos);
keys = SDL_GetKeyState(NULL);
if(keys[SDLK_DOWN] || keys[SDLK_KP2] || keys[SDLK_a] || joypos[JOY_DOWN])
{
Mix_PlayChannel(0,option,0);
if(menuvalue == 7)
menuvalue=1;
else
menuvalue++;
}
if(keys[SDLK_UP] || keys[SDLK_KP8] || keys[SDLK_q] || joypos[JOY_UP])
{
Mix_PlayChannel(0,option,0);
if(menuvalue == 1)
menuvalue = 7;
else
menuvalue--;
}
if(keys[SDLK_SPACE] || keys[SDLK_RETURN] || joypos[JOY_BUTTON0])
{
Mix_PlayChannel(0,option,0);
switch(menuvalue)
{
case 1:
startgame = 1;
break;
case 2:
dificulty++;
if(dificulty>3)
dificulty=1;
break;
case 3:
screen_mode();
setback();
joypos[JOY_BUTTON0]=0;
break;
case 4:
do_code();
break;
case 5:
help=1;
break;
case 6:
hiscores=1;
break;
case 7:
gameexit = 1;
break;
default:
break;
}
}
if(keys[SDLK_ESCAPE])
gameexit=1;
}
}
void code_events()
{
int n;
SDL_Event event;
while(SDL_PollEvent(&event)==1)
{
switch(event.type)
{
case SDL_KEYDOWN:
{
if(event.key.keysym.sym>41)
{
code[codechar] = event.key.keysym.sym;
if(code[codechar]>=97 && code[codechar]<=122)
code[codechar]=event.key.keysym.sym-32;
if(codechar < 3)
codechar++;
}
else
{
if(event.key.keysym.sym== SDLK_RETURN || event.key.keysym.sym == SDLK_ESCAPE)
inputloop=0;
if(event.key.keysym.sym== SDLK_BACKSPACE)
{
SDL_Rect coderect;
coderect.x=303;
coderect.y=235;
coderect.w=194;
coderect.h=44;
SDL_FillRect(screen, &coderect, SDL_MapRGB(screen->format,0,0,0));
codechar=0;
for(int n=0;n<4;n++)
code[n] = '.' ;
}
}
}
}
check_joystick_events(&event, joypos);
if (joypos[JOY_UP])
{
code[codechar]++;
if(code[codechar]>=97 && code[codechar]<=122)
code[codechar]-=32;
}
if (joypos[JOY_DOWN])
{
code[codechar]--;
if(code[codechar]>=97 && code[codechar]<=122)
code[codechar]-=32;
}
if (joypos[JOY_BUTTON0])
{
codechar++;
if(codechar > 3)
codechar=0;
}
if (joypos[JOY_BUTTON1])
inputloop=0;
}
}
void check_joystick_events(SDL_Event *event, Uint8 *joypos)
{
switch (event->type)
{
case SDL_JOYAXISMOTION: /* Handle Joystick Motion */
if( event->jaxis.axis == 0)
{ /* Left-Right movement code goes here */
if ( event->jaxis.value < -3200)
{
joypos[JOY_LEFT]=1;
joypos[JOY_RIGHT]=0;
}
else
{
if ( event->jaxis.value > 3200)
{
joypos[JOY_LEFT]=0;
joypos[JOY_RIGHT]=1;
}
else
{
joypos[JOY_LEFT]=0;
joypos[JOY_RIGHT]=0;
}
}
}
if( event->jaxis.axis == 1)
{ /* Up-Down movement code goes here */
if ( event->jaxis.value < -3200)
{
joypos[JOY_UP]=1;
joypos[JOY_DOWN]=0;
}
else
{
if ( event->jaxis.value > 3200)
{
joypos[JOY_UP]=0;
joypos[JOY_DOWN]=1;
}
else
{
joypos[JOY_UP]=0;
joypos[JOY_DOWN]=0;
}
}
}
break;
case SDL_JOYBUTTONDOWN: /* Handle Joystick Button Presses */
switch (event->jbutton.button)
{
case 0:
joypos[JOY_BUTTON0]=1; break;
case 1:
joypos[JOY_BUTTON1]=1;
break;
}
break;
case SDL_JOYBUTTONUP: /* Handle Joystick Button Releases */
switch (event->jbutton.button)
{
case 0:
joypos[JOY_BUTTON0]=0;
break;
case 1:
joypos[JOY_BUTTON1]=0;
break;
}
break;
}
}
void game_events()
{
int n;
SDL_Event event;
Uint8 *keys;
if(mplayer[dificulty].lives==0)
game_exit = 1;
while(SDL_PollEvent(&event)==1)
{
check_joystick_events(&event, joypos);
keys = SDL_GetKeyState(NULL);
mplayer[dificulty].left = 0;
mplayer[dificulty].right = 0;
if(keys[SDLK_h] || keys[SDLK_F1])
{
escape_exit=0;
SDL_Rect dst;
dst.x=300; dst.y=200; dst.w=192; dst.h=32;
SDL_Rect src;
src.x=dst.x-R_gamearea_x; src.y=dst.y-R_gamearea_y; src.w=dst.w; src.h=dst.h;
print_text(menufont, screen, 32, 32, dst.x, dst.y, "PAUSED");
SDL_UpdateRect(screen, dst.x, dst.y , dst.w, dst.h);
while(escape_exit==0)
{
pause_events();
SDL_Delay(5);
}
SDL_BlitSurface(screenbak, &src, screen, &dst);
SDL_UpdateRect(screen, dst.x, dst.y , dst.w, dst.w);
}
if(keys[SDLK_o] || keys[SDLK_LEFT] || keys[SDLK_KP4] || joypos[JOY_LEFT])
{
mplayer[dificulty].left = 1;
mplayer[dificulty].right = 0;
mplayer[dificulty].facingleft = 1;
}
if(keys[SDLK_p] || keys[SDLK_RIGHT] || keys[SDLK_KP6] || joypos[JOY_RIGHT])
{
mplayer[dificulty].right = 1;
mplayer[dificulty].left = 0;
mplayer[dificulty].facingleft = 0;
}
if(keys[SDLK_q] || keys[SDLK_UP] || keys[SDLK_KP8] || joypos[JOY_UP])
{
if(mplayer[dificulty].duck==1) // en esta rutina tiene que comprobar que si se quiere parar que no tenga nada encima que se lo impida
{
mplayer[dificulty].duck = 0;
mplayer[dificulty].framer = 1;
mplayer[dificulty].y = mplayer[dificulty].old_y - (P_h - P_h/2);
for(int n=0;n<=mplayer[dificulty].w-1;n++)
{
int x=int(mplayer[dificulty].x+n)/R_tileside;
int y=int((mplayer[dificulty].y - (P_h - P_h/2)+R_tileside)/R_tileside);
chk_touched(x,y);
if((mroom.data[x][y] >= 80) && (mroom.data[x][y] < 200))
{
mplayer[dificulty].duck = 1;
mplayer[dificulty].framer = 2;
mplayer[dificulty].y = mplayer[dificulty].old_y;
}
}
}
}
if(keys[SDLK_a] || keys[SDLK_DOWN] || keys[SDLK_KP2] || joypos[JOY_DOWN])
{
if(mplayer[dificulty].duck==0 && mplayer[dificulty].jump == 0 && mplayer[dificulty].infloor == 1)
{
mplayer[dificulty].y = mplayer[dificulty].y + (P_h - P_h/2);
mplayer[dificulty].ducked = 1;
}
if(mplayer[dificulty].jump == 0 && mplayer[dificulty].infloor == 1)
mplayer[dificulty].duck = 1;
}
if(keys[SDLK_SPACE] || keys[SDLK_KP0] || joypos[JOY_BUTTON0])
{
if((mplayer[dificulty].infloor==1)&&(mplayer[dificulty].duck==0)&&(mplayer[dificulty].y+P_h/R_tileside==int(mplayer[dificulty].y+P_h/R_tileside)))
{
mplayer[dificulty].jumpcounter=0;
mplayer[dificulty].startjump=int(mplayer[dificulty].y);
mplayer[dificulty].upflag=1;
mplayer[dificulty].downflag=0;
mplayer[dificulty].jump = 1;
Mix_Volume(0,100);
Mix_PlayChannel(0,jump,0);
}
}
if(keys[SDLK_ESCAPE])
{
game_exit = 1;
}
}
}

View File

@@ -0,0 +1,115 @@
/***************************************************************************
* Pachi el marciano *
* ----------------- *
* (c) Santiago Radeff (coding) *
* (c) Nicolas Radeff (graphics) *
* (c) Peter Hajba (music) *
* *
* T-1000@Bigfoot.com *
****************************************************************************
*******************************************************************
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version *
* 2 of the License, or (at your option) any later version. *
* *
*******************************************************************/
void init_intro()
{
SDL_Surface *temp;
dragontech=LoadT8(DATADIR"/Tgfx/dragontech.T8");
line1=LoadT8(DATADIR"/Tgfx/line1.T8");
line2=LoadT8(DATADIR"/Tgfx/line2.T8");
SDL_SetColorKey(dragontech, SDL_SRCCOLORKEY,SDL_MapRGB(dragontech->format,0,255,0));
SDL_SetColorKey(line1, SDL_SRCCOLORKEY,SDL_MapRGB(line1->format,0,0,0));
SDL_SetColorKey(line2, SDL_SRCCOLORKEY,SDL_MapRGB(line2->format,0,0,0));
comic_01=LoadT8(DATADIR"/Tgfx/comic_01.T8");
temp=SDL_CreateRGBSurface(SDL_SWSURFACE, screen_w, screen_h, screen_bpp, 255, 255, 255, 0);
SDL_FillRect(temp, NULL, SDL_MapRGB(temp->format,0,0,0));
black = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format,0,0,0));
}
void end_intro()
{
SDL_FreeSurface(dragontech);
SDL_FreeSurface(line1);
SDL_FreeSurface(line2);
SDL_FreeSurface(comic_01);
SDL_FreeSurface(black);
}
void intro()
{
init_intro();
double introtime=0;
escape_exit=0;
float title_alpha=0;
int title_done=0;
int n=1;
while(escape_exit==0)
{
if(n<=4) // 4 son los pasos a realizar en la primer parte de la intro
{
if(title_alpha<255)
{
switch(n)
{
case 1:
title_alpha=intro_blit(dragontech, 160, 100, 480, 170, title_alpha, 80, 1);
break;
case 2:
title_alpha=intro_blit(line1, 60, 300, 600, 40, title_alpha, 80, 1);
break;
case 3:
title_alpha=intro_blit(line2, 160, 350, 600, 40, title_alpha, 80, 1);
break;
case 4:
if(introtime>15)
title_alpha=intro_blit(black, 0,0,800,600, title_alpha, 80, 0);
break;
}
}
else
{
title_alpha=0;
n++;
}
}
credits_events();
delta_time();
introtime+=imove;
SDL_Delay(1);
if(introtime>20)
escape_exit=1;
}
escape_exit=0; n=1; title_alpha=0; introtime=0;
while(escape_exit==0)
{
if(title_alpha<255)
{
title_alpha=intro_blit(comic_01, 0, 0, 800, 600, title_alpha, 60, 0);
}
else
{
title_alpha=0;
n++;
}
credits_events();
delta_time();
introtime+=imove;
SDL_Delay(1);
if(introtime>25)
escape_exit=1;
}
end_intro();
}

View File

@@ -0,0 +1,134 @@
/***************************************************************************
* Pachi el marciano *
* ----------------- *
* (c) Santiago Radeff (coding) *
* (c) Nicolas Radeff (graphics) *
* (c) Peter Hajba (music) *
* *
* T-1000@Bigfoot.com *
****************************************************************************
*******************************************************************
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version *
* 2 of the License, or (at your option) any later version. *
* *
*******************************************************************/
void do_code()
{
Mix_Volume(3,100);
SDL_Rect coderect;
coderect.x=300;
coderect.y=232;
coderect.w=200;
coderect.h=50;
SDL_FillRect(screen, &coderect, SDL_MapRGB(screen->format,255,255,255));
coderect.x=303;
coderect.y=235;
coderect.w=194;
coderect.h=44;
SDL_FillRect(screen, &coderect, SDL_MapRGB(screen->format,0,0,0));
codechar=0;
inputloop=1;
// SDL_SetColorKey(menufont1,0,SDL_MapRGB(menufont1->format,0,255,0));
while(inputloop==1)
{
code_events();
print_text(menufont1, screen, 32, 32, 336, 241, "%s",code);
SDL_UpdateRect(screen, 300, 232, 200, 50);
}
// SDL_SetColorKey(menufont1,SDL_SRCCOLORKEY,SDL_MapRGB(menufont1->format,0,255,0));
// comparar si el codigo es correcto
startstage = 0;
int right = 0;
int n;
for(n=1;n < NUM_STAGES+1;n++)
{
if(strcmp(code,mstage[n-1].code)==0)
{
startstage=n-1;
right=1;
}
}
if(right==1)
Mix_PlayChannel(3,coderight,0);
else
Mix_PlayChannel(3,codewrong,0);
setback();
}
void do_menu()
{
SDL_Delay(1);
font = menufont;
int menustartpos=156;
if(menuvalue == 1) font = menufont1; else font = menufont;
print_text(font, screen, 32, 32 ,305, menustartpos, " PLAY");
if(menuvalue == 2) font = menufont1; else font = menufont;
{
SDL_Rect restoremenu;
restoremenu.x=305; restoremenu.y=menustartpos+(1*40);restoremenu.w=300;restoremenu.h=32;
SDL_BlitSurface(background,&restoremenu,screen,&restoremenu);
if(dificulty==1)
{
print_text(font, screen, 32, 32 ,305, menustartpos+(1*40), " EASY");
}
if(dificulty==2)
{
print_text(font, screen, 32, 32 ,305, menustartpos+(1*40), "NORMAL");
}
if(dificulty==3)
{
print_text(font, screen, 32, 32 ,305, menustartpos+(1*40), " HARD");
}
}
if(menuvalue == 3) font = menufont1; else font = menufont;
print_text(font, screen, 32, 32 ,305, menustartpos+(2*40), "SCREEN");
if(menuvalue == 4) font = menufont1; else font = menufont;
print_text(font, screen, 32, 32 ,305, menustartpos+(3*40), " CODE");
if(menuvalue == 5) font = menufont1; else font = menufont;
print_text(font, screen, 32, 32 ,305, menustartpos+(4*40), " HELP");
if(menuvalue == 6) font = menufont1; else font = menufont;
print_text(font, screen, 32, 32 ,305, menustartpos+(5*40), "SCORES");
if(menuvalue == 7) font = menufont1; else font = menufont;
print_text(font, screen, 32, 32 ,305, menustartpos+(6*40), " EXIT");
SDL_UpdateRect(screen, 300, 160, 240, 300);
}
void menu_loop()
{
do_menu();
if(!Mix_PlayingMusic())
Mix_PlayMusic(music,0);
SDL_Delay(1);
}
void menu()
{
load_menudata();
float alpha=0;
while(alpha<255)
{
alpha=intro_blit(background,0,0,800,600,alpha,200,0);
delta_time();
}
SDL_Flip(screen);
menuvalue=1;
while(gameexit==0 && startgame==0 && help==0 && hiscores==0)
{
menu_events();
menu_loop();
}
unload_menudata();
stop_music();
}

View File

@@ -0,0 +1,215 @@
/***************************************************************************
* Pachi el marciano *
* ----------------- *
* (c) Santiago Radeff (coding) *
* (c) Nicolas Radeff (graphics) *
* (c) Peter Hajba (music) *
* *
* T-1000@Bigfoot.com *
****************************************************************************
*******************************************************************
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version *
* 2 of the License, or (at your option) any later version. *
* *
*******************************************************************/
// -------------------------------------------------
// RUTINAS DE CHEQUEO DE COLISIONES DE LOS MONSTRUOS
// -------------------------------------------------
void check_monster_down(int n)
{
if((M_y[n] + M_h) > (R_tileside*(R_maxtiles_v-1)))
{
M_direction[n] = 1;
M_y[n]--;
}
if((M_y[n]+M_h)/R_tileside >= int(M_y[n]+M_h)/R_tileside)
{
for(int m=0;m<=M_w-1;m++)
{
if(mroom.data[int(M_x[n]+m)/R_tileside][int((M_y[n]+M_h)/R_tileside)] >= 40)
{
M_direction[n] = 1;
M_y[n]--;
}
}
}
// Chequeo de colision contra otro monstruo
for(int m=0;m<=M_max4room-1;m++)
{
if(n!=m && M_type[m]!=0)
{
if(M_y[n] < M_y[m]+M_h && M_y[n]+M_h > M_y[m])
if(M_x[n] < M_x[m]+M_w && M_x[n]+M_w > M_x[m])
{
M_direction[n] = 1;
M_y[n]-=3;
}
}
}
}
void check_monster_up(int n)
{
if(M_y[n] < R_tileside)
{
M_direction[n] = 0;
M_y[n]++;
}
// if((M_y[n])/R_tileside <= int(M_y[n])/R_tileside)
// {
for(int m=0;m<=M_w-1;m++)
{
if(mroom.data[int(M_x[n]+m)/R_tileside][int((M_y[n])/R_tileside)] >= 40)
{
M_direction[n] = 0;
M_y[n]++;
}
}
// }
// Chequeo de colision contra otro monstruo
for(int m=0;m<=M_max4room-1;m++)
{
if(m!=n && M_type[m]!=0)
{
if(M_y[n] < M_y[m]+M_h && M_y[n]+M_h > M_y[m])
if(M_x[n] < M_x[m]+M_w && M_x[n]+M_w > M_x[m])
{
M_direction[n] = 0;
M_y[n]+=3;
}
}
}
}
void check_monster_left(int n)
{
if(M_x[n] < R_tileside)
{
M_direction[n] = 0;
M_x[n]++;
}
if((M_x[n])/R_tileside >= int(M_x[n])/R_tileside)
{
for(int m=0;m<=M_h-1;m++)
{
if(mroom.data[int(M_x[n])/R_tileside][int((M_y[n]+m)/R_tileside)] >= 40)
{
M_direction[n] = 0;
M_x[n]++;
}
}
}
// Chequeo de colision contra otro monstruo
for(int m=0;m<=M_max4room-1;m++)
{
if(m!=n && M_type[m]!=0)
{
if(M_y[n] < M_y[m]+M_h && M_y[n]+M_h > M_y[m])
if(M_x[n] < M_x[m]+M_w && M_x[n]+M_w > M_x[m])
{
M_direction[n] = 0;
M_x[n]+=3;
}
}
}
}
void check_monster_right(int n)
{
if((M_x[n] + M_w) > (R_tileside*(R_maxtiles_h-1)))
{
M_direction[n] = 1;
M_x[n]--;
}
if((M_x[n]+M_w)/R_tileside >= int(M_x[n]+M_w)/R_tileside)
{
for(int m=0;m<=M_h-1;m++)
{
if(mroom.data[int(M_x[n]+M_w)/R_tileside][int((M_y[n]+m)/R_tileside)] >= 40)
{
M_direction[n] = 1;
M_x[n]--;
}
}
}
// Chequeo de colision contra otro monstruo
for(int m=0;m<=M_max4room-1;m++)
{
if(m!=n && M_type[m]!=0)
{
if(M_y[n] < M_y[m]+M_h && M_y[n]+M_h > M_y[m])
if(M_x[n] < M_x[m]+M_w && M_x[n]+M_w > M_x[m])
{
M_direction[n] = 1;
M_x[n]-=3;
}
}
}
}
void move_monster(int n)
{
if(M_type[n] > 12) // los monstruos que sean tipo mayor a 12 se mueven en el eje Y y los menores de mueven en el eje X
{
if(M_direction[n] == 1)
{
M_y[n]=M_y[n]-(M_speed[dificulty]*imove);
check_monster_up(n); //up
}
if(M_direction[n] == 0)
{
M_y[n]=M_y[n]+(M_speed[dificulty]*imove);
check_monster_down(n); //down
}
}
else
{
if(M_direction[n] == 1)
{
M_x[n]=M_x[n]-(M_speed[dificulty]*imove);
check_monster_left(n); // left
}
if(M_direction[n] == 0)
{
M_x[n]=M_x[n]+(M_speed[dificulty]*imove);
check_monster_right(n); //right
}
}
}
void print_monsters()
{
for(int n=0;n<=M_max4room-1;n++)
{
if(M_type[n] != 0)
{
oldmonsterpos.x = int(M_x[n]);
oldmonsterpos.y = int(M_y[n]);
oldmonsterpos.h = M_h;
oldmonsterpos.w = M_w;
oldmonsterposreal.x = int(M_x[n]+R_gamearea_x);
oldmonsterposreal.y = int(M_y[n]+R_gamearea_y);
monstersrc.y = M_type[n] * M_h;
monstersrc.x = ((M_frame - 1)+(M_direction[n]*M_frames)) * M_w;
monstersrc.h = M_h;
monstersrc.w = M_w;
move_monster(n);
monsterpos.x = int(M_x[n]);
monsterpos.y = int(M_y[n]);
monsterposreal.x = monsterpos.x + R_gamearea_x;
monsterposreal.y = monsterpos.y + R_gamearea_y;
SDL_BlitSurface(screenbak, &oldmonsterpos, screen, &oldmonsterposreal);
SDL_BlitSurface(monsters, &monstersrc, screen, &monsterposreal);
SDL_UpdateRect(screen,oldmonsterposreal.x,oldmonsterposreal.y,M_w,M_h);
SDL_UpdateRect(screen,monsterposreal.x,monsterposreal.y,M_w,M_h);
}
}
}

View File

@@ -0,0 +1,363 @@
/***************************************************************************
* Pachi el marciano *
* ----------------- *
* (c) Santiago Radeff (coding) *
* (c) Nicolas Radeff (graphics) *
* (c) Peter Hajba (music) *
* *
* T-1000@Bigfoot.com *
****************************************************************************
*******************************************************************
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version *
* 2 of the License, or (at your option) any later version. *
* *
*******************************************************************/
void screen_mode()
{
if(fullscreen)
{
screen = SDL_SetVideoMode(screen_w,screen_h,screen_bpp,0);
fullscreen = 0;
}
else
{
screen = SDL_SetVideoMode(screen_w,screen_h,screen_bpp,SDL_FULLSCREEN);
fullscreen = 1;
}
}
void print_credits()
{
int creditsfont_h = 25;
int creditsfont_w = 18;
if(needinput==1) // la variable needinput indica si se debe imprimir una nueva linea de texto
{
char line2print[100]; // esta es la cadena de texto que contiene el renglon a imprimir
for(int n=0; n<=37; n++)
line2print[n]=creditstext[n+(creditslinecounter*36)];
print_text(creditsfont, creditsbuffer, creditsfont_w, creditsfont_h, 0,400, line2print);
// imprime una linea de texto en la parte de abajo (no imprimible del primer buffer)
needinput=0;
creditslinecounter++;
if(creditslinecounter==creditslines)
{
creditslinecounter--;
wrapcounter++;
if(wrapcounter==100)
{
creditslinecounter=0;
wrapcounter=0;
}
}
}
else // si no se imprime una nueva linea se debe hacer el scroll entre los buffers
{
SDL_Rect cbuffer;
cbuffer.w = 600;
cbuffer.h = 440;
cbuffer.x = 0;
cbuffer.y = 1;
SDL_Rect cbuffer1;
cbuffer1.w = 600;
cbuffer1.h = 400;
cbuffer1.x = 0;
cbuffer1.y = 0;
SDL_Rect creditspos;
creditspos.w=600;
creditspos.h=400;
creditspos.x=100;
creditspos.y=100;
SDL_Rect bgpos;
bgpos.w=600;
bgpos.h=420;
bgpos.x=100;
bgpos.y=100;
SDL_SetColorKey(creditsbuffer, 0, 0);
SDL_SetAlpha(creditsbuffer, SDL_SRCALPHA, 255);
SDL_BlitSurface(creditsbuffer, &cbuffer, creditsbuffer1, &cbuffer1);
SDL_BlitSurface(creditsbuffer1, &cbuffer1, creditsbuffer, &cbuffer1);
SDL_BlitSurface(background, &bgpos, screen, &bgpos);
SDL_SetColorKey(creditsbuffer, SDL_SRCCOLORKEY, SDL_MapRGB(creditsbuffer->format, 0, 255, 0));
SDL_SetAlpha(creditsbuffer, SDL_SRCALPHA, 128);
SDL_BlitSurface(creditsbuffer, &cbuffer1, screen, &creditspos);
SDL_UpdateRect(screen,100,100,600,400);
SDL_Delay(50);
linegone++;
if(linegone == creditsfont_h)
{
needinput = 1;
linegone = 0;
}
}
}
void do_help()
{
load_helpgfx();
fadesurface(background, 0, 0, 150);
print_text(scorefont, screen, 16, 16, 72, 68, " HOW TO PLAY PACHI EL MARCIANO ");
print_text(scorefont1, screen, 16, 16, 72, 120, "KEYS:");
print_text(scorefont1, screen, 16, 16,100, 140, "RIGHT : P");
print_text(scorefont1, screen, 16, 16,100, 160, "LEFT : O");
print_text(scorefont1, screen, 16, 16,100, 180, "DUCK : A");
print_text(scorefont1, screen, 16, 16,100, 200, "STAND UP : Q");
print_text(scorefont1, screen, 16, 16,100, 220, "JUMP : SPACE");
print_text(scorefont1, screen, 16, 16,100, 240, "PAUSE : H OR F1");
print_text(scorefont1, screen, 16, 16, 72, 270, "YOU CAN ALSO USE THE CURSOR KEYS / KEYPAD");
print_text(scorefont, screen, 16, 16, 72, 300, " THE GOAL OF THE GAME IS TO COLLECT ALL ");
print_text(scorefont, screen, 16, 16, 72, 320, " THE OBJECTS OF EACH LEVEL, WHEN THIS IS ");
print_text(scorefont, screen, 16, 16, 72, 340, " DONE, THE EXIT GATE TO THE NEXT LEVEL ");
print_text(scorefont, screen, 16, 16, 72, 360, "WILL APPEAR, BUT BEWARE OF THE ENEMIES...");
SDL_Flip(screen);
escape_exit=0;
while(escape_exit == 0)
{
credits_events();
}
unload_helpgfx();
}
void print_monitor()
{
print_text(scorefont1,screen,16,16,30,485,"%s", mstage[stage-1].title);
print_text(scorefont,screen,16,16,30,510, "SCORE:%d", score);
print_text(scorefont,screen,16,16,30,528, "LIVES:%d", mplayer[dificulty].lives);
print_text(scorefont,screen,16,16,30,546, "STAGE:%d", stage);
print_text(scorefont,screen,16,16,30,564, "ITEMS:%d/%d",mplayer[dificulty].objects,mstage[stage-1].objects);
SDL_UpdateRect(screen, 30, 482, 500, 100);
}
void blinkscreen(int R,int G, int B, int A)
{
SDL_FillRect(screen,NULL,SDL_MapRGBA(screen->format,R,G,B,A));
SDL_Flip(screen);
setback();
SDL_Flip(screen);
}
void print_room()
{
int x,y;
SDL_Rect gamearea;
gamearea.x=R_gamearea_x;
gamearea.y=R_gamearea_y;
gamearea.h=448;
gamearea.w=736;
SDL_FillRect(screen,&gamearea,0);
SDL_Rect backs_dst;
SDL_Rect backs_src;
SDL_Rect backs_dstbak;
backs_src.w = R_back_x;
backs_src.h = R_back_y;
backs_dst.w = R_back_x;
backs_dst.h = R_back_y;
for(x=0;x < R_maxbacks_h;x++)
{
for(y=0;y < R_maxbacks_v;y++)
{
backs_dst.x = R_gamearea_x + (x*R_back_x);
backs_dst.y = R_gamearea_y + (y*R_back_y);
backs_dstbak.x = x*R_back_x;
backs_dstbak.y = y*R_back_y;
backs_src.y = (int(R_backdata[x][y]/6) * R_back_y);
backs_src.x = (R_backdata[x][y] - (int(R_backdata[x][y]/6) * 6))*R_back_x;
SDL_BlitSurface(backs,&backs_src,screen,&backs_dst);
}
}
SDL_Rect tiles_dst;
SDL_Rect tiles_dstbak;
SDL_Rect tiles_src;
tiles_src.w = R_tileside;
tiles_src.h = R_tileside;
for(x=0;x < R_maxtiles_h;x++)
{
for(y=0;y < R_maxtiles_v;y++)
{
tiles_dst.x = R_gamearea_x + (x*R_tileside);
tiles_dst.y = R_gamearea_y + (y*R_tileside);
tiles_dstbak.x = x*R_tileside;
tiles_dstbak.y = y*R_tileside;
tiles_src.y = (int(mroom.data[x][y]/20) * R_tileside);
tiles_src.x = (mroom.data[x][y] - (int(mroom.data[x][y]/20) * 20))*R_tileside;
if((mroom.data[x][y] != 0) && (mroom.data[x][y] != 239))
SDL_BlitSurface(tiles,&tiles_src,screen,&tiles_dst);
if(mroom.data[x][y] == 239 && stagecompleted == 1)
SDL_BlitSurface(tiles,&tiles_src,screen,&tiles_dst);
}
}
SDL_BlitSurface(screen,&gamearea,screenbak,NULL);
print_monitor(); //imprime la informacion del jugador (vidas, puntos, etc)
SDL_Flip(screen);
}
void showcode(char *str)
{
SDL_Rect code;
code.x=280; code.y=220;code.w=240;code.h=50;
SDL_FillRect(screen,&code,SDL_MapRGB(screen->format,255,255,255));
code.x+=2; code.y+=2;code.w-=4;code.h-=4;
SDL_FillRect(screen,&code,SDL_MapRGB(screen->format,0,0,0));
code.x=280; code.y=220;code.w=240;code.h=50;
print_text(scorefont,screen,16,16,code.x+8,code.y+7,"STAGE CODE IS:");
print_text(scorefont1,screen,16,16,code.x+90,code.y+27,"%s",str);
SDL_UpdateRect(screen, code.x, code.y, code.w, code.h);
escape_exit=0;
while(escape_exit==0)
{
credits_events();
SDL_Delay(1);
}
}
void setback()
{
SDL_BlitSurface(background,NULL,screen,NULL);
SDL_Flip(screen);
}
void fadesurface(SDL_Surface *surface, int x, int y, int speed)
{
SDL_Rect dst;
dst.x=x; dst.y=y;
float alpha=0;
while(alpha<255)
{
delta_time();
SDL_SetAlpha(surface, SDL_SRCALPHA, int(alpha));
SDL_BlitSurface(surface, NULL, screen, &dst);
SDL_Flip(screen);
alpha+=(speed*imove);
}
SDL_SetAlpha(surface, 0, 0);
SDL_BlitSurface(surface, NULL, screen, &dst);
SDL_Flip(screen);
}
// speed es la velocidad del fade y blackback es un flag que indica si debe poner un fondo de color antes de imprimir (1=negro, 2=blanco)
float intro_blit(SDL_Surface *surface, int x, int y, int w, int h, float blit_alpha, int speed, int back)
{
SDL_Rect dst;
dst.x=x; dst.y=y; dst.w=w; dst.h=h;
int alpha=int(blit_alpha);
SDL_SetAlpha(surface, SDL_SRCALPHA, alpha);
blit_alpha+=(speed*imove);
SDL_BlitSurface(surface, NULL, screen, &dst);
SDL_UpdateRect(screen, dst.x, dst.y, dst.w, dst.h);
if(back==1)
{
if(blit_alpha<255)
SDL_FillRect(screen, &dst, SDL_MapRGB(screen->format,0,0,0));
}
if(back==2)
{
if(blit_alpha<255)
SDL_FillRect(screen, &dst, SDL_MapRGB(screen->format,255,255,255));
}
if(blit_alpha>255)
{
SDL_SetAlpha(surface, 0, 0);
SDL_BlitSurface(surface, NULL, screen, &dst);
SDL_Flip(screen);
}
return(blit_alpha);
}
float fade(SDL_Surface *surface, int x, int y, int w, int h, int R, int G, int B, int speed, float blit_alpha)
{
SDL_Rect dst;
dst.x=x; dst.y=y; dst.w=w; dst.h=h;
int alpha=int (blit_alpha);
SDL_SetAlpha(surface, SDL_SRCALPHA, alpha);
blit_alpha-=(speed*imove);
SDL_FillRect(screen, &dst, SDL_MapRGB(screen->format,R,G,B));
SDL_BlitSurface(surface, NULL, screen, &dst);
SDL_UpdateRect(screen, dst.x, dst.y, dst.w, dst.h);
return(blit_alpha);
}
void showposter(int num)
{
if(num==CEMETERY || num==CAVES || num==CASTLE || num==CASTLE+1 || num==LAB)
{
escape_exit=0;
SDL_Surface *temp;
switch(num)
{
case CEMETERY:
background=LoadT8(DATADIR"/Tgfx/cemetery.T8");
fadesurface(background, 0, 0, 200);
escape_exit=0;
break;
case CAVES:
background=LoadT8(DATADIR"/Tgfx/comic_02.T8");
fadesurface(background, 0, 0, 200);
escape_exit=0;
while(escape_exit==0) { credits_events(); SDL_Delay(1); }
background=LoadT8(DATADIR"/Tgfx/cave.T8");
fadesurface(background, 0, 0, 200);
escape_exit=0;
break;
case CASTLE:
background=LoadT8(DATADIR"/Tgfx/comic_03.T8");
fadesurface(background, 0, 0, 200);
escape_exit=0;
while(escape_exit==0) { credits_events(); SDL_Delay(1); }
break;
case CASTLE+1:
background=LoadT8(DATADIR"/Tgfx/comic_04.T8");
fadesurface(background, 0, 0, 200);
escape_exit=0;
while(escape_exit==0) { credits_events(); SDL_Delay(1); }
background=LoadT8(DATADIR"/Tgfx/castle.T8");
fadesurface(background, 0, 0, 200);
escape_exit=0;
break;
case LAB:
background=LoadT8(DATADIR"/Tgfx/comic_05.T8");
fadesurface(background, 0, 0, 200);
escape_exit=0;
while(escape_exit==0) { credits_events(); SDL_Delay(1); }
background=LoadT8(DATADIR"/Tgfx/comic_06.T8");
fadesurface(background, 0, 0, 200);
escape_exit=0;
while(escape_exit==0) { credits_events(); SDL_Delay(1); }
background=LoadT8(DATADIR"/Tgfx/comic_07.T8");
fadesurface(background, 0, 0, 200);
escape_exit=0;
while(escape_exit==0) { credits_events(); SDL_Delay(1); }
background=LoadT8(DATADIR"/Tgfx/comic_08.T8");
fadesurface(background, 0, 0, 200);
escape_exit=0;
while(escape_exit==0) { credits_events(); SDL_Delay(1); }
background=LoadT8(DATADIR"/Tgfx/lab.T8");
fadesurface(background, 0, 0, 200);
escape_exit=0;
break;
default:
break;
}
while(escape_exit==0) { credits_events(); SDL_Delay(1); }
}
background=LoadT8(DATADIR"/Tgfx/gamepanel.T8");
fadesurface(background, 0, 0, 250);
}

View File

@@ -0,0 +1,384 @@
/***************************************************************************
* Pachi el marciano *
* ----------------- *
* (c) Santiago Radeff (coding) *
* (c) Nicolas Radeff (graphics) *
* (c) Peter Hajba (music) *
* *
* T-1000@Bigfoot.com *
****************************************************************************
*******************************************************************
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version *
* 2 of the License, or (at your option) any later version. *
* *
*******************************************************************/
void loose_life()
{
Mix_Volume(4,100);
Mix_PlayChannel(4,die,0);
blinkscreen(255,0,0,0);
mplayer[dificulty].x=mplayer[dificulty].start_x;
mplayer[dificulty].y=mplayer[dificulty].start_y;
mplayer[dificulty].h=mplayer[dificulty].h;
mplayer[dificulty].left=0;
mplayer[dificulty].right=0;
mplayer[dificulty].jump=0;
mplayer[dificulty].duck=0;
mplayer[dificulty].lives--;
mplayer[dificulty].jumpcounter=0;
mplayer[dificulty].dead=0;
if(mplayer[dificulty].lives>0)
{
blinkscreen(255,255,255,0);
load_room();
print_room();
init_monsters();
}
}
void pick_obj(int x, int y) // esta rutina elimina el objeto de la matriz objects, lo elimina de la pantalla y le suma la puntuacion conrrespondiente al jugador
{
initfade_object(x, y, mroom.data[x][y]);
fadingobject=1;
mroom.data[x][y]=0;
for(int n=0;n<5;n++)
{
if((mobject[(R_current-1)*5+n].x == x) && (mobject[(R_current-1)*5+n].y == y))
{
score = score + (50*dificulty);
if(sequence==mobject[(R_current-1)*5+n].seq)
{
gametimer=gametimer+5;
Mix_Volume(6,128);
Mix_PlayChannel(6,objseq,0);
}
mobject[(R_current-1)*5+n].type = 0;
mobject[(R_current-1)*5+n].x = 0;
mobject[(R_current-1)*5+n].y = 0;
mobject[(R_current-1)*5+n].seq = 0;
print_monitor();
}
}
mplayer[dificulty].objects++;
Mix_Volume(1,100);
if(mplayer[dificulty].objects==mstage[stage-1].objects)
{
stagecompleted = 1;
blinkscreen(255,255,255,0);
Mix_PlayChannel(1,stageready,0);
}
else
Mix_PlayChannel(1,obj,0);
print_room();
}
void chk_touched(int x, int y)
{
if((mroom.data[x][y] >= 239) && (stagecompleted == 1))
{
Mix_HaltMusic();
Mix_Volume(0,100);
Mix_PlayChannel(0,exitlevel,0);
mplayer[dificulty].stageup=1;
}
if((mroom.data[x][y] >= 220) && (mroom.data[x][y] < 239))
mplayer[dificulty].dead=1;
if((mroom.data[x][y] < 220) && (mroom.data[x][y] >= 200))
pick_obj(x,y);
}
void P_chk_right()
{
int x, y;
if(mplayer[dificulty].x + mplayer[dificulty].w >= (R_tileside*R_maxtiles_h))
{
R_current++;
mplayer[dificulty].x = 2;
mplayer[dificulty].start_x = int(mplayer[dificulty].x);
mplayer[dificulty].start_y = int(mplayer[dificulty].y);
if(mplayer[dificulty].duck==1)
mplayer[dificulty].start_y=mplayer[dificulty].start_y-(P_h - P_h/2); // P_h es la altura parado y P_h/2 la altura agachado
init_room();
}
for(int n=0;n<=mplayer[dificulty].h-mplayer[dificulty].tolerance;n++)
{
x=int(mplayer[dificulty].x+mplayer[dificulty].w)/R_tileside;
y=int((mplayer[dificulty].y+n)/R_tileside);
chk_touched(x, y);
if(mroom.data[x][y] >= 80 && mroom.data[x][y] < 200)
mplayer[dificulty].x=mplayer[dificulty].old_x;
}
}
void P_chk_left()
{
int x, y;
if(mplayer[dificulty].x < 2)
{
R_current--;
init_room();
mplayer[dificulty].x = R_maxtiles_h*R_tileside - mplayer[dificulty].w;
mplayer[dificulty].start_x = int(mplayer[dificulty].x); //estas variables son para cuando se pierde una vida se vuelve el player a esta posicion
mplayer[dificulty].start_y = int(mplayer[dificulty].y);
if(mplayer[dificulty].duck==1)
mplayer[dificulty].start_y=mplayer[dificulty].start_y-(P_h - P_h/2);
}
for(int n=0;n<=mplayer[dificulty].h-mplayer[dificulty].tolerance;n++)
{
x=int(mplayer[dificulty].x)/R_tileside; //posible P_x -1
y=int((mplayer[dificulty].y+1+n)/R_tileside);
chk_touched(x,y);
if(mroom.data[x][y] >= 80 && mroom.data[x][y] < 200)
mplayer[dificulty].x=mplayer[dificulty].old_x;
}
}
void chk_up()
{
int x, y;
if(mplayer[dificulty].y <= 1)
{
R_current = R_current - R_max_x;
mplayer[dificulty].y = float(((R_maxtiles_v-1)*R_tileside) - mplayer[dificulty].h - 1);
mplayer[dificulty].start_x = int(mplayer[dificulty].x); //estas variables son para cuando se pierde una vida se vuelve el player a esta posicion
mplayer[dificulty].start_y = int(mplayer[dificulty].y);
mplayer[dificulty].startjump=int(mplayer[dificulty].y+(R_tileside*1.5));
init_room();
}
for(int n=0;n<=mplayer[dificulty].w-1;n++)
{
x=int(mplayer[dificulty].x+n)/R_tileside;
y=int(mplayer[dificulty].y/R_tileside);
chk_touched(x,y); //esta rutina compruba que tipo de tile toca el personaje
if(mroom.data[x][y] >= 80 && mroom.data[x][y] < 200)
{
mplayer[dificulty].y=int((y+1)*R_tileside);
if(mplayer[dificulty].jump == 1 && mplayer[dificulty].upflag == 1)
{
mplayer[dificulty].upflag = 0;
mplayer[dificulty].downflag = 1;
}
}
}
}
void chk_down()
{
int x, y;
if((mplayer[dificulty].jump==0) || (mplayer[dificulty].downflag==1))
{
for(int n=0;n<mplayer[dificulty].w ;n++)
{
x=int(mplayer[dificulty].x+n)/R_tileside;
y=int((mplayer[dificulty].y+mplayer[dificulty].h+1)/R_tileside);
chk_touched(x,y);
if(mroom.data[x][y] >= 40 && mroom.data[x][y] < 200)
{
mplayer[dificulty].y=mplayer[dificulty].old_y;
mplayer[dificulty].infloor=1; // esta varible indica si esta en el suelo
mplayer[dificulty].y=int((mplayer[dificulty].y+(R_tileside/2))/R_tileside)*R_tileside;
mplayer[dificulty].jump=0;
mplayer[dificulty].jumpcounter=0;
mplayer[dificulty].upflag=0;
mplayer[dificulty].downflag=1;
}
}
if(mplayer[dificulty].y >= (R_maxtiles_v*R_tileside) - mplayer[dificulty].h)
{
R_current = R_current + R_max_x;
init_room();
mplayer[dificulty].y = 2;
mplayer[dificulty].start_x = int(mplayer[dificulty].x); //estas variables son para cuando se pierde una vida se vuelve el player a esta posicion
mplayer[dificulty].start_y = int(mplayer[dificulty].y);
}
}
}
void chk_colmonsters() //chequear colisiones contra monstruos
{
for(int n=0;n<=M_max4room-1;n++)
{
if(M_type[n] != 0)
if(mplayer[dificulty].y < M_y[n]+M_h-mplayer[dificulty].tolerance && mplayer[dificulty].y+mplayer[dificulty].h > M_y[n]+mplayer[dificulty].tolerance)
if(mplayer[dificulty].x < M_x[n]+M_h-mplayer[dificulty].tolerance && mplayer[dificulty].x+mplayer[dificulty].w > M_x[n]+mplayer[dificulty].tolerance)
mplayer[dificulty].dead=1;
}
}
void set_player_pos()
{
if(mplayer[dificulty].dead==0) // si el personaje esta muerto no chequea colisiones
{
mplayer[dificulty].infloor = 0;
mplayer[dificulty].old_x = mplayer[dificulty].x;
mplayer[dificulty].old_y = mplayer[dificulty].y;
chk_colmonsters(); // esta rutina chequea colisiones contra monstruos
if(mplayer[dificulty].duck == 1)
mplayer[dificulty].h=P_h/2;
else
mplayer[dificulty].h=P_h;
if(mplayer[dificulty].left==1)
{
if(mplayer[dificulty].duck==1)
mplayer[dificulty].speed=mplayer[dificulty].realspeed/2;
else
mplayer[dificulty].speed=mplayer[dificulty].realspeed;
mplayer[dificulty].x=mplayer[dificulty].x-(mplayer[dificulty].speed*imove);
P_chk_left();
}
if(mplayer[dificulty].right==1)
{
if(mplayer[dificulty].duck==1)
mplayer[dificulty].speed=mplayer[dificulty].realspeed/2;
else
mplayer[dificulty].speed=mplayer[dificulty].realspeed;
mplayer[dificulty].x=mplayer[dificulty].x+(mplayer[dificulty].speed*imove);
P_chk_right();
}
if(mplayer[dificulty].jump==1)
{
if(mplayer[dificulty].upflag==1)
{
mplayer[dificulty].jumpcounter=int(mplayer[dificulty].startjump-mplayer[dificulty].y);
mplayer[dificulty].maxjump=mplayer[dificulty].realmaxjump;
if(mplayer[dificulty].jumpcounter <= mplayer[dificulty].maxjump)
{
if(mplayer[dificulty].jumpcounter >= mplayer[dificulty].maxjump/1.5)
{
if(mplayer[dificulty].jumpslower==1)
{
mplayer[dificulty].y=mplayer[dificulty].y+(mplayer[dificulty].fallspeed*imove);
mplayer[dificulty].jumpslower=0;
}
else
mplayer[dificulty].jumpslower=1;
}
mplayer[dificulty].y=mplayer[dificulty].y-(mplayer[dificulty].fallspeed*imove);
}
else
{
mplayer[dificulty].downflag = 1;
mplayer[dificulty].upflag = 0;
}
chk_up();
}
if(mplayer[dificulty].downflag==1)
{
mplayer[dificulty].jumpcounter=int(mplayer[dificulty].y-mplayer[dificulty].startjump);
if(mplayer[dificulty].jumpcounter > 0)
{
mplayer[dificulty].maxjump=mplayer[dificulty].realmaxjump;
if(mplayer[dificulty].jumpcounter >= mplayer[dificulty].maxjump/1.5)
{
if(mplayer[dificulty].jumpslower==1)
{
mplayer[dificulty].y=mplayer[dificulty].y-(mplayer[dificulty].fallspeed*imove);
mplayer[dificulty].jumpslower=0;
}
else
mplayer[dificulty].jumpslower=1;
}
mplayer[dificulty].y=mplayer[dificulty].y+(mplayer[dificulty].fallspeed*imove);
}
else
{
mplayer[dificulty].jump = 0;
}
}
}
if(mplayer[dificulty].jump==0)
mplayer[dificulty].y=mplayer[dificulty].y+(mplayer[dificulty].fallspeed*imove); // para que se caiga si no hay suelo debajo
chk_down();
}
oldplayerpos.x = int(mplayer[dificulty].old_x);
oldplayerpos.y = int(mplayer[dificulty].old_y);
oldplayerpos.w = mplayer[dificulty].w;
oldplayerpos.h = mplayer[dificulty].h;
if(mplayer[dificulty].ducked==1)
{
mplayer[dificulty].ducked = 0;
oldplayerpos.h = oldplayerpos.h + (P_h - P_h/2);
oldplayerpos.y = oldplayerpos.y - (P_h - P_h/2);
}
playerpos.x = int(mplayer[dificulty].x);
playerpos.y = int(mplayer[dificulty].y);
}
void clean_player()
{
set_player_pos();
playerposreal.x = playerpos.x + R_gamearea_x;
playerposreal.y = playerpos.y + R_gamearea_y;
oldplayerposreal.x = oldplayerpos.x + R_gamearea_x;
oldplayerposreal.y = oldplayerpos.y + R_gamearea_y;
SDL_BlitSurface(screenbak,&oldplayerpos,screen, &oldplayerposreal);
}
void print_player()
{
playersrc.y = mplayer[dificulty].framer*P_h;
playersrc.x = mplayer[dificulty].w * (mplayer[dificulty].frame - 1 + mplayer[dificulty].facingleft*mplayer[dificulty].frames);
playersrc.w = mplayer[dificulty].w;
playersrc.h = mplayer[dificulty].h;
SDL_BlitSurface(player, &playersrc, screen, &playerposreal);
SDL_UpdateRect(screen,oldplayerposreal.x,oldplayerposreal.y,P_w,oldplayerpos.h);
SDL_UpdateRect(screen,playerposreal.x,playerposreal.y,mplayer[dificulty].w,mplayer[dificulty].h);
}
void animateplayer()
{
// Esta rutina pone el valor correspondiente a la fila de sprites en el archivo BMP del personaje en la variable framer
if(mplayer[dificulty].right!=0 || mplayer[dificulty].left != 0)
{
mplayer[dificulty].frame++;
if(mplayer[dificulty].duck==1 && mplayer[dificulty].right==0 && mplayer[dificulty].left==0)
mplayer[dificulty].frame--;
}
if(mplayer[dificulty].right==1 || mplayer[dificulty].left == 1)
mplayer[dificulty].framer = 1;
if(mplayer[dificulty].right==0 && mplayer[dificulty].left == 0 && mplayer[dificulty].duck==0) // parado
{
mplayer[dificulty].framer = 0;
mplayer[dificulty].frame++;
}
if(mplayer[dificulty].duck==1) // agachado
mplayer[dificulty].framer = 2;
if(mplayer[dificulty].jump==1 && mplayer[dificulty].upflag==1) // saltando (subiendo)
{
mplayer[dificulty].framer = 3;
mplayer[dificulty].frame = 1;
}
if(mplayer[dificulty].downflag==1 && mplayer[dificulty].infloor == 0 && mplayer[dificulty].duck== 0) // cayendo o saltando (bajando)
{
mplayer[dificulty].framer = 3;
mplayer[dificulty].frame = 2;
}
if(mplayer[dificulty].frame > mplayer[dificulty].frames)
mplayer[dificulty].frame=1;
}

View File

@@ -0,0 +1,44 @@
void stop_music();
void credits_events();
void menu_events();
void setback();
void fadesurface(SDL_Surface *surface, int x, int y, int speed);
void screen_mode();
void setgame();
void start_game();
void load_menufont();
void unload_menufont();
void do_code();
void do_hiscores();
void load_room();
void print_room();
void init_room();
void init_objects();
void initfade_object(int x, int y, int object);
float fade_object(float alpha);
double delta_time();
void init_monsters();
void print_monsters();
void chk_touched(int x, int y);
void print_player();
void animateplayer();
void respawn();
void print_timer();
void stage_up();
void flushevents();
void screen_fx();
void bright_obj(int bright_x, int bright_y);
void check_joystick_events(SDL_Event *event, Uint8 *joypos);
void game_loop();
void show_arrow(int arrow, int show);
void win_game();

View File

@@ -0,0 +1,41 @@
#define easy 1
#define normal 2
#define hard 3
void setgame()
{
stage=startstage;
startstage=0;
score=0;
gametimer=0;
mplayer[easy].realspeed=150;
mplayer[normal].realspeed=150;
mplayer[hard].realspeed=180;
mplayer[easy].fallspeed=150;
mplayer[normal].fallspeed=150;
mplayer[hard].fallspeed=180;
mplayer[easy].realmaxjump=80;
mplayer[normal].realmaxjump=70;
mplayer[hard].realmaxjump=70;
mplayer[easy].tolerance=10;
mplayer[normal].tolerance=8;
mplayer[hard].tolerance=5;
M_speed[easy]=130;
M_speed[normal]=150;
M_speed[hard]=200;
for(int n=1;n<=3;n++)
{
mplayer[n].lives=maxlives;
mplayer[n].frames=10;
mplayer[n].h=P_h;
mplayer[n].w=P_w;
}
}

View File

@@ -0,0 +1,13 @@
Mix_Music *music;
Mix_Chunk *jump;
Mix_Chunk *obj;
Mix_Chunk *objseq;
Mix_Chunk *die;
Mix_Chunk *stageready;
Mix_Chunk *exitlevel;
Mix_Chunk *timer;
Mix_Chunk *storm;
Mix_Chunk *respawnsnd;
Mix_Chunk *option;
Mix_Chunk *coderight;
Mix_Chunk *codewrong;

View File

@@ -0,0 +1,98 @@
void init_stages ()
{
mstage[0].title=" HARD LANDING ! ";
mstage[0].music=DATADIR"/music/stage1.s3m.ogg";
mstage[0].objects=10;
mstage[0].time=190;
mstage[0].code="HARD";
mstage[1].title=" ENTRANCE TO CEMETERY ";
mstage[1].music=DATADIR"/music/stage1.s3m.ogg";
mstage[1].objects=12;
mstage[1].time=205;
mstage[1].code="MARS";
mstage[2].title=" INTO THE CEMETERY (1) ";
mstage[2].music=DATADIR"/music/stage1.s3m.ogg";
mstage[2].objects=12;
mstage[2].time=350;
mstage[2].code="CMTR";
mstage[3].title=" INTO THE CEMETERY (2) ";
mstage[3].music=DATADIR"/music/stage1.s3m.ogg";
mstage[3].objects=19;
mstage[3].time=290;
mstage[3].code="TOMB";
mstage[4].title=" WHERE IS THE EXIT GATE? ";
mstage[4].music=DATADIR"/music/stage1.s3m.ogg";
mstage[4].objects=18;
mstage[4].time=370;
mstage[4].code="SKLL";
mstage[5].title=" PASSAGE TO THE CAVES ";
mstage[5].music=DATADIR"/music/stage1.s3m.ogg";
mstage[5].objects=10;
mstage[5].time=120;
mstage[5].code="EVAC";
mstage[6].title=" THE CAVES ";
mstage[6].music=DATADIR"/music/stage2.stm.ogg";
mstage[6].objects=14;
mstage[6].time=250;
mstage[6].code="EYES";
mstage[7].title=" DEN OF RATS ";
mstage[7].music=DATADIR"/music/stage2.stm.ogg";
mstage[7].objects=15;
mstage[7].time=250;
mstage[7].code="RATS";
mstage[8].title=" THE PIT ";
mstage[8].music=DATADIR"/music/stage2.stm.ogg";
mstage[8].objects=20;
mstage[8].time=300;
mstage[8].code="DIRT";
mstage[9].title=" THE CASTLE GARDENS ";
mstage[9].music=DATADIR"/music/stage2.stm.ogg";
mstage[9].objects=13;
mstage[9].time=210;
mstage[9].code="CAST";
mstage[10].title=" THE CASTLE HALL ";
mstage[10].music=DATADIR"/music/stage3.s3m.ogg";
mstage[10].objects=15;
mstage[10].time=250;
mstage[10].code="HALL";
mstage[11].title=" TOWER ENTRANCE ";
mstage[11].music=DATADIR"/music/stage3.s3m.ogg";
mstage[11].objects=20;
mstage[11].time=150;
mstage[11].code="TTWR";
mstage[12].title=" THE FIRST TOWER ";
mstage[12].music=DATADIR"/music/stage3.s3m.ogg";
mstage[12].objects=17;
mstage[12].time=140;
mstage[12].code="TWR1";
mstage[13].title=" THE TWO TOWERS ";
mstage[13].music=DATADIR"/music/stage3.s3m.ogg";
mstage[13].objects=26;
mstage[13].time=200;
mstage[13].code="2TWR";
mstage[14].title=" THE SECRET PLACE ";
mstage[14].music=DATADIR"/music/stage3.s3m.ogg";
mstage[14].objects=20;
mstage[14].time=150;
mstage[14].code="DXTR";
mstage[15].title=" THE LABORATORY ";
mstage[15].music=DATADIR"/music/stage4.s3m.ogg";
mstage[15].objects=90;
mstage[15].time=540;
mstage[15].code="XLAB";
}

View File

@@ -0,0 +1,57 @@
struct Cobject
{
int type;
int x;
int y;
int seq;
int stage;
};
struct Cplayer
{
float x, y; // posiciones x, y
float old_x, old_y; // posiciones anteriores de x y
int w, h; // anchura y altura
int speed; // velocidad
int realspeed; // copia de velocidad, se usa para restaurar el valor de speed en caso que haya sido modificado
int fallspeed; // velocidad de caida libre
int frames; // cantidad de frames de animacion
int frame, framer; // frame actual y fila de frames actual (las filas son: quieto, corriendo, agachado, saltando, cayendo)
int left, right, jump, duck;
int start_x, start_y; // posiciones iniciales en la pantalla
int lives; // vidas del jugador
int tolerance; // tolerancia de la deteccion de colisiones contra los monstruos
int objects; // objetos recogidos en la pantalla actual
int startjump;
int jumpcounter; // contador de altura del selto
int maxjump; // altura del salto
int realmaxjump; // copia de altura del salto en caso que haya que restaurarlo
int dead; // inficador si esta muerto
int stageup; // indicador si la pantalla esta completa
int upflag, downflag;
int infloor;
int facingleft;
int ducked;
int jumpslower;
};
struct Cstages
{
char * title;
char * music;
int objects;
int time;
char * code;
};
struct Croom
{
int data[R_maxtiles_h][R_maxtiles_v]; // los datos (tiles) de la habitacion
int stage; // a que stage pertenece
};
Croom mroom;
Cobject mobject[2000]; // almacena los objetos del juego
Cplayer mplayer[4];
Cstages mstage[NUM_STAGES];

View File

@@ -0,0 +1,35 @@
// --- Fonts
SDL_Surface *font;
SDL_Surface *scorefont;
SDL_Surface *scorefont1;
SDL_Surface *scorefont2;
SDL_Surface *menufont;
SDL_Surface *menufont1;
// --- Screen
SDL_Surface *screen;
SDL_Surface *background;
SDL_Surface *backs;
SDL_Surface *tiles;
SDL_Surface *screenbak;
// --- FX
SDL_Surface *bright;
SDL_Surface *creditsbuffer;
SDL_Surface *creditsbuffer1;
SDL_Surface *creditsfont;
SDL_Surface *left;
SDL_Surface *right;
// --- Monsters
SDL_Surface *monsters;
// --- Player
SDL_Surface *player;
// --- Intro
SDL_Surface *dragontech;
SDL_Surface *line1;
SDL_Surface *line2;
SDL_Surface *comic_01;
SDL_Surface *black;

View File

@@ -0,0 +1,32 @@
void print_text(SDL_Surface *font, SDL_Surface *surface, int font_w, int font_h, int text_x, int text_y, char *str, ...) //Rutina para imprimir texto estatico en la pantalla
{
SDL_Rect srctxt; // la posicion donde se encuentra el caracter en el bitmap
SDL_Rect dsttxt; // la posicion donde se imprimira el texto
char texto [100];
va_list ap;
va_start(ap, str);
vsprintf(texto, str, ap);
va_end(ap);
srctxt.w = font_w;
srctxt.h = font_h;
srctxt.y = 0;
int linecounter = 0 ; // este contador se utiliza para saber en que linea imprimimos el texto
int charpos = 0;
for(int charcounter = 0; charcounter <= (strlen(texto));charcounter++)
{
int curchar=texto[charcounter];
if(curchar == 94)
{
linecounter++;
charpos = -1;
}
srctxt.x = (curchar - 32) * font_w;
dsttxt.x = (text_x + (charpos * font_w));
dsttxt.y = (text_y + (linecounter * font_h));
charpos++;
SDL_BlitSurface (font,&srctxt,surface,&dsttxt);
}
}