mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-08 06:06:43 +01:00
PIGS!!!
This commit is contained in:
parent
249c89ab67
commit
7dc4dc7a73
2 changed files with 64 additions and 15 deletions
66
src/level.c
66
src/level.c
|
@ -19,6 +19,7 @@
|
||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <math.h>
|
||||||
#include "moonwalk.h"
|
#include "moonwalk.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "pause.h"
|
#include "pause.h"
|
||||||
|
@ -167,6 +168,15 @@ void Obst_MoveUpDown(struct Game *game, struct Obstacle *obstacle) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Obst_MoveSin(struct Game *game, struct Obstacle *obstacle) {
|
||||||
|
float* a = (float*)obstacle->data;
|
||||||
|
/*PrintConsole(game, "%p - %f", obstacle, obstacle->y);*/
|
||||||
|
obstacle->y -= sin(*a)*4;
|
||||||
|
*a+=tps(game, 4.5);
|
||||||
|
obstacle->y += sin(*a)*4;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool GenerateObstacles(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
|
bool GenerateObstacles(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
|
||||||
/*float* tmp; bool* in;*/
|
/*float* tmp; bool* in;*/
|
||||||
int* count;
|
int* count;
|
||||||
|
@ -190,17 +200,33 @@ bool GenerateObstacles(struct Game *game, struct TM_Action *action, enum TM_Acti
|
||||||
obst->prev = NULL;
|
obst->prev = NULL;
|
||||||
obst->x = 100;
|
obst->x = 100;
|
||||||
obst->y = (rand()%91)-1;
|
obst->y = (rand()%91)-1;
|
||||||
obst->speed = 0;
|
obst->speed = 1;
|
||||||
obst->points = -10;
|
obst->points = -10;
|
||||||
obst->hit = false;
|
obst->hit = false;
|
||||||
if (rand()%100<=50) {
|
obst->rows = 1;
|
||||||
obst->callback=Obst_MoveUpDown;
|
obst->cols = 1;
|
||||||
|
obst->pos = 0;
|
||||||
|
obst->blanks = 0;
|
||||||
|
obst->anim_speed = 0;
|
||||||
|
obst->tmp_pos = 0;
|
||||||
|
if (rand()%100<=33) {
|
||||||
|
obst->callback= &Obst_MoveUpDown;
|
||||||
obst->bitmap = &(game->level.obst_bmps.pie);
|
obst->bitmap = &(game->level.obst_bmps.pie);
|
||||||
} else {
|
|
||||||
obst->callback = NULL;
|
|
||||||
obst->bitmap = &(game->level.obst_bmps.muffin);
|
|
||||||
}
|
|
||||||
obst->data = (void*)(rand()%2);
|
obst->data = (void*)(rand()%2);
|
||||||
|
} else if (rand()%100<=50) {
|
||||||
|
obst->callback = NULL;
|
||||||
|
obst->data = NULL;
|
||||||
|
obst->bitmap = &(game->level.obst_bmps.muffin);
|
||||||
|
} else {
|
||||||
|
obst->callback = &Obst_MoveSin;
|
||||||
|
obst->data = malloc(sizeof(float));
|
||||||
|
*((float*)obst->data) = 0;
|
||||||
|
obst->bitmap = &(game->level.obst_bmps.pig);
|
||||||
|
obst->rows = 3;
|
||||||
|
obst->cols = 3;
|
||||||
|
obst->speed = 1.2;
|
||||||
|
obst->anim_speed = 2;
|
||||||
|
}
|
||||||
if (game->level.obstacles) {
|
if (game->level.obstacles) {
|
||||||
game->level.obstacles->prev = obst;
|
game->level.obstacles->prev = obst;
|
||||||
obst->next = game->level.obstacles;
|
obst->next = game->level.obstacles;
|
||||||
|
@ -286,11 +312,11 @@ void Level_Draw(struct Game *game) {
|
||||||
struct Obstacle *tmp = game->level.obstacles;
|
struct Obstacle *tmp = game->level.obstacles;
|
||||||
while (tmp) {
|
while (tmp) {
|
||||||
/*PrintConsole(game, "DRAWING %f %f", tmp->x, tmp->y);*/
|
/*PrintConsole(game, "DRAWING %f %f", tmp->x, tmp->y);*/
|
||||||
if (tmp->x > -10) {
|
|
||||||
int x = (tmp->x/100.0)*al_get_display_width(game->display);
|
int x = (tmp->x/100.0)*al_get_display_width(game->display);
|
||||||
int y = (tmp->y/100.0)*al_get_display_height(game->display);
|
int y = (tmp->y/100.0)*al_get_display_height(game->display);
|
||||||
int w = al_get_bitmap_width(*(tmp->bitmap));
|
int w = al_get_bitmap_width(*(tmp->bitmap))/tmp->cols;
|
||||||
int h = al_get_bitmap_height(*(tmp->bitmap));
|
int h = al_get_bitmap_height(*(tmp->bitmap))/tmp->rows;
|
||||||
|
if (x > -w) {
|
||||||
if (!tmp->hit)
|
if (!tmp->hit)
|
||||||
if ((((x>=derpyx+0.38*derpyw+derpyo) && (x<=derpyx+0.94*derpyw+derpyo)) || ((x+w>=derpyx+0.38*derpyw+derpyo) && (x+w<=derpyx+0.94*derpyw+derpyo))) &&
|
if ((((x>=derpyx+0.38*derpyw+derpyo) && (x<=derpyx+0.94*derpyw+derpyo)) || ((x+w>=derpyx+0.38*derpyw+derpyo) && (x+w<=derpyx+0.94*derpyw+derpyo))) &&
|
||||||
(((y>=derpyy+0.26*derpyh) && (y<=derpyy+0.76*derpyh)) || ((y+h>=derpyy+0.26*derpyh) && (y+h<=derpyy+0.76*derpyh)))) {
|
(((y>=derpyy+0.26*derpyh) && (y<=derpyy+0.76*derpyh)) || ((y+h>=derpyy+0.26*derpyh) && (y+h<=derpyy+0.76*derpyh)))) {
|
||||||
|
@ -301,11 +327,23 @@ void Level_Draw(struct Game *game) {
|
||||||
TM_AddBackgroundAction(&LevelFailed, NULL, 0, "levelfailed");
|
TM_AddBackgroundAction(&LevelFailed, NULL, 0, "levelfailed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
al_draw_bitmap(*(tmp->bitmap), x, y, 0);
|
|
||||||
|
al_draw_bitmap_region(*(tmp->bitmap),w*(tmp->pos%tmp->cols), h*(tmp->pos/tmp->cols),w,h,x,y,0);
|
||||||
|
|
||||||
|
if (tmp->anim_speed) {
|
||||||
|
tmp->tmp_pos+=tps(game, 60);
|
||||||
|
if (tmp->tmp_pos >= tmp->anim_speed) {
|
||||||
|
tmp->pos++;
|
||||||
|
tmp->tmp_pos = 0;
|
||||||
|
}
|
||||||
|
if (tmp->pos>=tmp->cols*tmp->rows-tmp->blanks) tmp->pos=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*al_draw_bitmap(*(tmp->bitmap), x, y, 0);*/
|
||||||
if (game->level.debug_show_sprite_frames) al_draw_rectangle(x, y, x+w, y+h, al_map_rgba(255,0,0,255), 3);
|
if (game->level.debug_show_sprite_frames) al_draw_rectangle(x, y, x+w, y+h, al_map_rgba(255,0,0,255), 3);
|
||||||
|
|
||||||
if (tmp->hit) colision = true;
|
if (tmp->hit) colision = true;
|
||||||
tmp->x -= tps(game, game->level.speed*game->level.speed_modifier*60)*310;
|
tmp->x -= tps(game, game->level.speed*game->level.speed_modifier*60*tmp->speed)*310;
|
||||||
if (tmp->callback) tmp->callback(game, tmp);
|
if (tmp->callback) tmp->callback(game, tmp);
|
||||||
tmp = tmp->next;
|
tmp = tmp->next;
|
||||||
} else {
|
} else {
|
||||||
|
@ -656,7 +694,7 @@ void Level_UnloadBitmaps(struct Game *game) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Level_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, float)) {
|
void Level_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, float)) {
|
||||||
PROGRESS_INIT(11);
|
PROGRESS_INIT(12);
|
||||||
int x = 0;
|
int x = 0;
|
||||||
struct Spritesheet *tmp = game->level.derpy_sheets;
|
struct Spritesheet *tmp = game->level.derpy_sheets;
|
||||||
while (tmp) {
|
while (tmp) {
|
||||||
|
@ -692,6 +730,8 @@ void Level_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, floa
|
||||||
PROGRESS;
|
PROGRESS;
|
||||||
game->level.obst_bmps.pie = LoadScaledBitmap("menu/pie.png", al_get_display_width(game->display)*0.1, al_get_display_height(game->display)*0.1);
|
game->level.obst_bmps.pie = LoadScaledBitmap("menu/pie.png", al_get_display_width(game->display)*0.1, al_get_display_height(game->display)*0.1);
|
||||||
PROGRESS;
|
PROGRESS;
|
||||||
|
game->level.obst_bmps.pig = LoadScaledBitmap("levels/pig.png", al_get_display_width(game->display)*0.15*3, al_get_display_height(game->display)*0.2*3);
|
||||||
|
PROGRESS;
|
||||||
game->level.obst_bmps.muffin = LoadScaledBitmap("levels/muffin.png", al_get_display_width(game->display)*0.07, al_get_display_height(game->display)*0.1);
|
game->level.obst_bmps.muffin = LoadScaledBitmap("levels/muffin.png", al_get_display_width(game->display)*0.07, al_get_display_height(game->display)*0.1);
|
||||||
PROGRESS;
|
PROGRESS;
|
||||||
game->level.welcome = al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display)/2);
|
game->level.welcome = al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display)/2);
|
||||||
|
|
13
src/main.h
13
src/main.h
|
@ -63,11 +63,19 @@ struct Moonwalk {
|
||||||
/*! \brief Structure representing obstacles and power-ups flying through the level. */
|
/*! \brief Structure representing obstacles and power-ups flying through the level. */
|
||||||
struct Obstacle {
|
struct Obstacle {
|
||||||
ALLEGRO_BITMAP **bitmap; /*!< Pointer to bitmap used by obstacle. */
|
ALLEGRO_BITMAP **bitmap; /*!< Pointer to bitmap used by obstacle. */
|
||||||
float x; /*!< Horizontal position on the screen, in range 0-1. */
|
float x; /*!< Horizontal position on the screen, in range 0-100. */
|
||||||
float y; /*!< Vertical position on the screen, in range 0-1. */
|
float y; /*!< Vertical position on the screen, in range 0-100. */
|
||||||
float speed; /*!< Horizontal speed of obstracle. */
|
float speed; /*!< Horizontal speed of obstracle. */
|
||||||
int points; /*!< Number of points given when hit by player. Positive gives HP to power, negative takes it. */
|
int points; /*!< Number of points given when hit by player. Positive gives HP to power, negative takes it. */
|
||||||
bool hit; /*!< Indicates if this obstacle was already hit by the player or not. */
|
bool hit; /*!< Indicates if this obstacle was already hit by the player or not. */
|
||||||
|
|
||||||
|
int cols; /*!< Number of columns in spritesheet. */
|
||||||
|
int rows; /*!< Number of rows in spritesheet. */
|
||||||
|
int pos; /*!< Current position in spritesheet. */
|
||||||
|
int blanks; /*!< Number of blank frames at the end of the spritesheet. */
|
||||||
|
float tmp_pos; /*!< Temporary counter used to slow down spritesheet animation. */
|
||||||
|
float anim_speed; /*!< Speed of spritesheet animation. */
|
||||||
|
|
||||||
void (*callback)(struct Game*, struct Obstacle*); /*!< Pointer to function called to update obstacle position, animate it, etc. */
|
void (*callback)(struct Game*, struct Obstacle*); /*!< Pointer to function called to update obstacle position, animate it, etc. */
|
||||||
void *data; /*!< Pointer passed to callback function. */
|
void *data; /*!< Pointer passed to callback function. */
|
||||||
struct Obstacle *prev; /*!< Previous obstacle on the list. */
|
struct Obstacle *prev; /*!< Previous obstacle on the list. */
|
||||||
|
@ -128,6 +136,7 @@ struct Level {
|
||||||
struct {
|
struct {
|
||||||
ALLEGRO_BITMAP *pie; /*!< Pie bitmap. */
|
ALLEGRO_BITMAP *pie; /*!< Pie bitmap. */
|
||||||
ALLEGRO_BITMAP *muffin; /*!< Muffin bitmap. */
|
ALLEGRO_BITMAP *muffin; /*!< Muffin bitmap. */
|
||||||
|
ALLEGRO_BITMAP *pig; /*!< Pig spritesheet bitmap. */
|
||||||
} obst_bmps; /*!< Obstacle bitmaps. */
|
} obst_bmps; /*!< Obstacle bitmaps. */
|
||||||
struct Obstacle *obstacles; /*!< List of obstacles being currently rendered. */
|
struct Obstacle *obstacles; /*!< List of obstacles being currently rendered. */
|
||||||
struct Moonwalk moonwalk; /*!< Moonwalk placeholder data. */
|
struct Moonwalk moonwalk; /*!< Moonwalk placeholder data. */
|
||||||
|
|
Loading…
Reference in a new issue