aboutsummaryrefslogtreecommitdiff
path: root/src/platform.c
diff options
context:
space:
mode:
authorptitSeb2017-11-30 22:49:38 +0100
committerptitSeb2017-11-30 22:49:38 +0100
commitde29b11a88dbdd3af0824e59b51528b91ee73c54 (patch)
treee1aabf8752043998663279fae4359a18c4b4af07 /src/platform.c
parentd87f450f51372ddf013e6bac09f1ef588e6f8bea (diff)
downloadhydracastlelabyrinth-de29b11a88dbdd3af0824e59b51528b91ee73c54.tar.gz
hydracastlelabyrinth-de29b11a88dbdd3af0824e59b51528b91ee73c54.tar.bz2
hydracastlelabyrinth-de29b11a88dbdd3af0824e59b51528b91ee73c54.zip
First commit. Version works on Linux (keyboard only, not configurable)
Diffstat (limited to 'src/platform.c')
-rw-r--r--src/platform.c223
1 files changed, 223 insertions, 0 deletions
diff --git a/src/platform.c b/src/platform.c
new file mode 100644
index 0000000..4435aa7
--- /dev/null
+++ b/src/platform.c
@@ -0,0 +1,223 @@
+#include "platform.h"
+#include "game.h"
+#include "PHL.h"
+#include "hero.h"
+#include <stdlib.h>
+
+void createPlatform(int type, int xstart, int ystart, int xend, int yend, int spd, int secret)
+{
+ int i;
+ for (i = 0; i < MAX_PLATFORMS; i++) {
+ if (platforms[i] == NULL) {
+ Platform* p = malloc(sizeof *p);
+ p->id = i;
+ p->type = type;
+
+ p->x = p->xstart = xstart;
+ p->y = p->ystart = ystart;
+
+ p->xend = xend;
+ p->yend = yend;
+
+ p->timer = 0;
+
+ p->secret = secret;
+
+ if (roomSecret == 1) {
+ p->secret = 0;
+ }
+
+ p->visible = 1;
+ if (p->secret == 1) {
+ p->visible = 0;
+ }
+
+ if (type == 1) {
+ p->xend = p->x + 1;
+ p->yend = p->y;
+ }
+
+ p->state = 0;
+ p->spd = spd;
+
+ p->mask.circle = 0;
+ p->mask.unused = 0;
+ if (p->secret == 1) {
+ p->mask.unused = 1;
+ }
+ p->mask.x = xstart;
+ p->mask.y = ystart;
+ p->mask.w = p->mask.h = 40;
+
+ platforms[i] = p;
+ i = MAX_PLATFORMS;
+ }
+ }
+}
+
+void platformStep(Platform* p)
+{
+ char isSolid = p->visible;
+
+ //Megaman blocks
+ if (p->type == 2) {
+ int myStep = p->xend,
+ maxSteps = p->yend;
+
+ p->timer += 1;
+ if (p->timer >= maxSteps * 60 + 60) {
+ p->timer = 0;
+ }
+
+ //Play sound
+ if (p->timer == myStep * 60) {
+ PHL_PlaySound(sounds[sndPi03], CHN_SOUND);
+ }
+
+ if (p->timer > myStep * 60 && p->timer <= (myStep * 60) + 60) {
+ isSolid = 1;
+ p->visible = 1;
+
+ //Blink effect
+ if (p->timer > myStep * 60 + 30) {
+ p->visible = p->timer % 2;
+ }
+ }else{
+ isSolid = 0;
+ p->mask.unused = 1;
+ p->visible = 0;
+
+ //Fall off platform
+ if (getHeroMask().x > p->mask.x + p->mask.w || getHeroMask().x + getHeroMask().w < p->mask.x) {
+ }else if (heroy == p->y - 40 && getHeroVsp() >= 0) {
+ setHeroOnground(0);
+ }
+ }
+ }
+
+ if (isSolid == 1) {
+ p->mask.unused = 0;
+
+ int targx = p->xend,
+ targy = p->yend;
+
+ if (p->state == 1) {
+ targx = p->xstart;
+ targy = p->ystart;
+ }
+
+ //Check if the player is standing on top
+ int isontop = 0;
+ int isabove = 0;
+ if (getHeroMask().x > p->mask.x + p->mask.w || getHeroMask().x + getHeroMask().w < p->mask.x) {
+ }else if (heroy == p->y - 40 && getHeroVsp() >= 0) {
+ isontop = 1;
+ }else if (heroy < p->y - 40) {
+ isabove = 1;
+ }
+
+ //Move platform
+ if (p->y != targy) {
+ if (p->y < targy) {
+ p->y += p->spd;
+ if (isontop == 1) {
+ heroy += p->spd;
+ }
+ }else{
+ p->y -= p->spd;
+ if (isontop == 1) {
+ heroy -= p->spd;
+ }else{
+ p->mask.y = p->y;
+ if (checkCollision(p->mask, getHeroMask()) && isabove == 1) {
+ heroy = p->y - 40;
+ }
+ }
+ }
+ }
+
+ if (p->x != targx) {
+ if (p->x < targx) {
+ p->x += p->spd;
+ if (isontop == 1) {
+ herox += p->spd;
+ }
+ }else{
+ p->x -= p->spd;
+ if (isontop == 1) {
+ herox -= p->spd;
+ }
+ }
+ }
+
+ if (p->x == targx && p->y == targy) {
+ if (p->state == 0) {
+ p->state = 1;
+ }else{
+ p->state = 0;
+ }
+ }
+
+ if (p->type == 0) //Moving platform
+ {
+
+ }
+ else if (p->type == 1) { //Loose block
+ if (p->spd != 0) {
+ p->timer -= 1;
+ if (p->timer <= 0) {
+ createRockSmash(p->x + 20, p->y + 20);
+ if (isontop == 1) {
+ setHeroOnground(0);
+ }
+ platformDestroy(p->id);
+ /*createEffectExtra(4, p->x, p->y, -1, 0, 0);
+ createEffectExtra(4, p->x, p->y, -1, 0, 1);
+ createEffectExtra(4, p->x, p->y, 1, 0, 0);
+ createEffectExtra(4, p->x, p->y, 1, 0, 1);
+ */
+ }
+ }
+
+ if (p->spd == 0 && isontop == 1) {
+ p->spd = 2;
+ p->timer = 30;
+ }
+ }
+
+ //Update Mask
+ p->mask.x = p->x;
+ p->mask.y = p->y;
+ }else{
+ //p->mask.unused = 1;
+ if (p->secret == 1) {
+ if (roomSecret == 1) {
+ p->mask.unused = 0;
+ p->visible = 1;
+ p->secret = 0;
+ playSecret();
+ }
+ }
+ }
+}
+
+void platformDraw(Platform* p)
+{
+ if (p->visible == 1) {
+ int cropX = p->type * 40;
+
+ if (p->type == 3) {
+ cropX = 9 * 40;
+ }
+
+ PHL_DrawSurfacePart(p->x, p->y, cropX, 400, 40, 40, images[imgMisc20]);
+ }
+}
+
+void platformDestroy(int id)
+{
+ if (platforms[id] != NULL) {
+ free(platforms[id]);
+ }
+ platforms[id] = NULL;
+} \ No newline at end of file