void update_raw(SPRITESPTR raw) { int nflags = 0; raw->shape->body->v = cpv(-180, 0); if(raw->sdata.x <= 600 && raw->sdata.x >= 550) { set_anim_flags_on_sprite(raw, MATTACK); } add_element_to_render_queue(raw->sdata.currentimg->image, raw->sdata.x, raw->sdata.y, nflags, RCOLOR(255, 255, 255, 255), NULL); if((raw->sdata.animflags & MATTACK)) { int x = raw->sdata.x-5*raw->sdata.anim_counter; int y = raw->sdata.y+30; SIMAGEPTR lazer = search_image_list_for_element(&(raw->ifirstptr), "LAZER"); raw->sdata.anim_counter++; raw->sdata.currentimg = search_image_list_for_element(&(raw->ifirstptr), "RAW_2"); if(x+lazer->width <= raw->sdata.x) { raw->sdata.currentimg = search_image_list_for_element(&(raw->ifirstptr), "RAW_1"); } if(x+lazer->width <= 0) { raw->sdata.anim_counter = 0; remove_anim_flags_on_sprite(raw, MATTACK); } SPRITESPTR stman = search_sprite_list_for_element("STICKMAN"); if((x >= stman->sdata.x && x <= stman->sdata.x+stman->sdata.currentimg->width) && (y >= stman->sdata.y && y <= stman->sdata.y+stman->sdata.currentimg->height) && !(stman->sdata.animflags & MDAMAGED) && !(stman->sdata.animflags & MRECOVER)) { lives--; set_anim_flags_on_sprite(stman, MDAMAGED); raw->sdata.anim_counter = 0; remove_anim_flags_on_sprite(raw, MATTACK); } add_element_to_render_queue(lazer->image, x, y, nflags, RCOLOR(255, 255, 255, 255), NULL); } raw->sdata.x = raw->shape->body->p.x-raw->sdata.currentimg->width/2; raw->sdata.y = raw->shape->body->p.y-raw->sdata.currentimg->height/2; if(raw->sdata.x+raw->sdata.currentimg->width <= 0) cpSpaceAddPostStepCallback(get_global_cpSpace(), &remove_enemy, raw, NULL); }
// Checks for mouse input, called once every frame void* mousehandler(MOUSE* mouse_s, void *data) { MOUSE *mouse = (MOUSE*)mouse_s; GDATAPTR game = (GDATAPTR)data; if((mouse->button & MOUSE_L_NEW) && game->gamestarted) { SPRITESPTR sprite = search_sprite_list_for_element("BRICK_WALL"); SPRITESPTR fsprite = sprite; if(sprite != NULL) { do { if(strcmp(sprite->slabel, "BRICK_WALL") == 0) set_anim_flags_on_sprite(sprite, MDOWN); sprite = sprite->nextsprite; } while(sprite != fsprite); } } // if((mouse->button & MOUSE_R)) // { // set_anim_flags_on_sprite(search_sprite_list_for_element("STICKMAN"), MRIGHT); // } // if(mouse->dz > 0) // { // set_anim_flags_on_sprite(search_sprite_list_for_element("STICKMAN"), MRIGHT); // } return NULL; }
void collision_end_lose(cpSpace *Space, void *obj, void *unused) { // cpShape *shape = (cpShape*)obj; // SPRITESPTR sprite = (SPRITESPTR)shape->data; SPRITESPTR stman = search_sprite_list_for_element("STICKMAN"); lives--; set_anim_flags_on_sprite(stman, MDAMAGED); }
// Checks for keyboard input, called once every frame void* keyhandler(String key, void *data) { GDATAPTR game = (GDATAPTR)data; if(game->gamestarted) { if((key[ALLEGRO_KEY_W] & KEYNEW) || (key[ALLEGRO_KEY_UP] & KEYNEW)) { set_anim_flags_on_sprite(search_sprite_list_for_element("STICKMAN"), MUP); } if((key[ALLEGRO_KEY_S] & KEYNEW) || (key[ALLEGRO_KEY_DOWN] & KEYNEW)) { set_anim_flags_on_sprite(search_sprite_list_for_element("STICKMAN"), MDOWN); } if((key[ALLEGRO_KEY_SPACE] & KEYNEW)) { set_anim_flags_on_sprite(search_sprite_list_for_element("STICKMAN"), MATTACK); } } if((key[ALLEGRO_KEY_ESCAPE] & KEYPRESSED)) { game->exit = true; game->gamestarted = false; } if((key[ALLEGRO_KEY_M] & KEYNEW)) { return_to_main_menu(game); } if((key[ALLEGRO_KEY_P] & KEYNEW)) { if(game->paused) { exit_pause(game); mpressed = true; } else { if (game->gamestarted) game->paused = true; } } return NULL; }
// Performs animations for the stickman and adds the sprites to the render queue void update_stickman(void) { SPRITESPTR stman = search_sprite_list_for_element("STICKMAN"); SPRITESPTR ground = search_sprite_list_for_element("GROUND"); float height = (search_image_list_for_element(&stman->ifirstptr, "STICKFIGURE_MOVE_1"))->height; float y = stman->shape->body->p.y-height/2; int cx = 0, cy = 0, nflags = 0; static _Bool up = false, down = false; ALLEGRO_COLOR color = RCOLOR(255, 255, 255, 255); if(!start) { //static int sx = 0; //static int sy = 0; if(y+height >= ground->sdata.y) stman->sdata.anim_counter++; stman->sdata.currentimg = search_image_list_for_element(&stman->ifirstptr, "STICKFIGURE_MOVE_1"); if(stman->sdata.anim_counter >= 20) { stman->sdata.anim_counter = 0; stman->shape->e = 0.1; stman->shape->u = 0.9; //sx = stman->shape->body->p.x; //sy = stman->shape->body->p.y; start = true; } } else if((stman->sdata.animflags & MUP) && !down) { if(y+height >= ground->sdata.y && !up) { cpVect currentvel = stman->shape->body->v; stman->shape->body->v = cpv(0, -stman->sdata.dy); cpVect newvel = stman->shape->body->v; stman->shape->body->v = cpvadd(currentvel, newvel); up = true; } else if(y+height >= ground->sdata.y && up) { remove_anim_flags_on_sprite(stman, MUP); up = false; } stman->sdata.currentimg = search_image_list_for_element(&stman->ifirstptr, "STICKFIGURE_MOVE_1"); } else if((stman->sdata.animflags & MDOWN)) { down = true; static int dcounter = 0; dcounter++; if(dcounter > 65) { down = false; remove_anim_flags_on_sprite(stman, MDOWN); dcounter = 0; } stman->sdata.currentimg = search_image_list_for_element(&stman->ifirstptr, "STICKFIGURE_SLIDE"); cy = 15; } else { stman->sdata.anim_counter++; if(stman->sdata.anim_counter < 5) stman->sdata.currentimg = search_image_list_for_element(&stman->ifirstptr, "STICKFIGURE_MOVE_1"); else if(stman->sdata.anim_counter > 5 && stman->sdata.anim_counter < 10) stman->sdata.currentimg = search_image_list_for_element(&stman->ifirstptr, "STICKFIGURE_MOVE_2"); else if(stman->sdata.anim_counter > 10) stman->sdata.anim_counter = 0; } if((stman->sdata.animflags & MATTACK)) { static int counter = 0; counter++; if(counter > 44) { remove_anim_flags_on_sprite(stman, MATTACK); counter = 0; } if(up) { stman->sdata.currentimg = search_image_list_for_element(&stman->ifirstptr, "STICKFIGURE_ATTACK_JUMP"); } else if(down) { stman->sdata.currentimg = search_image_list_for_element(&stman->ifirstptr, "STICKFIGURE_ATTACK_SLIDE"); cy = 20; } else stman->sdata.currentimg = search_image_list_for_element(&stman->ifirstptr, "STICKFIGURE_ATTACK_RUN"); } if ((stman->sdata.animflags & MDAMAGED)) { static int counter = 0; counter++; stman->sdata.currentimg = search_image_list_for_element(&stman->ifirstptr, "STICKFIGURE_DEAD"); if(stman->sdata.x+stman->sdata.currentimg->width <= 0 || counter >= 60) { remove_anim_flags_on_sprite(stman, MDAMAGED); set_anim_flags_on_sprite(stman, MRECOVER); stman->shape->body->p.x = 70; stman->shape->body->v = cpvzero; counter = 0; } } if((stman->sdata.animflags & MRECOVER)) { static int counter = 0; counter++; if(counter >= 15 && counter <= 30) color = RCOLOR(255, 255, 255, 105); else if(counter >= 45 && counter <= 60) color = RCOLOR(255, 255, 255, 105); else if(counter >= 75 && counter <= 90) color = RCOLOR(255, 255, 255, 105); else if(counter >= 105 && counter <= 120) color = RCOLOR(255, 255, 255, 105); if(counter >= 120) { counter = 0; remove_anim_flags_on_sprite(stman, MRECOVER); } } if((int)stman->shape->body->p.x != 50 && start && y+height >= ground->sdata.y && !(stman->sdata.animflags & MDAMAGED)) { stman->shape->body->p.x = 70; } add_element_to_render_queue(stman->sdata.currentimg->image, stman->sdata.x+cx, stman->sdata.y+cy, nflags, color, NULL); stman->sdata.x = stman->shape->body->p.x-stman->sdata.currentimg->width/2; stman->sdata.y = stman->shape->body->p.y-stman->sdata.currentimg->height/2; }