From d6735eea1647be9eb9e3566fe6e3dadcc130ea5c Mon Sep 17 00:00:00 2001 From: Rob Pearce Date: Fri, 27 Jan 2006 06:27:57 +0000 Subject: [PATCH] o --- Makefile | 2 + Makefile.posix | 2 + Makefile.windows | 2 + blank.bmp | Bin 0 -> 822 bytes cheese.bmp | Bin 0 -> 822 bytes dwarf.jpg | Bin 0 -> 4086 bytes emptylevel | 32 ++ full.bmp | Bin 0 -> 822 bytes greentiles | 67 +++ ladder.bmp | Bin 0 -> 822 bytes laddertop.bmp | Bin 0 -> 822 bytes land.bmp | Bin 0 -> 822 bytes left.bmp | Bin 0 -> 822 bytes level.dat | 31 ++ level1.dat | 32 ++ oldblank.bmp | Bin 0 -> 822 bytes pdwarf.png | Bin 0 -> 907 bytes pdwarffall.png | Bin 0 -> 724 bytes pdwarfjump.png | Bin 0 -> 816 bytes pfall.bmp | Bin 0 -> 1374 bytes pjump.bmp | Bin 0 -> 1374 bytes player.bmp | Bin 0 -> 1374 bytes rat.bmp | Bin 0 -> 2574 bytes ratcaught.bmp | Bin 0 -> 1198 bytes ratdead.bmp | Bin 0 -> 1198 bytes rc.c | 1316 ++++++++++++++++++++++++++++++++++++++++++++++ rc.h | 163 ++++++ right.bmp | Bin 0 -> 822 bytes sky.bmp | Bin 0 -> 822 bytes slopedown.bmp | Bin 0 -> 822 bytes slopeup.bmp | Bin 0 -> 822 bytes spikes.bmp | Bin 0 -> 822 bytes svn-commit.tmp | 37 ++ testlevel | 32 ++ tiles.conf | 37 ++ 35 files changed, 1753 insertions(+) create mode 100644 Makefile create mode 100644 Makefile.posix create mode 100644 Makefile.windows create mode 100644 blank.bmp create mode 100644 cheese.bmp create mode 100644 dwarf.jpg create mode 100644 emptylevel create mode 100644 full.bmp create mode 100644 greentiles create mode 100644 ladder.bmp create mode 100644 laddertop.bmp create mode 100644 land.bmp create mode 100644 left.bmp create mode 100644 level.dat create mode 100644 level1.dat create mode 100644 oldblank.bmp create mode 100644 pdwarf.png create mode 100644 pdwarffall.png create mode 100644 pdwarfjump.png create mode 100644 pfall.bmp create mode 100644 pjump.bmp create mode 100644 player.bmp create mode 100644 rat.bmp create mode 100644 ratcaught.bmp create mode 100644 ratdead.bmp create mode 100644 rc.c create mode 100644 rc.h create mode 100644 right.bmp create mode 100644 sky.bmp create mode 100644 slopedown.bmp create mode 100644 slopeup.bmp create mode 100644 spikes.bmp create mode 100644 svn-commit.tmp create mode 100644 testlevel create mode 100644 tiles.conf diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..315e428 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +rc: rc.c rc.h + gcc -mwindows -Wall -orc -g rc.c `sdl-config --cflags --libs` -I/usr/local/include -L/usr/local/lib -lSDLmain -lSDL -lSDL_image -lSDL_gfx diff --git a/Makefile.posix b/Makefile.posix new file mode 100644 index 0000000..315e428 --- /dev/null +++ b/Makefile.posix @@ -0,0 +1,2 @@ +rc: rc.c rc.h + gcc -mwindows -Wall -orc -g rc.c `sdl-config --cflags --libs` -I/usr/local/include -L/usr/local/lib -lSDLmain -lSDL -lSDL_image -lSDL_gfx diff --git a/Makefile.windows b/Makefile.windows new file mode 100644 index 0000000..619fd17 --- /dev/null +++ b/Makefile.windows @@ -0,0 +1,2 @@ +rc: rc.c rc.h + gcc -mwindows -mno-cygwin -Wall -orc.exe -DWINDOWS -g rc.c `sdl-config --cflags --libs` -I/usr/local/include -lmingw32 -L/usr/local/lib -lSDLmain -lSDL -lSDL_image -lSDL_gfx diff --git a/blank.bmp b/blank.bmp new file mode 100644 index 0000000000000000000000000000000000000000..4b7beea27a4c4729c8fdea67db12ae458e22ea51 GIT binary patch literal 822 zcmZ?rHDhJ~12Z700mK4O%*Y@C7H0s;AK`;whyVjaAVVPWD2E}3c*Q`KWT*#fAqmmi VJ*1jXlHgFo1$^5lp?1h=VIYV?flyO@JtdkeEgx e>qS-xXCo_sYlq8XGLY2+*~9>d7GhM=MhyU@(C+yF literal 0 HcmV?d00001 diff --git a/dwarf.jpg b/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qkvL3GjM^LCDQEOzqrYNcuNU%NH+7g<_y z?U;2-msm`~#d%sZ015lXRM3`l+mk)lKyg@_jdsdosp_->o3p=V$Ri5f;T*(+l6$Ce z=5g(+TNXMO-kFp*S(OLo)Yol+bbn`@0z%%+KZnX9<)1xz_U)x!|EyS35LCh1sCz_B zz((;p}EZ%P$+}+PdI5&_%Q_Mo~9Q+VgS;8>Jv^`+j-0`VY}IH~uWNN-4G&77+x+@_%$Ady#yqoHh4#hQS+u3Idtg zoI)2ntv5pzavxQvNsmmJ;Ko&p4rSHaF*0zmn`D!Qe;j|-gk9i&0jE_o7}a&M4O2;H~p`TxQ_~732EZPlS(*Cuw-M z)!dVpFQz!-Z*Od0a@wqfsjbo*kp{Gwp-DaHpZPymSN9$rW{t#k#T5~M`IU9`(uUbH zXS$KF(ww%v^MZ`kRCBwA4@*`}#VqlN5fdmg zsve39#WaxLJtv!4A?K4ywgx!U5LJ<=i@g9DGogG{PZqtsNSPm-Z=B1na|q;pjW~y~ zoj-fNAGHIt9R#?(28xOX5pRX&hxqq|buI}A*x{BGo3@ zgC4S*-$iONz_Fh*KjMa*+a7F*x#IEt@|PXGW9y?9Y9bb0>rn&IdbjFw3M@OA#f#*g GzWWcB20o7f literal 0 HcmV?d00001 diff --git a/emptylevel b/emptylevel new file mode 100644 index 0000000..cb3f7f5 --- /dev/null +++ b/emptylevel @@ -0,0 +1,32 @@ +tileset greentiles +bg 0 +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +*00000000000000000000000000000000000000* +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/full.bmp b/full.bmp new file mode 100644 index 0000000000000000000000000000000000000000..eeedda991d8dab0577c8df621b780ed85769c730 GIT binary patch literal 822 zcmZ?rHDhJ~12Z700mK4O%*Y@C7H0s;AK`;whyalMKe&-Y1Ensc+yn}PXrLTGp}iDp MCpFOMY#q#b0AR!boB#j- literal 0 HcmV?d00001 diff --git a/greentiles b/greentiles new file mode 100644 index 0000000..e75bb15 --- /dev/null +++ b/greentiles @@ -0,0 +1,67 @@ +tile blank +id 0 +solid 0 +file blank.bmp +end + +tile land +id 1 +solid 1 +file land.bmp +end + +tile slopeup +id 2 +solid 2 +lowness 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0 +file slopeup.bmp +end + +tile slopedown +id 3 +solid 2 +lowness 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 +file slopedown.bmp +end + +tile full +id 4 +solid 1 +file full.bmp +end + +tile sky +id 5 +solid 0 +file sky.bmp +end + +tile ladder +id 6 +solid 0 +file ladder.bmp +end + +tile laddertop +id 7 +solid 1 +file laddertop.bmp +end + +tile right +id 8 +solid 1 +file right.bmp +end + +tile left +id 9 +solid 1 +file left.bmp +end + +tile spikes +id 10 +solid 0 +file spikes.bmp +end diff --git a/ladder.bmp b/ladder.bmp new file mode 100644 index 0000000000000000000000000000000000000000..4558afc1a20d1294442319cf4bda4945194764d8 GIT binary patch literal 822 zcmZ?rHDhJ~12Z700mK4O%*Y@C7H0s;AK`;whyaXqX!uVM!PJ6if{K9(Fx4ZAAhRK+ z;TOR#OP+i1>%wm%epyT(5u=_|_mHX{*$v2SOxI$H5Tl+{_mHX{*$v2SOxI$H;8G6& D#jxUs literal 0 HcmV?d00001 diff --git a/laddertop.bmp b/laddertop.bmp new file mode 100644 index 0000000000000000000000000000000000000000..05b59a4874593c4876d64abd26b2c1ca414eef72 GIT binary patch literal 822 zcmZ?rHDhJ~12Z700mK4O%*Y@C7H0s;AK`;whyalM4?+$N{|O?9N=notn}E!QSdCu< zzbrw=0~KJJfL|A;dSnq~_Rw~}Ljwu!cW3~n6&vTU#bL#>QF{+^fww!4_oyL8mW6>{vln`=xk=dr2hM%& z^EuD=`y4m`JbXB(_@6k`-91)bqg56hJKEGUdq z8XF(s)CZ^goH|i1@A~zhuq=zGPuGb=nlMd^lP6CA(AD*t@IWoCF=B1aYHWN2fJEYZ z!r>4AH>ak#b9crCTzRp!W_9BI_qcWIXKqeSdpwp*Yv<`4JKCq5<;3K733p#vuQeG4 zJ<(R)J#xfN_V&KbK!3lxuYx{4b4K;FwN?E%h^WdrAx+cdaVFy?ewa)!JNpL!x36C1 z^Zo(i=P!69%Fjke#czKm#gUw=*mjiVGB$Fv} zKFQ-uhL!a!)4$xV9{I0--j6Hniyc;pmW2i8_cQ`<{-Z%krU{_RL3g7x)TWdKY?~`@ zyvgsoLVR-WEC8iaiLb7G<93t|01&XB`7%-|0KOa<1whwzk0((MmB&m=41mk89ssEF zMTgP&;kGW6((tSs!^7%cET-~3vj8sQ=Q5eJW`gV#{71X31Rmw zEH2Nwo}8G-ZitNv{eLMzaJz^mWUprsPNY}YSkrv&cT)FbN}Elek6dv(z9VE9P3%!G z6yK;1(U8wmW81t{TdQ`2ns$ekZa;fS3PSLxlqVgnWuskZ|Lc-VUqqE*gkLq!n+rUcuV?v*qT}E{tgP%)E))p(iAMjWA-qX hExtrBSfah%=07?gL%Obk6CeNp002ovPDHLkV1nU=qNM-; literal 0 HcmV?d00001 diff --git a/pdwarffall.png b/pdwarffall.png new file mode 100644 index 0000000000000000000000000000000000000000..2d397d44ac9c2c7a7aa70762538ad3f16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V;`_j z*t_Y76CCsh$a(+odTx077B9xauFr2F>5O3)9h=3WECQ|uhKoy}h^(3@ke*^_(OL9b zh4Jh48*ffYrk<2aGUY{uD4p0(GYTr99LLBo0?q4f*qey9F_oaw#MZw5A(9N$h*l%~ j;p!G;n*&x~KO8;E&y!d9q?4(4LUFOR34hp4^)5Xev( literal 0 HcmV?d00001 diff --git a/player.bmp b/player.bmp new file mode 100644 index 0000000000000000000000000000000000000000..829f2a3363fca0086f4a0c81a05e3348fc6026f5 GIT binary patch literal 1374 zcmcJNI}*Y$3!$&t=8QYQAd}St#d8= zan54pL@&K!*X5$zILB|VCH!lqjZW)36)W|%!xK7-R%l}dK}`W?+s6)rPv*n m_f33eB!$REnVzv`XFOw-o3^MLgr5jv?Y1kW;+IADPw@j@zh4Ug literal 0 HcmV?d00001 diff --git a/rat.bmp b/rat.bmp new file mode 100644 index 0000000000000000000000000000000000000000..dc2a660a1c2fab859bc152c6606453827de6a0be GIT binary patch literal 2574 zcmeH@F%E-33>GP+18U>HwH_3|Ct*na#2fET0wie5tv-bTNdfQ`0 zeIY006Zx~^x{_2c>ak?7= P;XpVL4uk{YK)nM$|4&k9 literal 0 HcmV?d00001 diff --git a/ratcaught.bmp b/ratcaught.bmp new file mode 100644 index 0000000000000000000000000000000000000000..149f0fc3bb617476e9560dccf4de21070ec343f4 GIT binary patch literal 1198 zcma)$(G9{d5JQ8+HxfUH5tx7h_-7wJI}tPVgT0Cy7sr>T4V7~8`TXwsc)pJ*e|OXy z-Wl(LcSu*%lwO#BPJG$umSGr_aV@hUm_wy#Bxw0KhkJly0(?t2#e^6Kd=wZo>zq3b z)Jzw{io*E5EnU*Cw$k)HS@b@m=?tjZ5oIwIqyNA)xx;96V5+|w$I%_FTNs~7lVJ_J z*&t_PN@;@Qi~?;qk7ul6+8A7Z0Q}U?Uj8MV(oBM<&?3hg0B_a|9nUm0LORm9AQ}KP IF_}Sp0VSI)$p8QV literal 0 HcmV?d00001 diff --git a/ratdead.bmp b/ratdead.bmp new file mode 100644 index 0000000000000000000000000000000000000000..d57b572993c25f77ec83c4901b2a5366496f3c5c GIT binary patch literal 1198 zcma))%MAiS3`2v&8Ho#`1S+5a?)1ZPE20YeTFiLlWd4kHvR=n8;lShhK3Y0=)En*@ z_kw${E2`NG{m+Rv8OyS59*NrBRxyXV0Aicz=(KaQ!;pX>!vvw2mhNv*yDPxJ@0@Nr zn$ARbq&*$gC`~^mUC$YHe}FzF!Ut0^`VU-_6Go#8rutQT`h&^TxXh>#1sT?2Ha`%R z*v;_3iHrg{7hl{%tYZ2Y0n}=h{5U;p^(43opE#^J+P+$bPMa(ogtTO_K^y=aVloTy E1?E1?Z2$lO literal 0 HcmV?d00001 diff --git a/rc.c b/rc.c new file mode 100644 index 0000000..213fac0 --- /dev/null +++ b/rc.c @@ -0,0 +1,1316 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include "rc.h" + +SDL_Surface *screen; + +int curlevelnum = 1; +level_t *curlevel; + +sprite_t *sprite = NULL; /* main sprite list */ +sprite_t *player; +sprite_t *lastsprite; + +SDL_Color red = {255, 0, 0, 0}; +SDL_Color white = {255, 255, 255, 0}; + +int timer = 0; +int toggletimer = 0; + +int main (int argc, char **argv) { + Uint8 *keys; + sprite_t *s,*nextsprite; + + if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE)==-1) { + printf("SDL_Init: %s\n", SDL_GetError()); + exit(1); + } + + atexit(cleanup); + + screen = SDL_SetVideoMode(640,480,16,SDL_HWSURFACE|SDL_DOUBLEBUF); + + + if (loadimagesets()) { + return 1; + } + if (loadlevel(curlevelnum)) { + return 1; + } + + drawlevel(); + SDL_Flip(screen); + + timer = 0; + +printf("player y is %0.1f\n",player->y); +fflush(stdout); + while (1) { + /* remove player */ + for (s = sprite ; s ; s = s->next) { + removesprite(s); + } + removenetting(player); + + /* check for death & update movement status*/ + for (s = sprite ; s ; s = nextsprite) { + s->moved = B_FALSE; + nextsprite = s->next; + if (s->dead == 4) { + killsprite(s); + } + + } + + + /* check for keys */ + SDL_PumpEvents(); + keys = SDL_GetKeyState(NULL); + if (keys[SDLK_RETURN]) { + if (toggletimer == 0) { + SDL_WM_ToggleFullScreen(screen); + toggletimer = 50; + } + } + if (keys[SDLK_ESCAPE]) { + return 1; + } + if (keys[SDLK_RIGHT]) { + if (!player->jumping) { + if (!isonladder(player) || player->falling || isonground(player)) { + movex(player, player->speed); + } + } + player->dir = 1; + } + if (keys[SDLK_LEFT]) { + if (!player->jumping) { + if (!isonladder(player) || player->falling || isonground(player)) { + movex(player, -player->speed); + } + } + player->dir = -1; + } + if (keys[SDLK_UP]) { + if (isonladder(player) || isladderabove(player)) { + player->y -= player->speed; + } + } + if (keys[SDLK_x]) { + if (!player->jumping) { + if (!player->falling) { + if (isonground(player) || isonladder(player)) { + player->jumping = 1; + if (keys[SDLK_RIGHT]) { + player->jumpdir = 1; + } else if (keys[SDLK_LEFT]) { + player->jumpdir = -1; + } else { + player->jumpdir = 0; + } + player->jumpspeed = 5; + } + } + } + } + if (keys[SDLK_z]) { + if (!player->netting) { + if (keys[SDLK_DOWN]) { + /* slam */ + if ((!player->slamming) && (isonground(player))) { + player->slamming = B_TRUE; + player->slamangle = 0; + player->netxstart = player->x - (player->img->w/2)*player->dir; + player->netystart = player->y; + } + } else { + /* shoot net */ + player->netting = 1; + player->netspeed = NETSPEED; + player->netlen = 0; + player->netdir = player->dir; + } + } + } + + for (s = sprite; s ; s = s->next) { + movesprite(s); + } + + + /* gravity */ + for (s = sprite ; s ; s = s->next) { + dogravity(s); + } + + /* tile effects */ + for (s = sprite ; s ; s = s->next) { + dotileeffects(s); + } + + /* check collisions */ + for (s = sprite ; s ; s = s->next) { + checkcollide(s); + } + + drawnetting(player); + + /* draw player */ + for (s = sprite ; s ; s = s->next) { + drawsprite(s); + } + + SDL_Flip(screen); + if (++timer == 100) timer = 0; + if (toggletimer > 0) toggletimer--; + } + + return 0; + +} + + +void cleanup(void) { + SDL_Quit(); +} + +void checkcollide(sprite_t *s) { + sprite_t *s2; + int collide; + int xdiff,ydiff; + + for (s2 = sprite ; s2 ; s2 = s2->next) { + collide = B_TRUE; + if (s2 == s) collide = B_FALSE; + else if (s2->dead) collide = B_FALSE; + + if (collide) { + /* check for colission with our net */ + if ((s->netting) && (!s2->caughtby)) { + xdiff = (s->x + s->netlen*s->netdir) - s2->x; + if (xdiff < 0) xdiff = -xdiff; + ydiff = s->netystart - s2->y; + if (ydiff < 0) ydiff = -ydiff; + + if ((xdiff <= s2->img->w) && (ydiff <= s2->img->h)) { + s2->caughtby = s; + s2->caughtstate = 1; + } + } else { + /* check for collision with us */ + xdiff = s->x - s2->x; + if (xdiff < 0) xdiff = -xdiff; + ydiff = s->y - s2->y; + if (ydiff < 0) ydiff = -ydiff; + + if ((xdiff <= s->img->w/2 + s2->img->w/2) && + (ydiff <= s->img->h/2 + s2->img->h/2)) { + /* COLLISION! */ + if (isfruit(s2->id)) { + if (s == player) { + /* kill the fruit */ + s2->dead = 4; + /* give points to the player */ + } + } + if (ismonster(s2->id)) { + /* TODO: kill player */ + } + } + } + } + } +} + +tiletype_t *gettile(int tid) { + tiletype_t *t; + + for (t = tiletype; t ; t = t->next) { + if (t->id == tid) return t; + } + + return NULL; +} + +void movesprite(sprite_t *s) { + int rv; + + /* avoid edges of screen */ + if (s->y < s->img->h) { + s->y = s->img->h; + } + + + if (s->jumping) { + movex(s, s->jumpdir*s->speed); + return; + } else if (s->caughtby) { + if (s->caughtby->slamming) { + + /* */ + + s->x = s->caughtby->netxstart; + s->y = s->caughtby->netystart; + } else { + /* stay at position of net */ + s->y = s->caughtby->y; + if (s->caughtstate == 1) { + s->x = s->caughtby->x + (s->caughtby->netlen*s->caughtby->netdir); + } else { + s->x = s->caughtby->x + (s->caughtby->img->w/2) * -(s->caughtby->dir); + } + } + return; + } else if (s->dead == 1) { /* just set to dead */ + s->xs = ((rand() % 7)) - 3; + s->ys = ((rand() % 3) + 2) * -1; + s->dead = 2; + s->bounces = 0; + return; + } else if (s->dead == 2) { /* dying */ + s->x += s->xs; + s->y += s->ys; + if (s->x >= (640-(s->img->w/2))) { + if (s->xs > 0) { + s->xs = -s->xs; + s->bounces++; + } + } else if (s->x <= s->img->w/2) { + if (s->xs < 0) { + s->xs = -s->xs; + s->bounces++; + } + } + + if (s->y >= (480-(s->img->h/2))) { + if (s->ys > 0) { + s->ys = -s->ys; + s->bounces++; + } + } else if (s->y <= s->img->h) { + if (s->ys < 0) { + s->ys = -s->ys; + s->bounces++; + } + } + if ((s->bounces >= 2) && (s->ys > 0)) { + s->dead = 3; + } + return; + } else if (s->dead == 3) { /* final fall */ + s->x += s->xs; + s->y += s->ys; + if (s->x >= (640-(s->img->w/2))) { + if (s->xs > 0) { + s->xs = -s->xs; + s->bounces++; + } + } else if (s->x <= s->img->w/2) { + if (s->xs < 0) { + s->xs = -s->xs; + s->bounces++; + } + } + + if (s->y >= (480-(s->img->h/2))) { + if (s->ys > 0) { + s->ys = -s->ys; + s->bounces++; + } + } else if (s->y <= s->img->h) { + if (s->ys < 0) { + s->ys = -s->ys; + s->bounces++; + } + } + + + + if ((s->ys > 0) && (s->y >= TILEH)) { + if (isonground(s)) { + int x,y,ty; + s->dead = 4; + /* change into a fruit */ + x = s->x; + gettileat(s->x,s->y-1,NULL,&ty); + y = ty*TILEH + TILEH - 2; + addsprite(P_CHEESE, x, y, "Cheese"); + } + } + return; + } + + if (isonground(s)) { + if ((!s->falling) && (!s->jumping)) { + adjustheight(s); + } + } + + if (s->id == P_RAT) { + if (!s->falling) { + tiletype_t *tt; + /* if there's not a hole in front of us, move */ + + tt = gettileat(s->x + s->dir+s->speed,s->y,NULL,NULL); + if (tt->solid == S_NOTSOLID) { + s->dir = -s->dir; + } else { + rv = movex(s, s->dir*s->speed); + if (rv) { + s->dir = -s->dir; + } + } + } + } + +} + +void dotileeffects(sprite_t *s) { + tiletype_t *tt; + if (s->jumping || s->dead || s->caughtby) { + return; + } + + tt = gettileat(s->x,s->y+3,NULL,NULL); + if (tt->id == T_RIGHT) { + movex(s, 1.5); + } + if (tt->id == T_LEFT) { + movex(s, -1.5); + } +} + +void drawtile(int x, int y) { + SDL_Rect area; + tiletype_t *tt; + + if ((x < 0) || (y < 0) || (x >= LEVELW) || (y >= LEVELH)) { + return; + } + + area.x = x * TILEW; + area.y = y * TILEH; + area.w = 0; + area.h = 0; + /* draw blank tile first */ + tt = gettile(curlevel->bgtileid); + SDL_BlitSurface(tt->img, NULL, screen, &area); + + tt = gettile(curlevel->map[y*LEVELW+x]); + if (tt->id != curlevel->bgtileid) { + SDL_BlitSurface(tt->img, NULL, screen, &area); + } +} + +void drawlevel(void) { + int x,y; + + for (x = 0; x < LEVELW; x++) { + for (y = 0; y < LEVELH; y++) { + drawtile(x,y); + } + } +} + +int loadlevel(int lnum) { + FILE *f; + int x,y; + char buf[BUFLEN]; + char filename[BUFLEN]; + char *p; + int tileid; + int i; + + + level = malloc(sizeof(level_t)); + + level->id = 0; + sprintf(level->name, "Level %d",lnum); + level->prev = NULL; + level->next = NULL; + + /* default */ + level->p1x = 0; + level->p1y = 0; + + sprintf(filename, "level%d.dat",lnum); + f = fopen(filename,"rt"); + if (!f) { + printf("can't open level file\n"); + return B_TRUE; + } + + /* clear tiletype linked list */ + while (tiletype != NULL) { + tiletype_t *tt; + + /* kill first tile */ + if (tiletype->img) { + SDL_FreeSurface(tiletype->img); + tiletype->img = NULL; + tt = tiletype->next; + free(tiletype); + tiletype = tt; + } + } + + /* TODO: clear player linked list */ + + /* read tileset */ + fgets(buf, BUFLEN, f); + if (strstr(buf, "tileset") == buf) { + p = strtok(buf, " "); + p = strtok(NULL, " "); + + /* strip newline */ + p[strlen(p)-1] = '\0'; + + if (loadtiletypes(p)) { + printf("Cannot load tileset file: %s\n", p); + return B_TRUE; + } + + } else { + printf("invalid tileset file in line: '%s'\n",buf); + return B_TRUE; + } + + + + + /* read background tile */ + fgets(buf, BUFLEN, f); + if (strstr(buf, "bg") == buf) { + p = strtok(buf, " "); + p = strtok(NULL, " "); + level->bgtileid = atoi(p); + if (!gettile(level->bgtileid)) { + printf("invalid background tile id: %d\n",level->bgtileid); + return B_TRUE; + } + printf("Background tile id is %d (%s)\n",level->bgtileid,(gettile(level->bgtileid)->name)); + } else { + printf("invalid background tile id line: '%s'\n",buf); + return B_TRUE; + } + + x = 0; + y = 0; + level->nummonsters = 0; + fgets(buf, BUFLEN, f); + while (!feof(f)) { + for (p = buf; *p; p++) { + if (*p == '~') { + tileid = T_LAND; + } else if (*p == '=') { + tileid = T_LADDER; + } else if (*p == '-') { + tileid = T_LADDERTOP; + } else if (*p == '>') { + tileid = T_RIGHT; + } else if (*p == '<') { + tileid = T_LEFT; + } else if (*p == '^') { + tileid = T_SPIKES; + } else if (*p == 'r') { + tileid = level->bgtileid; + level->initm[level->nummonsters].startx = x*TILEW+(TILEW/2); + level->initm[level->nummonsters].starty = y*TILEH+(TILEH-2); + level->initm[level->nummonsters].id = P_RAT; + level->nummonsters++; + } else if (*p == '*') { + tileid = T_FULL; + } else if (*p == '/') { + tileid = T_SLOPEUP; + } else if (*p == '\\') { + tileid = T_SLOPEDOWN; + } else if (*p == '1') { + tileid = level->bgtileid; + level->p1x = x; + level->p1y = y; + } else { + tileid = level->bgtileid; + } + if (!gettile(tileid)) { + printf("invalid tileid: %d\n",tileid); + fclose(f); + return B_TRUE; + } + if ((x > LEVELW) || (y > LEVELH)) { + printf("Level position out of range: %d,%d\n",x,y); + fclose(f); + return B_TRUE; + } + level->map[y*LEVELW+x] = tileid; + x++; + } + if (x < LEVELW+1) { + printf("Not enough tiles on line: y = %d\n",y); + fclose(f); + return B_TRUE; + } + y++; + x = 0; + fgets(buf, BUFLEN, f); + } + fclose(f); + + if (y < LEVELH) { + printf("Incomplete level: y=%d, should be %d.\n", + y,LEVELH); + return B_TRUE; + } + + if ((level->p1x == 0) || (level->p1y == 0)) { + printf("Level is missing player 1 start position.\n"); + return B_TRUE; + } + + /* set current level pointer */ + curlevel = level; + + /* add player */ + addsprite(P_PLAYER, (curlevel->p1x * TILEW) + (TILEW/2), + (curlevel->p1y * TILEH) + TILEH-2 , "Player" ); + player = lastsprite; + + /* add monsters */ + for (i = 0; i < level->nummonsters; i++) { + addsprite(level->initm[i].id, + level->initm[i].startx, level->initm[i].starty, "Monster"); + + } + + return B_FALSE; +} + +int loadtiletypes(char *filename) { + tiletype_t *t = NULL; + int i; + int state; + FILE *f; + char buf[BUFLEN]; + char *p,*pp; + + state = 0; + f = fopen(filename,"rt"); + if (!f) { + printf("can't open tiles file\n"); + return B_TRUE; + } + + fgets(buf, BUFLEN, f); + while (!feof(f)) { + if (state == 0) { + if (strstr(buf, "tile") == buf) { + if (t == NULL) { + tiletype = malloc(sizeof(tiletype_t)); + t = tiletype; + t->prev = NULL; + } else { + t->next = malloc(sizeof(tiletype_t)); + t->next->prev = t; + + t = t->next; + } + p = strtok(buf, " "); + p = strtok(NULL, " "); + /* strip newline */ + p[strlen(p)-1] = '\0'; + strcpy(t->name, p); + + /* defaults */ + t->id = 0; + t->solid = B_TRUE; + for (i = 0; i < TILEW; i++) { + t->lowness[i] = 0; + } + t->img = NULL; + t->next = NULL; + state = 1; + } + } else if (state == 1) { /* inside a definition */ + if (strstr(buf, "end") == buf) { + printf("got tile %d: %s (solid=%d)\n",t->id,t->name,t->solid); + state = 0; + } else if (strstr(buf, "id") == buf) { + p = strtok(buf, " "); + p = strtok(NULL, " "); + t->id = atoi(p); + } else if (strstr(buf, "lowness") == buf) { + p = strtok(buf, " "); + p = strtok(NULL, " "); + pp = strtok(p, ","); + for (i = 0;i < TILEW; i++) { + t->lowness[i] = atoi(pp); + pp = strtok(NULL, ","); + } + } else if (strstr(buf, "solid") == buf) { + p = strtok(buf, " "); + p = strtok(NULL, " "); + t->solid = atoi(p); + } else if (strstr(buf, "file") == buf) { + p = strtok(buf, " "); + p = strtok(NULL, " "); + if (t->img) { + SDL_FreeSurface(t->img); + t->img = NULL; + } + /* strip newline */ + p[strlen(p)-1] = '\0'; + t->img = IMG_Load(p); + if (!t->img) { + printf("cannot load tile image file: '%s'\n",p); + fclose(f); + return B_TRUE; + } + SDL_SetColorKey(t->img, SDL_SRCCOLORKEY, SDL_MapRGB(screen->format, 0, 0, 0)); + + } + } + fgets(buf, BUFLEN, f); + } + + fclose(f); + return B_FALSE; + +} + +int loadimagesets(void) { + int p,i; + imageset[P_PLAYER].img[F_WALK1] = IMG_Load("pdwarf.png"); + imageset[P_PLAYER].img[F_JUMP] = IMG_Load("pdwarfjump.png"); + imageset[P_PLAYER].img[F_FALL] = IMG_Load("pdwarffall.png"); + imageset[P_PLAYER].img[F_CAUGHT] = IMG_Load("pdwarf.png"); + imageset[P_PLAYER].img[F_DEAD] = IMG_Load("pdwarf.png"); + /* next 3 are auto generated */ + imageset[P_PLAYER].numimages = 8; + + imageset[P_RAT].img[F_WALK1] = IMG_Load("rat.bmp"); + imageset[P_RAT].img[F_JUMP] = IMG_Load("rat.bmp"); + imageset[P_RAT].img[F_FALL] = IMG_Load("rat.bmp"); + imageset[P_RAT].img[F_CAUGHT] = IMG_Load("ratcaught.bmp"); + imageset[P_RAT].img[F_DEAD] = IMG_Load("ratdead.bmp"); + /* next 3 are auto generated */ + imageset[P_RAT].numimages = 8; + + imageset[P_CHEESE].img[F_WALK1] = IMG_Load("cheese.bmp"); + imageset[P_CHEESE].numimages = 1; + + /* generate rotated/flipped images */ + for (p = 0; p < MAXPTYPES; p++) { + imageset[p].img[F_DEAD2] = rotozoomSurface(imageset[p].img[F_DEAD],90,1,0); + imageset[p].img[F_DEAD3] = rotozoomSurface(imageset[p].img[F_DEAD],180,1,0); + imageset[p].img[F_DEAD4] = rotozoomSurface(imageset[p].img[F_DEAD],270,1,0); + + for (i = 0; i < imageset[p].numimages; i++) { + SDL_SetColorKey(imageset[p].img[i], + SDL_SRCCOLORKEY, SDL_MapRGB(screen->format, 0, 0, 0)); + + imageset[p].img[MAXFRAMES+i] = + rotozoomSurfaceXY(imageset[p].img[i], 0, -1,1,0); + } + } + + return B_FALSE; +} + +double getspeed(int id) { + if (id == P_PLAYER) return 1; + else if (id == P_RAT) return 1.5; + else if (id == P_CHEESE) return 0; + return 1; +} + +int addsprite(int id, int x, int y, char *name ) { + sprite_t *s; + + if (sprite == NULL) { + sprite = malloc(sizeof(sprite_t)); + s = sprite; + s->prev = NULL; + } else { + s = lastsprite; + s->next = malloc(sizeof(sprite_t)); + s->next->prev = s; + + s = s->next; + } + + + s->id = id; + s->x = x; + s->y = y; + s->img = imageset[id].img[F_WALK1]; + if (s->y > (480 - TILEH-1)) { + s->y = 480 - TILEH-1; + } + strcpy(s->name, name); + + if (s == sprite) { + s->netbg = SDL_CreateRGBSurface(SDL_HWSURFACE, + 200, 10, + screen->format->BitsPerPixel, screen->format->Rmask, + screen->format->Gmask,screen->format->Bmask, + screen->format->Amask); + } else { + s->netbg = NULL; + } + + s->speed = getspeed(id); + s->jumping = 0; + s->jumpdir = 1; + s->netting = 0; + s->falling = 0; + s->fallspeed = 0; + s->dir = 1; + s->slamming = 0; + s->dead = 0; + + s->caughtby = NULL; + s->caughtstate = 0; + + s->next = NULL; + + lastsprite = s; + + return B_FALSE; +} + +int loadsprites(void) { + addsprite(P_PLAYER, 100, 400, "Player 1"); + player = lastsprite; + addsprite(P_RAT, 200, 200, "Rat"); + addsprite(P_RAT, 400, 200, "Rat"); + return B_FALSE; +} + + +tiletype_t *gettileat(int pixx,int pixy, int *tilex,int *tiley) { + int tx,ty; + tx = pixx / TILEW; + ty = pixy / TILEH; + if (tilex != NULL) { + *tilex = tx; + } + if (tiley != NULL) { + *tiley = ty; + } + + return gettile(curlevel->map[ty*LEVELW+tx]); +} + +void drawnetting(sprite_t *s) { + int sx; + SDL_Rect area; + + if (s->netting) { + + sx = s->x; + s->nety = s->y - (s->img->h/2); + + s->netxstart = s->x; + s->netystart = s->nety - 3; + + if (s->netdir == 1) { + area.x = s->netxstart + TILEW/2; + } else { + area.x = s->netxstart - TILEW/2 - s->netlen; + } + area.y = s->netystart; + area.w = s->netlen; + area.h = 7; + SDL_BlitSurface(screen, &area,s->netbg, NULL); + + drawline16(screen,sx,s->nety,s->x + s->netdir*s->netlen,s->nety-3,white); + drawline16(screen,sx,s->nety,s->x + s->netdir*s->netlen,s->nety,white); + drawline16(screen,sx,s->nety,s->x + s->netdir*s->netlen,s->nety+3,white); + } else if (s->slamming) { + double dist; + int x,y; + dist = (s->slamangle * (180/M_PI))/2; + + s->netxstart = s->x + cos(s->slamangle-(180*(M_PI/180)))*dist*s->dir; + s->netystart = s->y + sin(s->slamangle-(180*(M_PI/180)))*dist; + + /* middle line */ + drawline16(screen,s->x,s->y - s->img->h/2, + s->netxstart,s->netystart,white); + /* left line */ + x = s->x + cos(s->slamangle-(5*(M_PI/180))-(180*(M_PI/180)))*dist*s->dir; + y = s->y + sin(s->slamangle-(5*(M_PI/180))-(180*(M_PI/180)))*dist; + drawline16(screen,s->x,s->y - s->img->h/2,x, y, white); + /* right line */ + x = s->x + cos(s->slamangle+(5*(M_PI/180))-(180*(M_PI/180)))*dist*s->dir; + y = s->y + sin(s->slamangle+(5*(M_PI/180))-(180*(M_PI/180)))*dist; + drawline16(screen,s->x,s->y - s->img->h/2,x, y, white); + } + +} + +void drawsprite(sprite_t *s) { + SDL_Rect area; + int frame; + + /* select frame */ + if (isfruit(s->id)) { + frame = F_WALK1; + } else if (s->dead) { + frame = F_DEAD + ((timer/2) % 4); + } else if (s->caughtby) { + frame = F_CAUGHT; + } else if (s->jumping) { + frame = F_JUMP; + } else if (s->falling) { + frame = F_FALL; + } else { + if (s->moved) { + if ((timer/6) % 2 == 0) { + frame = F_WALK1; + } else { + frame = F_JUMP; + } + } else { + frame = F_WALK1; + } + + } + /* x-flip if required */ + if (s->dir == -1) { + frame += MAXFRAMES; + } + + s->img = imageset[s->id].img[frame]; + + area.x = s->x - (s->img->w/2); + area.y = s->y - (s->img->h); + area.w = 0; + area.h = 0; + SDL_BlitSurface(s->img, NULL, screen, &area); + + /* caughtby lines */ + if ((s->caughtby) && (s->caughtstate == 2)){ + drawline16(screen, s->x,s->y - s->img->h, + s->caughtby->x,s->caughtby->y-(s->caughtby->img->h/2), white); + drawline16(screen, s->x,s->y - (s->img->h/2), + s->caughtby->x,s->caughtby->y-(s->caughtby->img->h/2), white); + drawline16(screen, s->x,s->y, + s->caughtby->x,s->caughtby->y-(s->caughtby->img->h/2), white); + } + +} + +void removenetting(sprite_t *s) { + SDL_Rect area,sarea; + + if (s->netting) { + sarea.x = 0; + sarea.y = 0; + sarea.w = s->netlen; + sarea.h = 7; + + if (s->netdir == 1) { + area.x = s->netxstart + TILEW/2; + } else { + area.x = s->netxstart - TILEW/2 - s->netlen; + } + area.y = s->netystart; + area.w = s->netlen; + area.h = 7; + + if (s->netbg != NULL) { + SDL_BlitSurface(s->netbg, &sarea, screen, &area); + } + } +} + + +void killsprite(sprite_t *s) { + sprite_t *nextone, *lastone; + + nextone = s->next; + if (nextone != NULL) { + nextone->prev = s->prev; + } else { /*last sprite */ + lastsprite = s->prev; + } + + if (s->prev == NULL) { + /* first sprite */ + nextone = sprite->next; + free(sprite); + sprite = nextone; + } else { + lastone = s->prev; + free (lastone->next ); + lastone->next = nextone; + } +} + +void removesprite(sprite_t *s) { + int startx,starty,endx,endy; + int x,y; + + /* find topleft-most tile */ + gettileat(s->x - s->img->w, s->y - s->img->h,&startx,&starty); + /* find bottomright-most tile */ + gettileat(s->x + s->img->w, s->y + s->img->h,&endx,&endy); + + if (s->slamming) { + if (s->dir == -1) { + startx -= 5; + endx += 1; + } else { + startx -= 1; + endx += 5; + } + starty -= 2; + endy += 1; + } + + /* draw the tiles */ + for (y = starty; y <= endy; y++) { + for (x = startx; x <= endx; x++) { + drawtile(x,y); + } + } +} + + +int isonladder(sprite_t *s) { + tiletype_t *tthere; + tthere = gettileat(s->x,s->y, NULL,NULL); + if ((tthere->id == T_LADDER) || (tthere->id == T_LADDERTOP)) { + return B_TRUE; + } + + return B_FALSE; +} + +int isladderabove(sprite_t *s) { + tiletype_t *tthere; + tthere = gettileat(s->x,s->y-TILEH, NULL,NULL); + if (tthere->id == T_LADDER) { + return B_TRUE; + } + + return B_FALSE; +} + +int isonground(sprite_t *s) { + /* get tile below sprite's feet */ + if (isongroundpoint(s, s->x, s->y)) { + return B_TRUE; + } + if (!s->falling) { + if (isongroundpoint(s, s->x + s->img->w/2, s->y)) { + return B_TRUE; + } + if (isongroundpoint(s, s->x - s->img->w/2, s->y)) { + return B_TRUE; + } + } + + return B_FALSE; +} + +int isongroundpoint(sprite_t *s, int x,int y) { + tiletype_t *tt; + int tilex,tiley; + int xoff; + int groundy; + + tt = gettileat(x,y, &tilex, &tiley); + /* get offset */ + xoff = x - (tilex*TILEW); + + /* if it's not solid... */ + if (tt->solid == 0) { + return B_FALSE; + } else { + /* check height of tile at that position */ + groundy = tiley*TILEH + tt->lowness[xoff]; + + /* above ground level */ + if (y < groundy) { + return B_FALSE; + } else if (y > groundy + 3) { + /* below ground level */ + return B_FALSE; + } else if (s->falling) { + tiletype_t *abovetile; + /* falling, on a tile, but with tiles above you */ + abovetile = gettileat(x,y-TILEH, NULL, NULL); + if (abovetile->solid) { + return B_FALSE; + } + } + + } + + return B_TRUE; +} + +void dogravity(sprite_t *s) { + sprite_t *s2; + + if (s->dead) return; + if (isonladder(s) && !s->falling && !s->jumping) { + s->falling = B_FALSE; + return; + } + + if (s->jumping) { + s->falling = B_FALSE; + s->y -= s->jumpspeed; + s->jumping++; + if (s->jumping % 5 == 0) { + if (s->jumpspeed > 0) s->jumpspeed--; + else { + s->jumping = 0; + s->falling = B_TRUE; + s->fallspeed = 0; + } + } + } else { + if (isonground(s)) { + s->falling = B_FALSE; + } else { + s->falling = B_TRUE; + s->y += s->fallspeed; + if ((timer % 10 == 0) && (s->fallspeed < FALLSPEED)) { + s->fallspeed++; + } + } + } + + if (s->netting) { + s->netlen += s->netspeed; + s->netting++; + if (s->netting % 2 == 0) { + if (s->netspeed > -NETSPEED) s->netspeed--; + else { + s->netting = 0; + for (s2 = sprite ; s2 ; s2 = s2->next) { + if ((s2->caughtby == s) && (s2->caughtstate == 1)) { + s2->caughtstate = 2; + } + } + } + } + } + + if (s->slamming) { + s->slamangle += (10 * (M_PI/180)); + if (s->slamangle >= (190 * (M_PI/180))) { + /* if we hit the ground, kill anything we've caught */ + s->slamming = 0; + + for (s2 = sprite; s2 ; s2 = s2->next) { + if (s2->caughtby == s) { + if (isongroundpoint(s2,s2->x,s->y)) { + s2->dead = 1; + } + s2->caughtby = NULL; + + } + } + } + } +} + + +int movex(sprite_t *s,double amt) { + double newx,newy; + double curx,cury; + int tilex,tiley; + tiletype_t *tt,*tt2; + int newxoff,newgroundy; + int newtilex,newtiley; + + double amtdir; + + tt = gettileat(s->x, s->y, &tilex,&tiley); + + if (amt > 0) amtdir = 1; + else (amtdir = -1); + + curx = s->x; + cury = s->y; + + /* check for blockage in front of us */ + newx = s->x + (amtdir*(s->img->w/2)); + newy = cury-TILEH; + tt2 = gettileat(newx,newy,&newtilex,&newtiley); + if (tt2->solid == S_SOLID) { + return B_TRUE; + } + + /* get new position */ + newx = curx + amt; + newy = cury-2; + tt2 = gettileat(newx,newy,&newtilex,&newtiley); + newxoff = newx - (newtilex*TILEW); + newgroundy = newtiley*TILEH + tt2->lowness[newxoff]; + + /* new block is at least partially solid */ + if (tt2->solid == S_SOLID) { + return B_TRUE; + } else if (tt2->solid == S_SLOPE) { + /* we can move, but need to adjust our height */ + s->x += amt; + adjustheight(s); + } else { + /* new block is empty */ + s->x += amt; + } + + s->moved = B_TRUE; + return B_FALSE; +} + +void adjustheight(sprite_t *s) { + tiletype_t *tt; + int xoff,groundy; + int tilex,tiley; + + tt = gettileat(s->x,s->y-1,&tilex,&tiley); + if (tt->solid == S_SLOPE) { + xoff = s->x - (tilex*TILEW); + groundy = tiley*TILEH + tt->lowness[xoff]; + s->y = groundy; + } else if (tt->solid == S_SOLID) { + while (tt->solid == S_SOLID) { + s->y--; + tt = gettileat(s->x,s->y-1,&tilex,&tiley); + } + } +} + +int isfruit(int id) { + if (id == P_CHEESE) return B_TRUE; + + return B_FALSE; +} + +int ismonster(int id) { + if (id == P_RAT) return B_TRUE; + + return B_FALSE; +} + + +inline void drawpixel16(SDL_Surface *screen, int x, int y, SDL_Color c) +{ + Uint16 *bufp; + + /* check x/y */ + if (x >= screen->w) return; + if (y >= screen->h) return; + if (x < 0) return; + if (y < 0) return; + + bufp = (Uint16 *)screen->pixels + (y*screen->pitch / 2) + x; + *bufp = SDL_MapRGB(screen->format, c.r, c.g, c.b); +} + + +void drawline16(SDL_Surface *screen, int x1, int y1, int x2, int y2, SDL_Color c) { + int deltax, deltay; + int numpixels; + int d; + int dinc1,dinc2,xinc1,xinc2,yinc1,yinc2; + int i; + int x; + int y; + int maskcount = 0; + int maskindex = 0; + + + + deltax = (x2 - x1); + if (deltax < 0) deltax = -deltax; + deltay = (y2 - y1); + if (deltay < 0) deltay = -deltay; + + if (deltax >= deltay) { + numpixels = deltax + 1; + d = (deltay*2) - deltax; + dinc1 = deltay << 1; + dinc2 = (deltay-deltax) << 1; + xinc1 = 1; + xinc2 = 1; + yinc1 = 0; + yinc2 = 1; + } else { + numpixels = deltay + 1; + d = (deltax*2) - deltay; + dinc1 = deltax << 1; + dinc2 = (deltax - deltay) << 1; + xinc1 = 0; + xinc2 = 1; + yinc1 = 1; + yinc2 = 1; + } + + if (x1 > x2) { + xinc1 = - xinc1; + xinc2 = - xinc2; + } + if (y1 > y2) { + yinc1 = - yinc1; + yinc2 = - yinc2; + } + + x = x1; y = y1; + + maskcount = 0; + maskindex = 0; + for (i = 0; i < numpixels; i++) { + + drawpixel16(screen,x,y,c); + + + + if (d < 0) { + d += dinc1; + x += xinc1; + y += yinc1; + } else { + d += dinc2; + x += xinc2; + y += yinc2; + } + } +} + + +void drawbox16(SDL_Surface *screen, int x1, int y1, int x2, int y2, SDL_Color *c, SDL_Color *fc) { + if (fc != NULL) { + /* fill */ + if (((x2 - x1) >= 2) && ((y2 - y1) >= 2)) { + int y; + for (y = (y1+1) ; y <= (y2-1); y++) { + drawline16(screen, x1+1, y, x2-1,y,*fc); + } + } + } + drawline16(screen,x1,y1,x2,y1,*c); + drawline16(screen,x1,y1,x1,y2,*c); + drawline16(screen,x1,y2,x2,y2,*c); + drawline16(screen,x2,y1,x2,y2,*c); +} + diff --git a/rc.h b/rc.h new file mode 100644 index 0000000..7747066 --- /dev/null +++ b/rc.h @@ -0,0 +1,163 @@ +#include + +#define NETSPEED 9 + +#define MAXMONSTERSPERLEVEL 20 + +#define MAXPTYPES 3 +#define MAXFRAMES 8 + +#define TILEH 16 +#define TILEW 16 + +#define LEVELW 40 +#define LEVELH 30 + +#define BUFLEN 512 +#define SMALLBUFLEN 32 + +#define FALLSPEED 4 + +#define B_TRUE -1 +#define B_FALSE 0 + + +typedef struct tiletype_s { + int id; + char name[SMALLBUFLEN]; + int lowness[TILEW]; + int solid; + SDL_Surface *img; + struct tiletype_s *next; + struct tiletype_s *prev; +} tiletype_t; +tiletype_t *tiletype; + +typedef struct initialmonster_s { + int startx; + int starty; + int id; +} initialmonster_t; + +typedef struct level_s { + int id; + int bgtileid; + char name[SMALLBUFLEN]; + int map[LEVELW*LEVELH]; + struct level_s *next; + struct level_s *prev; + int p1x; /* player 1 start pos */ + int p1y; + int nummonsters; + initialmonster_t initm[MAXMONSTERSPERLEVEL]; + +} level_t; +level_t *level; + +typedef struct sprite_s { + int id; + double speed; + int falling; + int fallspeed; + int jumping; + int jumpdir; + + int dead; + int bounces; + + struct sprite_s *caughtby; + int caughtstate; + + int jumpspeed; + int slamming; + double slamangle; + int netting; + int netspeed; + int netdir; + int netlen; + int nety; + int netxstart; + int netystart; + + int moved; + + double xs,ys; + + double x,y; + int dir; + SDL_Surface *img; + SDL_Surface *netbg; + struct sprite_s *next; + struct sprite_s *prev; + char name[SMALLBUFLEN]; +} sprite_t; + +typedef struct imageset_s { + SDL_Surface *img[MAXFRAMES*2]; + int numimages; +} imageset_t; +imageset_t imageset[MAXPTYPES]; + + +void cleanup(void); +int addsprite(int id,int x, int y, char *name); +int loadtiletypes(char *filename); +tiletype_t *gettileat(int pixx,int pixy, int *tilex, int *tiley); +int loadlevel(int lnum); +int loadsprites(void); +int loadimagesets(void); +void drawlevel(void); +void drawtile(int x, int y); +void removesprite(sprite_t *s); +void removenetting(sprite_t *s); +void drawsprite(sprite_t *s); +void drawnetting(sprite_t *s); +void dogravity(sprite_t *s); +void dotileeffects(sprite_t *s); +int movex(sprite_t *s,double amt); +void movesprite(sprite_t *s); +int isonground(sprite_t *s); +int isongroundpoint(sprite_t *s, int x, int y); +int isonladder(sprite_t *s); +int isladderabove(sprite_t *s); +int isfruit(int id); +int ismonster(int id); +void killsprite(sprite_t *s); +void checkcollide(sprite_t *s); +double getspeed(int id); +void adjustheight(sprite_t *s); + +#define S_NOTSOLID 0 +#define S_SOLID 1 +#define S_SLOPE 2 + +#define P_PLAYER 0 +#define P_RAT 1 +#define P_CHEESE 2 + +#define F_WALK1 0 +#define F_JUMP 1 +#define F_FALL 2 +#define F_CAUGHT 3 +#define F_DEAD 4 +#define F_DEAD2 5 +#define F_DEAD3 6 +#define F_DEAD4 7 + +#define T_BLANK 0 +#define T_LAND 1 +#define T_SLOPEUP 2 +#define T_SLOPEDOWN 3 +#define T_FULL 4 +#define T_SKY 5 +#define T_LADDER 6 +#define T_LADDERTOP 7 +#define T_RIGHT 8 +#define T_LEFT 9 +#define T_SPIKES 10 + + +inline void drawpixel16(SDL_Surface *screen, int x, int y, SDL_Color c); +inline void drawbox16(SDL_Surface *screen, int x1,int y1,int x2,int y2,SDL_Color *c,SDL_Color *fc); +void drawline16(SDL_Surface *screen, int x1, int y1, int x2, int y2, SDL_Color c); + diff --git a/right.bmp b/right.bmp new file mode 100644 index 0000000000000000000000000000000000000000..4702df3c41354f5f18baba584b8082299141d0ec GIT binary patch literal 822 zcmZ?rHDhJ~12Z700mK4O%*Y@C7H0s;AK`;whyalMKco=Qxg5 FE&x+r^gjRq literal 0 HcmV?d00001 diff --git a/sky.bmp b/sky.bmp new file mode 100644 index 0000000000000000000000000000000000000000..08b28e1b34a28c5a7ff1ddca09eb900bb1833c72 GIT binary patch literal 822 ucmZ?rHDhJ~12Z700mK4O%*Y@C7H0s;AK`;whyVk_|NoJQ3L(9iH*cEOJDB+(;&3rBbap!v4@;i-MW4W6VmtKR)y`pMW{{vVR1x$1Aj7|DK+ dUgm0^PqWPvgmWJ9_FnHflG)D2&71=NXI;9vfh7O{ literal 0 HcmV?d00001 diff --git a/slopeup.bmp b/slopeup.bmp new file mode 100644 index 0000000000000000000000000000000000000000..a65469e7c16bb066343c3726c37b4d2ab6066b01 GIT binary patch literal 822 zcma)&K@NZ*3(^b literal 0 HcmV?d00001 diff --git a/spikes.bmp b/spikes.bmp new file mode 100644 index 0000000000000000000000000000000000000000..d94d639300216f7aa35c56cfd5eec069551ec919 GIT binary patch literal 822 zcmchT!3}^Q3`H^CjYmgt0tVpjP7LQ>SX%fJi4e{w=o=kc6>bbooX#Lxs82C z_va!d2KSVbyp0GVM=&rgPoI7cYI%eh;!hs?LtrsDgZp%On23dlF;a3p}3njVQ%t>*00000000000 +~~0000000000=0000000/********\0000000000 +~~0100000000=0000/~~**********\000000000 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tiles.conf b/tiles.conf new file mode 100644 index 0000000..5719b16 --- /dev/null +++ b/tiles.conf @@ -0,0 +1,37 @@ +tile blank +id 0 +solid 0 +file blank.bmp +end + +tile land +id 1 +solid 1 +file land.bmp +end + +tile slopeup +id 2 +solid 2 +lowness 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0 +file slopeup.bmp +end + +tile slopedown +id 3 +solid 2 +lowness 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 +file slopedown.bmp +end + +tile full +id 4 +solid 1 +file full.bmp +end + +tile sky +id 5 +solid 0 +file sky.bmp +end