void jumpnrun_process_enemy(jumpnrun_enemy                   *self,
                            badge_framebuffer                *fb,
                            struct jumpnrun_game_state       *state,
                            struct jumpnrun_level            *lv,
                            struct jumpnrun_tile_range const *visible_tiles,
                            vec2d                            *player_inertia_mod) {
  // Despawned enemies are reset to their spawn position, so enemy_in_spawn_area will determine whether the spawn point is in the spawn area.
  if(self->base.flags & JUMPNRUN_ENEMY_SPAWNED) {
    if(!enemy_in_spawn_area(self, state) || fixed_point_gt(rectangle_top (enemy_hitbox(self)), FIXED_INT(BADGE_DISPLAY_HEIGHT))) {
      jumpnrun_enemy_despawn(self);
    } else if(jumpnrun_moveable_dying(&self->base)) {
      if(jumpnrun_moveable_finished_dying(&self->base)) {
        jumpnrun_enemy_despawn(self);
      } else {
        if(fb) {
          jumpnrun_render_splosion(fb, state, &self->base);
        }
        ++self->base.tick_minor;
      }
    } else {
      if((self->base.flags & JUMPNRUN_ENEMY_MOVING) || enemy_on_screen(self, state)) {
        self->base.flags |= JUMPNRUN_ENEMY_MOVING;

        self->type->move_tick(self, state, lv, visible_tiles, player_inertia_mod);
        self->type->collision_shots(self, state);
        if     (fixed_point_lt(self->base.inertia.x, FIXED_INT(0))) { self->base.flags &= ~JUMPNRUN_MOVEABLE_MIRRORED; }
        else if(fixed_point_ne(self->base.inertia.x, FIXED_INT(0))) { self->base.flags |=  JUMPNRUN_MOVEABLE_MIRRORED; }
      }

      if(fb) {
        jumpnrun_render_enemy(fb, state, self);
      }
    }
  } else if(self->base.flags & JUMPNRUN_ENEMY_UNAVAILABLE) {
    if(!enemy_in_spawn_area(self, state)) {
      self->base.flags &= ~JUMPNRUN_ENEMY_UNAVAILABLE;
    }
  } else if(enemy_in_spawn_area(self, state)) {
    // enemy unspawned, available and in spawn zone.
    enemy_spawn(self);
  }
}
Exemple #2
0
void map_load(int i) {
	int x, y, layer, tmp, x2, y2;
	map.powerups=0;
	map.sections=-1;
	map.lines[0]=0;
	boss_shooting=0;
	for(x=0; x<map.map[i]->layer->tilemap->w; x++) {
		if(!(x%(MAP_SECTION_WIDTH))) {
			map.sections++;
			map.lines[map.sections]=0;
		}
		for(y=0; y<map.map[i]->layer->tilemap->h; y++) {
			switch((tmp=map.map[i]->layer->tilemap->data[y*map.map[i]->layer->tilemap->w+x])&0xF0) {
				case 0x30:
					map.enemy[map.enemies]=enemy_spawn(x*TILE_SIZE, y*TILE_SIZE, tmp&0xF, model.enemy[tmp&0xF]);
					if(tmp==0x30)
						map.enemy[map.enemies]->weapon.normal.right=shape_copy_copy(model.enemy_right);
					if(tmp==0x33)
						map.enemy[map.enemies]->health=600;
					map.enemies++;
					break;
				case 0x50:
					map.powerup[map.powerups].x=x*TILE_SIZE;
					map.powerup[map.powerups].y=y*TILE_SIZE;
					map.powerup[map.powerups].type=tmp&0xF;
					map.powerup[map.powerups].taken=0;
					map.powerup[map.powerups].shape=shape_copy_copy(model.powerup[tmp&0xF]);
					map.powerups++;
					break;
				default:
					break;
			}
			for(layer=1; layer<map.map[i]->layers; layer++) {
				switch(map.map[i]->layer[layer].tilemap->data[y*map.map[i]->layer[layer].tilemap->w+x]) {
					case 0x90:
						for(tmp=0; map.map[i]->layer[layer].tilemap->data[(y+tmp)*map.map[i]->layer[layer].tilemap->w+x]!=0xA0; tmp--);
						x2=TILE_SIZE*x;
						y2=TILE_SIZE*(y+tmp)+TILE_SIZE;
						d_render_line_move(map.line[map.sections], map.lines[map.sections], TILE_SIZE*x, TILE_SIZE*y+TILE_SIZE, x2, y2);
						break;
					case 0x91:
						for(tmp=0; map.map[i]->layer[layer].tilemap->data[y*map.map[i]->layer[layer].tilemap->w+x+tmp]!=0xA1; tmp++);
						x2=TILE_SIZE*(x+tmp)+TILE_SIZE;
						y2=TILE_SIZE*y;
						d_render_line_move(map.line[map.sections], map.lines[map.sections], TILE_SIZE*x+TILE_SIZE, TILE_SIZE*y+TILE_SIZE, x2, y2+TILE_SIZE);
						break;
					case 0x92:
						for(tmp=0; map.map[i]->layer[layer].tilemap->data[(y+tmp)*map.map[i]->layer[layer].tilemap->w+x-tmp]!=0xA2; tmp--);
						x2=TILE_SIZE*(x-tmp)+TILE_SIZE;
						y2=TILE_SIZE*(y+tmp)+TILE_SIZE;
						d_render_line_move(map.line[map.sections], map.lines[map.sections], TILE_SIZE*x+TILE_SIZE, TILE_SIZE*y+TILE_SIZE, x2, y2);
						break;
					case 0x93:
						for(tmp=0; map.map[i]->layer[layer].tilemap->data[(y+tmp)*map.map[i]->layer[layer].tilemap->w+x+tmp]!=0xA3; tmp++);
						x2=TILE_SIZE*(x+tmp)+TILE_SIZE;
						y2=TILE_SIZE*(y+tmp)+TILE_SIZE;
						d_render_line_move(map.line[map.sections], map.lines[map.sections], TILE_SIZE*x+TILE_SIZE, TILE_SIZE*y+TILE_SIZE, x2, y2);
						break;
					default:
						continue;
				}
				map.line_coord[map.sections][map.lines[map.sections]].x1=TILE_SIZE*x;
				map.line_coord[map.sections][map.lines[map.sections]].y1=TILE_SIZE*y;
				map.line_coord[map.sections][map.lines[map.sections]].x2=x2;//+TILE_SIZE/2;
				map.line_coord[map.sections][map.lines[map.sections]].y2=y2;//+TILE_SIZE/2;
				map.lines[map.sections]++;
			}
		}
	}
	map.current=i;
	player_spawn(64, 128, model.player, model.gun, model.grenade);
	camera_x = 0;
	camera_scroll_speed = CAMERA_SCROLL_SPEED;
}